chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] the (##sys#call-host) FFI trick


From: Ashley Bone
Subject: Re: [Chicken-users] the (##sys#call-host) FFI trick
Date: Mon, 01 Aug 2005 16:30:50 -0500
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050716)

I've now managed to port about half our bigloo libraries
to chicken using define-external combined with ##sys#call-host
to provide the C entry points and to transfer control to the
host C++ program.

So far I've only encountered one very minor problem.  I'm able
to build static or shared libraries on all platforms with no problem,
but on freaking windows we rely on import libraries when
linking with C/C++ code.  define-external doesn't declare the generated
function as dllexport, so it's not exported from the DLL.

I tried using qualifiers with define-external, eg:

(define-external "__declspec(dllexport)" (string_length (c-string str)) int ....

which generates:

C_extern  int  __declspec(dllexport) string_length(char * t0);

Depending on the function's return type, the MS compiler is picky about
where the __declspec is placed:  the above seems to work ok, but change
the return type to char* and the compiler pukes.  It really wants the
__declspec before the return type.

So, I did the easiest thing possible and modified c-backend.scm:

(define (generate-foreign-callback-stub-prototypes stubs) (for-each (lambda (stub) (gen #t) (generate-foreign-callback-header "C_externexport " stub) (gen #\;) )
  stubs) )

I just changed C_extern to C_externexport in the above function and rebuilt
chicken.  Now when _MSC_VER and PIC are defined, the function is exported.

Anyway, except for this one minor side issue, this "FFI trick" is working perfectly.

later,

ashley




reply via email to

[Prev in Thread] Current Thread [Next in Thread]