Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1009 [C#] bool & OUTPUT typemap does not work

closed-fixed
csharp (36)
5
2009-04-21
2009-04-11
Milo Yip
No

As shown in the following example, *jarg4 has not been initialized to zero, so writing to *arg4 can only write the first byte of *jarg4. If the other three bytes are non-zero initially, then after calling the wrapper in C# the bool parameter must be true, no matter what C++ side outputs.

This is non-deterministic because *jarg4 is passed by interop and it is
non-initailized.

// in Runtime.i
%include <typemaps.i>
class Runtime {
bool GetField(int object, const char* fieldName, bool& OUTPUT);
};

// Runtime.cxx

SWIGEXPORT unsigned int SWIGSTDCALL CSharp_Runtime_GetField__SWIG_1(void *
jarg1, int jarg2, char * jarg3, unsigned int * jarg4) {
unsigned int jresult ;
Mil::Script::Runtime *arg1 = (Mil::Script::Runtime *) 0 ;
Mil::Script::Object arg2 ;
char *arg3 = (char *) 0 ;
bool *arg4 = 0 ;
bool result;

arg1 = (Mil::Script::Runtime *)jarg1;
arg2 = (Mil::Script::Object)jarg2;
arg3 = (char *)jarg3;
arg4 = (bool *)jarg4;
result = (bool)(arg1)->GetField(arg2,(char const *)arg3,*arg4);
jresult = result;
return jresult;
}

Discussion

  • William Fulton
    William Fulton
    2009-04-21

    I can't replicate the bug, but agree there is a problem. Fixed for swig-1.3.40. Please wait for the new release or add in this typemap:

    %typemap(in) bool *OUTPUT, bool &OUTPUT
    %{ *$input = 0;
    $1 = ($1_ltype)$input; %}

     
  • William Fulton
    William Fulton
    2009-04-21

    • labels: --> csharp
    • assigned_to: nobody --> wsfulton
    • status: open --> closed-fixed