diff --git a/Examples/test-suite/python/input.i b/Examples/test-suite/python/input.i index 8626773a3..b704e1a73 100644 --- a/Examples/test-suite/python/input.i +++ b/Examples/test-suite/python/input.i @@ -2,9 +2,9 @@ %apply int *INPUT {int *bar}; -%typemap(out) int * Foo::foo { +%typemap(out, fragment=SWIG_From_frag(int)) int * Foo::foo { if ($1) { - $result = PyInt_FromLong(*$1); + $result = SWIG_From(int)(*$1); } else { Py_INCREF(Py_None); $result = Py_None; @@ -14,7 +14,7 @@ %inline { struct Foo { - int *foo(int *bar) { + int *foo(int *bar = 0) { if (bar) { *bar *= 2; } @@ -23,20 +23,10 @@ }; } - - %include std_string.i %apply std::string *INPUT {std::string *bar}; -%typemap(out) int * sfoo { - if ($1) { - $result = PyInt_FromLong(*$1); - } else { - Py_INCREF(Py_None); - $result = Py_None; - } -} -%typemap(out, fragment=SWIG_From_frag(std::string)) std::string * sfoo { +%typemap(out, fragment=SWIG_From_frag(std::string)) std::string *sfoo { if ($1) { $result = SWIG_From(std::string)(*$1); } else { @@ -46,7 +36,7 @@ } %inline %{ - std::string *sfoo(std::string *bar) { + std::string *sfoo(std::string *bar = 0) { if (bar) *bar += " world"; return (bar) ? bar : 0; } diff --git a/Examples/test-suite/python/input_runme.py b/Examples/test-suite/python/input_runme.py index d4778ff8a..f5ef6dc8b 100644 --- a/Examples/test-suite/python/input_runme.py +++ b/Examples/test-suite/python/input_runme.py @@ -7,9 +7,14 @@ if f.foo(2) != 4: if f.foo(None)!= None: raise RuntimeError +if f.foo()!= None: + raise RuntimeError + if sfoo("Hello") != "Hello world": raise RuntimeError if sfoo(None) != None: raise RuntimeError - + +if sfoo() != None: + raise RuntimeError