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

Dave Mason dvmason at gmail.com
Tue Jun 21 00:30:43 UTC 2011


Hi Eliot,

I started a reply, but then started pursuing ideas you'd triggered...

On 2011-Jun-17, at 13:26 , Eliot Miranda wrote:

> 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).
>
> [...]
>
> 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?

Yes, Smalltalk.  It's a simple recursive-descent parser.  I'm working  
on a paper for ESUG.  And I'll publicsh the code as soon as it's in  
some kind of useful shape (probably after the ESUG CFP date).

> 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

Wanted to avoid a temp file.

> 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.

Yeah, I could add a preprocessor to the parser, but given that the  
whole project is to leverage system tools already available in other  
languages...  The downside is that many constants are #defined, and it  
might be good to get those available.

So in the short term I think I'm just going to use FFI and call  
fread.  In the longer term, I may well add a preprocessor.

> 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).

On MacOSX, at least, there is a:
	extern int * __error(void);
which returns a pointer to a thread-specific errno, so that errno is  
actually defined as:
	#define errno (*__error())
so I can get at that safely.

../Dave




More information about the Squeak-dev mailing list