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
#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 );
}


Attachment: testcase.lisp
Description: Binary data

Attachment: Makefile
Description: Binary data

_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to