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

Close

#788 Error C2026 when creating long NotImplementedError message

closed-fixed
Marcelo Matus
python (259)
5
2007-09-18
2007-01-08
Casey Raymondson
No

When wrapping an overloaded function with Python, SWIG 1.3.31 creates an error message that will be displayed if a Python program calls the function with an invalid list of arguments. For example, the error message might say:

NotImplementedError: Wrong number of arguments for overloaded function 'new_Overloaded'.
Possible C/C++ prototypes are:
Overloaded(int)
Overloaded(int,int)
Overloaded(int,int,int)

If the function has a large number of possible prototypes, it is possible for this error message string to exceed 2048 characters. If the string exceeds this length, the _wrap.cxx file generated by SWIG can no longer compile in Visual Studio .NET 2003, because the compiler returns "Compiler Error C2026: string too big, trailing characters truncated" upon seeing a string literal greater than 2048 characters.

As a workaround, I have modified line 1509 of Source/Modules/python.cxx in my local copy of SWIG 1.3.31.

Old version of line 1509:
Printf(protoTypes, " %s(%s)\\n", Getattr(sibl, "name"), ParmList_protostr(Getattr(sibl, "wrap:parms")));

New version of line 1509:
Printf(protoTypes, "\"\" %s(%s)\\n", Getattr(sibl, "name"), ParmList_protostr(Getattr(sibl, "wrap:parms")));

This separates the error message string into multiple string literals in the generated _wrap.cxx file, and Visual Studio .NET 2003 is now able to compile _wrap.cxx with no problems.

Should this change be applied to the SWIG repository?

Discussion

  • Aloys
    Aloys
    2007-05-20

    Logged In: YES
    user_id=1616463
    Originator: NO

    Hi,

    I'm having the same exact problem for python AND Java.
    I think I will have to apply this fix locally as well.
    Would be good to have it in the standard SWIG.

    Cheers

     
  • Olly Betts
    Olly Betts
    2007-09-18

    • status: open --> closed-fixed
     
  • Olly Betts
    Olly Betts
    2007-09-18

    Logged In: YES
    user_id=14972
    Originator: NO

    I've applied patch#1723770 which fixes this for Python. A comment mentions a similar problem with Java, but no patch or even an example showing the problem was provided, so I'm going to close this bug. If you still see this problem with Java, please reopen and attach a patch or an example which demonstrates it.