diff options
author | Marcelo Matus <mmatus@acms.arizona.edu> | 2004-10-18 00:31:24 +0000 |
---|---|---|
committer | Marcelo Matus <mmatus@acms.arizona.edu> | 2004-10-18 00:31:24 +0000 |
commit | 09608bc2c5431e5b00a9c0bffa9fad7414d57694 (patch) | |
tree | ab0971048bc3a3314fd2376e22eef9c3e510075d /Lib | |
parent | 53f6f300a01da4168ff31af7b92b10c600b252e4 (diff) | |
download | swig-09608bc2c5431e5b00a9c0bffa9fad7414d57694.tar.gz |
more docs/split and cleaning
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6421 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/python/pyprimtypes.swg | 2 | ||||
-rw-r--r-- | Lib/python/pystdcommon.swg | 12 | ||||
-rw-r--r-- | Lib/python/pystrbase.swg | 9 | ||||
-rw-r--r-- | Lib/python/pyswigtype.swg | 47 | ||||
-rw-r--r-- | Lib/python/pyvaltypes.swg | 2 | ||||
-rw-r--r-- | Lib/python/pyvoid.swg | 4 | ||||
-rw-r--r-- | Lib/python/std_basic_string.i | 93 | ||||
-rw-r--r-- | Lib/python/std_string.i | 44 | ||||
-rw-r--r-- | Lib/python/std_wstring.i | 39 |
9 files changed, 177 insertions, 75 deletions
diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 1eb181692..e1bfb6018 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -111,7 +111,7 @@ SWIGINTERNSHORT int if (value > max_value) { if (errmsg) { PyErr_Format(PyExc_OverflowError, - "value %lud is greater than '%s' minimum %lud", + "value %lu is greater than '%s' minimum %lu", value, errmsg, max_value); } return 0; diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg index f0b936746..27cb6916f 100644 --- a/Lib/python/pystdcommon.swg +++ b/Lib/python/pystdcommon.swg @@ -95,12 +95,12 @@ namespace swig { template <class Type> struct traits_asval<Type*> { static bool asval(PyObject *obj, Type **val) { if (val) { - Type *p = 0; - int res = traits_asptr<Type>::asptr(obj, &p); - if (res) { - typedef typename noconst_traits<Type*>::noconst_type noconst_type; - *(const_cast<noconst_type*>(val)) = p; - return true; + typedef typename noconst_traits<Type>::noconst_type noconst_type; + noconst_type *p = 0; + int res = traits_asptr<noconst_type>::asptr(obj, &p); + if (res) { + *(const_cast<noconst_type**>(val)) = p; + return true; } else { return false; } diff --git a/Lib/python/pystrbase.swg b/Lib/python/pystrbase.swg index ed787d51f..16df6d938 100644 --- a/Lib/python/pystrbase.swg +++ b/Lib/python/pystrbase.swg @@ -137,8 +137,7 @@ %apply Char* { Char [] }; %apply const Char* { const Char [] }; -%typemap(varin,fragment=#SWIG_AsCharArray, - warning="462:Unable to set variable of type Char []") Char [] +%typemap(varin,warning="462:Unable to set variable of type Char []") Char [] { PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only"); return 1; @@ -173,6 +172,12 @@ $1 = temp; } +%typemap(in,fragment=#SWIG_AsCharArray) const Char (&)[ANY] (Char temp[$1_dim0]) +{ + if (!SWIG_AsCharArray($input, temp, $1_dim0)) {SWIG_arg_fail($argnum);SWIG_fail;} + $1 = &temp; +} + %typemap(out,fragment=#SWIG_FromCharArray) Char [ANY], const Char[ANY] { diff --git a/Lib/python/pyswigtype.swg b/Lib/python/pyswigtype.swg index ed9d0a195..4a75b2a0d 100644 --- a/Lib/python/pyswigtype.swg +++ b/Lib/python/pyswigtype.swg @@ -8,6 +8,12 @@ "SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown); if (SWIG_arg_fail($argnum)) SWIG_fail;"; +%typemap(in) SWIGTYPE* const& ($*ltype temp) + "SWIG_Python_ConvertPtr($input, (void **)&temp, $*descriptor, SWIG_POINTER_EXCEPTION | $disown); + if (SWIG_arg_fail($argnum)) SWIG_fail; + $1 = &temp; + "; + %typemap(in) SWIGTYPE *DISOWN "SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN); if (SWIG_arg_fail($argnum)) SWIG_fail;"; @@ -22,14 +28,17 @@ if (SWIG_arg_fail($argnum)) SWIG_fail;"; /* Object passed by value. Convert to a pointer */ -%typemap(in) SWIGTYPE ($<ype argp) - "SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION); +%typemap(in) SWIGTYPE { + $<ype argp; + SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION); if (SWIG_arg_fail($argnum)) SWIG_fail; if (argp == NULL) { - SWIG_null_ref(SWIG_TypePrettyName($descriptor)); + SWIG_null_ref(SWIG_TypePrettyName($&descriptor)); } if (SWIG_arg_fail($argnum)) SWIG_fail; - $1 = *argp;"; + $1 = *argp; +} + /* Pointer to a class member */ %typemap(in) SWIGTYPE (CLASS::*) @@ -46,7 +55,10 @@ /* Pointers, references, and arrays */ %typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] - "$result = SWIG_NewPointerObj((void*)($1), $1_descriptor, $owner);"; + "$result = SWIG_NewPointerObj((void*)($1), $descriptor, $owner);"; + +%typemap(out) SWIGTYPE* const& + "$result = SWIG_NewPointerObj((void*)(*$1), $*descriptor, $owner);"; /* Dynamic casts */ @@ -57,23 +69,23 @@ /* Member pointer */ %typemap(out) SWIGTYPE (CLASS::*) - "$result = SWIG_NewPackedObj((void*)(&$1), sizeof($1_type), $1_descriptor);"; + "$result = SWIG_NewPackedObj((void*)(&$1), sizeof($type), $descriptor);"; /* Primitive types--return by value */ #ifdef __cplusplus %typemap(out) SWIGTYPE { $&1_ltype resultptr; - resultptr = new $1_ltype(static_cast<$1_type &>($1)); - $result = SWIG_NewPointerObj((void *)(resultptr), $&1_descriptor, 1); + resultptr = new $ltype(SWIG_static_cast($1,$type &)); + $result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1); } #else %typemap(out /* warning="452:Default return typemap could be unsafe" */) SWIGTYPE { - $&1_ltype resultptr; - resultptr = ($&1_ltype) malloc(sizeof($1_type)); - memmove(resultptr, &$1, sizeof($1_type)); - $result = SWIG_NewPointerObj((void *)(resultptr), $&1_descriptor, 1); + $<ype resultptr; + resultptr = ($<ype) malloc(sizeof($type)); + memmove(resultptr, &$1, sizeof($type)); + $result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1); } #endif @@ -99,13 +111,19 @@ %typemap(varin) SWIGTYPE * { void *temp; - if ((SWIG_ConvertPtr($input, &temp, $1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) { + if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) { SWIG_append_errmsg("C/C++ variable '$name'"); return 1; } $1 = ($ltype) temp; } +%typemap(varin,warning="462:Unable to set dimensionless array variable") SWIGTYPE [] +{ + PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only"); + return 1; +} + %typemap(varin) SWIGTYPE & { void *temp; if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) { @@ -191,7 +209,8 @@ * --- Typechecking rules --- * ------------------------------------------------------------ */ -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] +%typecheck(SWIG_TYPECHECK_POINTER) + SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { void *ptr; if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) { diff --git a/Lib/python/pyvaltypes.swg b/Lib/python/pyvaltypes.swg index dae39d569..4704641df 100644 --- a/Lib/python/pyvaltypes.swg +++ b/Lib/python/pyvaltypes.swg @@ -22,7 +22,7 @@ /* out */ %define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...) - %typemap(out,fragment=pyfrag) Type + %typemap(out,fragment=pyfrag) Type, const Type { $result = from_meth(SWIG_static_cast($1,$basetype)); } %typemap(out,fragment=pyfrag) const Type& diff --git a/Lib/python/pyvoid.swg b/Lib/python/pyvoid.swg index 639a74eaf..1a4e8bd12 100644 --- a/Lib/python/pyvoid.swg +++ b/Lib/python/pyvoid.swg @@ -10,8 +10,8 @@ } } -%typemap(in) const void *& ($basetype temp) { - SWIG_ConvertPtr($input,SWIG_reinterpret_cast(&temp,void **),0,SWIG_POINTER_EXCEPTION|$disown); +%typemap(in) const void *& ($*ltype temp) { + SWIG_ConvertPtr($input,(void **)&temp,0,SWIG_POINTER_EXCEPTION|$disown); if (SWIG_arg_fail($argnum)) SWIG_fail; $1 = &temp; } diff --git a/Lib/python/std_basic_string.i b/Lib/python/std_basic_string.i index d2d74c5b9..e8baf889f 100644 --- a/Lib/python/std_basic_string.i +++ b/Lib/python/std_basic_string.i @@ -1,4 +1,97 @@ +#if !defined(SWIG_STD_STRING) && !defined(SWIG_STD_WSTRING) +#define SWIG_STD_BASIC_STRING + %include <pycontainer.swg> + #define %swig_basic_string(Type...) %swig_sequence_methods_val(Type) + +%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header", + fragment="SWIG_AsCharPtrAndSize") { + SWIGINTERN int + SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val) + { + static swig_type_info* string_info = + SWIG_TypeQuery("std::basic_string<char> *"); + std::string *vptr; + if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) { + if (val) *val = vptr; + return SWIG_OLDOBJ; + } else { + PyErr_Clear(); + char* buf = 0 ; size_t size = 0; + if (SWIG_AsCharPtrAndSize(obj, &buf, &size)) { + if (buf) { + if (val) *val = new std::string(buf, size - 1); + return SWIG_NEWOBJ; + } + } else { + PyErr_Clear(); + } + if (val) { + PyErr_SetString(PyExc_TypeError,"a string is expected"); + } + return 0; + } + } +} + +%fragment(SWIG_From_frag(std::basic_string<char>),"header", + fragment="SWIG_FromCharArray") { +SWIGINTERNSHORT PyObject* + SWIG_From(std::basic_string<char>)(const std::string& s) + { + return SWIG_FromCharArray(s.data(), s.size()); + } +} + + +%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header", + fragment="SWIG_AsWCharPtrAndSize") { +SWIGINTERN int + SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val) + { + static swig_type_info* string_info = + SWIG_TypeQuery("std::basic_string<wchar_t> *"); + std::wstring *vptr; + if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) { + if (val) *val = vptr; + return SWIG_OLDOBJ; + } else { + PyErr_Clear(); + wchar_t *buf = 0 ; size_t size = 0; + int res = 0; + if ((res = SWIG_AsWCharPtrAndSize(obj, &buf, &size))) { + if (buf) { + if (val) *val = new std::wstring(buf, size - 1); + if (res == SWIG_NEWOBJ) SWIG_delete_array(buf); + return SWIG_NEWOBJ; + } + } else { + PyErr_Clear(); + } + if (val) { + PyErr_SetString(PyExc_TypeError,"a wstring is expected"); + } + return 0; + } + } +} + +%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header", + fragment="SWIG_FromWCharArray") { +SWIGINTERNSHORT PyObject* + SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s) + { + return SWIG_FromWCharArray(s.data(), s.size()); + } +} + + + %include <std/std_basic_string.i> + +%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<char>); +%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>); + +#endif diff --git a/Lib/python/std_string.i b/Lib/python/std_string.i index 736da6299..d8cf79db4 100644 --- a/Lib/python/std_string.i +++ b/Lib/python/std_string.i @@ -2,24 +2,25 @@ // std::string // +#ifndef SWIG_STD_BASIC_STRING +#define SWIG_STD_STRING %include <pystrings.swg> -%include <std_basic_string.i> - -/* plain strings */ namespace std { - %std_comp_methods(basic_string<char>); - typedef basic_string<char> string; + %feature("novaluewrapper") string; + class string; } + /* defining the std::string asptr/from methods */ -%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header", + +%fragment(SWIG_AsPtr_frag(std::string),"header", fragment="SWIG_AsCharPtrAndSize") { SWIGINTERN int - SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val) + SWIG_AsPtr(std::string)(PyObject* obj, std::string **val) { static swig_type_info* string_info = SWIG_TypeQuery("std::string *"); std::string *vptr; @@ -43,37 +44,24 @@ namespace std return 0; } } - - SWIGINTERNSHORT int - SWIG_AsPtr(std::string)(PyObject* obj, std::string **val) - { - return SWIG_AsPtr(std::basic_string<char>)(obj, val); - } } -%fragment(SWIG_From_frag(std::basic_string<char>),"header", +%fragment(SWIG_From_frag(std::string),"header", fragment="SWIG_FromCharArray") { SWIGINTERNSHORT PyObject* - SWIG_From(std::basic_string<char>)(const std::string& s) - { - return SWIG_FromCharArray(s.data(), s.size()); - } - -SWIGINTERNSHORT PyObject* SWIG_From(std::string)(const std::string& s) { - return SWIG_From(std::basic_string<char>)(s); + return SWIG_FromCharArray(s.data(), s.size()); } } - %fragment(SWIG_AsVal_frag(std::string),"header", - fragment=SWIG_AsPtr_frag(std::basic_string<char>)) { + fragment=SWIG_AsPtr_frag(std::string)) { SWIGINTERN int SWIG_AsVal(std::string)(PyObject* obj, std::string *val) { std::string* s; - int res = SWIG_AsPtr(std::basic_string<char>)(obj, &s); + int res = SWIG_AsPtr(std::string)(obj, &s); if (res && s) { if (val) *val = *s; if (res == SWIG_NEWOBJ) delete s; @@ -86,6 +74,10 @@ SWIGINTERN int } } - -%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<char>); %typemap_asptrfromn(SWIG_CCode(STRING), std::string); + +#else + +%include <std/std_string.i> + +#endif diff --git a/Lib/python/std_wstring.i b/Lib/python/std_wstring.i index 93ce67f55..87b098f7b 100644 --- a/Lib/python/std_wstring.i +++ b/Lib/python/std_wstring.i @@ -2,24 +2,23 @@ // std::wstring // +#ifndef SWIG_STD_BASIC_STRING +#define SWIG_STD_WSTRING %include <pywstrings.swg> -%include <std_basic_string.i> - -/* wide strings */ namespace std { - %std_comp_methods(basic_string<wchar_t>); - typedef basic_string<wchar_t> wstring; + %feature("novaluewrapper") wstring; + class wstring; } /* defining the std::string asptr/from methods */ -%fragment(SWIG_AsPtr_frag(std::basic_string<wchar_t>),"header", +%fragment(SWIG_AsPtr_frag(std::wstring),"header", fragment="SWIG_AsWCharPtrAndSize") { SWIGINTERN int - SWIG_AsPtr(std::basic_string<wchar_t>)(PyObject* obj, std::wstring **val) + SWIG_AsPtr(std::wstring)(PyObject* obj, std::wstring **val) { static swig_type_info* string_info = SWIG_TypeQuery("std::wstring *"); std::wstring *vptr; @@ -46,36 +45,25 @@ SWIGINTERN int } } -SWIGINTERNSHORT int - SWIG_AsPtr(std::wstring)(PyObject* obj, std::wstring **val) - { - return SWIG_AsPtr(std::basic_string<wchar_t>)(obj, val); - } } -%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header", +%fragment(SWIG_From_frag(std::wstring),"header", fragment="SWIG_FromWCharArray") { SWIGINTERNSHORT PyObject* - SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s) - { - return SWIG_FromWCharArray(s.data(), s.size()); - } - -SWIGINTERNSHORT PyObject* SWIG_From(std::wstring)(const std::wstring& s) { - return SWIG_From(std::basic_string<wchar_t>)(s); + return SWIG_FromWCharArray(s.data(), s.size()); } } %fragment(SWIG_AsVal_frag(std::wstring),"header", - fragment=SWIG_AsPtr_frag(std::basic_string<wchar_t>)) { + fragment=SWIG_AsPtr_frag(std::wstring)) { SWIGINTERN int SWIG_AsVal(std::wstring)(PyObject* obj, std::wstring *val) { std::wstring *s; - int res = SWIG_AsPtr(std::basic_string<wchar_t>)(obj, &s); + int res = SWIG_AsPtr(std::wstring)(obj, &s); if (res && s) { if (val) *val = *s; if (res == SWIG_NEWOBJ) delete s; @@ -88,5 +76,10 @@ SWIGINTERN int } } -%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>); %typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring); + +#else + +%include <std/std_wstring.i> + +#endif |