using <> when including lib files, fix char{ANY], add char FIXSIZE[ANY], fix pyfragments.swg, fixing *.swg and *.i names

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6250 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-09-17 06:17:35 +00:00
commit 349e6bc6ee
29 changed files with 182 additions and 83 deletions

View file

@ -1,11 +1,11 @@
%include complex_common.i
/* /*
* C complex wrap * C complex typemaps
* ISO C99: 7.3 Complex arithmetic <complex.h> * ISO C99: 7.3 Complex arithmetic <complex.h>
*/ */
%include <pycomplex.swg>
%{ %{
#include <complex.h> #include <complex.h>
%} %}

View file

@ -10,7 +10,7 @@
* some way. * some way.
*/ */
%include "pytuplehlp.swg" %include <pytuplehlp.swg>
/* %cstring_input_binary(TYPEMAP, SIZE) /* %cstring_input_binary(TYPEMAP, SIZE)
* *

View file

@ -1,4 +1,4 @@
%include std_common.i %include <std_common.i>
/* /*
The %implict macro allows a SwigType to be accepted The %implict macro allows a SwigType to be accepted

View file

@ -123,7 +123,7 @@ output values.
// Author: Robin Dunn // Author: Robin Dunn
//---------------------------------------------------------------------- //----------------------------------------------------------------------
%include pytuplehlp.swg %include <pytuplehlp.swg>
%define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type) %define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type)
%typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0), %typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0),

View file

@ -8,18 +8,42 @@
methods. In the other cases, some extra work is needed. methods. In the other cases, some extra work is needed.
*/ */
%fragment(SWIG_From_frag(signed char),"header") {
%insert(header) { SWIG_define(SWIG_From(signed char), PyInt_FromLong)
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(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("<limits.h>","header") %{ %fragment("<limits.h>","header") %{
#include <limits.h> #include <limits.h>
%} %}
@ -87,7 +111,7 @@ SWIGSTATICINLINE(int)
if (value > max_value) { if (value > max_value) {
if (errmsg) { if (errmsg) {
PyErr_Format(PyExc_OverflowError, PyErr_Format(PyExc_OverflowError,
"value %ld is greater than '%s' minimum %ld", "value %lud is greater than '%s' minimum %lud",
value, errmsg, max_value); value, errmsg, max_value);
} }
return 0; return 0;

View file

@ -1,6 +1,6 @@
// //
// Use this macro if you prefer to preserve the size of char // Use the macro SWIG_PRESERVE_CARRAY_SIZE if you prefer to preserve
// arrays, ie // the size of char arrays, ie
// ------------------------------------------ // ------------------------------------------
// C Side => Python Side // C Side => Python Side
// ------------------------------------------ // ------------------------------------------
@ -176,9 +176,14 @@
} }
%typemap(out,fragment=#SWIG_FromCharArray) %typemap(out,fragment=#SWIG_FromCharArray)
Char [ANY], const Char[ANY] Char [ANY], const Char[ANY]
"$result = SWIG_FromCharArray($1, $1_dim0);"; {
size_t size = $1_dim0;
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
while (size && ($1[size - 1] == '\0')) --size;
%#endif
$result = SWIG_FromCharArray($1, size);
}
/* varin */ /* varin */
@ -197,9 +202,9 @@
Char [ANY], const Char [ANY] Char [ANY], const Char [ANY]
{ {
size_t size = $1_dim0; size_t size = $1_dim0;
#ifndef SWIG_PRESERVE_CARRAY_SIZE %#ifndef SWIG_PRESERVE_CARRAY_SIZE
while (size && ($1[size - 1] == '\0')) --size; while (size && ($1[size - 1] == '\0')) --size;
#endif %#endif
$result = SWIG_FromCharArray($1, size); $result = SWIG_FromCharArray($1, size);
} }
@ -207,13 +212,25 @@
%typemap(constcode,fragment=#SWIG_FromCharArray) %typemap(constcode,fragment=#SWIG_FromCharArray)
Char [ANY], const Char [ANY] 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 */ /* directorin */
%typemap(directorin,fragment=#SWIG_FromCharArray) %typemap(directorin,fragment=#SWIG_FromCharArray)
Char [ANY], const Char [ANY] 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 */ /* directorout */
@ -238,11 +255,53 @@
%typemap(throws,fragment=#SWIG_FromCharArray) %typemap(throws,fragment=#SWIG_FromCharArray)
Char [ANY], const Char[ANY] 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; 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 --- * --- String & length ---

View file

@ -126,14 +126,14 @@ SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
} }
if (val) { if (val) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"a char array of maximum size %ld is expected", "a char array of maximum size %lud is expected",
size); (unsigned long) size);
} }
return 0; return 0;
} }
%} %}
%fragment("SWIG_FromCharArray","header") %{ %fragment("SWIG_FromCharArray","header") {
SWIGSTATICINLINE(PyObject *) SWIGSTATICINLINE(PyObject *)
SWIG_FromCharArray(const char* carray, size_t size) 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)); return PyString_FromStringAndSize(carray, swig_numeric_cast(size,int));
} }
} }
%} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* The plain char * handling * The plain char * handling

View file

@ -7,7 +7,7 @@
/* Python.h has to appear first */ /* Python.h has to appear first */
%insert(runtime) %{ %insert(runtime) %{
#include "Python.h" #include <Python.h>
%} %}
%insert(runtime) "precommon.swg"; %insert(runtime) "precommon.swg";
@ -19,46 +19,46 @@
#define %shadow %insert("shadow") #define %shadow %insert("shadow")
#define %pythoncode %insert("python") #define %pythoncode %insert("python")
%include "pymacros.swg" %include <pymacros.swg>
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* 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 * SWIGTYPE typemaps
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%include "pyswigtype.swg" %include <pyswigtype.swg>
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Typemap specializations * Typemap specializations
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%include "pyinout.swg" %include <pyinout.swg>
%include "pyvoid.swg" %include <pyvoid.swg>
%include "pyobject.swg" %include <pyobject.swg>
%include "pystrbase.swg" %include <pystrbase.swg>
%include "pystrings.swg" %include <pystrings.swg>
%include "pyvaltypes.swg" %include <pyvaltypes.swg>
%include "pyptrtypes.swg" %include <pyptrtypes.swg>
%include "pyprimtypes.swg" %include <pyprimtypes.swg>
%include "pymisctypes.swg" %include <pymisctypes.swg>
%include "pyenum.swg" %include <pyenum.swg>
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Overloaded operator support * Overloaded operator support
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%include "pyopers.swg" %include <pyopers.swg>
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Warnings for Python keywords * Warnings for Python keywords
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */
%include "pythonkw.swg" %include <pythonkw.swg>
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* The start of the Python initialization function * The start of the Python initialization function

View file

@ -122,7 +122,7 @@ SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
} }
if (val) { if (val) {
PyErr_Format(PyExc_TypeError, 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); size);
} }
return 0; return 0;

View file

@ -1,5 +1,5 @@
%include exception.i %include <exception.i>
%include std_container.i %include <std_container.i>
%{ %{
#include <string> #include <string>

View file

@ -13,6 +13,7 @@
#if defined(__SUNPRO_CC) #if defined(__SUNPRO_CC)
#define SWIG_STD_NOASSIGN_STL #define SWIG_STD_NOASSIGN_STL
#define SWIG_STD_NOINSERT_TEMPLATE_STL
#endif #endif
%} %}
@ -50,7 +51,7 @@
// Common code for supporting the STD C++ namespace // Common code for supporting the STD C++ namespace
// //
%include pyptrtypes.swg %include <pyptrtypes.swg>
%{ %{
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>

View file

@ -1,7 +1,8 @@
#ifndef SWIG_STD_COMPLEX_I_ /*
#define SWIG_STD_COMPLEX_I_ * STD C++ complex typemaps
*/
%include complex_common.i %include <pycomplex.swg>
%{ %{
#include <complex> #include <complex>
@ -19,5 +20,3 @@
%typemap_primitive(SWIG_CCode(CPLXDBL), std::complex<double>); %typemap_primitive(SWIG_CCode(CPLXDBL), std::complex<double>);
%typemap_primitive(SWIG_CCode(CPLXFLT), std::complex<float>); %typemap_primitive(SWIG_CCode(CPLXFLT), std::complex<float>);
#endif //SWIG_STD_COMPLEX_I_

View file

@ -1,6 +1,6 @@
%include std_common.i %include <pycontainer.swg>
%include pycontainer.i %include <std_common.i>
%include exception.i %include <exception.i>
%{ %{
#include <algorithm> #include <algorithm>

View file

@ -2,7 +2,7 @@
// std::deque // std::deque
// Python implementation // Python implementation
%include std_container.i %include <std_container.i>
// Deque // Deque

View file

@ -2,7 +2,7 @@
// std::list // std::list
// Python implementation // Python implementation
%include std_container.i %include <std_container.i>
// List // List

View file

@ -2,8 +2,8 @@
// std::map // std::map
// Python implementation // Python implementation
%include std_pair.i %include <std_pair.i>
%include std_container.i %include <std_container.i>
%define %std_map_methods_common(map) %define %std_map_methods_common(map)
%std_container_methods(SWIG_arg(map)); %std_container_methods(SWIG_arg(map));

View file

@ -2,7 +2,7 @@
// std::map // std::map
// Python implementation // Python implementation
%include std_map.i %include <std_map.i>
%define %std_multimap_methods(...) %define %std_multimap_methods(...)

View file

@ -2,7 +2,7 @@
// std::set // std::set
// Python implementation // Python implementation
%include std_set.i %include <std_set.i>
// Multiset // Multiset
@ -44,7 +44,15 @@
namespace swigpy { namespace swigpy {
template <class PySeq, class T> template <class PySeq, class T>
void assign(const PySeq& pyseq, std::multiset<T>* seq) { void assign(const PySeq& pyseq, std::multiset<T>* 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()); seq->insert(pyseq.begin(), pyseq.end());
#endif
} }
template <class T> template <class T>

View file

@ -1,4 +1,4 @@
%include std_common.i %include <std_common.i>
%{ %{
#include <utility> #include <utility>

View file

@ -2,7 +2,7 @@
// std::set // std::set
// Python implementation // Python implementation
%include std_container.i %include <std_container.i>
// Set // Set
@ -84,7 +84,15 @@
namespace swigpy { namespace swigpy {
template <class PySeq, class T> template <class PySeq, class T>
void assign(const PySeq& pyseq, std::set<T>* seq) { void assign(const PySeq& pyseq, std::set<T>* 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()); seq->insert(pyseq.begin(), pyseq.end());
#endif
} }
template <class T> template <class T>

View file

@ -12,8 +12,8 @@
// However, I think I'll wait until someone asks for it... // However, I think I'll wait until someone asks for it...
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
%include pystrings.swg %include <pystrings.swg>
%include std_basic_string.i %include <std_basic_string.i>
/* plain strings */ /* plain strings */

View file

@ -2,7 +2,7 @@
// std::vector // std::vector
// Python implementation // Python implementation
%include std_container.i %include <std_container.i>
// Vector // Vector

View file

@ -7,7 +7,7 @@
// std_vector.i instead. // std_vector.i instead.
// //
%include std_container.i %include <std_container.i>
// Vector // Vector

View file

@ -1,5 +1,5 @@
%include wchar.i %include <wchar.i>
%include std_basic_string.i %include <std_basic_string.i>
/* wide strings */ /* wide strings */

View file

@ -50,12 +50,12 @@ To use these, suppose you had a C function like this :
You could wrap it with SWIG as follows : You could wrap it with SWIG as follows :
%include typemaps.i %include <typemaps.i>
double fadd(double *INPUT, double *INPUT); double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive : or you can use the %apply directive :
%include typemaps.i %include <typemaps.i>
%apply double *INPUT { double *a, double *b }; %apply double *INPUT { double *a, double *b };
double fadd(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 : You could wrap it with SWIG as follows :
%include typemaps.i %include <typemaps.i>
double modf(double x, double *OUTPUT); double modf(double x, double *OUTPUT);
or you can use the %apply directive : or you can use the %apply directive :
%include typemaps.i %include <typemaps.i>
%apply double *OUTPUT { double *ip }; %apply double *OUTPUT { double *ip };
double modf(double x, 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 : You could wrap it with SWIG as follows :
%include typemaps.i %include <typemaps.i>
void neg(double *INOUT); void neg(double *INOUT);
or you can use the %apply directive : or you can use the %apply directive :
%include typemaps.i %include <typemaps.i>
%apply double *INOUT { double *x }; %apply double *INOUT { double *x };
void neg(double *x); void neg(double *x);
@ -160,7 +160,7 @@ phased out in future releases.
*/ */
%include pyinout.swg %include <pyinout.swg>
#ifdef SWIG_INOUT_NODEF #ifdef SWIG_INOUT_NODEF
/* /*

View file

@ -4,4 +4,4 @@
%types(wchar_t *); %types(wchar_t *);
%include pywstrings.swg %include <pywstrings.swg>