[squeak-dev] FFI and capturing external program input in Squeak/Pharo

Eliot Miranda eliot.miranda at gmail.com
Fri Jun 17 17:26:18 UTC 2011


Hi Dave,

On Fri, Jun 17, 2011 at 9:34 AM, Dave Mason <dmason at mason-rose.ca> wrote:

> I'm working on making a clean interface layer on top of FFI (and possibly
> Alien and NativeBoost).
>
> It will look something like:
>
>        FFIParse createFFI: #System category: 'My-Category' library:
> 'System'.
>        System parseSystemHeader: 'sys/resource.h'.
>        rusage := System struct: #rusage.
>        System getrusage: 0 with: rusage.
>        Transcript show: 'Used ';
>                         show: rusage ru_utime tv_sec;
>                         show: '.';
>                         show: rusage ru_utime tv_usec;
>                         show: ' seconds of user CPU time';
>                         cr.
>        System parseSystemHeaer: 'unistd.h';
>                sleep: 5.
>        pid := System getpid
>
> I have a very compact, almost compete C header parser


This is in Smalltalk right?  How is it implemented?  Haver you published it
yet?  Are you planning to publish it open source or keep it private?


> but I need to be able to get the output from
>        popen("echo \"#include <unistd.h>\"|gcc -E -","r")

or equivalent.


OSProcess would work. Also system would work.

self system: 'echo \"#include <unistd.h>\"|gcc -E - >outfile.i'.
(FileStream oldFileNamed: 'outfile.i') contentsOfEntireFile


But if you have a complete C header parser why can't you implement inclusion
yourself?  Wy do you need gcc to preprocess?  You should be able to do
everything that the preprocessor does yourself.

 The popen is easy enough to get at through FFI, but is there a way to
> connect either the FILE* or the file descriptor up to some ReadStream.  In
> the worst case, I could probably use FFI to call fread(3) but is there a
> better way?
>
> I'd also appreciate any simple examples of using FFI, especially with
> ExternalStructure subclasses.
>
> Finally is there a way to get external variables such as 'extern int
> errno;' ?
>

Not conveniently yet, but its doable.  Note that errno is an interesting
example because typically it is completely different in a -pthreads
compilation (thread-local) to a single-threaded compilation (global
variable).


> Thanks in advance!
>

best,
Eliot


>
> ../Dave
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110617/ce349a1c/attachment.htm


More information about the Squeak-dev mailing list