fix directorout + cosmetic

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6888 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-12-16 00:57:39 +00:00
commit e7c1108ed1
2 changed files with 56 additions and 50 deletions

View file

@ -5,9 +5,9 @@
/* in */ /* in */
%define PYPTR_IN_TYPEMAP(asptr_meth,pyfrag,...) %define PYPTR_IN_TYPEMAP(asptr_meth,pyfrag,Type...)
%typemap(in,fragment=pyfrag) __VA_ARGS__ { %typemap(in,fragment=pyfrag) Type {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0; Type *ptr = (Type *)0;
int res = asptr_meth($input, &ptr); int res = asptr_meth($input, &ptr);
if (!res) { if (!res) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
@ -19,8 +19,8 @@
$1 = *ptr; $1 = *ptr;
if (res == SWIG_NEWOBJ) delete ptr; if (res == SWIG_NEWOBJ) delete ptr;
} }
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & (int res = 0) { %typemap(in,fragment=pyfrag) const Type & (int res = 0) {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0; Type *ptr = (Type *)0;
res = asptr_meth($input, &ptr); res = asptr_meth($input, &ptr);
if (!res) { if (!res) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
@ -32,15 +32,15 @@
$1 = ptr; $1 = ptr;
} }
%typemap(freearg) const __VA_ARGS__ & %typemap(freearg) const Type &
"if (res$argnum == SWIG_NEWOBJ) delete $1;"; "if (res$argnum == SWIG_NEWOBJ) delete $1;";
%enddef %enddef
/* varin */ /* varin */
%define PYPTR_VARIN_TYPEMAP(asptr_meth,pyfrag,...) %define PYPTR_VARIN_TYPEMAP(asptr_meth,pyfrag,Type...)
%typemap(varin,fragment=pyfrag) __VA_ARGS__ { %typemap(varin,fragment=pyfrag) Type {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0; Type *ptr = (Type *)0;
int res = asptr_meth($input, &ptr); int res = asptr_meth($input, &ptr);
if (!res) { if (!res) {
if (!PyErr_Occurred()) if (!PyErr_Occurred())
@ -59,9 +59,9 @@
/* directorout */ /* directorout */
%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,...) %define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
%typemap(directorargout,fragment=pyfrag) __VA_ARGS__ *DIRECTOROUT ($*1_ltype temp) { %typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
__VA_ARGS__ *ptr = 0; Type *ptr = 0;
int res = asptr_meth($input, &ptr); int res = asptr_meth($input, &ptr);
if (!res || !ptr) if (!res || !ptr)
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth"); throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
@ -69,46 +69,52 @@
$result = &temp; $result = &temp;
if (res == SWIG_NEWOBJ) delete ptr; if (res == SWIG_NEWOBJ) delete ptr;
} }
%typemap(directorout,fragment=pyfrag) __VA_ARGS__ { %typemap(directorout,fragment=pyfrag) Type {
__VA_ARGS__ *ptr = 0; Type *ptr = 0;
int res = asptr_meth($input, &ptr); int res = asptr_meth($input, &ptr);
if (!res || !ptr) if (!res || !ptr)
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth"); throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
$result = *ptr; $result = *ptr;
if (res == SWIG_NEWOBJ) delete ptr; if (res == SWIG_NEWOBJ) delete ptr;
} }
%typemap(directorout,fragment=pyfrag,warning="470:Using thread unsafe wrapping, consider using a lvalue return type.") const __VA_ARGS__& { %typemap(directorout,fragment=pyfrag,warning="470:Possible thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
__VA_ARGS__ *ptr = 0; Type *ptr = 0;
int res = asptr_meth($input, &ptr); int res = asptr_meth($input, &ptr);
if (!res || !ptr) if (!res || !ptr)
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth"); throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
static $*1_ltype temp = *ptr; $result = ptr;
$result = &temp; if (res == SWIG_NEWOBJ) {
if (res == SWIG_NEWOBJ) delete ptr; /* Possible thread/reentrant problem here! */
static $*ltype temp = *ptr;
$result = &temp;
delete ptr;
} else {
$result = ptr;
}
} }
%typemap(directorout,fragment=pyfrag) __VA_ARGS__ &DIRECTOROUT = __VA_ARGS__ %typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
%enddef %enddef
/* typecheck */ /* typecheck */
%define PYPTR_TYPECHECK_TYPEMAP(check,asptr_meth,pyfrag,...) %define PYPTR_TYPECHECK_TYPEMAP(check,asptr_meth,pyfrag,Type...)
%typemap(typecheck,precedence=check,fragment=pyfrag) %typemap(typecheck,precedence=check,fragment=pyfrag)
__VA_ARGS__, const __VA_ARGS__& Type, const Type&
"$1 = asptr_meth($input, (__VA_ARGS__**)(0));"; "$1 = asptr_meth($input, (Type**)(0));";
%enddef %enddef
/* /*
typemap definition for types with AsPtr/From methods typemap definition for types with AsPtr/From methods
*/ */
%define %typemap_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, ...) %define %typemap_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
%fragment(SWIG_AsVal_frag(__VA_ARGS__),"header", %fragment(SWIG_AsVal_frag(Type),"header",
fragment=SWIG_AsPtr_frag(__VA_ARGS__)) %{ fragment=SWIG_AsPtr_frag(Type)) %{
SWIGINTERNSHORT int SWIGINTERNSHORT int
SWIG_AsVal(__VA_ARGS__)(PyObject* obj, __VA_ARGS__ *val) SWIG_AsVal(Type)(PyObject* obj, Type *val)
{ {
__VA_ARGS__ *v = (__VA_ARGS__ *)0; Type *v = (Type *)0;
int res = SWIG_AsPtr(__VA_ARGS__)(obj, &v); int res = SWIG_AsPtr(Type)(obj, &v);
if (!res || !v) return 0; if (!res || !v) return 0;
if (val) { if (val) {
*val = *v; *val = *v;
@ -117,37 +123,37 @@
return 1; return 1;
} }
%} %}
%fragment(SWIG_As_frag(__VA_ARGS__),"header", %fragment(SWIG_As_frag(Type),"header",
fragment=SWIG_AsVal_frag(__VA_ARGS__)) %{ fragment=SWIG_AsVal_frag(Type)) %{
SWIGINTERNSHORT __VA_ARGS__ SWIGINTERNSHORT Type
SWIG_As(__VA_ARGS__)(PyObject* obj) SWIG_As(Type)(PyObject* obj)
{ {
__VA_ARGS__ v; Type v;
SWIG_AsVal(__VA_ARGS__)(obj, &v); SWIG_AsVal(Type)(obj, &v);
return v; return v;
} }
%} %}
PYPTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__); PYPTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
PYPTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__); PYPTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
PYPTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__); PYPTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
PYPTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth), PYPTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth),
SWIG_arg(AsPtrFrag), __VA_ARGS__); SWIG_arg(AsPtrFrag), Type);
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__); %typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
PYPTR_INPUT_TYPEMAP(SWIG_arg(CheckCode),SWIG_arg(AsPtrMeth), PYPTR_INPUT_TYPEMAP(SWIG_arg(CheckCode),SWIG_arg(AsPtrMeth),
SWIG_arg(AsPtrFrag),__VA_ARGS__); SWIG_arg(AsPtrFrag),Type);
PYPTR_INOUT_TYPEMAP(__VA_ARGS__); PYPTR_INOUT_TYPEMAP(Type);
%enddef %enddef
/* /*
typemap for simple swig types with only AsPtr/From methods typemap for simple swig types with only AsPtr/From methods
*/ */
%define %typemap_asptrfromn(CheckCode, ...) %define %typemap_asptrfromn(CheckCode, Type...)
%typemap_asptrfrom(SWIG_arg(CheckCode), %typemap_asptrfrom(SWIG_arg(CheckCode),
SWIG_arg(SWIG_AsPtr(__VA_ARGS__)), SWIG_arg(SWIG_AsPtr(Type)),
SWIG_arg(SWIG_From(__VA_ARGS__)), SWIG_arg(SWIG_From(Type)),
SWIG_arg(SWIG_AsPtr_frag(__VA_ARGS__)), SWIG_arg(SWIG_AsPtr_frag(Type)),
SWIG_arg(SWIG_From_frag(__VA_ARGS__)), SWIG_arg(SWIG_From_frag(Type)),
__VA_ARGS__); Type);
%enddef %enddef

View file

@ -78,8 +78,8 @@
if (PyErr_Occurred()) if (PyErr_Occurred())
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth"); throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
} }
%typemap(directorout,fragment=pyfrag) const Type& { %typemap(directorout,fragment=pyfrag,warning="470:Using thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
$basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype); static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
$result = &temp; $result = &temp;
if (PyErr_Occurred()) if (PyErr_Occurred())
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth"); throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");