From d7f8258414f300cc6656bb00cec982a7324f2056 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 31 Jan 2004 01:13:31 +0000 Subject: [PATCH] Updated SWIG runtime code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25421 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/include/wx/wxPython/wxPython.h | 11 + wxPython/include/wx/wxPython/wxPython_int.h | 29 ++- wxPython/src/_core_api.i | 11 + wxPython/src/common.swg | 1 - wxPython/src/libpy.c | 266 +++++++++++++++++++- wxPython/src/pyrun.swg | 194 ++------------ 6 files changed, 334 insertions(+), 178 deletions(-) diff --git a/wxPython/include/wx/wxPython/wxPython.h b/wxPython/include/wx/wxPython/wxPython.h index a9980970db..739805ec57 100644 --- a/wxPython/include/wx/wxPython/wxPython.h +++ b/wxPython/include/wx/wxPython/wxPython.h @@ -55,6 +55,17 @@ static void wxPyCoreAPI_IMPORT() { #define SWIG_Python_InstallConstants(a,b) (wxPyCoreAPIPtr->p_SWIG_Python_InstallConstants(a,b)) #define SWIG_Python_MustGetPtr(a,b,c,d) (wxPyCoreAPIPtr->p_SWIG_Python_MustGetPtr(a,b,c,d)) +#define SWIG_PyObj_AsCharPtr(a,b) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsCharPtr(a,b)) +#define SWIG_PyObj_FromCharPtr(a) (wxPyCoreAPIPtr->p_SWIG_PyObj_FromCharPtr(a)) +#define SWIG_PyObj_AsUnsignedLong(a) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsUnsignedLong(a)) +#define SWIG_PyObj_AsLongInRange(a,b,c,d) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsLongInRange(a,b,c,d)) +#define SWIG_PyObj_AsUnsignedLongInRange(a,b,c) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsUnsignedLongInRange(a,b,c)) +#define SWIG_PyObj_AsNewCharPtr(a,b) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsNewCharPtr(a,b)) +#define SWIG_PyObj_AsCharPtrAndSize(a,b,c,d) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsCharPtrAndSize(a,b,c,d)) +#define SWIG_PyObj_AsCharArray(a,b,c,d) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsCharArray(a,b,c,d)) +#define SWIG_PyObj_FromCharArray(a,b) (wxPyCoreAPIPtr->p_SWIG_PyObj_FromCharArray(a,b)) +#define SWIG_PyObj_AsFloatConv(a,b) (wxPyCoreAPIPtr->p_SWIG_PyObj_AsFloatConv(a,b)) + #define wxPyCheckSwigType(a) (wxPyCoreAPIPtr->p_wxPyCheckSwigType(a)) #define wxPyConstructObject(a,b,c) (wxPyCoreAPIPtr->p_wxPyConstructObject(a,b,c)) #define wxPyConvertSwigPtr(a,b,c) (wxPyCoreAPIPtr->p_wxPyConvertSwigPtr(a,b,c)) diff --git a/wxPython/include/wx/wxPython/wxPython_int.h b/wxPython/include/wx/wxPython/wxPython_int.h index fd0cb3478d..ffba341273 100644 --- a/wxPython/include/wx/wxPython/wxPython_int.h +++ b/wxPython/include/wx/wxPython/wxPython_int.h @@ -335,7 +335,24 @@ typedef char* (*p_SWIG_Python_UnpackData_t)(char *c, void *, int); typedef PyObject* (*p_SWIG_Python_NewPointerObj_t)(void *, swig_type_info *,int own); typedef PyObject* (*p_SWIG_Python_NewPackedObj_t)(void *, int sz, swig_type_info *); typedef void (*p_SWIG_Python_InstallConstants_t)(PyObject *d, swig_const_info constants[]); -typedef void* (*p_SWIG_Python_MustGetPtr_t)(PyObject *, swig_type_info *, int, int); +typedef void* (*p_SWIG_Python_MustGetPtr_t)(PyObject *, swig_type_info *, int, int); + +typedef char* (*p_SWIG_PyObj_AsCharPtr_t)(PyObject *obj, swig_type_info* pchar_info); +typedef PyObject * (*p_SWIG_PyObj_FromCharPtr_t)(const char* cptr); +typedef unsigned long (*p_SWIG_PyObj_AsUnsignedLong_t)(PyObject * obj); +typedef long (*p_SWIG_PyObj_AsLongInRange_t)(PyObject * obj, const char* type, + long min_value, long max_value); +typedef unsigned long (*p_SWIG_PyObj_AsUnsignedLongInRange_t)(PyObject *obj, const char* type, + unsigned long max_value); +typedef char * (*p_SWIG_PyObj_AsNewCharPtr_t)(PyObject *obj, swig_type_info* pchar_info); +typedef void (*p_SWIG_PyObj_AsCharPtrAndSize_t)(PyObject *obj, swig_type_info* pchar_info, + char** cptr, size_t* size); +typedef void (*p_SWIG_PyObj_AsCharArray_t)(PyObject *obj, swig_type_info* pchar_info, + char* carray, size_t size); +typedef PyObject * (*p_SWIG_PyObj_FromCharArray_t)(const char* carray, size_t size); +typedef float (*p_SWIG_PyObj_AsFloatConv_t)(PyObject *obj, py_objasdbl_conv pyconv); + + struct wxPyCoreAPI { @@ -358,6 +375,16 @@ struct wxPyCoreAPI { p_SWIG_Python_InstallConstants_t p_SWIG_Python_InstallConstants; p_SWIG_Python_MustGetPtr_t p_SWIG_Python_MustGetPtr; + p_SWIG_PyObj_AsCharPtr_t p_SWIG_PyObj_AsCharPtr; + p_SWIG_PyObj_FromCharPtr_t p_SWIG_PyObj_FromCharPtr; + p_SWIG_PyObj_AsUnsignedLong_t p_SWIG_PyObj_AsUnsignedLong; + p_SWIG_PyObj_AsLongInRange_t p_SWIG_PyObj_AsLongInRange; + p_SWIG_PyObj_AsUnsignedLongInRange_t p_SWIG_PyObj_AsUnsignedLongInRange; + p_SWIG_PyObj_AsNewCharPtr_t p_SWIG_PyObj_AsNewCharPtr; + p_SWIG_PyObj_AsCharPtrAndSize_t p_SWIG_PyObj_AsCharPtrAndSize; + p_SWIG_PyObj_AsCharArray_t p_SWIG_PyObj_AsCharArray; + p_SWIG_PyObj_FromCharArray_t p_SWIG_PyObj_FromCharArray; + p_SWIG_PyObj_AsFloatConv_t p_SWIG_PyObj_AsFloatConv; bool (*p_wxPyCheckSwigType)(const wxChar* className); PyObject* (*p_wxPyConstructObject)(void* ptr, const wxChar* className, int setThisOwn); diff --git a/wxPython/src/_core_api.i b/wxPython/src/_core_api.i index 7c44223ef7..989a8fe53e 100644 --- a/wxPython/src/_core_api.i +++ b/wxPython/src/_core_api.i @@ -150,6 +150,17 @@ static wxPyCoreAPI API = { (p_SWIG_Python_InstallConstants_t)SWIG_Python_InstallConstants, (p_SWIG_Python_MustGetPtr_t)SWIG_Python_MustGetPtr, + (p_SWIG_PyObj_AsCharPtr_t)SWIG_PyObj_AsCharPtr, + (p_SWIG_PyObj_FromCharPtr_t)SWIG_PyObj_FromCharPtr, + (p_SWIG_PyObj_AsUnsignedLong_t)SWIG_PyObj_AsUnsignedLong, + (p_SWIG_PyObj_AsLongInRange_t)SWIG_PyObj_AsLongInRange, + (p_SWIG_PyObj_AsUnsignedLongInRange_t)SWIG_PyObj_AsUnsignedLongInRange, + (p_SWIG_PyObj_AsNewCharPtr_t)SWIG_PyObj_AsNewCharPtr, + (p_SWIG_PyObj_AsCharPtrAndSize_t)SWIG_PyObj_AsCharPtrAndSize, + (p_SWIG_PyObj_AsCharArray_t)SWIG_PyObj_AsCharArray, + (p_SWIG_PyObj_FromCharArray_t)SWIG_PyObj_FromCharArray, + (p_SWIG_PyObj_AsFloatConv_t)SWIG_PyObj_AsFloatConv, + wxPyCheckSwigType, wxPyConstructObject, wxPyConvertSwigPtr, diff --git a/wxPython/src/common.swg b/wxPython/src/common.swg index 4f6fba1445..6c79330d6b 100644 --- a/wxPython/src/common.swg +++ b/wxPython/src/common.swg @@ -70,6 +70,5 @@ SWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int); #ifdef __cplusplus } - #endif diff --git a/wxPython/src/libpy.c b/wxPython/src/libpy.c index 3005cae5ba..f53df745f2 100644 --- a/wxPython/src/libpy.c +++ b/wxPython/src/libpy.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------------------- * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.20 + * Version 1.3.22 * * This file is not intended to be easily readable and contains a number of * coding conventions designed to improve portability and efficiency. Do not make @@ -279,6 +279,7 @@ SWIG_UnpackData(char *c, void *ptr, int sz) { } #endif + /*********************************************************************** * python.swg * @@ -326,7 +327,7 @@ typedef struct swig_const_info { SWIG_Python_NewPointerObj(p, type, flags) #define SWIG_MustGetPtr(p, type, argnum, flags) \ SWIG_Python_MustGetPtr(p, type, argnum, flags) - + /* Python-specific SWIG API */ #define SWIG_newvarlink() \ SWIG_Python_newvarlink() @@ -339,6 +340,8 @@ typedef struct swig_const_info { #define SWIG_InstallConstants(d, constants) \ SWIG_Python_InstallConstants(d, constants) +typedef double (*py_objasdbl_conv)(PyObject *obj); + #ifdef SWIG_NOINCLUDE SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int); @@ -350,8 +353,31 @@ SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, int SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, int sz, swig_type_info *); SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]); +/* ----------------------------------------------------------------------------- + * the needed conversions between C++ and python + * ----------------------------------------------------------------------------- */ +/* basic types */ +/* + utilities +*/ +SWIGIMPORT(char* ) SWIG_PyObj_AsCharPtr(PyObject *obj, swig_type_info* pchar_info); +SWIGIMPORT(PyObject *) SWIG_PyObj_FromCharPtr(const char* cptr); +SWIGIMPORT(unsigned long) SWIG_PyObj_AsUnsignedLong(PyObject * obj); +SWIGIMPORT(long) SWIG_PyObj_AsLongInRange(PyObject * obj, const char* type, + long min_value, long max_value); +SWIGIMPORT(unsigned long) SWIG_PyObj_AsUnsignedLongInRange(PyObject *obj, const char* type, + unsigned long max_value); +SWIGIMPORT(char *) SWIG_PyObj_AsNewCharPtr(PyObject *obj, swig_type_info* pchar_info); +SWIGIMPORT(void) SWIG_PyObj_AsCharPtrAndSize(PyObject *obj, swig_type_info* pchar_info, + char** cptr, size_t* size); +SWIGIMPORT(void) SWIG_PyObj_AsCharArray(PyObject *obj, swig_type_info* pchar_info, + char* carray, size_t size); +SWIGIMPORT(PyObject *) SWIG_PyObj_FromCharArray(const char* carray, size_t size); +SWIGIMPORT(float) SWIG_PyObj_AsFloatConv(PyObject *obj, py_objasdbl_conv pyconv); + #else + /* ----------------------------------------------------------------------------- * global variable support code. * ----------------------------------------------------------------------------- */ @@ -640,6 +666,196 @@ SWIG_Python_NewPackedObj(void *ptr, int sz, swig_type_info *type) { return PyString_FromString(result); } +/* ----------------------------------------------------------------------------- + * the needed conversions between C++ and python + * ----------------------------------------------------------------------------- */ + +#include +#include +#include + +SWIGRUNTIME(unsigned long) +SWIG_PyObj_AsUnsignedLong(PyObject * obj) +{ + if (PyLong_Check(obj)) { + return PyLong_AsUnsignedLong(obj); + } else { + long i = PyInt_AsLong(obj); + if ( !PyErr_Occurred() && (i < 0)) { + PyErr_SetString(PyExc_TypeError, "negative value for unsigned type"); + } + return i; + } +} + +SWIGRUNTIME(long) +SWIG_PyObj_AsLongInRange(PyObject * obj, const char* type, + long min_value, long max_value) +{ + long value = PyInt_Check(obj) ? PyInt_AsLong(obj) : PyLong_AsLongLong(obj); + if (!PyErr_Occurred()) { + if (value < min_value) { + PyObject *err = + PyString_FromFormat("value %ld is less than '%s' minimum %ld", + value, type, min_value); + + PyErr_SetObject(PyExc_OverflowError, err); + Py_XDECREF(err); + } else if (value > max_value) { + PyObject *err = + PyString_FromFormat("value %ld is greater than '%s' maximum %ld", + value, type, max_value); + PyErr_SetObject(PyExc_OverflowError, err); + Py_XDECREF(err); + } + } + return value; +} + +SWIGRUNTIME(unsigned long) +SWIG_PyObj_AsUnsignedLongInRange(PyObject *obj, const char* type, + unsigned long max_value) +{ + unsigned long value = SWIG_PyObj_AsUnsignedLong(obj); + if (!PyErr_Occurred()) { + if (value > max_value) { + PyObject *err = + PyString_FromFormat("value %ld is greater than '%s' minimum %ld", + value, type, max_value); + PyErr_SetObject(PyExc_OverflowError, err); + Py_XDECREF(err); + } + } + return value; +} + +SWIGRUNTIME(float) +SWIG_PyObj_AsFloatConv(PyObject *obj, py_objasdbl_conv pyconv) +{ + double value = pyconv(obj); + if (!PyErr_Occurred()) { + if (value < FLT_MIN) { + PyObject *err = + PyString_FromFormat("value %g is less than float minimum %g", + value, FLT_MIN); + PyErr_SetObject(PyExc_OverflowError, err); + Py_XDECREF(err); + } else if (value > FLT_MAX) { + PyObject *err = + PyString_FromFormat("value %g is greater than float maximum %g", + value, FLT_MAX); + PyErr_SetObject(PyExc_OverflowError, err); + Py_XDECREF(err); + } + } + return (float) value; +} + +SWIGRUNTIME(void) +SWIG_PyObj_AsCharPtrAndSize(PyObject *obj, swig_type_info* pchar_info, + char** cptr, size_t* size) +{ + int psize; + if ((!pchar_info) || SWIG_ConvertPtr(obj,(void **)cptr, pchar_info, 0) == -1) { + if (pchar_info && PyErr_Occurred()) PyErr_Clear(); + PyString_AsStringAndSize(obj, cptr, &psize); + *size = (size_t) psize; + } else { + /* don't like strlen, but ... */ + *size = (*cptr) ? (strlen(*cptr) + 1) : 0; + } +} + + +SWIGRUNTIME(char*) +SWIG_PyObj_AsNewCharPtr(PyObject *obj, swig_type_info* pchar_info) +{ + char *res = 0; + char* cptr; size_t csize; + SWIG_PyObj_AsCharPtrAndSize(obj, pchar_info, &cptr, &csize); + if (!PyErr_Occurred() && cptr) { + /* we add the '0' terminator if needed */ + size_t size = (csize && !(cptr[csize - 1])) ? csize : csize + 1; + if (size) { +#ifdef __cplusplus + res = new char[size]; +#else + res = malloc(size); +#endif + if (csize) memcpy(res, cptr, csize); + if (csize < size) res[csize] = 0; + } + } + return res; +} + +SWIGRUNTIME(PyObject *) +SWIG_PyObj_FromCharArray(const char* carray, size_t size) +{ + if (size > INT_MAX) { + PyObject *err = + PyString_FromFormat("a char array of size %d is not allowed in python", + size); + PyErr_SetObject(PyExc_TypeError, err); + Py_XDECREF(err); + Py_INCREF(Py_None); + return Py_None; + } else { + int psize = (int) size; + return PyString_FromStringAndSize(carray, psize); + } +} + +SWIGRUNTIME(void) +SWIG_PyObj_AsCharArray(PyObject *obj, swig_type_info* pchar_info, + char* carray, size_t size) +{ + char* cptr; size_t csize; + SWIG_PyObj_AsCharPtrAndSize(obj, pchar_info, &cptr, &csize); + if (!PyErr_Occurred()) { + /* in C (but not in C++) you can do: + + char x[5] = "hello"; + + ie, assing the array using an extra '0' char. Here, + we assume the C behavior... + */ + if ((csize == size + 1) && !(cptr[csize-1])) --csize; + if (csize > size) { + PyObject *err = + PyString_FromFormat("a char array of maximum size %d is expected", + size); + PyErr_SetObject(PyExc_TypeError, err); + Py_XDECREF(err); + } else { + if (csize) memcpy(carray, cptr, csize); + if (csize < size) memset(carray + csize, 0, size - csize); + } + } +} + +SWIGRUNTIME(PyObject *) +SWIG_PyObj_FromCharPtr(const char* cptr) +{ + if (cptr) { + return PyString_FromString(cptr); + } else { + Py_INCREF(Py_None); + return Py_None; + } +} + +SWIGRUNTIME(char* ) +SWIG_PyObj_AsCharPtr(PyObject *obj, swig_type_info* pchar_info) +{ + char* ptr; + if (SWIG_ConvertPtr(obj,(void **)&ptr, pchar_info, 0) == -1) { + if (PyErr_Occurred()) PyErr_Clear(); + ptr = PyString_AsString(obj); + } + return ptr; +} + /* Install Constants */ SWIGRUNTIME(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { @@ -654,7 +870,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { obj = PyFloat_FromDouble(constants[i].dvalue); break; case SWIG_PY_STRING: - obj = PyString_FromString((char *) constants[i].pvalue); + obj = SWIG_PyObj_FromCharPtr((char *) constants[i].pvalue); break; case SWIG_PY_POINTER: obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); @@ -684,9 +900,11 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { #endif + /* -------- TYPES TABLE (BEGIN) -------- */ -static swig_type_info *swig_types[1]; +#define SWIGTYPE_p_char swig_types[0] +static swig_type_info *swig_types[2]; /* -------- TYPES TABLE (END) -------- */ @@ -697,6 +915,44 @@ static swig_type_info *swig_types[1]; #define SWIG_init init_swigrun #define SWIG_name "_swigrun" + +#include +#include +#include + +#ifndef SWIGSTATIC +#ifdef __cplusplus +#define SWIGSTATIC(a) static inline a +#else +#define SWIGSTATIC(a) static a +#endif +#endif + +#ifndef numeric_cast +#ifdef __cplusplus +#ifdef HAVE_NUMERIC_CAST +#define numeric_cast(type,a) numeric_cast(a) +#else +#define numeric_cast(type,a) static_cast(a) +#endif +#else +#define numeric_cast(type,a) (type)(a) +#endif +#endif + + + +#define SWIG_PyObj_FromSignedChar PyInt_FromLong +#define SWIG_PyObj_FromUnsignedChar PyInt_FromLong +#define SWIG_PyObj_FromShort PyInt_FromLong +#define SWIG_PyObj_FromUnsignedShort PyInt_FromLong +#define SWIG_PyObj_FromInt PyInt_FromLong +#define SWIG_PyObj_FromLong PyInt_FromLong +#define SWIG_PyObj_FromFloat PyFloat_FromDouble +#define SWIG_PyObj_FromDouble PyFloat_FromDouble +#define SWIG_PyObj_FromFloat PyFloat_FromDouble +#define SWIG_PyObj_FromDouble PyFloat_FromDouble + #ifdef __cplusplus extern "C" { #endif @@ -707,8 +963,10 @@ static PyMethodDef SwigMethods[] = { /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ +static swig_type_info _swigt__p_char[] = {{"_p_char", 0, "char *", 0},{"_p_char"},{0}}; static swig_type_info *swig_types_initial[] = { +_swigt__p_char, 0 }; diff --git a/wxPython/src/pyrun.swg b/wxPython/src/pyrun.swg index b28713ead6..a1502dc364 100644 --- a/wxPython/src/pyrun.swg +++ b/wxPython/src/pyrun.swg @@ -10,178 +10,6 @@ #include "Python.h" -#include -#include - -#ifdef __cplusplus -#define SWIG_STATIC_INLINE static inline -#else -#define SWIG_STATIC_INLINE static -#endif - -SWIG_STATIC_INLINE long -SPyObj_AsLong(PyObject * obj) -{ - return PyInt_Check(obj) ? PyInt_AsLong(obj) : PyLong_AsLong(obj); -} - -SWIG_STATIC_INLINE unsigned long -SPyObj_AsUnsignedLong(PyObject * obj) -{ - if (PyLong_Check(obj)) { - return PyLong_AsUnsignedLong(obj); - } else { - long i = PyInt_AsLong(obj); - if ( !PyErr_Occurred() && (i < 0)) { - PyErr_SetString(PyExc_TypeError, "negative value for unsigned type"); - } - return i; - } -} - -#if !defined(_MSC_VER) -SWIG_STATIC_INLINE PyObject* -SPyObj_FromLongLong(long long value) -{ - return (value > (long)(LONG_MAX)) ? - PyLong_FromLongLong(value) : PyInt_FromLong((long)value); -} -#endif - -SWIG_STATIC_INLINE PyObject* -SPyObj_FromUnsignedLong(unsigned long value) -{ - return (value > (unsigned long)(LONG_MAX)) ? - PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)value); -} - -#if !defined(_MSC_VER) -SWIG_STATIC_INLINE PyObject* -SPyObj_FromUnsignedLongLong(unsigned long long value) -{ - return (value > (unsigned long long)(LONG_MAX)) ? - PyLong_FromUnsignedLongLong(value) : PyInt_FromLong((long)value); -} -#endif - -SWIG_STATIC_INLINE long -SPyObj_AsLongInRange(PyObject * obj, long min_value, long max_value) -{ - long value = SPyObj_AsLong(obj); - if (!PyErr_Occurred()) { - if (value < min_value) { - PyErr_SetString(PyExc_OverflowError,"value is smaller than type minimum"); - } else if (value > max_value) { - PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum"); - } - } - return value; -} - -SWIG_STATIC_INLINE unsigned long -SPyObj_AsUnsignedLongInRange(PyObject *obj, unsigned long max_value) -{ - unsigned long value = SPyObj_AsUnsignedLong(obj); - if (!PyErr_Occurred()) { - if (value > max_value) { - PyErr_SetString(PyExc_OverflowError,"value is greater than type maximum"); - } - } - return value; -} - -SWIG_STATIC_INLINE signed char -SPyObj_AsSignedChar(PyObject *obj) { - return (signed char)SPyObj_AsLongInRange(obj, SCHAR_MIN, SCHAR_MAX); -} - -SWIG_STATIC_INLINE short -SPyObj_AsShort(PyObject *obj) { - return (short)SPyObj_AsLongInRange(obj, SHRT_MIN, SHRT_MAX); -} - -SWIG_STATIC_INLINE int -SPyObj_AsInt(PyObject *obj) { - return SPyObj_AsLongInRange(obj, INT_MIN, INT_MAX); -} - -SWIG_STATIC_INLINE unsigned char -SPyObj_AsUnsignedChar(PyObject *obj) { - return (unsigned char)SPyObj_AsUnsignedLongInRange(obj, UCHAR_MAX); -} - -SWIG_STATIC_INLINE unsigned short -SPyObj_AsUnsignedShort(PyObject *obj) { - return (unsigned short)SPyObj_AsUnsignedLongInRange(obj, USHRT_MAX); -} - -SWIG_STATIC_INLINE unsigned int -SPyObj_AsUnsignedInt(PyObject *obj) { - return SPyObj_AsUnsignedLongInRange(obj, UINT_MAX); -} - -#if !defined(_MSC_VER) -SWIG_STATIC_INLINE long long -SPyObj_AsLongLong(PyObject *obj) { - return PyInt_Check(obj) ? - PyInt_AsLong(obj) : PyLong_AsLongLong(obj); -} - -SWIG_STATIC_INLINE unsigned long long -SPyObj_AsUnsignedLongLong(PyObject *obj) { - return PyLong_Check(obj) ? - PyLong_AsUnsignedLongLong(obj) : SPyObj_AsUnsignedLong(obj); -} -#endif - -SWIG_STATIC_INLINE double -SPyObj_AsDouble(PyObject *obj) { - return (PyFloat_Check(obj)) ? PyFloat_AsDouble(obj) : - (double)((PyInt_Check(obj)) ? PyInt_AsLong(obj) : PyLong_AsLongLong(obj)); -} - -SWIG_STATIC_INLINE float -SPyObj_AsFloat(PyObject *obj) { - double value = SPyObj_AsDouble(obj); - if (!PyErr_Occurred()) { - if (value < FLT_MIN) { - PyErr_SetString(PyExc_OverflowError,"float is smaller than flt_min"); - } else if (value > FLT_MAX) { - PyErr_SetString(PyExc_OverflowError,"float is greater than flt_max"); - } - } - return (float) value; -} - -SWIG_STATIC_INLINE char -SPyObj_AsChar(PyObject *obj) { - char c = (PyString_Check(obj) && PyString_Size(obj) == 1) ? - PyString_AsString(obj)[0] - : (char) SPyObj_AsLongInRange(obj, CHAR_MIN, CHAR_MAX); - if (PyErr_Occurred()) { - PyErr_Clear(); - PyErr_SetString(PyExc_TypeError, "a char is required"); - } - return c; -} - -SWIG_STATIC_INLINE PyObject * -SPyObj_FromChar(char c) { - return PyString_FromStringAndSize(&c,1); -} - -SWIG_STATIC_INLINE PyObject * -SPyObj_FromCharPtr(const char* cptr) { - return cptr ? PyString_FromString(cptr) : Py_BuildValue((char*)""); -} - -SWIG_STATIC_INLINE int -SPyObj_AsBool(PyObject *obj) { - return SPyObj_AsLong/*Long*/(obj) ? 1 : 0; -} - - - #ifdef __cplusplus extern "C" { #endif @@ -230,6 +58,7 @@ typedef struct swig_const_info { #define SWIG_InstallConstants(d, constants) \ SWIG_Python_InstallConstants(d, constants) +typedef double (*py_objasdbl_conv)(PyObject *obj); SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int); SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own); @@ -240,6 +69,27 @@ SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, int SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, int sz, swig_type_info *); SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]); +/* ----------------------------------------------------------------------------- + * the needed conversions between C++ and python + * ----------------------------------------------------------------------------- */ +/* basic types */ +/* + utilities +*/ +SWIGIMPORT(char* ) SWIG_PyObj_AsCharPtr(PyObject *obj, swig_type_info* pchar_info); +SWIGIMPORT(PyObject *) SWIG_PyObj_FromCharPtr(const char* cptr); +SWIGIMPORT(unsigned long) SWIG_PyObj_AsUnsignedLong(PyObject * obj); +SWIGIMPORT(long) SWIG_PyObj_AsLongInRange(PyObject * obj, const char* type, + long min_value, long max_value); +SWIGIMPORT(unsigned long) SWIG_PyObj_AsUnsignedLongInRange(PyObject *obj, const char* type, + unsigned long max_value); +SWIGIMPORT(char *) SWIG_PyObj_AsNewCharPtr(PyObject *obj, swig_type_info* pchar_info); +SWIGIMPORT(void) SWIG_PyObj_AsCharPtrAndSize(PyObject *obj, swig_type_info* pchar_info, + char** cptr, size_t* size); +SWIGIMPORT(void) SWIG_PyObj_AsCharArray(PyObject *obj, swig_type_info* pchar_info, + char* carray, size_t size); +SWIGIMPORT(PyObject *) SWIG_PyObj_FromCharArray(const char* carray, size_t size); +SWIGIMPORT(float) SWIG_PyObj_AsFloatConv(PyObject *obj, py_objasdbl_conv pyconv); /* Contract support */ -- 2.47.2