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:
parent
0420621ce7
commit
349e6bc6ee
29 changed files with 182 additions and 83 deletions
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
%include complex_common.i
|
||||
|
||||
/*
|
||||
* C complex wrap
|
||||
* C complex typemaps
|
||||
* ISO C99: 7.3 Complex arithmetic <complex.h>
|
||||
*/
|
||||
|
||||
|
||||
%include <pycomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* some way.
|
||||
*/
|
||||
|
||||
%include "pytuplehlp.swg"
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
/* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%include std_common.i
|
||||
%include <std_common.i>
|
||||
|
||||
/*
|
||||
The %implict macro allows a SwigType to be accepted
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ output values.
|
|||
// Author: Robin Dunn
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
%include pytuplehlp.swg
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
%define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type)
|
||||
%typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0),
|
||||
|
|
|
|||
|
|
@ -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("<limits.h>","header") %{
|
||||
#include <limits.h>
|
||||
%}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ---
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
/* Python.h has to appear first */
|
||||
|
||||
%insert(runtime) %{
|
||||
#include "Python.h"
|
||||
#include <Python.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "precommon.swg";
|
||||
|
|
@ -19,46 +19,46 @@
|
|||
#define %shadow %insert("shadow")
|
||||
#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
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "pyswigtype.swg"
|
||||
%include <pyswigtype.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* 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 <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>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
%include "pyopers.swg"
|
||||
%include <pyopers.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Warnings for Python keywords
|
||||
* ------------------------------------------------------------ */
|
||||
%include "pythonkw.swg"
|
||||
%include <pythonkw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The start of the Python initialization function
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
%include exception.i
|
||||
%include std_container.i
|
||||
%include <exception.i>
|
||||
%include <std_container.i>
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -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 <pyptrtypes.swg>
|
||||
%{
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -19,5 +20,3 @@
|
|||
%typemap_primitive(SWIG_CCode(CPLXDBL), std::complex<double>);
|
||||
%typemap_primitive(SWIG_CCode(CPLXFLT), std::complex<float>);
|
||||
|
||||
|
||||
#endif //SWIG_STD_COMPLEX_I_
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%include std_common.i
|
||||
%include pycontainer.i
|
||||
%include exception.i
|
||||
%include <pycontainer.swg>
|
||||
%include <std_common.i>
|
||||
%include <exception.i>
|
||||
|
||||
%{
|
||||
#include <algorithm>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::deque
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// Deque
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::list
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// List
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
// std::map
|
||||
// Python implementation
|
||||
|
||||
%include std_pair.i
|
||||
%include std_container.i
|
||||
%include <std_pair.i>
|
||||
%include <std_container.i>
|
||||
|
||||
%define %std_map_methods_common(map)
|
||||
%std_container_methods(SWIG_arg(map));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::map
|
||||
// Python implementation
|
||||
|
||||
%include std_map.i
|
||||
%include <std_map.i>
|
||||
|
||||
|
||||
%define %std_multimap_methods(...)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::set
|
||||
// Python implementation
|
||||
|
||||
%include std_set.i
|
||||
%include <std_set.i>
|
||||
|
||||
// Multiset
|
||||
|
||||
|
|
@ -44,7 +44,15 @@
|
|||
namespace swigpy {
|
||||
template <class PySeq, class T>
|
||||
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());
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%include std_common.i
|
||||
%include <std_common.i>
|
||||
|
||||
%{
|
||||
#include <utility>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::set
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// Set
|
||||
|
||||
|
|
@ -84,7 +84,15 @@
|
|||
namespace swigpy {
|
||||
template <class PySeq, class T>
|
||||
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());
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include pystrings.swg
|
||||
%include std_basic_string.i
|
||||
%include <pystrings.swg>
|
||||
%include <std_basic_string.i>
|
||||
|
||||
/* plain strings */
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// std::vector
|
||||
// Python implementation
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// Vector
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
// std_vector.i instead.
|
||||
//
|
||||
|
||||
%include std_container.i
|
||||
%include <std_container.i>
|
||||
|
||||
// Vector
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
%include wchar.i
|
||||
%include std_basic_string.i
|
||||
%include <wchar.i>
|
||||
%include <std_basic_string.i>
|
||||
|
||||
/* wide strings */
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <typemaps.i>
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%include <typemaps.i>
|
||||
%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 <typemaps.i>
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%include <typemaps.i>
|
||||
%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 <typemaps.i>
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%include <typemaps.i>
|
||||
%apply double *INOUT { 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
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
%types(wchar_t *);
|
||||
|
||||
%include pywstrings.swg
|
||||
%include <pywstrings.swg>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue