chicken-users
[Top][All Lists]
Advanced

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

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


From: felix winkelmann
Subject: [Chicken-users] Re: the (##sys#call-host) FFI trick
Date: Wed, 3 Aug 2005 08:51:03 +0200

Thanks, I've applied your change. It really makes
much more sense to use "C_externexport".


cheers,
felix


On 8/1/05, Ashley Bone <address@hidden> wrote:
> 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
> 
> 
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/chicken-users
>




reply via email to

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