diff --git a/Lib/python/ccomplex.i b/Lib/python/ccomplex.i index 25c6a8a9e..49cbc76d5 100644 --- a/Lib/python/ccomplex.i +++ b/Lib/python/ccomplex.i @@ -1,11 +1,11 @@ - -%include complex_common.i - /* - * C complex wrap + * C complex typemaps * ISO C99: 7.3 Complex arithmetic */ + +%include + %{ #include %} diff --git a/Lib/python/cstring.i b/Lib/python/cstring.i index 444264b44..e5f2c2792 100644 --- a/Lib/python/cstring.i +++ b/Lib/python/cstring.i @@ -10,7 +10,7 @@ * some way. */ -%include "pytuplehlp.swg" +%include /* %cstring_input_binary(TYPEMAP, SIZE) * diff --git a/Lib/python/implicit.i b/Lib/python/implicit.i index 32835e2cc..eab268e8f 100644 --- a/Lib/python/implicit.i +++ b/Lib/python/implicit.i @@ -1,4 +1,4 @@ -%include std_common.i +%include /* The %implict macro allows a SwigType to be accepted diff --git a/Lib/python/complex_common.i b/Lib/python/pycomplex.swg similarity index 100% rename from Lib/python/complex_common.i rename to Lib/python/pycomplex.swg diff --git a/Lib/python/pycontainer.i b/Lib/python/pycontainer.swg similarity index 100% rename from Lib/python/pycontainer.i rename to Lib/python/pycontainer.swg diff --git a/Lib/python/fragments.i b/Lib/python/pyfragments.swg similarity index 100% rename from Lib/python/fragments.i rename to Lib/python/pyfragments.swg diff --git a/Lib/python/pyinout.swg b/Lib/python/pyinout.swg index cb28ca1ca..229385830 100644 --- a/Lib/python/pyinout.swg +++ b/Lib/python/pyinout.swg @@ -123,7 +123,7 @@ output values. // Author: Robin Dunn //---------------------------------------------------------------------- -%include pytuplehlp.swg +%include %define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type) %typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0), diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index f8fe86cf7..5c5c4e87e 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -8,18 +8,42 @@ methods. In the other cases, some extra work is needed. */ - -%insert(header) { -SWIG_define(SWIG_From(signed char), PyInt_FromLong) -SWIG_define(SWIG_From(unsigned char), PyInt_FromLong) -SWIG_define(SWIG_From(short), PyInt_FromLong) -SWIG_define(SWIG_From(unsigned short), PyInt_FromLong) -SWIG_define(SWIG_From(int), PyInt_FromLong) -SWIG_define(SWIG_From(long), PyInt_FromLong) -SWIG_define(SWIG_From(float), PyFloat_FromDouble) -SWIG_define(SWIG_From(double), PyFloat_FromDouble) +%fragment(SWIG_From_frag(signed char),"header") { + SWIG_define(SWIG_From(signed char), PyInt_FromLong) } +%fragment(SWIG_From_frag(unsigned char),"header") { + SWIG_define(SWIG_From(unsigned char), PyInt_FromLong) +} + +%fragment(SWIG_From_frag(short),"header") { + SWIG_define(SWIG_From(short), PyInt_FromLong) +} + +%fragment(SWIG_From_frag(unsigned short),"header") { + SWIG_define(SWIG_From(unsigned short), PyInt_FromLong) +} + +%fragment(SWIG_From_frag(int),"header") { + SWIG_define(SWIG_From(int), PyInt_FromLong) +} + +%fragment(SWIG_From_frag(long),"header") { + SWIG_define(SWIG_From(long), PyInt_FromLong) +} + +%fragment(SWIG_From_frag(float),"header") { + SWIG_define(SWIG_From(float), PyFloat_FromDouble) +} + +%fragment(SWIG_From_frag(double),"header") { + SWIG_define(SWIG_From(double), PyFloat_FromDouble) +} + +/* + Here, we have all the complex AsVal/From methods +*/ + %fragment("","header") %{ #include %} @@ -87,7 +111,7 @@ SWIGSTATICINLINE(int) if (value > max_value) { if (errmsg) { PyErr_Format(PyExc_OverflowError, - "value %ld is greater than '%s' minimum %ld", + "value %lud is greater than '%s' minimum %lud", value, errmsg, max_value); } return 0; diff --git a/Lib/python/pystrbase.swg b/Lib/python/pystrbase.swg index 71a2cb9da..3a9ec1f46 100644 --- a/Lib/python/pystrbase.swg +++ b/Lib/python/pystrbase.swg @@ -1,6 +1,6 @@ // -// Use this macro if you prefer to preserve the size of char -// arrays, ie +// Use the macro SWIG_PRESERVE_CARRAY_SIZE if you prefer to preserve +// the size of char arrays, ie // ------------------------------------------ // C Side => Python Side // ------------------------------------------ @@ -176,9 +176,14 @@ } %typemap(out,fragment=#SWIG_FromCharArray) - Char [ANY], const Char[ANY] - "$result = SWIG_FromCharArray($1, $1_dim0);"; - + Char [ANY], const Char[ANY] +{ + size_t size = $1_dim0; +%#ifndef SWIG_PRESERVE_CARRAY_SIZE + while (size && ($1[size - 1] == '\0')) --size; +%#endif + $result = SWIG_FromCharArray($1, size); +} /* varin */ @@ -197,9 +202,9 @@ Char [ANY], const Char [ANY] { size_t size = $1_dim0; -#ifndef SWIG_PRESERVE_CARRAY_SIZE +%#ifndef SWIG_PRESERVE_CARRAY_SIZE while (size && ($1[size - 1] == '\0')) --size; -#endif +%#endif $result = SWIG_FromCharArray($1, size); } @@ -207,13 +212,25 @@ %typemap(constcode,fragment=#SWIG_FromCharArray) Char [ANY], const Char [ANY] - "PyDict_SetItemString(d,\"$symname\", SWIG_FromCharArray($value, $value_dim0));"; +{ + size_t size = $value_dim0; +%#ifndef SWIG_PRESERVE_CARRAY_SIZE + while (size && ($value[size - 1] == '\0')) --size; +%#endif + PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size)); +} /* directorin */ %typemap(directorin,fragment=#SWIG_FromCharArray) Char [ANY], const Char [ANY] - "$input = SWIG_FromCharArray($1_name, $1_dim0);"; +{ + size_t size = $1_dim0; +%#ifndef SWIG_PRESERVE_CARRAY_SIZE + while (size && ($1_name[size - 1] == '\0')) --size; +%#endif + $input = SWIG_FromCharArray($1_name, size); +} /* directorout */ @@ -238,11 +255,53 @@ %typemap(throws,fragment=#SWIG_FromCharArray) Char [ANY], const Char[ANY] { - PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, $1_dim0)); + size_t size = $1_dim0; +%#ifndef SWIG_PRESERVE_CARRAY_SIZE + while (size && ($1[size - 1] == '\0')) --size; +%#endif + PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size)); SWIG_fail; } +/* ------------------------------------------------------------------- + * --- Really fix size Char arrays, including '\0'chars at the end --- + * ------------------------------------------------------------------- */ +%typemap(varout,fragment=#SWIG_FromCharArray) + Char FIXSIZE[ANY], const Char FIXSIZE[ANY] +{ + size_t size = $1_dim0; + $result = SWIG_FromCharArray($1, size); +} + +%typemap(out,fragment=#SWIG_FromCharArray) + Char FIXSIZE[ANY], const Char FIXSIZE[ANY] +{ + size_t size = $1_dim0; + $result = SWIG_FromCharArray($1, size); +} + +%typemap(constcode,fragment=#SWIG_FromCharArray) + Char FIXSIZE[ANY], const Char FIXSIZE[ANY] +{ + size_t size = $value_dim0; + PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size)); +} + +%typemap(directorin,fragment=#SWIG_FromCharArray) + Char FIXSIZE[ANY], const Char FIXSIZE[ANY] +{ + size_t size = $1_dim0; + $input = SWIG_FromCharArray($1_name, size); +} + +%typemap(throws,fragment=#SWIG_FromCharArray) + Char FIXSIZE[ANY], const Char FIXSIZE[ANY] +{ + size_t size = $1_dim0; + PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size)); + SWIG_fail; +} /* ------------------------------------------------------------ * --- String & length --- diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg index 1679ce91a..a42c829e7 100644 --- a/Lib/python/pystrings.swg +++ b/Lib/python/pystrings.swg @@ -126,14 +126,14 @@ SWIG_AsCharArray(PyObject *obj, char *val, size_t size) } if (val) { PyErr_Format(PyExc_TypeError, - "a char array of maximum size %ld is expected", - size); + "a char array of maximum size %lud is expected", + (unsigned long) size); } return 0; } %} -%fragment("SWIG_FromCharArray","header") %{ +%fragment("SWIG_FromCharArray","header") { SWIGSTATICINLINE(PyObject *) SWIG_FromCharArray(const char* carray, size_t size) { @@ -144,7 +144,7 @@ SWIG_FromCharArray(const char* carray, size_t size) return PyString_FromStringAndSize(carray, swig_numeric_cast(size,int)); } } -%} +} /* ------------------------------------------------------------ * The plain char * handling diff --git a/Lib/python/python.swg b/Lib/python/python.swg index 197e52489..1bd8091bc 100644 --- a/Lib/python/python.swg +++ b/Lib/python/python.swg @@ -7,7 +7,7 @@ /* Python.h has to appear first */ %insert(runtime) %{ -#include "Python.h" +#include %} %insert(runtime) "precommon.swg"; @@ -19,46 +19,46 @@ #define %shadow %insert("shadow") #define %pythoncode %insert("python") -%include "pymacros.swg" +%include /* ----------------------------------------------------------------------------- - * Look for user fragments.i file. If not found, include empty system one. + * Look for user fragments file. If not found, include empty system one. * ----------------------------------------------------------------------------- */ -%include "fragments.i" +%include "pyfragments.swg" /* ----------------------------------------------------------------------------- * SWIGTYPE typemaps * ----------------------------------------------------------------------------- */ -%include "pyswigtype.swg" +%include /* ----------------------------------------------------------------------------- * Typemap specializations * ----------------------------------------------------------------------------- */ -%include "pyinout.swg" -%include "pyvoid.swg" -%include "pyobject.swg" -%include "pystrbase.swg" -%include "pystrings.swg" -%include "pyvaltypes.swg" -%include "pyptrtypes.swg" -%include "pyprimtypes.swg" -%include "pymisctypes.swg" -%include "pyenum.swg" +%include +%include +%include +%include +%include +%include +%include +%include +%include +%include /* ------------------------------------------------------------ * Overloaded operator support * ------------------------------------------------------------ */ -%include "pyopers.swg" +%include /* ------------------------------------------------------------ * Warnings for Python keywords * ------------------------------------------------------------ */ -%include "pythonkw.swg" +%include /* ------------------------------------------------------------ * The start of the Python initialization function diff --git a/Lib/python/pywstrings.swg b/Lib/python/pywstrings.swg index 5e23fd26a..5c09fa4ed 100644 --- a/Lib/python/pywstrings.swg +++ b/Lib/python/pywstrings.swg @@ -122,7 +122,7 @@ SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size) } if (val) { PyErr_Format(PyExc_TypeError, - "a wchar_t array of maximum size %ld is expected", + "a wchar_t array of maximum size %lud is expected", size); } return 0; diff --git a/Lib/python/std_basic_string.i b/Lib/python/std_basic_string.i index 901b382c7..e1835eeeb 100644 --- a/Lib/python/std_basic_string.i +++ b/Lib/python/std_basic_string.i @@ -1,5 +1,5 @@ -%include exception.i -%include std_container.i +%include +%include %{ #include diff --git a/Lib/python/std_common.i b/Lib/python/std_common.i index f60ae63ba..7f93b9bf5 100644 --- a/Lib/python/std_common.i +++ b/Lib/python/std_common.i @@ -13,6 +13,7 @@ #if defined(__SUNPRO_CC) #define SWIG_STD_NOASSIGN_STL +#define SWIG_STD_NOINSERT_TEMPLATE_STL #endif %} @@ -50,7 +51,7 @@ // Common code for supporting the STD C++ namespace // -%include pyptrtypes.swg +%include %{ #include #include diff --git a/Lib/python/std_complex.i b/Lib/python/std_complex.i index 671419d4a..fbb8dbb44 100644 --- a/Lib/python/std_complex.i +++ b/Lib/python/std_complex.i @@ -1,7 +1,8 @@ -#ifndef SWIG_STD_COMPLEX_I_ -#define SWIG_STD_COMPLEX_I_ +/* + * STD C++ complex typemaps + */ -%include complex_common.i +%include %{ #include @@ -19,5 +20,3 @@ %typemap_primitive(SWIG_CCode(CPLXDBL), std::complex); %typemap_primitive(SWIG_CCode(CPLXFLT), std::complex); - -#endif //SWIG_STD_COMPLEX_I_ diff --git a/Lib/python/std_container.i b/Lib/python/std_container.i index d1261c3ee..583891d68 100644 --- a/Lib/python/std_container.i +++ b/Lib/python/std_container.i @@ -1,6 +1,6 @@ -%include std_common.i -%include pycontainer.i -%include exception.i +%include +%include +%include %{ #include diff --git a/Lib/python/std_deque.i b/Lib/python/std_deque.i index 6013231cc..7a89b1244 100644 --- a/Lib/python/std_deque.i +++ b/Lib/python/std_deque.i @@ -2,7 +2,7 @@ // std::deque // Python implementation -%include std_container.i +%include // Deque diff --git a/Lib/python/std_list.i b/Lib/python/std_list.i index 1e716c883..15c7b4422 100644 --- a/Lib/python/std_list.i +++ b/Lib/python/std_list.i @@ -2,7 +2,7 @@ // std::list // Python implementation -%include std_container.i +%include // List diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 46e04a0e4..d2b18a9b5 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -2,8 +2,8 @@ // std::map // Python implementation -%include std_pair.i -%include std_container.i +%include +%include %define %std_map_methods_common(map) %std_container_methods(SWIG_arg(map)); diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 0dd44d199..780c63639 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -2,7 +2,7 @@ // std::map // Python implementation -%include std_map.i +%include %define %std_multimap_methods(...) diff --git a/Lib/python/std_multiset.i b/Lib/python/std_multiset.i index b2abde3d8..3c3d3246e 100644 --- a/Lib/python/std_multiset.i +++ b/Lib/python/std_multiset.i @@ -2,7 +2,7 @@ // std::set // Python implementation -%include std_set.i +%include // Multiset @@ -44,7 +44,15 @@ namespace swigpy { template void assign(const PySeq& pyseq, std::multiset* seq) { +#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL + typedef typename PySeq::value_type value_type; + typename PySeq::const_iterator it = pyseq.begin(); + for (;it != pyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } +#else seq->insert(pyseq.begin(), pyseq.end()); +#endif } template diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i index af33663cc..f427613ab 100644 --- a/Lib/python/std_pair.i +++ b/Lib/python/std_pair.i @@ -1,4 +1,4 @@ -%include std_common.i +%include %{ #include diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i index 69c76ca90..4d4394170 100644 --- a/Lib/python/std_set.i +++ b/Lib/python/std_set.i @@ -2,7 +2,7 @@ // std::set // Python implementation -%include std_container.i +%include // Set @@ -84,7 +84,15 @@ namespace swigpy { template void assign(const PySeq& pyseq, std::set* seq) { +#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL + typedef typename PySeq::value_type value_type; + typename PySeq::const_iterator it = pyseq.begin(); + for (;it != pyseq.end(); ++it) { + seq->insert(seq->end(),(value_type)(*it)); + } +#else seq->insert(pyseq.begin(), pyseq.end()); +#endif } template diff --git a/Lib/python/std_string.i b/Lib/python/std_string.i index b42c33bf0..357d54c2b 100644 --- a/Lib/python/std_string.i +++ b/Lib/python/std_string.i @@ -12,8 +12,8 @@ // However, I think I'll wait until someone asks for it... // ------------------------------------------------------------------------ -%include pystrings.swg -%include std_basic_string.i +%include +%include /* plain strings */ diff --git a/Lib/python/std_vector.i b/Lib/python/std_vector.i index 4b14256b9..c39381ad1 100644 --- a/Lib/python/std_vector.i +++ b/Lib/python/std_vector.i @@ -2,7 +2,7 @@ // std::vector // Python implementation -%include std_container.i +%include // Vector diff --git a/Lib/python/std_vectora.i b/Lib/python/std_vectora.i index 6f9045c42..b211aced2 100644 --- a/Lib/python/std_vectora.i +++ b/Lib/python/std_vectora.i @@ -7,7 +7,7 @@ // std_vector.i instead. // -%include std_container.i +%include // Vector diff --git a/Lib/python/std_wstring.i b/Lib/python/std_wstring.i index cf82ee28b..a69763459 100644 --- a/Lib/python/std_wstring.i +++ b/Lib/python/std_wstring.i @@ -1,5 +1,5 @@ -%include wchar.i -%include std_basic_string.i +%include +%include /* wide strings */ diff --git a/Lib/python/typemaps.i b/Lib/python/typemaps.i index e7bb14e4f..2c4d3cf52 100644 --- a/Lib/python/typemaps.i +++ b/Lib/python/typemaps.i @@ -50,12 +50,12 @@ To use these, suppose you had a C function like this : You could wrap it with SWIG as follows : - %include typemaps.i + %include double fadd(double *INPUT, double *INPUT); or you can use the %apply directive : - %include typemaps.i + %include %apply double *INPUT { double *a, double *b }; double fadd(double *a, double *b); @@ -92,12 +92,12 @@ returns the integer part in one of its parameters).K: You could wrap it with SWIG as follows : - %include typemaps.i + %include double modf(double x, double *OUTPUT); or you can use the %apply directive : - %include typemaps.i + %include %apply double *OUTPUT { double *ip }; double modf(double x, double *ip); @@ -137,12 +137,12 @@ For example, suppose you were trying to wrap the following function : You could wrap it with SWIG as follows : - %include typemaps.i + %include void neg(double *INOUT); or you can use the %apply directive : - %include typemaps.i + %include %apply double *INOUT { double *x }; void neg(double *x); @@ -160,7 +160,7 @@ phased out in future releases. */ -%include pyinout.swg +%include #ifdef SWIG_INOUT_NODEF /* diff --git a/Lib/python/wchar.i b/Lib/python/wchar.i index 1a76001b3..2743b4b9b 100644 --- a/Lib/python/wchar.i +++ b/Lib/python/wchar.i @@ -4,4 +4,4 @@ %types(wchar_t *); -%include pywstrings.swg +%include