fix *INPUT typemaps for ptr types, now a null value is ok
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6897 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b316e6445a
commit
839e80a70b
4 changed files with 70 additions and 5 deletions
|
|
@ -20,6 +20,7 @@ CPP_TEST_CASES += \
|
||||||
file_test \
|
file_test \
|
||||||
implicittest \
|
implicittest \
|
||||||
inout \
|
inout \
|
||||||
|
input \
|
||||||
inplaceadd \
|
inplaceadd \
|
||||||
kwargs \
|
kwargs \
|
||||||
li_std_except \
|
li_std_except \
|
||||||
|
|
|
||||||
53
Examples/test-suite/python/input.i
Normal file
53
Examples/test-suite/python/input.i
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
%module input
|
||||||
|
|
||||||
|
%apply int *INPUT {int *bar};
|
||||||
|
|
||||||
|
%typemap(out) int * Foo::foo {
|
||||||
|
if ($1) {
|
||||||
|
$result = PyInt_FromLong(*$1);
|
||||||
|
} else {
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
$result = Py_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%inline
|
||||||
|
{
|
||||||
|
struct Foo {
|
||||||
|
int *foo(int *bar) {
|
||||||
|
if (bar) {
|
||||||
|
*bar *= 2;
|
||||||
|
}
|
||||||
|
return (bar) ? bar : 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%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 {
|
||||||
|
if ($1) {
|
||||||
|
$result = SWIG_From(std::string)(*$1);
|
||||||
|
} else {
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
$result = Py_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
std::string *sfoo(std::string *bar) {
|
||||||
|
if (bar) *bar += " world";
|
||||||
|
return (bar) ? bar : 0;
|
||||||
|
}
|
||||||
|
%}
|
||||||
15
Examples/test-suite/python/input_runme.py
Normal file
15
Examples/test-suite/python/input_runme.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from input import *
|
||||||
|
|
||||||
|
f = Foo()
|
||||||
|
if f.foo(2) != 4:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if f.foo(None)!= None:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if sfoo("Hello") != "Hello world":
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if sfoo(None) != None:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
@ -80,11 +80,7 @@ or you can use the %apply directive :
|
||||||
res = asptr_meth($input, &$1);
|
res = asptr_meth($input, &$1);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
SWIG_type_error("$basetype", $input);
|
SWIG_type_error("$basetype", $input);
|
||||||
} else {
|
}
|
||||||
if (!$1) {
|
|
||||||
SWIG_null_ref("$basetype");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue