Merge branch 'master' into gsoc2009-matevz

parser.y still to be fixed up

Conflicts:
	Doc/Devel/engineering.html
	Examples/Makefile.in
	Lib/allegrocl/allegrocl.swg
	Lib/csharp/csharp.swg
	Lib/csharp/enums.swg
	Lib/csharp/enumsimple.swg
	Lib/csharp/enumtypesafe.swg
	Lib/java/java.swg
	Lib/python/pydocs.swg
	Lib/r/rtype.swg
	Source/Include/swigwarn.h
	Source/Modules/octave.cxx
	Source/Modules/python.cxx
	Source/Modules/ruby.cxx
	Source/Swig/scanner.c
	Source/Swig/stype.c
	Source/Swig/swig.h
	configure.ac
This commit is contained in:
William S Fulton 2013-01-28 07:01:37 +00:00
commit e805d5f925
1074 changed files with 54339 additions and 20134 deletions

View file

@ -6,6 +6,10 @@
#define SHARED_PTR_DISOWN 0
#endif
%fragment("SWIG_null_deleter_python", "header", fragment="SWIG_null_deleter") {
%#define SWIG_NO_NULL_DELETER_SWIG_BUILTIN_INIT
}
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
@ -75,7 +79,8 @@
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * {
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN));
}
@ -98,7 +103,7 @@
$1 = %const_cast((smartarg ? smartarg->get() : 0), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE * {
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE * {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_0) : 0;
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -119,7 +124,7 @@
$1 = %const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(out, fragment="SWIG_null_deleter") CONST TYPE & {
%typemap(out, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -141,7 +146,7 @@
$1 = *%const_cast(%reinterpret_cast(argp, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)->get(), $1_ltype);
}
}
%typemap(varout, fragment="SWIG_null_deleter") CONST TYPE & {
%typemap(varout, fragment="SWIG_null_deleter_python") CONST TYPE & {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(&$1 SWIG_NO_NULL_DELETER_0);
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -163,7 +168,7 @@
}
$1 = &temp;
}
%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& {
%typemap(out, fragment="SWIG_null_deleter_python") TYPE *CONST& {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner);
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -311,5 +316,7 @@
%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
%enddef

510
Lib/python/builtin.swg Normal file
View file

@ -0,0 +1,510 @@
#define SWIGPY_UNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_DESTRUCTOR_CLOSURE(wrapper) \
SWIGINTERN void \
wrapper##_closure(PyObject *a) { \
SwigPyObject *sobj; \
sobj = (SwigPyObject *)a; \
if (sobj->own) { \
PyObject *o = wrapper(a, NULL); \
Py_XDECREF(o); \
} \
PyObject_Del(a); \
}
#define SWIGPY_INQUIRY_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult; \
int result; \
pyresult = wrapper(a, NULL); \
result = pyresult && PyObject_IsTrue(pyresult) ? 1 : 0; \
Py_XDECREF(pyresult); \
return result; \
}
#define SWIGPY_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
typedef ternaryfunc ternarycallfunc;
#define SWIGPY_TERNARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(b); \
Py_XINCREF(c); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_TERNARYCALLFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *callable_object, PyObject *args, PyObject *) { \
return wrapper(callable_object, args); \
}
#define SWIGPY_LENFUNC_CLOSURE(wrapper) \
SWIGINTERN Py_ssize_t \
wrapper##_closure(PyObject *a) { \
PyObject *resultobj; \
Py_ssize_t result; \
resultobj = wrapper(a, NULL); \
result = PyNumber_AsSsize_t(resultobj, NULL); \
Py_DECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(d ? 3 : 2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
if (d) { \
PyTuple_SET_ITEM(tuple, 2, d); \
Py_INCREF(d); \
} \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_DECREF(tuple); \
Py_XDECREF(resultobj); \
return result; \
}
#define SWIGPY_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *tuple, *result; \
tuple = PyTuple_New(1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
result = wrapper(a, tuple); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a, Py_ssize_t b) { \
PyObject *arg, *result; \
arg = _PyLong_FromSsize_t(b); \
result = wrapper(a, arg); \
Py_DECREF(arg); \
return result; \
}
#define SWIGPY_SSIZEOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, Py_ssize_t b, PyObject *c) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_OBJOBJARGPROC_CLOSURE(wrapper) \
SWIGINTERN int \
wrapper##_closure(PyObject *a, PyObject *b, PyObject *c) { \
PyObject *tuple, *resultobj; \
int result; \
tuple = PyTuple_New(c ? 2 : 1); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, b); \
Py_XINCREF(b); \
if (c) { \
PyTuple_SET_ITEM(tuple, 1, c); \
Py_XINCREF(c); \
} \
resultobj = wrapper(a, tuple); \
result = resultobj ? 0 : -1; \
Py_XDECREF(resultobj); \
Py_DECREF(tuple); \
return result; \
}
#define SWIGPY_REPRFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
return wrapper(a, NULL); \
}
#define SWIGPY_HASHFUNC_CLOSURE(wrapper) \
SWIGINTERN long \
wrapper##_closure(PyObject *a) { \
PyObject *pyresult; \
long result; \
pyresult = wrapper(a, NULL); \
if (!pyresult || !PyLong_Check(pyresult)) \
return -1; \
result = PyLong_AsLong(pyresult); \
Py_DECREF(pyresult); \
return result; \
}
#define SWIGPY_ITERNEXT_CLOSURE(wrapper) \
SWIGINTERN PyObject * \
wrapper##_closure(PyObject *a) { \
PyObject *result; \
result = wrapper(a, NULL); \
if (result && result == Py_None) { \
Py_DECREF(result); \
result = NULL; \
} \
return result; \
}
#ifdef __cplusplus
extern "C" {
#endif
SWIGINTERN int
SwigPyBuiltin_BadInit(PyObject *self, PyObject *SWIGUNUSEDPARM(args), PyObject *SWIGUNUSEDPARM(kwds)) {
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
return -1;
}
SWIGINTERN void
SwigPyBuiltin_BadDealloc(PyObject *pyobj) {
SwigPyObject *sobj;
sobj = (SwigPyObject *)pyobj;
if (sobj->own) {
PyErr_Format(PyExc_TypeError, "Swig detected a memory leak in type '%.300s': no callable destructor found.", pyobj->ob_type->tp_name);
}
}
typedef struct {
PyCFunction get;
PyCFunction set;
} SwigPyGetSet;
SWIGINTERN PyObject *
SwigPyBuiltin_GetterClosure (PyObject *obj, void *closure) {
SwigPyGetSet *getset;
PyObject *tuple, *result;
if (!closure)
return SWIG_Py_Void();
getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
tuple = PyTuple_New(0);
assert(tuple);
result = (*getset->get)(obj, tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject *
SwigPyBuiltin_FunpackGetterClosure (PyObject *obj, void *closure) {
SwigPyGetSet *getset;
PyObject *result;
if (!closure)
return SWIG_Py_Void();
getset = (SwigPyGetSet *)closure;
if (!getset->get)
return SWIG_Py_Void();
result = (*getset->get)(obj, NULL);
return result;
}
SWIGINTERN int
SwigPyBuiltin_SetterClosure (PyObject *obj, PyObject *val, void *closure) {
SwigPyGetSet *getset;
PyObject *tuple, *result;
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
tuple = PyTuple_New(1);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, val);
Py_XINCREF(val);
result = (*getset->set)(obj, tuple);
Py_DECREF(tuple);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN int
SwigPyBuiltin_FunpackSetterClosure (PyObject *obj, PyObject *val, void *closure) {
SwigPyGetSet *getset;
PyObject *result;
if (!closure) {
PyErr_Format(PyExc_TypeError, "Missing getset closure");
return -1;
}
getset = (SwigPyGetSet *)closure;
if (!getset->set) {
PyErr_Format(PyExc_TypeError, "Illegal member variable assignment in type '%.300s'", obj->ob_type->tp_name);
return -1;
}
result = (*getset->set)(obj, val);
Py_XDECREF(result);
return result ? 0 : -1;
}
SWIGINTERN void
SwigPyStaticVar_dealloc(PyDescrObject *descr) {
_PyObject_GC_UNTRACK(descr);
Py_XDECREF(PyDescr_TYPE(descr));
Py_XDECREF(PyDescr_NAME(descr));
PyObject_GC_Del(descr);
}
SWIGINTERN PyObject *
SwigPyStaticVar_repr(PyGetSetDescrObject *descr) {
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromFormat("<class attribute '%S' of type '%s'>", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
return PyString_FromFormat("<class attribute '%s' of type '%s'>", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
}
SWIGINTERN int
SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg) {
PyDescrObject *descr;
descr = (PyDescrObject *)self;
Py_VISIT((PyObject*) PyDescr_TYPE(descr));
return 0;
}
SWIGINTERN PyObject *
SwigPyStaticVar_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *SWIGUNUSEDPARM(type)) {
if (descr->d_getset->get != NULL)
return descr->d_getset->get(obj, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not readable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
return NULL;
}
SWIGINTERN int
SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value) {
if (descr->d_getset->set != NULL)
return descr->d_getset->set(obj, value, descr->d_getset->closure);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "attribute '%.300S' of '%.100s' objects is not writable", PyDescr_NAME(descr), PyDescr_TYPE(descr)->tp_name);
#else
PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", PyString_AsString(PyDescr_NAME(descr)), PyDescr_TYPE(descr)->tp_name);
#endif
return -1;
}
SWIGINTERN int
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) {
PyObject *attribute;
descrsetfunc local_set;
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
local_set = attribute->ob_type->tp_descr_set;
if (local_set != NULL)
return local_set(attribute, (PyObject *)type, value);
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
} else {
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif
}
return -1;
}
SWIGINTERN PyTypeObject*
SwigPyStaticVar_Type(void) {
static PyTypeObject staticvar_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else
PyObject_HEAD_INIT(&PyType_Type)
0,
#endif
"swig_static_var_getset_descriptor",
sizeof(PyGetSetDescrObject),
0,
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)SwigPyStaticVar_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
0, /* tp_doc */
SwigPyStaticVar_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
(descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
};
staticvar_type = tmp;
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
staticvar_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&staticvar_type) < 0)
return NULL;
#endif
}
return &staticvar_type;
}
SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {
PyGetSetDescrObject *descr;
descr = (PyGetSetDescrObject *)PyType_GenericAlloc(SwigPyStaticVar_Type(), 0);
assert(descr);
Py_XINCREF(type);
PyDescr_TYPE(descr) = type;
PyDescr_NAME(descr) = PyString_InternFromString(getset->name);
descr->d_getset = getset;
if (PyDescr_NAME(descr) == NULL) {
Py_DECREF(descr);
descr = NULL;
}
return descr;
}
SWIGINTERN void
SwigPyBuiltin_InitBases (PyTypeObject *type, PyTypeObject **bases) {
int base_count = 0;
PyTypeObject **b;
PyObject *tuple;
int i;
if (!bases[0]) {
bases[0] = SwigPyObject_type();
bases[1] = NULL;
}
type->tp_base = bases[0];
Py_INCREF((PyObject *)bases[0]);
for (b = bases; *b != NULL; ++b)
++base_count;
tuple = PyTuple_New(base_count);
for (i = 0; i < base_count; ++i) {
PyTuple_SET_ITEM(tuple, i, (PyObject *)bases[i]);
Py_INCREF((PyObject *)bases[i]);
}
type->tp_bases = tuple;
}
SWIGINTERN PyObject *
SwigPyBuiltin_ThisClosure (PyObject *self, void *SWIGUNUSEDPARM(closure)) {
PyObject *result;
result = (PyObject *)SWIG_Python_GetSwigThis(self);
Py_XINCREF(result);
return result;
}
SWIGINTERN void
SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
{
#if PY_VERSION_HEX >= 0x03000000
type->ob_base.ob_base.ob_type = metatype;
#else
type->ob_type = metatype;
#endif
}
#ifdef __cplusplus
}
#endif

View file

@ -1,5 +1,49 @@
%define %array_class(TYPE,NAME)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "sq_item", functype="ssizeargfunc") NAME::__getitem__;
%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") NAME::__setitem__;
%inline %{
typedef struct {
TYPE *el;
} NAME;
%}
%extend NAME {
NAME(size_t nelements) {
NAME *arr = %new_instance(NAME);
arr->el = %new_array(nelements, TYPE);
return arr;
}
~NAME() {
%delete_array(self->el);
%delete(self);
}
TYPE __getitem__(size_t index) {
return self->el[index];
}
void __setitem__(size_t index, TYPE value) {
self->el[index] = value;
}
TYPE * cast() {
return self->el;
}
static NAME *frompointer(TYPE *t) {
return %reinterpret_cast(t, NAME *);
}
};
%types(NAME = TYPE);
#else
%array_class_wrap(TYPE,NAME,__getitem__,__setitem__)
#endif
%enddef
%include <typemaps/carrays.swg>

View file

@ -250,7 +250,7 @@ namespace Swig {
std::cerr << "This exception was caught by the SWIG unexpected exception handler." << std::endl
<< "Try using %feature(\"director:except\") to avoid reaching this point." << std::endl
<< std::endl
<< "Exception is being re-thrown, program will like abort/terminate." << std::endl;
<< "Exception is being re-thrown, program will likely abort/terminate." << std::endl;
throw;
}
@ -404,11 +404,11 @@ namespace Swig {
}
/* methods to implement pseudo protected director members */
virtual bool swig_get_inner(const char* /* protected_method_name */) const {
virtual bool swig_get_inner(const char* /* swig_protected_method_name */) const {
return true;
}
virtual void swig_set_inner(const char* /* protected_method_name */, bool /* val */) const {
virtual void swig_set_inner(const char* /* swig_protected_method_name */, bool /* swig_val */) const {
}
/* ownership management */
@ -459,6 +459,18 @@ namespace Swig {
}
return own;
}
template <typename Type>
static PyObject* swig_pyobj_disown(PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args))
{
SwigPyObject *sobj = (SwigPyObject *)pyobj;
sobj->own = 0;
Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<Type *>(sobj->ptr));
if (d)
d->swig_disown();
return PyWeakref_NewProxy(pyobj, NULL);
}
};
#ifdef __THREAD__

View file

@ -4,9 +4,6 @@
#ifdef __cplusplus
extern "C" {
#if 0
} /* cc-mode */
#endif
#endif
/* -----------------------------------------------------------------------------
@ -32,19 +29,19 @@ typedef struct swig_const_info {
* Wrapper of PyInstanceMethod_New() used in Python 3
* It is exported to the generated module, used for -fastproxy
* ----------------------------------------------------------------------------- */
SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *self, PyObject *func)
{
#if PY_VERSION_HEX >= 0x03000000
SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *func)
{
return PyInstanceMethod_New(func);
#else
return NULL;
#endif
}
#else
SWIGRUNTIME PyObject* SWIG_PyInstanceMethod_New(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(func))
{
return NULL;
}
#endif
#ifdef __cplusplus
#if 0
{ /* cc-mode */
#endif
}
#endif

View file

@ -43,6 +43,9 @@ namespace swig {
%apply PyObject * {SwigPtr_PyObject};
%apply PyObject * const& {SwigPtr_PyObject const&};
%typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);";
/* For output */
%typemap(out,noblock=1) SwigPtr_PyObject {
$result = (PyObject *)$1;

View file

@ -4,8 +4,7 @@
* Python sequence <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
* the the mapping between C++ and Python, thanks to the C++
* templates.
* the mapping between C++ and Python, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
@ -14,6 +13,12 @@
%{
#include <iostream>
#if PY_VERSION_HEX >= 0x03020000
# define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
#else
# define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
#endif
%}
@ -99,7 +104,7 @@ namespace swig {
}
}
%fragment("SwigPySequence_Base","header")
%fragment("SwigPySequence_Base","header",fragment="<stddef.h>")
{
%#include <functional>
@ -183,8 +188,9 @@ namespace swig {
}
namespace swig {
template <class Difference>
inline size_t
check_index(ptrdiff_t i, size_t size, bool insert = false) {
check_index(Difference i, size_t size, bool insert = false) {
if ( i < 0 ) {
if ((size_t) (-i) <= size)
return (size_t) (i + size);
@ -193,20 +199,42 @@ namespace swig {
} else if (insert && ((size_t) i == size)) {
return size;
}
throw std::out_of_range("index out of range");
}
inline size_t
slice_index(ptrdiff_t i, size_t size) {
if ( i < 0 ) {
if ((size_t) (-i) <= size) {
return (size_t) (i + size);
template <class Difference>
void
slice_adjust(Difference i, Difference j, Py_ssize_t step, size_t size, Difference &ii, Difference &jj, bool insert = false) {
if (step == 0) {
throw std::invalid_argument("slice step cannot be zero");
} else if (step > 0) {
// Required range: 0 <= i < size, 0 <= j < size
if (i < 0) {
ii = 0;
} else if (i < (Difference)size) {
ii = i;
} else if (insert && (i >= (Difference)size)) {
ii = (Difference)size;
}
if ( j < 0 ) {
jj = 0;
} else {
throw std::out_of_range("index out of range");
jj = (j < (Difference)size) ? j : (Difference)size;
}
} else {
return ( (size_t) i < size ) ? ((size_t) i) : size;
// Required range: -1 <= i < size-1, -1 <= j < size-1
if (i < -1) {
ii = -1;
} else if (i < (Difference) size) {
ii = i;
} else if (i >= (Difference)(size-1)) {
ii = (Difference)(size-1);
}
if (j < -1) {
jj = -1;
} else {
jj = (j < (Difference)size ) ? j : (Difference)(size-1);
}
}
}
@ -228,58 +256,156 @@ namespace swig {
template <class Sequence, class Difference>
inline Sequence*
getslice(const Sequence* self, Difference i, Difference j) {
getslice(const Sequence* self, Difference i, Difference j, Py_ssize_t step) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size);
typename Sequence::size_type jj = swig::slice_index(j, size);
Difference ii = 0;
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj);
if (jj > ii) {
typename Sequence::const_iterator vb = self->begin();
typename Sequence::const_iterator ve = self->begin();
std::advance(vb,ii);
std::advance(ve,jj);
return new Sequence(vb, ve);
if (step > 0) {
typename Sequence::const_iterator sb = self->begin();
typename Sequence::const_iterator se = self->begin();
std::advance(sb,ii);
std::advance(se,jj);
if (step == 1) {
return new Sequence(sb, se);
} else {
Sequence *sequence = new Sequence();
typename Sequence::const_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (Py_ssize_t c=0; c<step && it!=se; ++c)
it++;
}
return sequence;
}
} else {
return new Sequence();
Sequence *sequence = new Sequence();
if (ii > jj) {
typename Sequence::const_reverse_iterator sb = self->rbegin();
typename Sequence::const_reverse_iterator se = self->rbegin();
std::advance(sb,size-ii-1);
std::advance(se,size-jj-1);
typename Sequence::const_reverse_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (Py_ssize_t c=0; c<-step && it!=se; ++c)
it++;
}
}
return sequence;
}
}
template <class Sequence, class Difference, class InputSeq>
inline void
setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) {
setslice(Sequence* self, Difference i, Difference j, Py_ssize_t step, const InputSeq& is = InputSeq()) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size, true);
typename Sequence::size_type jj = swig::slice_index(j, size);
if (jj < ii) jj = ii;
size_t ssize = jj - ii;
if (ssize <= v.size()) {
typename Sequence::iterator sb = self->begin();
typename InputSeq::const_iterator vmid = v.begin();
std::advance(sb,ii);
std::advance(vmid, jj - ii);
self->insert(std::copy(v.begin(), vmid, sb), vmid, v.end());
Difference ii = 0;
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj, true);
if (step > 0) {
if (jj < ii)
jj = ii;
if (step == 1) {
size_t ssize = jj - ii;
if (ssize <= is.size()) {
// expanding/staying the same size
typename Sequence::iterator sb = self->begin();
typename InputSeq::const_iterator isit = is.begin();
std::advance(sb,ii);
std::advance(isit, jj - ii);
self->insert(std::copy(is.begin(), isit, sb), isit, is.end());
} else {
// shrinking
typename Sequence::iterator sb = self->begin();
typename Sequence::iterator se = self->begin();
std::advance(sb,ii);
std::advance(se,jj);
self->erase(sb,se);
sb = self->begin();
std::advance(sb,ii);
self->insert(sb, is.begin(), is.end());
}
} else {
size_t replacecount = (jj - ii + step - 1) / step;
if (is.size() != replacecount) {
char msg[1024];
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
throw std::invalid_argument(msg);
}
typename Sequence::const_iterator isit = is.begin();
typename Sequence::iterator it = self->begin();
std::advance(it,ii);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(step-1); ++c)
it++;
}
}
} else {
typename Sequence::iterator sb = self->begin();
typename Sequence::iterator se = self->begin();
std::advance(sb,ii);
std::advance(se,jj);
self->erase(sb,se);
self->insert(sb, v.begin(), v.end());
if (jj > ii)
jj = ii;
size_t replacecount = (ii - jj - step - 1) / -step;
if (is.size() != replacecount) {
char msg[1024];
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
throw std::invalid_argument(msg);
}
typename Sequence::const_iterator isit = is.begin();
typename Sequence::reverse_iterator it = self->rbegin();
std::advance(it,size-ii-1);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(-step-1); ++c)
it++;
}
}
}
template <class Sequence, class Difference>
inline void
delslice(Sequence* self, Difference i, Difference j) {
delslice(Sequence* self, Difference i, Difference j, Py_ssize_t step) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size, true);
typename Sequence::size_type jj = swig::slice_index(j, size);
if (jj > ii) {
typename Sequence::iterator sb = self->begin();
typename Sequence::iterator se = self->begin();
std::advance(sb,ii);
std::advance(se,jj);
self->erase(sb,se);
Difference ii = 0;
Difference jj = 0;
swig::slice_adjust(i, j, step, size, ii, jj, true);
if (step > 0) {
if (jj > ii) {
typename Sequence::iterator sb = self->begin();
std::advance(sb,ii);
if (step == 1) {
typename Sequence::iterator se = self->begin();
std::advance(se,jj);
self->erase(sb,se);
} else {
typename Sequence::iterator it = sb;
size_t delcount = (jj - ii + step - 1) / step;
while (delcount) {
it = self->erase(it);
if (it==self->end())
break;
for (Py_ssize_t c=0; c<(step-1); ++c)
it++;
delcount--;
}
}
}
} else {
if (ii > jj) {
typename Sequence::reverse_iterator sb = self->rbegin();
std::advance(sb,size-ii-1);
typename Sequence::reverse_iterator it = sb;
size_t delcount = (ii - jj - step - 1) / -step;
while (delcount) {
self->erase((++it).base());
if (it==self->rend())
break;
for (Py_ssize_t c=0; c<(-step-1); ++c)
it++;
delcount--;
}
}
}
}
}
@ -587,18 +713,31 @@ namespace swig
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%pythoncode {def __iter__(self): return self.iterator()}
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "tp_iter", functype="getiterfunc") iterator;
#else
%pythoncode {def __iter__(self): return self.iterator()}
#endif
}
#endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef
/**** The python container methods ****/
%define %swig_container_methods(Container...)
/* deprecated in Python 2 */
#if 1
%newobject __getslice__;
#endif
%newobject __getitem__(PySliceObject *slice);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "nb_nonzero", functype="inquiry") __nonzero__;
%feature("python:slot", "sq_length", functype="lenfunc") __len__;
#endif // SWIGPYTHON_BUILTIN
%extend {
bool __nonzero__() const {
@ -614,14 +753,26 @@ namespace swig
return self->size();
}
}
%enddef
%define %swig_sequence_methods_common(Sequence...)
%swig_sequence_iterator(%arg(Sequence))
%swig_container_methods(%arg(Sequence))
%fragment("SwigPySequence_Base");
#if defined(SWIGPYTHON_BUILTIN)
//%feature("python:slot", "sq_item", functype="ssizeargfunc") __getitem__;
//%feature("python:slot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
//%feature("python:slot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
//%feature("python:slot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif // SWIGPYTHON_BUILTIN
%extend {
value_type pop() throw (std::out_of_range) {
if (self->size() == 0)
@ -633,24 +784,29 @@ namespace swig
/* typemap for slice object support */
%typemap(in) PySliceObject* {
if (!PySlice_Check($input)) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
}
$1 = (PySliceObject *) $input;
}
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
$1 = PySlice_Check($input);
}
Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range) {
return swig::getslice(self, i, j);
/* deprecated in Python 2 */
#if 1
Sequence* __getslice__(difference_type i, difference_type j) throw (std::out_of_range, std::invalid_argument) {
return swig::getslice(self, i, j, 1);
}
void __setslice__(difference_type i, difference_type j, const Sequence& v)
throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v);
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence()) throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, 1, v);
}
void __delslice__(difference_type i, difference_type j) throw (std::out_of_range) {
swig::delslice(self, i, j);
void __delslice__(difference_type i, difference_type j) throw (std::out_of_range, std::invalid_argument) {
swig::delslice(self, i, j, 1);
}
#endif
void __delitem__(difference_type i) throw (std::out_of_range) {
self->erase(swig::getpos(self,i));
@ -660,39 +816,56 @@ namespace swig
/* Overloaded methods for Python 3 compatibility
* (Also useful in Python 2.x)
*/
Sequence* __getitem__(PySliceObject *slice) throw (std::out_of_range) {
Sequence* __getitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return NULL;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
return swig::getslice(self, i, j);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
return swig::getslice(self, id, jd, step);
}
void __setitem__(PySliceObject *slice, const Sequence& v)
throw (std::out_of_range, std::invalid_argument) {
void __setitem__(PySliceObject *slice, const Sequence& v) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
swig::setslice(self, i, j, v);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::setslice(self, id, jd, step, v);
}
void __delitem__(PySliceObject *slice)
throw (std::out_of_range) {
void __setitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
swig::delslice(self, i,j);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::delslice(self, id, jd, step);
}
void __delitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::delslice(self, id, jd, step);
}
}
%enddef
%define %swig_sequence_methods(Sequence...)
@ -710,6 +883,7 @@ namespace swig
self->push_back(x);
}
}
%enddef
%define %swig_sequence_methods_val(Sequence...)
@ -727,6 +901,7 @@ namespace swig
self->push_back(x);
}
}
%enddef

View file

@ -1,20 +1,24 @@
// basic doc for primitive types....
// Documentation for use with the autodoc feature.
#ifdef SWIG_DOC_DOXYGEN_STYLE
%typemap(doc) SWIGTYPE "@param $1_name $1_type value";
%typemap(doc) SWIGTYPE * "@param $1_name $1_type value";
%typemap(doc) const SWIGTYPE & "@param $1_name $1_type value";
%typemap(doc) const SWIGTYPE && "@param $1_name $1_type value";
%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type value";
#else
%typemap(doc) SWIGTYPE "$1_name: $1_type value";
%typemap(doc) SWIGTYPE * "$1_name: $1_type value";
%typemap(doc) const SWIGTYPE & "$1_name: $1_type value";
%typemap(doc) const SWIGTYPE && "$1_name: $1_type value";
%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type value";
%typemap(doc) SWIGTYPE "@param $1_name $1_type";
%typemap(doc) SWIGTYPE * "@param $1_name $1_type";
%typemap(doc) const SWIGTYPE & "@param $1_name $1_type";
%typemap(doc) const SWIGTYPE && "@param $1_name $1_type";
%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type";
%typemap(doc) SWIGTYPE *INOUT "$1_name: $1_type input/ouput value";
%typemap(doc) SWIGTYPE *INPUT "$1_name: $1_type input value";
%typemap(doc) SWIGTYPE *OUTPUT "$1_name: $1_type output value";
%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "@param $1_name $1_type (input/output)";
%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "@param $1_name $1_type (input)";
%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "@param $1_name $1_type (output)";
#else
%typemap(doc) SWIGTYPE "$1_name: $1_type";
%typemap(doc) SWIGTYPE * "$1_name: $1_type";
%typemap(doc) const SWIGTYPE & "$1_name: $1_type";
%typemap(doc) const SWIGTYPE && "$1_name: $1_type";
%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type";
%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "$1_name: $1_type (input/output)";
%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "$1_name: $1_type (input)";
%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "$1_name: $1_type (output)";
#endif

View file

@ -5,7 +5,16 @@
#define PyInt_Check(x) PyLong_Check(x)
#define PyInt_AsLong(x) PyLong_AsLong(x)
#define PyInt_FromLong(x) PyLong_FromLong(x)
#define PyInt_FromSize_t(x) PyLong_FromSize_t(x)
#define PyString_Check(name) PyBytes_Check(name)
#define PyString_FromString(x) PyUnicode_FromString(x)
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
#define PyString_AsString(str) PyBytes_AsString(str)
#define PyString_Size(str) PyBytes_Size(str)
#define PyString_InternFromString(key) PyUnicode_InternFromString(key)
#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
#endif
@ -145,4 +154,65 @@ PyObject *PyBool_FromLong(long ok)
typedef int Py_ssize_t;
# define PY_SSIZE_T_MAX INT_MAX
# define PY_SSIZE_T_MIN INT_MIN
typedef inquiry lenfunc;
typedef intargfunc ssizeargfunc;
typedef intintargfunc ssizessizeargfunc;
typedef intobjargproc ssizeobjargproc;
typedef intintobjargproc ssizessizeobjargproc;
typedef getreadbufferproc readbufferproc;
typedef getwritebufferproc writebufferproc;
typedef getsegcountproc segcountproc;
typedef getcharbufferproc charbufferproc;
static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc))
{
long result = 0;
PyObject *i = PyNumber_Int(x);
if (i) {
result = PyInt_AsLong(i);
Py_DECREF(i);
}
return result;
}
#endif
#if PY_VERSION_HEX < 0x02050000
#define PyInt_FromSize_t(x) PyInt_FromLong((long)x)
#endif
#if PY_VERSION_HEX < 0x02040000
#define Py_VISIT(op) \
do { \
if (op) { \
int vret = visit((op), arg); \
if (vret) \
return vret; \
} \
} while (0)
#endif
#if PY_VERSION_HEX < 0x02030000
typedef struct {
PyTypeObject type;
PyNumberMethods as_number;
PyMappingMethods as_mapping;
PySequenceMethods as_sequence;
PyBufferProcs as_buffer;
PyObject *name, *slots;
} PyHeapTypeObject;
#endif
#if PY_VERSION_HEX < 0x02030000
typedef destructor freefunc;
#endif
#if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \
(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \
(PY_MAJOR_VERSION > 3))
# define SWIGPY_USE_CAPSULE
# define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
#endif
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
#endif

View file

@ -138,24 +138,23 @@ SWIGINTERN PyTypeObject*
swig_varlink_type(void) {
static char varlink__doc__[] = "Swig var link object";
static PyTypeObject varlink_type;
static int type_init = 0;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp
= {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0)
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
0, /* Number of items in variable part (ob_size) */
0, /* ob_size */
#endif
(char *)"swigvarlink", /* Type name (tp_name) */
sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */
0, /* Itemsize (tp_itemsize) */
(destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */
(printfunc) swig_varlink_print, /* Print (tp_print) */
(getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */
(setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */
(char *)"swigvarlink", /* tp_name */
sizeof(swig_varlinkobject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor) swig_varlink_dealloc, /* tp_dealloc */
(printfunc) swig_varlink_print, /* tp_print */
(getattrfunc) swig_varlink_getattr, /* tp_getattr */
(setattrfunc) swig_varlink_setattr, /* tp_setattr */
0, /* tp_compare */
(reprfunc) swig_varlink_repr, /* tp_repr */
0, /* tp_as_number */
@ -179,16 +178,21 @@ swig_varlink_type(void) {
#if PY_VERSION_HEX >= 0x02030000
0, /* tp_del */
#endif
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version */
#endif
#ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */
#endif
};
varlink_type = tmp;
/* for Python 3 we already assigned ob_type in PyVarObject_HEAD_INIT() */
#if PY_VERSION_HEX < 0x03000000
varlink_type.ob_type = &PyType_Type;
#endif
type_init = 1;
#if PY_VERSION_HEX < 0x02020000
varlink_type.ob_type = &PyType_Type;
#else
if (PyType_Ready(&varlink_type) < 0)
return NULL;
#endif
}
return &varlink_type;
}
@ -239,7 +243,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
for (i = 0; constants[i].type; ++i) {
switch(constants[i].type) {
case SWIG_PY_POINTER:
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
obj = SWIG_InternalNewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
break;
case SWIG_PY_BINARY:
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
@ -320,10 +324,19 @@ SWIGEXPORT
void
#endif
SWIG_init(void) {
PyObject *m, *d;
PyObject *m, *d, *md;
#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef SWIG_module = {
# if PY_VERSION_HEX >= 0x03020000
PyModuleDef_HEAD_INIT,
# else
{
PyObject_HEAD_INIT(NULL)
NULL, /* m_init */
0, /* m_index */
NULL, /* m_copy */
},
# endif
(char *) SWIG_name,
NULL,
-1,
@ -335,6 +348,47 @@ SWIG_init(void) {
};
#endif
#if defined(SWIGPYTHON_BUILTIN)
static SwigPyClientData SwigPyObject_clientdata = {0, 0, 0, 0, 0, 0, 0};
static PyGetSetDef this_getset_def = {
(char *)"this", &SwigPyBuiltin_ThisClosure, NULL, NULL, NULL
};
static SwigPyGetSet thisown_getset_closure = {
(PyCFunction) SwigPyObject_own,
(PyCFunction) SwigPyObject_own
};
static PyGetSetDef thisown_getset_def = {
(char *)"thisown", SwigPyBuiltin_GetterClosure, SwigPyBuiltin_SetterClosure, NULL, &thisown_getset_closure
};
PyObject *metatype_args;
PyTypeObject *builtin_pytype;
int builtin_base_count;
swig_type_info *builtin_basetype;
PyObject *tuple;
PyGetSetDescrObject *static_getset;
PyTypeObject *metatype;
SwigPyClientData *cd;
PyObject *public_interface, *public_symbol;
PyObject *this_descr;
PyObject *thisown_descr;
int i;
(void)builtin_pytype;
(void)builtin_base_count;
(void)builtin_basetype;
(void)tuple;
(void)static_getset;
/* metatype is used to implement static member variables. */
metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
assert(metatype_args);
metatype = (PyTypeObject *) PyType_Type.tp_call((PyObject *) &PyType_Type, metatype_args, NULL);
assert(metatype);
Py_DECREF(metatype_args);
metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
assert(PyType_Ready(metatype) >= 0);
#endif
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
@ -343,10 +397,47 @@ SWIG_init(void) {
#else
m = Py_InitModule((char *) SWIG_name, SwigMethods);
#endif
d = PyModule_GetDict(m);
md = d = PyModule_GetDict(m);
(void)md;
SWIG_InitializeModule(0);
#ifdef SWIGPYTHON_BUILTIN
SwigPyObject_stype = SWIG_MangledTypeQuery("_p_SwigPyObject");
assert(SwigPyObject_stype);
cd = (SwigPyClientData*) SwigPyObject_stype->clientdata;
if (!cd) {
SwigPyObject_stype->clientdata = &SwigPyObject_clientdata;
SwigPyObject_clientdata.pytype = SwigPyObject_TypeOnce();
} else if (SwigPyObject_TypeOnce()->tp_basicsize != cd->pytype->tp_basicsize) {
PyErr_SetString(PyExc_RuntimeError, "Import error: attempted to load two incompatible swig-generated modules.");
# if PY_VERSION_HEX >= 0x03000000
return NULL;
# else
return;
# endif
}
/* All objects have a 'this' attribute */
this_descr = PyDescr_NewGetSet(SwigPyObject_type(), &this_getset_def);
(void)this_descr;
/* All objects have a 'thisown' attribute */
thisown_descr = PyDescr_NewGetSet(SwigPyObject_type(), &thisown_getset_def);
(void)thisown_descr;
public_interface = PyList_New(0);
public_symbol = 0;
(void)public_symbol;
PyDict_SetItemString(md, "__all__", public_interface);
Py_DECREF(public_interface);
for (i = 0; SwigMethods[i].ml_name != NULL; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, SwigMethods[i].ml_name);
for (i = 0; swig_const_table[i].name != 0; ++i)
SwigPyBuiltin_AddPublicSymbol(public_interface, swig_const_table[i].name);
#endif
SWIG_InstallConstants(d,swig_const_table);
%}

View file

@ -11,7 +11,7 @@
%include <std_common.i>
%fragment("SwigPyIterator","header") {
%fragment("SwigPyIterator","header",fragment="<stddef.h>") {
namespace swig {
struct stop_iteration {
};
@ -128,10 +128,18 @@ namespace swig {
return desc;
}
};
%#if defined(SWIGPYTHON_BUILTIN)
inline PyObject* make_output_iterator_builtin (PyObject *pyself)
{
Py_INCREF(pyself);
return pyself;
}
%#endif
}
}
%fragment("SwigPyIterator_T","header",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
%fragment("SwigPyIterator_T","header",fragment="<stddef.h>",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
template<typename OutIterator>
class SwigPyIterator_T : public SwigPyIterator
@ -302,6 +310,7 @@ namespace swig {
{
return new SwigPyIteratorOpen_T<OutIter>(current, seq);
}
}
}
@ -329,9 +338,15 @@ namespace swig
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
%nodirector SwigPyIterator;
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
%feature("python:slot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
#else
%extend SwigPyIterator {
%pythoncode {def __iter__(self): return self}
}
#endif
%catches(swig::stop_iteration) SwigPyIterator::value() const;
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
@ -347,7 +362,6 @@ namespace swig
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
struct SwigPyIterator
{
protected:

View file

@ -20,8 +20,8 @@
* However, this file may be removed in future release of SWIG, so using this file to
* keep these inappropriate names in your SWIG interface file is also not recommended.
* Instead, we provide a simple tool for converting your interface files to
* the new naming convention. You can download the tool here:
* https://swig.svn.sourceforge.net/svnroot/swig/trunk/Tools/pyname_patch.py
* the new naming convention. You can get the tool from the SWIG distribution:
* Tools/pyname_patch.py
*/
%fragment("PySequence_Base", "header", fragment="SwigPySequence_Base") {}

View file

@ -1,45 +1,140 @@
/* ------------------------------------------------------------
* Overloaded operator support
The directives in this file apply whether or not you use the
-builtin option to SWIG, but operator overloads are particularly
attractive when using -builtin, because they are much faster
than named methods.
If you're using the -builtin option to SWIG, and you want to define
python operator overloads beyond the defaults defined in this file,
here's what you need to know:
There are two ways to define a python slot function: dispatch to a
statically defined function; or dispatch to a method defined on the
operand.
To dispatch to a statically defined function, use %feature("python:<slot>"),
where <slot> is the name of a field in a PyTypeObject, PyNumberMethods,
PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example:
%{
static long myHashFunc (PyObject *pyobj) {
MyClass *cobj;
// Convert pyobj to cobj
return (cobj->field1 * (cobj->field2 << 7));
}
%}
%feature("python:tp_hash") MyClass "myHashFunc";
NOTE: It is the responsibility of the programmer (that's you) to ensure
that a statically defined slot function has the correct signature.
If, instead, you want to dispatch to an instance method, you can
use %feature("python:slot"). For example:
class MyClass {
public:
long myHashFunc () const;
...
};
%feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc;
NOTE: Some python slots use a method signature which does not
match the signature of SWIG-wrapped methods. For those slots,
SWIG will automatically generate a "closure" function to re-marshall
the arguments before dispatching to the wrapped method. Setting
the "functype" attribute of the feature enables SWIG to generate
a correct closure function.
--------------------------------------------------------------
The tp_richcompare slot is a special case: SWIG automatically generates
a rich compare function for all wrapped types. If a type defines C++
operator overloads for comparison (operator==, operator<, etc.), they
will be called from the generated rich compare function. If you
want to explicitly choose a method to handle a certain comparison
operation, you may use %feature("python:slot") like this:
class MyClass {
public:
bool lessThan (const MyClass& x) const;
...
};
%feature("python:slot", "Py_LT") MyClass::lessThan;
... where "Py_LT" is one of the rich comparison opcodes defined in the
python header file object.h.
If there's no method defined to handle a particular comparsion operation,
the default behavior is to compare pointer values of the wrapped
C++ objects.
--------------------------------------------------------------
For more information about python slots, including their names and
signatures, you may refer to the python documentation :
http://docs.python.org/c-api/typeobj.html
* ------------------------------------------------------------ */
#ifdef __cplusplus
#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
%pybinoperator(__add__, *::operator+);
%pybinoperator(__pos__, *::operator+());
%pybinoperator(__pos__, *::operator+() const);
%pybinoperator(__sub__, *::operator-);
%pybinoperator(__neg__, *::operator-());
%pybinoperator(__neg__, *::operator-() const);
%pybinoperator(__mul__, *::operator*);
%pybinoperator(__div__, *::operator/);
%pybinoperator(__mod__, *::operator%);
%pybinoperator(__lshift__, *::operator<<);
%pybinoperator(__rshift__, *::operator>>);
%pybinoperator(__and__, *::operator&);
%pybinoperator(__or__, *::operator|);
%pybinoperator(__xor__, *::operator^);
%pybinoperator(__lt__, *::operator<);
%pybinoperator(__le__, *::operator<=);
%pybinoperator(__gt__, *::operator>);
%pybinoperator(__ge__, *::operator>=);
%pybinoperator(__eq__, *::operator==);
%pybinoperator(__ne__, *::operator!=);
#if defined(SWIGPYTHON_BUILTIN)
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:slot", #slt, functype=#functp) oper; %feature("python:slot", #slt, functype=#functp) pyname;
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:compare", #comptype) oper; %feature("python:compare", #comptype) pyname;
#else
#define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
#endif
%pybinoperator(__add__, *::operator+, binaryfunc, nb_add);
%pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive);
%pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive);
%pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract);
%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
%pybinoperator(__div__, *::operator/, binaryfunc, nb_div);
%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
%pybinoperator(__and__, *::operator&, binaryfunc, nb_and);
%pybinoperator(__or__, *::operator|, binaryfunc, nb_or);
%pybinoperator(__xor__, *::operator^, binaryfunc, nb_xor);
%pycompare(__lt__, *::operator<, Py_LT);
%pycompare(__le__, *::operator<=, Py_LE);
%pycompare(__gt__, *::operator>, Py_GT);
%pycompare(__ge__, *::operator>=, Py_GE);
%pycompare(__eq__, *::operator==, Py_EQ);
%pycompare(__ne__, *::operator!=, Py_NE);
%feature("python:slot", "nb_truediv", functype="binaryfunc") *::operator/;
/* Special cases */
%rename(__invert__) *::operator~;
%feature("python:slot", "nb_invert", functype="unaryfunc") *::operator~;
%rename(__call__) *::operator();
%feature("python:slot", "tp_call", functype="ternarycallfunc") *::operator();
#if defined(SWIGPYTHON_BUILTIN)
%pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero);
#else
%feature("shadow") *::operator bool %{
def __nonzero__(self):
return $action(self)
__bool__ = __nonzero__
%};
%rename(__nonzero__) *::operator bool;
#endif
/* Ignored operators */
%ignoreoperator(LNOT) operator!;
@ -90,18 +185,22 @@ __bool__ = __nonzero__
*/
#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#if defined(SWIGPYTHON_BUILTIN)
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %feature("python:slot", #slt, functype=#functp) Oper; %rename(SwigPyOper) Oper
#else
#define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#endif
%pyinplaceoper(__iadd__ , *::operator +=);
%pyinplaceoper(__isub__ , *::operator -=);
%pyinplaceoper(__imul__ , *::operator *=);
%pyinplaceoper(__idiv__ , *::operator /=);
%pyinplaceoper(__imod__ , *::operator %=);
%pyinplaceoper(__iand__ , *::operator &=);
%pyinplaceoper(__ior__ , *::operator |=);
%pyinplaceoper(__ixor__ , *::operator ^=);
%pyinplaceoper(__ilshift__, *::operator <<=);
%pyinplaceoper(__irshift__, *::operator >>=);
%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
%pyinplaceoper(__idiv__ , *::operator /=, binaryfunc, nb_inplace_divide);
%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
%pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor);
%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
/* Finally, in python we need to mark the binary operations to fail as

View file

@ -25,10 +25,30 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
}
}
/* int */
%fragment(SWIG_From_frag(int),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(int)(int value)
{
return PyInt_FromLong((long) value);
}
}
/* unsigned int */
%fragment(SWIG_From_frag(unsigned int),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned int)(unsigned int value)
{
return PyInt_FromSize_t((size_t) value);
}
}
/* long */
%fragment(SWIG_From_frag(long),"header") {
%define_as(SWIG_From_dec(long), PyInt_FromLong)
%define_as(SWIG_From_dec(long), PyLong_FromLong)
}
%fragment(SWIG_AsVal_frag(long),"header",
@ -80,7 +100,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long)(unsigned long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long));
PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long));
}
}
@ -89,6 +109,7 @@ SWIG_From_dec(unsigned long)(unsigned long value)
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
{
%#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj)) {
long v = PyInt_AsLong(obj);
if (v >= 0) {
@ -97,7 +118,9 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
} else {
return SWIG_OverflowError;
}
} else if (PyLong_Check(obj)) {
} else
%#endif
if (PyLong_Check(obj)) {
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;
@ -139,7 +162,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(long long)(long long value)
{
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long));
}
}
@ -193,7 +216,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long));
}
}

File diff suppressed because it is too large Load diff

View file

@ -11,3 +11,6 @@
%insert(runtime) "pyapi.swg"; /* Python API */
%insert(runtime) "pyrun.swg"; /* Python run-time code */
#if defined(SWIGPYTHON_BUILTIN)
%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */
#endif

View file

@ -6,7 +6,7 @@ namespace swig {
*/
template <class Type> struct traits_from_ptr {
static PyObject *from(Type *val, int owner = 0) {
return SWIG_NewPointerObj(val, type_info<Type>(), owner);
return SWIG_InternalNewPointerObj(val, type_info<Type>(), owner);
}
};

View file

@ -86,7 +86,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
if (size > INT_MAX) {
swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
return pchar_descriptor ?
SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
} else {
%#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));

View file

@ -3,7 +3,7 @@
*/
#define PYTHONKW(x) %keywordwarn("'" `x` "' is a python keyword, renaming to '_" `x` "'", rename="_%s") `x`
#define PYTHONBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in python") "::"`x`
#define PYTHONBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in python") `x`
/*
@ -105,7 +105,6 @@ PYTHONBN(setattr);
PYTHONBN(slice);
PYTHONBN(sorted);
PYTHONBN(staticmethod);
PYTHONBN(staticmethod);
PYTHONBN(str);
PYTHONBN(sum);
PYTHONBN(super);
@ -124,7 +123,8 @@ PYTHONBN(zip);
*/
PYTHONBN(True);
PYTHONBN(False);
PYTHONBN(None);
PYTHONKW(None);
/*

View file

@ -51,7 +51,11 @@
#define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj)
/* set constant */
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
#if defined(SWIGPYTHON_BUILTIN)
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, name,obj)
#else
#define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
#endif
/* raise */
#define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc)
@ -95,4 +99,3 @@
}
}

View file

@ -2,6 +2,14 @@
* utility methods for wchar_t strings
* ------------------------------------------------------------ */
%{
#if PY_VERSION_HEX >= 0x03020000
# define SWIGPY_UNICODE_ARG(obj) ((PyObject*) (obj))
#else
# define SWIGPY_UNICODE_ARG(obj) ((PyUnicodeObject*) (obj))
#endif
%}
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") {
SWIGINTERN int
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
@ -20,7 +28,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
Py_ssize_t len = PyUnicode_GetSize(obj);
if (cptr) {
*cptr = %new_array(len + 1, wchar_t);
PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len);
PyUnicode_AsWideChar(SWIGPY_UNICODE_ARG(obj), *cptr, len);
(*cptr)[len] = 0;
}
if (psize) *psize = (size_t) len + 1;
@ -50,7 +58,7 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
if (size > INT_MAX) {
swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor();
return pwchar_descriptor ?
SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
SWIG_InternalNewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : SWIG_Py_Void();
} else {
return PyUnicode_FromWideChar(carray, %numeric_cast(size,int));
}

View file

@ -33,6 +33,36 @@ namespace swig {
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(PyObject *obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static PyObject *from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>

View file

@ -5,19 +5,19 @@
%fragment("StdMapTraits","header",fragment="StdSequenceTraits")
{
namespace swig {
template <class SwigPySeq, class K, class T >
template <class SwigPySeq, class K, class T, class Compare, class Alloc >
inline void
assign(const SwigPySeq& swigpyseq, std::map<K,T > *map) {
typedef typename std::map<K,T>::value_type value_type;
assign(const SwigPySeq& swigpyseq, std::map<K,T,Compare,Alloc > *map) {
typedef typename std::map<K,T,Compare,Alloc >::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
map->insert(value_type(it->first, it->second));
}
}
template <class K, class T>
struct traits_asptr<std::map<K,T> > {
typedef std::map<K,T> map_type;
template <class K, class T, class Compare, class Alloc>
struct traits_asptr<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
static int asptr(PyObject *obj, map_type **val) {
int res = SWIG_ERROR;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
@ -27,7 +27,7 @@
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
res = traits_asptr_stdseq<map_type, std::pair<K, T> >::asptr(items, val);
} else {
map_type *p;
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
@ -38,34 +38,38 @@
}
};
template <class K, class T >
struct traits_from<std::map<K,T> > {
typedef std::map<K,T> map_type;
template <class K, class T, class Compare, class Alloc >
struct traits_from<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
typedef typename map_type::const_iterator const_iterator;
typedef typename map_type::size_type size_type;
static PyObject *asdict(const map_type& map) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
SWIG_PYTHON_THREAD_END_BLOCK;
return obj;
}
static PyObject *from(const map_type& map) {
swig_type_info *desc = swig::type_info<map_type>();
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
return SWIG_InternalNewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
} else {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
if (pysize < 0) {
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
return NULL;
}
PyObject *obj = PyDict_New();
for (const_iterator i= map.begin(); i!= map.end(); ++i) {
swig::SwigVar_PyObject key = swig::from(i->first);
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
SWIG_PYTHON_THREAD_END_BLOCK;
return obj;
return asdict(map);
}
}
};
@ -136,6 +140,7 @@
{
return new SwigPyMapValueITerator_T<OutIter>(current, begin, end, seq);
}
}
}
@ -143,15 +148,46 @@
%swig_sequence_iterator(Map);
%swig_container_methods(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_length", functype="lenfunc") __len__;
%feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__;
%feature("python:slot", "tp_iter", functype="getiterfunc") key_iterator;
%extend {
mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
%newobject iterkeys(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject itervalues(PyObject **PYTHON_SELF);
swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%newobject iteritems(PyObject **PYTHON_SELF);
swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
}
#else
%extend {
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
}
#endif
%extend {
mapped_type const & __getitem__(const key_type& key) throw (std::out_of_range) {
Map::const_iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::iterator i = self->find(key);
if (i != self->end())
@ -236,21 +272,33 @@
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
%pythoncode {def __iter__(self): return self.key_iterator()}
%pythoncode {def iterkeys(self): return self.key_iterator()}
%pythoncode {def itervalues(self): return self.value_iterator()}
%pythoncode {def iteritems(self): return self.iterator()}
}
%enddef
%define %swig_map_methods(Map...)
%swig_map_common(Map)
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
#endif
%extend {
// This will be called through the mp_ass_subscript slot to delete an entry.
void __setitem__(const key_type& key) {
self->erase(key);
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x;
}
PyObject* asdict() {
return swig::traits_from< Map >::asdict(*self);
}
}
%enddef

View file

@ -42,7 +42,7 @@
static PyObject *from(const multimap_type& multimap) {
swig_type_info *desc = swig::type_info<multimap_type>();
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
return SWIG_InternalNewPointerObj(new multimap_type(multimap), desc, SWIG_POINTER_OWN);
} else {
size_type size = multimap.size();
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;

View file

@ -116,9 +116,65 @@
}
};
}
#if defined(SWIGPYTHON_BUILTIN)
SWIGINTERN Py_ssize_t
SwigPython_std_pair_len (PyObject *a)
{
return 2;
}
SWIGINTERN PyObject*
SwigPython_std_pair_repr (PyObject *o)
{
PyObject *tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttrString(o, (char*) "first"));
PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttrString(o, (char*) "second"));
PyObject *result = PyObject_Repr(tuple);
Py_DECREF(tuple);
return result;
}
SWIGINTERN PyObject*
SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b)
{
PyObject *result = PyObject_GetAttrString(a, b % 2 ? (char*) "second" : (char*) "first");
return result;
}
SWIGINTERN int
SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
{
int result = PyObject_SetAttrString(a, b % 2 ? (char*) "second" : (char*) "first", c);
return result;
}
#endif
}
%feature("python:sq_length") std::pair "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T,U*> "SwigPython_std_pair_len";
%feature("python:sq_length") std::pair<T*,U*> "SwigPython_std_pair_len";
%feature("python:tp_repr") std::pair "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T,U*> "SwigPython_std_pair_repr";
%feature("python:tp_repr") std::pair<T*,U*> "SwigPython_std_pair_repr";
%feature("python:sq_item") std::pair "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_item") std::pair<T*,U*> "SwigPython_std_pair_getitem";
%feature("python:sq_ass_item") std::pair "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T,U*> "SwigPython_std_pair_setitem";
%feature("python:sq_ass_item") std::pair<T*,U*> "SwigPython_std_pair_setitem";
%define %swig_pair_methods(pair...)
#if !defined(SWIGPYTHON_BUILTIN)
%extend {
%pythoncode {def __len__(self): return 2
def __repr__(self): return str((self.first, self.second))
@ -133,6 +189,7 @@ def __setitem__(self, index, val):
else:
self.second = val}
}
#endif
%enddef
%include <std/std_pair.i>

View file

@ -49,6 +49,14 @@
return *(swig::cgetpos(self, i));
}
void add(value_type x) {
self->insert(x);
}
void discard(value_type x) {
self->erase(x);
}
};
%enddef