#788 Error C2026 when creating long NotImplementedError message

python (259)

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:

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?


  • Aloys

    Aloys - 2007-05-20

    Logged In: YES
    Originator: NO


    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.


  • Olly Betts

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

    Olly Betts - 2007-09-18

    Logged In: YES
    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.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks