extending std_string and more fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5771 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8cc9533152
commit
2568b57d46
11 changed files with 248 additions and 111 deletions
|
|
@ -7,106 +7,66 @@
|
|||
|
||||
%define PYPTR_IN_TYPEMAP(pyobj_asptr,pyfrag,...)
|
||||
%typemap(in,fragment=pyfrag) __VA_ARGS__ {
|
||||
__VA_ARGS__ *ptr;
|
||||
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0;
|
||||
int res = pyobj_asptr($input, &ptr);
|
||||
if (!res) SWIG_fail;
|
||||
if (!res || !ptr) SWIG_fail;
|
||||
$1 = *ptr;
|
||||
if (res > 1) delete ptr;
|
||||
if (res == SWIG_NEWPTR) delete ptr;
|
||||
}
|
||||
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & (int res = 0)
|
||||
"if (!(res = pyobj_asptr($input, &$1))) SWIG_fail;";
|
||||
"if (!(res = pyobj_asptr($input, &$1)) || !($1)) SWIG_fail;";
|
||||
|
||||
%typemap(freearg) const __VA_ARGS__ &
|
||||
"if (res$argnum > 1) delete $1;";
|
||||
%enddef
|
||||
|
||||
/* out */
|
||||
|
||||
%define PYPTR_OUT_TYPEMAP(pyobj_from,pyfrag,...)
|
||||
%typemap(out,fragment=pyfrag) __VA_ARGS__
|
||||
"$result = pyobj_from($1);";
|
||||
%typemap(out,fragment=pyfrag) const __VA_ARGS__&
|
||||
"$result = pyobj_from(*($1));";
|
||||
%enddef
|
||||
|
||||
/* varin */
|
||||
|
||||
%define PYPTR_VARIN_TYPEMAP(pyobj_asptr,pyfrag,...)
|
||||
%typemap(varin,fragment=pyfrag) __VA_ARGS__ {
|
||||
__VA_ARGS__ *ptr;
|
||||
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0;
|
||||
int res = pyobj_asptr($input, &ptr);
|
||||
if (!res) {
|
||||
if (!res || !ptr) {
|
||||
PyErr_SetString(PyExc_TypeError, "C variable '$name ($1_ltype)'");
|
||||
return 1;
|
||||
}
|
||||
if (!res) SWIG_fail;
|
||||
$1 = *ptr;
|
||||
if (res > 1) delete ptr;
|
||||
if (res == SWIG_NEWPTR) delete ptr;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* varout */
|
||||
|
||||
%define PYPTR_VAROUT_TYPEMAP(pyobj_from,pyfrag,...)
|
||||
%typemap(varout,fragment=pyfrag) __VA_ARGS__, const __VA_ARGS__&
|
||||
"$result = pyobj_from($1);";
|
||||
%enddef
|
||||
|
||||
/* Primitive types */
|
||||
%define PYPTR_CONSTCODE_TYPEMAP(pyobj_from,pyfrag,...)
|
||||
%typemap(constcode,fragment=pyfrag) __VA_ARGS__
|
||||
"PyDict_SetItemString(d,\"$symname\", pyobj_from($value));";
|
||||
%enddef
|
||||
|
||||
|
||||
/* directorin */
|
||||
|
||||
%define PYPTR_DIRECTORIN_TYPEMAP(pyobj_from,pyfrag,...)
|
||||
%typemap(directorin,fragment=pyfrag) __VA_ARGS__
|
||||
"$input = pyobj_from($1_name);";
|
||||
%enddef
|
||||
|
||||
/* directorout */
|
||||
|
||||
%define PYPTR_DIRECTOROUT_TYPEMAP(pyobj_asptr,pyfrag,...)
|
||||
%typemap(directorargout,fragment=pyfrag) __VA_ARGS__ *DIRECTOROUT ($*1_ltype temp) {
|
||||
__VA_ARGS__ *ptr;
|
||||
__VA_ARGS__ *ptr = 0;
|
||||
int res = pyobj_asptr($input, &ptr);
|
||||
if (!res)
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using pyobj_asptr");
|
||||
temp = *ptr;
|
||||
$result = &temp;
|
||||
if (res > 1) delete ptr;
|
||||
if (res == SWIG_NEWPTR) delete ptr;
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) __VA_ARGS__ {
|
||||
__VA_ARGS__ *ptr;
|
||||
__VA_ARGS__ *ptr = 0;
|
||||
int res = pyobj_asptr($input, &ptr);
|
||||
if (!res)
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using pyobj_asptr");
|
||||
$result = *ptr;
|
||||
if (res > 1) delete ptr;
|
||||
if (res == SWIG_NEWPTR) delete ptr;
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) const __VA_ARGS__& ($*1_ltype temp) {
|
||||
__VA_ARGS__ *ptr;
|
||||
__VA_ARGS__ *ptr = 0;
|
||||
int res = pyobj_asptr($input, &ptr);
|
||||
if (!res)
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using pyobj_asptr");
|
||||
temp = *ptr;
|
||||
$result = &temp;
|
||||
if (res > 1) delete ptr;
|
||||
if (res == SWIG_NEWPTR) delete ptr;
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) __VA_ARGS__ &DIRECTOROUT = __VA_ARGS__
|
||||
%enddef
|
||||
|
||||
/* throws */
|
||||
|
||||
%define PYPTR_THROWS_TYPEMAP(pyobj_from,pyfrag,...)
|
||||
%typemap(throws,fragment=pyfrag) __VA_ARGS__ {
|
||||
PyErr_SetObject(PyExc_RuntimeError, pyobj_from($1));
|
||||
SWIG_fail;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%define PYPTR_TYPECHECK_TYPEMAP(check,pyobj_asptr,pyfrag,...)
|
||||
|
|
@ -121,25 +81,40 @@
|
|||
|
||||
%define %typemap_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, ...)
|
||||
PYPTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__);
|
||||
PYPTR_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYPTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__);
|
||||
PYPTR_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYPTR_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYPTR_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYPTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), __VA_ARGS__);
|
||||
PYPTR_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag),__VA_ARGS__);
|
||||
PYPTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth),
|
||||
SWIG_arg(AsPtrFrag), __VA_ARGS__);
|
||||
SWIG_arg(AsPtrFrag), __VA_ARGS__);
|
||||
PYVAL_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYVAL_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYVAL_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYVAL_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), __VA_ARGS__);
|
||||
PYVAL_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag),__VA_ARGS__);
|
||||
%enddef
|
||||
|
||||
/*
|
||||
typemap for simple swig types with only AsPtr/From conversor methods
|
||||
typemap for simple swig types with only AsPtr/From methods
|
||||
*/
|
||||
|
||||
%define %typemap_asptrfromn(CheckCode, ...)
|
||||
%fragment(SWIG_AsVal_frag(__VA_ARGS__),"header",
|
||||
fragment=SWIG_AsPtr_frag(__VA_ARGS__)) %{
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsVal_meth(__VA_ARGS__)(PyObject* obj, __VA_ARGS__ *val)
|
||||
{
|
||||
__VA_ARGS__ *v = (__VA_ARGS__ *)0;
|
||||
int res = SWIG_AsPtr_meth(__VA_ARGS__)(obj, &v);
|
||||
if (!res || !v) return 0;
|
||||
if (val) {
|
||||
*val = *v;
|
||||
if (res == SWIG_NEWPTR) delete v;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
%}
|
||||
%typemap_asptrfrom(SWIG_arg(CheckCode),
|
||||
SWIG_AsPtr_meth(__VA_ARGS__),
|
||||
SWIG_From_meth(__VA_ARGS__),
|
||||
SWIG_arg(SWIG_AsPtr_meth(__VA_ARGS__)),
|
||||
SWIG_arg(SWIG_From_meth(__VA_ARGS__)),
|
||||
SWIG_arg(SWIG_AsPtr_frag(__VA_ARGS__)),
|
||||
SWIG_arg(SWIG_From_frag(__VA_ARGS__)),
|
||||
__VA_ARGS__);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue