[cffi-devel] corrupted foreign structure testcase with latest CFFI and LW 4.4.6

Jack Unrue jdunrue at gmail.com
Sun Jun 4 22:51:23 UTC 2006


I've run into a problem where populating a foreign
structure and then passing it to a foreign function behaves
correctly if my Lisp code is interpreted, but the structure
fields appear to be corrupted if my function is compiled.
This is with CFFI versions later than 0.9.0, and on
LW 4.4.6 under WinXP.

When I invoke the dump-it function in interpreted mode,
the output file contains the expected result:

cbSize:   4
style:    01abcdef

When I (compile 'dump-it) and then invoke it, the
output file contains garbage:

cbSize:   -1412567292
style:    01abcd01

This testcase works fine with the same LW version
but CFFI 0.9.0. It also works fine with CLISP 2.38
and latest CFFI.

CFFI versions 0.9.1, 060514, and a build produced
from a darcs pull today all show the problem on LW.
I haven't tried bisecting any further.

See attached testcase.lisp and structs.c. I've also attached
a simple Makefile for compiling with gcc. The foreign function
dump_blah writes a file called 'dump_output.txt' in the current
working directory.

-- 
Jack Unrue
-------------- next part --------------

#include <stdio.h>

#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

struct blah
{
    unsigned int cbSize;
    unsigned int style;
};

extern "C" DLLEXPORT
void dump_blah( blah* ptr )
{
    FILE* out = fopen( "dump_output.txt", "w" );

    if (!out)
        return;
    fprintf( out, "cbSize:   %d\n",   ptr->cbSize );
    fprintf( out, "style:    %08x\n", ptr->style );
    fclose( out );
}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: testcase.lisp
Type: application/octet-stream
Size: 379 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20060604/f33ee302/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 142 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20060604/f33ee302/attachment-0001.obj>


More information about the cffi-devel mailing list