Menu

#1127 [php] segv on overloaded methods with different return types

closed-fixed
php (58)
5
2011-02-18
2011-01-31
Paul Colby
No

Consider the following example:

%module example
class A { };
class B {
public:
int foo(int x);
A foo(string y);
};

This example causes swig to segfault:

$ swig -c++ -php example.i
Segmentation fault

The segmentation fault only occurs if all of the following is true:
* there are at least two overloaded class methods that return different types.
* at least one return type is a class that has been declared to SWIG (eg "class A {};" above).

I'll submit a patch soon that will simply report an error instead of segfaulting, but I don't really consider it a "solution" - more just a temporary fix, and an indication of where the error occurs, so that hopefully someone else who understands php.cxx can take it further :)

One possible workaround is to rename one of the overloads, ie the above example can be fixed by adding:

%rename(foo2) foo(int);

Discussion

  • Olly Betts

    Olly Betts - 2011-02-18

    The segfault is because int isn't a class, so the correct response is to just skip to the next potential return type.

    Fixed in SVN r12471.

     
  • Olly Betts

    Olly Betts - 2011-02-18
    • summary: Segfault on overloaded methods with different return types --> [php] segv on overloaded methods with different return types
    • status: open --> closed-fixed
     

Log in to post a comment.