logo       

Re: Swig + Python + C++ + overloading + None = SEGV.: msg#00186

programming.swig

Subject: Re: Swig + Python + C++ + overloading + None = SEGV.

Thanks,

now it doesn't crash via seg fault, but by using a python error message,

Marcelo



Timo Korvola wrote:

Hello,

I just noticed that if you pass None from Python to an overloaded C++
function as the argument overloading resolution is based on, you will
probably crash the interpreter. The reason is that it uses
SWIG_ConvertPtr for typechecking and that will always succeed on None,
converting it to a null pointer, which usually gets dereferenced later.

Example:
----8<----
%module oltest

%{
#include <iostream>
using namespace std;
%}

%inline %{
struct foo {
int x;
};
struct bar {
float y;
};

static void
foobar( foo x) {
cout << "foo " << x.x << endl;
}

static void
foobar( bar x) {
cout << "bar " << x.y << endl;
}
%}
---->8----
Compile and import to Python, then try oltest.foobar( None).



_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise