Hello, Any allegro experts around? I wrote cffi bindings (Dec-15) for some functions in wxWidgets, the bindings work smoothly on clisp and lispworks.
But they crash on allegro. Then I tried to write the allego bindings directly, but it still crashes.
Please help on why this is happening or how to fix it?
Thanks.
The different bindings and corresponding C code:
The dll file which I was using can be found at:
http://cvs.sourceforge.net/viewcvs.py/wxcl/wxcl/lib/
P.S.- I am using a Windows XP machine.
Surendra Singhi efuzzyone@netscape.net writes:
Hello, Any allegro experts around? I wrote cffi bindings (Dec-15) for some functions in wxWidgets, the bindings work smoothly on clisp and lispworks.
But they crash on allegro. Then I tried to write the allego bindings directly, but it still crashes.
OK, I debugged further and found out that my allegro bindings were incorrect which was causing segmentation faults, but cffi bindings still seem to be correct as they work on clisp and lispworks.
If I have C header file containing declarations as
typedef void _cdecl (*ClosureFun)(void* _evt ); void ELJApp_InitializeC(ClosureFun closure, int _argc, char** _argv) { closure(NULL); ..... }
The incorrect allegro bindings which I wrote are:
(ff:def-foreign-call (ELJApp_InitializeC "ELJApp_InitializeC") ((closure (* :void)) (_argc :int fixnum) (_argv (* :void))) :returning :void)
(ff:defun-foreign-callable init-func ((evt (* :void))) (print "hello-world"))
(Eljapp_initializeC #'init-func 0 nil)
How do I fix these incorrect allegro bindings?
Thanks.
Surendra Singhi efuzzyone@netscape.net writes:
Surendra Singhi efuzzyone@netscape.net writes:
Hello, Any allegro experts around? I wrote cffi bindings (Dec-15) for some functions in wxWidgets, the bindings work smoothly on clisp and lispworks.
But they crash on allegro. Then I tried to write the allego bindings directly, but it still crashes.
OK, I debugged further and found out that my allegro bindings were incorrect which was causing segmentation faults, but cffi bindings still seem to be correct as they work on clisp and lispworks.
After fixing the bindings it was still crashing, the reason for that was because I was passing 'nil' as an argument to a function, thinking that allegro will convert it to 'C' null value.
Unfortunately, allegro doesn't do so and this was causing the bindings to crash. For precisely the same reason cffi bindings also crash for allegro but worked for clisp, and lispworks because they convert nil to 'C' null value.
Is there any uniform way of passing C null value to functions? Should I pass `0'?
Thanks.
On 2005-dec-18, at 13:25, Surendra Singhi wrote:
Is there any uniform way of passing C null value to functions? Should I pass `0'?
Glad you were able to fix this issue! You should pass (cffi:null- pointer). CLISP does convert NIL to the null pointer which is unfortunate for this reason (Hi Joerg!) :-) And it seems Lispworks does too.
The lack of uniformity is very unfortunate here. This needs to be fixed. We should either a) translate nil->null everywhere, b) don't translate nil->null anywhere or c) offer the two alternatives through two different types.
Luís Oliveira luismbo@gmail.com writes:
On 2005-dec-18, at 13:25, Surendra Singhi wrote:
Is there any uniform way of passing C null value to functions? Should I pass `0'?
Glad you were able to fix this issue! You should pass (cffi:null- pointer). CLISP does convert NIL to the null pointer which is unfortunate for this reason (Hi Joerg!) :-) And it seems Lispworks does too.
The lack of uniformity is very unfortunate here. This needs to be fixed. We should either a) translate nil->null everywhere, b) don't translate nil->null anywhere or c) offer the two alternatives through two different types.
It will be interesting to know what other lisp implementations like CMUCL, SBCL do? I will vote for clisp's and lispworks approach, it seems least surprising to me.
Another related issue is when a C function returns a null pointer. The behavior in that case should be also uniform.
Thanks.