#794 error C2440 when compile SWIG generated code

closed-wont-fix
5
2007-03-13
2007-01-29
David
No

Hello

I am getting the following errors when I try to compile the code generated by swigwin-1.3.31

here is the code that causes the error and theerror text

Error 1

error C2440: '=' : cannot convert from 'void (__cdecl *)(sync_source_reader *)' to 'void (__stdcall *)(sync_source_reader *)'
z:\development\common\code\syncsort_jni\syncsort_swig_wrap.c 1334

SWIGEXPORT void JNICALL Java_loadsystem_match_SyncSortJNIJNI_sync_1source_1reader_1read_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
struct sync_source_reader *arg1 = (struct sync_source_reader *) 0 ;
void (*arg2)(struct sync_source_reader *) = (void (*)(struct sync_source_reader *)) 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(struct sync_source_reader **)&jarg1;
arg2 = *(void (**)(struct sync_source_reader *))&jarg2;
if (arg1) (arg1)->read = arg2;

}

Error 2

error C2440: '=' : cannot convert from 'int (__cdecl *)(sync_target_writer *,unsigned int,unsigned int)' to 'int (__stdcall *)(sync_target_writer *,unsigned int,unsigned int)'
z:\development\common\code\syncsort_jni\syncsort_swig_wrap.c 1475

SWIGEXPORT void JNICALL Java_loadsystem_match_SyncSortJNIJNI_sync_1target_1writer_1write_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
struct sync_target_writer *arg1 = (struct sync_target_writer *) 0 ;
int (*arg2)(struct sync_target_writer *,unsigned int,unsigned int) = (int (*)(struct sync_target_writer *,unsigned int,unsigned int)) 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(struct sync_target_writer **)&jarg1;
arg2 = *(int (**)(struct sync_target_writer *,unsigned int,unsigned int))&jarg2;
if (arg1) (arg1)->write = arg2;

}

Discussion

  • David

    David - 2007-01-29

    The entire wrapper code

     
  • William Fulton

    William Fulton - 2007-01-31

    Logged In: YES
    user_id=242951
    Originator: NO

    Please provide the source code in a small interface file to show the problem - just the relevant code you are wrapping which is causing the problem. Which version of which compiler are you using?

     
  • David

    David - 2007-01-31

    Interface file

     
  • David

    David - 2007-01-31

    Logged In: YES
    user_id=1704652
    Originator: YES

    I am ucing VisualStudio 2005

    I am attaching the files you wanted
    File Added: syncsort_swig.i

     
  • David

    David - 2007-01-31

    Logged In: YES
    user_id=1704652
    Originator: YES

    File Added: syncsort.h

     
  • David

    David - 2007-01-31
     
  • David

    David - 2007-01-31

    Logged In: YES
    user_id=1704652
    Originator: YES

    File Added: sync.h

     
  • David

    David - 2007-01-31
     
  • William Fulton

    William Fulton - 2007-03-13
    • labels: 102868 --> code generation (general)
    • status: open --> closed-wont-fix
     
  • William Fulton

    William Fulton - 2007-03-13

    Logged In: YES
    user_id=242951
    Originator: NO

    The source of the problem is this...

    #if defined(_WIN32)
    #define SYNCAPI __stdcall
    #else
    #define SYNCAPI
    #endif

    struct sync_source_reader
    {
    void (SYNCAPI *read) (struct sync_source_reader *);
    };

    I'm afraid that this isn't supported, nor is it likely to be supported as it is not ISO C/C++. __stdcall is a Microsoft extension to the standard. The best workaround I can think of is to ignore the function pointer, eg:

    %ignore sync_source_reader::read;

    or modify the source to use the default calling convention. Alternatively make the variable readonly:

    %immutable sync_source_reader::read;

    There probably isn't much you can do with this function pointer from Java anyway.

     

Log in to post a comment.