Hi guys,
OK, I have a first working version and so I wanted to share it with you. I have not yet the time to start writing the doc since I just finished the first pass on the code. Tomorrow I will start with the doc. But I thought some of you may be interested in taking a look even without formal "doc" (and some feedback/iteration may avoid re-writing docs..). If you have no clue what I am talking about, then this summary is for you: ---------- When we use FFI to call a certain library it's quite common that we need to pass as argument certain constants (for example, SIGKILL to kill()). These constants are defined in C header files and can even change it's value in different paltforms. These constants also are sometimes defined by the C preprocessor and so there is not way to get those values from FFI. If you don't have the value of those constants, you cannot make the FFI call. ---------- I have tested the tool in OSX and CentOS using latest Pharo 5.0. It won't work in Windows right now. As usual, all classes and methods have comments and there are enough tests. At the end, I decided the C program will output a very naive Smalltalk literal array kind of thingy. The tool then parses that output and directly creates a init method (which is compiled into the SharedPool class) for that platform which is then called automatically at startup (only if initialization is needed). As for real examples, I started to write constants for libc: signal.h (to use kill()) , wait.h (to use wait() famility), fcntl.h (to use ... xxx()) , and errno.h. You can take a look to the package 'FFICHeaderExtractor-LibC'. Note that for running the tests you need 'cc' findable by path in OSX and 'gcc' in Unix. To load the code in a latest Pharo 5.0, execute: Metacello new baseline: 'FFICHeaderExtractor'; repository: 'github://marianopeck/FFICHeaderExtractor:master/repository'; load. Any feedback is appreciated. I will start writing the doc now. BTW: Big thanks to Eliot Miranda which helped me answering noob questions and providing useful code and guidelines. Best, On Sat, Jan 23, 2016 at 1:12 PM, Eliot Miranda <[hidden email]> wrote:
|
Nice. I was writing little C programs to tell me various constants... it sounds like this automates that and keeps the interaction in Smalltalk. -C -- Craig Latta Black Page Digital postbus 10784 1001ET Amsterdam, Netherlands [hidden email] +31 6 2757 7177 (SMS ok) + 1 415 287 3547 (no SMS) |
On Tue, Jan 26, 2016 at 8:34 AM, Craig Latta <[hidden email]> wrote:
Yeah, exactly. It is automate that and the result can be stored as "init" methods (one per platform) in the shared pools directly. Also, it will take care of initializing them (searching the correct init method for the current platform) at startup. Note that I called the project FFICHeaderExtractor and not FFICConstantsExtractor. If time allows, I would also like to get info from structs: sizeof and how they are defined internally. That would be yet another feature to let more things to be done via FFI. See https://github.com/marianopeck/FFICHeaderExtractor/issues/1 But that would require some more effort!
|
Free forum by Nabble | Edit this page |