errorProcExt2 failure

Started by sunmountain, November 19, 2011, 02:12:47 AM

Previous topic - Next topic

sunmountain

Hi,

in my FFI code, I need to sure that ffi_prep_cif went ok, so I added this:


status = ffi_prep_cif(&cif,FFI_DEFAULT_ABI,2,&ffi_type_uint,argt);
if(status != FFI_OK)
    {
    return(errorProcExt2(ERR_FFI_PREP_FAILED, stuffString(ffi->name)));
    }
else
    {
    ffi_call(&cif,ffi->func,&result,aval);
    }


For debugging purposes I changed status != FFI_OK to status == FFI_OK, to provoke an error.

If I now try this newLisp snippet:
(import "msvcrt" "printf" "cdecl")
(fcall printf a b c)
(exit 0)


the program crashes and calls the debugger.



Last message is (after adding additional messages and error numbers):



ERR: ffi preparation failed in function fcall : "printf"



As said, the newLisp.exe crashes.



It doesn't matter, at which point I call errorProcExt2, even right after entering the function.

Lutz

#1
in newlisp.c lines 2444 to 2448 should look like this:


#ifdef FFI
        varPrintf(device,"%s<%lX>", (char *)((FFIMPORT *)cell->aux)->name,
                                                 cell->contents);
#else
        varPrintf(device,"%s<%lX>", (char *)cell->aux, cell->contents);
#endif


the two lines were swapped and the structure name had a typo.



also updated here: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/



ps: you are based on official development 10.3.6, right? There where still changes in nl-import.c after my initial FFI preparations.



ps: FFI now by default disabled (2011-11-20)

sunmountain

#2
It did not solve all problems (it still crashes at the same point),

but first I will create functioning ffi interface (at least fcall), before digging into this.

Yes, I took 10.3.7 and integrated my code.

I think I'll have to ask gdb what is wrong here.



Man, I learn alot these days.

But as more as I do so, the more I appreciate the way newLisp works :-)

Lutz

#3
The crash was happening when printing the name of the imported function. Just make sure lines 2444 to 2448 in newlisp.c are as outlined in my previous post and based on 10.3.6.  The 10.3.7 file can change several times during the day and often is an untested snapshot.



If you want, you can send me intermediate work, which I can merge and post a version in a private directory for you on newlisp.org. This is, how I have worked with others in the past.