aboutsummaryrefslogtreecommitdiff
path: root/Lib/python
diff options
context:
space:
mode:
authorAlistair Delva <adelva@google.com>2024-04-10 14:15:29 -0700
committerAlistair Delva <adelva@google.com>2024-04-11 12:58:28 -0700
commitd0f0f90be16c2ac553b5fa08512045273135147a (patch)
tree5d9ebb7a04807ea8a609ddd18b0162bc87530e4b /Lib/python
parent6ffc1dbf29ba98c4d8aa71ebc9b484e973fe1030 (diff)
downloadswig-master.tar.gz
Update to v4.2.1HEADmastermain
Change-Id: I47cef2be94299220d80265d949a95b58eee2c23b
Diffstat (limited to 'Lib/python')
-rw-r--r--Lib/python/README1
-rw-r--r--Lib/python/argcargv.i17
-rw-r--r--Lib/python/boost_shared_ptr.i6
-rw-r--r--Lib/python/builtin.swg52
-rw-r--r--Lib/python/carrays.i4
-rw-r--r--Lib/python/ccomplex.i13
-rw-r--r--Lib/python/defarg.swg37
-rw-r--r--Lib/python/director.swg112
-rw-r--r--Lib/python/embed.i47
-rw-r--r--Lib/python/pyabc.i20
-rw-r--r--Lib/python/pybuffer.i108
-rw-r--r--Lib/python/pyclasses.swg4
-rw-r--r--Lib/python/pycomplex.swg2
-rw-r--r--Lib/python/pycontainer.swg352
-rw-r--r--Lib/python/pydocs.swg48
-rw-r--r--Lib/python/pyerrors.swg13
-rw-r--r--Lib/python/pyhead.swg68
-rw-r--r--Lib/python/pyinit.swg245
-rw-r--r--Lib/python/pyname_compat.i7
-rw-r--r--Lib/python/pyprimtypes.swg13
-rw-r--r--Lib/python/pyrun.swg695
-rw-r--r--Lib/python/pyruntime.swg24
-rw-r--r--Lib/python/pystdcommon.swg17
-rw-r--r--Lib/python/pystrings.swg60
-rw-r--r--Lib/python/pythonkw.swg2
-rw-r--r--Lib/python/pythreads.swg10
-rw-r--r--Lib/python/pytypemaps.swg2
-rw-r--r--Lib/python/std_array.i46
-rw-r--r--Lib/python/std_auto_ptr.i44
-rw-r--r--Lib/python/std_carray.i54
-rw-r--r--Lib/python/std_filesystem.i121
-rw-r--r--Lib/python/std_map.i18
-rw-r--r--Lib/python/std_multimap.i12
-rw-r--r--Lib/python/std_multiset.i11
-rw-r--r--Lib/python/std_pair.i4
-rw-r--r--Lib/python/std_set.i11
-rw-r--r--Lib/python/std_string_view.i135
-rw-r--r--Lib/python/std_unique_ptr.i39
-rw-r--r--Lib/python/std_unordered_map.i16
-rw-r--r--Lib/python/std_unordered_multimap.i12
-rw-r--r--Lib/python/std_unordered_multiset.i11
-rw-r--r--Lib/python/std_unordered_set.i11
-rw-r--r--Lib/python/swigmove.i1
-rw-r--r--Lib/python/typemaps.i6
44 files changed, 1502 insertions, 1029 deletions
diff --git a/Lib/python/README b/Lib/python/README
index fa8ef61e7..70968e7dd 100644
--- a/Lib/python/README
+++ b/Lib/python/README
@@ -101,4 +101,3 @@ std_container.i general common code for the STD/STL containers
std_vectora.i vector + allocator (allocators are now supported in STD/STL)
typemaps.i old in/out typemaps (doesn't need to be included)
-defarg.swg for processing default arguments with shadow classes
diff --git a/Lib/python/argcargv.i b/Lib/python/argcargv.i
index 717fe7334..af71840f5 100644
--- a/Lib/python/argcargv.i
+++ b/Lib/python/argcargv.i
@@ -1,13 +1,10 @@
-/* ------------------------------------------------------------
- * --- Argc & Argv ---
- * ------------------------------------------------------------ */
+/* -------------------------------------------------------------
+ * SWIG library containing argc and argv multi-argument typemaps
+ * ------------------------------------------------------------- */
%fragment("SWIG_AsArgcArgv","header",fragment="SWIG_AsCharPtrAndSize") {
SWIGINTERN int
-SWIG_AsArgcArgv(PyObject *input,
- swig_type_info *ppchar_info,
- size_t *argc, char ***argv, int *owner)
-{
+SWIG_AsArgcArgv(PyObject *input, swig_type_info *ppchar_info, size_t *argc, char ***argv, int *owner) {
void *vptr;
int res = SWIG_ConvertPtr(input, &vptr, ppchar_info, 0);
if (!SWIG_IsOK(res)) {
@@ -51,7 +48,7 @@ SWIG_AsArgcArgv(PyObject *input,
} else {
/* seems dangerous, but the user asked for it... */
size_t i = 0;
- if (argv) { while (*argv[i] != 0) ++i;}
+ if (argv) { while (*argv[i] != 0) ++i;}
if (argc) *argc = i;
if (owner) *owner = 0;
return SWIG_OK;
@@ -66,10 +63,10 @@ SWIG_AsArgcArgv(PyObject *input,
%typemap(in,noblock=0,fragment="SWIG_AsArgcArgv") (int ARGC, char **ARGV) (int res,char **argv = 0, size_t argc = 0, int owner= 0) {
res = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &argv, &owner);
- if (!SWIG_IsOK(res)) {
+ if (!SWIG_IsOK(res)) {
$1 = 0; $2 = 0;
%argument_fail(SWIG_TypeError, "int ARGC, char **ARGV", $symname, $argnum);
- } else {
+ } else {
$1 = %static_cast(argc,$1_ltype);
$2 = %static_cast(argv, $2_ltype);
}
diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i
index 709e7811d..bfd8787c0 100644
--- a/Lib/python/boost_shared_ptr.i
+++ b/Lib/python/boost_shared_ptr.i
@@ -39,7 +39,7 @@
}
}
%typemap(out) CONST TYPE {
- SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1));
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@@ -58,12 +58,12 @@
}
}
%typemap(varout) CONST TYPE {
- SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1));
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
- smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
+ smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(SWIG_STD_MOVE($1)));
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) CONST TYPE (void *swig_argp, int swig_res = 0) {
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 28051e67b..6c2c311e6 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -6,7 +6,11 @@ SWIGINTERN Py_hash_t
SwigPyObject_hash(PyObject *obj) {
SwigPyObject *sobj = (SwigPyObject *)obj;
void *ptr = sobj->ptr;
+#if PY_VERSION_HEX < 0x03020000
+ return (Py_hash_t)(Py_ssize_t)ptr;
+#else
return (Py_hash_t)ptr;
+#endif
}
SWIGINTERN Py_hash_t
@@ -211,7 +215,11 @@ SwigPyStaticVar_Type(void) {
sizeof(PyGetSetDescrObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
- 0, /* tp_print */
+#if PY_VERSION_HEX < 0x030800b4
+ (printfunc)0, /* tp_print */
+#else
+ (Py_ssize_t)0, /* tp_vectorcall_offset */
+#endif
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
@@ -256,6 +264,15 @@ SwigPyStaticVar_Type(void) {
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
+#if PY_VERSION_HEX >= 0x030c0000
+ 0, /* tp_watched */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -289,7 +306,11 @@ SwigPyObjectType(void) {
PyType_Type.tp_basicsize, /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
- 0, /* tp_print */
+#if PY_VERSION_HEX < 0x030800b4
+ (printfunc)0, /* tp_print */
+#else
+ (Py_ssize_t)0, /* tp_vectorcall_offset */
+#endif
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
@@ -334,6 +355,15 @@ SwigPyObjectType(void) {
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
+#if PY_VERSION_HEX >= 0x030c0000
+ 0, /* tp_watched */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -402,10 +432,10 @@ SwigPyBuiltin_ThisClosure (PyObject *self, void *SWIGUNUSEDPARM(closure)) {
SWIGINTERN void
SwigPyBuiltin_SetMetaType (PyTypeObject *type, PyTypeObject *metatype)
{
-#if PY_VERSION_HEX >= 0x03000000
- type->ob_base.ob_base.ob_type = metatype;
+#if PY_VERSION_HEX >= 0x030900a4
+ Py_SET_TYPE(type, metatype);
#else
- type->ob_type = metatype;
+ Py_TYPE(type) = metatype;
#endif
}
@@ -510,8 +540,10 @@ SwigPyBuiltin_ternaryfunc_closure(SwigPyWrapperFunction wrapper, PyObject *a, Py
assert(tuple);
Py_INCREF(b);
PyTuple_SET_ITEM(tuple, 0, b);
- Py_INCREF(c);
- PyTuple_SET_ITEM(tuple, 1, c);
+ if (c) {
+ Py_INCREF(c);
+ PyTuple_SET_ITEM(tuple, 1, c);
+ }
result = wrapper(a, tuple);
Py_DECREF(tuple);
return result;
@@ -626,8 +658,10 @@ SwigPyBuiltin_ssizeobjargproc_closure(SwigPyWrapperFunction wrapper, PyObject *a
tuple = PyTuple_New(2);
assert(tuple);
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b));
- Py_INCREF(c);
- PyTuple_SET_ITEM(tuple, 1, c);
+ if (c) {
+ Py_INCREF(c);
+ PyTuple_SET_ITEM(tuple, 1, c);
+ }
resultobj = wrapper(a, tuple);
result = resultobj ? 0 : -1;
Py_XDECREF(resultobj);
diff --git a/Lib/python/carrays.i b/Lib/python/carrays.i
index 74b2be9c4..a7b6120d3 100644
--- a/Lib/python/carrays.i
+++ b/Lib/python/carrays.i
@@ -7,7 +7,3 @@
%enddef
%include <typemaps/carrays.swg>
-
-
-
-
diff --git a/Lib/python/ccomplex.i b/Lib/python/ccomplex.i
index 28872b985..b99f96a48 100644
--- a/Lib/python/ccomplex.i
+++ b/Lib/python/ccomplex.i
@@ -12,15 +12,16 @@
#include <complex.h>
%}
+#define complex _Complex
/* C complex constructor */
#define CCplxConst(r, i) ((r) + I*(i))
-%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
-%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+%swig_cplxflt_convn(float _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double _Complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(_Complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
-%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
-%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double _Complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, _Complex);
diff --git a/Lib/python/defarg.swg b/Lib/python/defarg.swg
deleted file mode 100644
index 59450bd82..000000000
--- a/Lib/python/defarg.swg
+++ /dev/null
@@ -1,37 +0,0 @@
-/* This file defines an internal function for processing default arguments
- with proxy classes.
-
- There seems to be no straightforward way to write proxy functions
- involving default arguments. For example :
-
- def foo(arg1,arg2,*args):
- proxyc.foo(arg1,arg2,args)
-
- This fails because args is now a tuple and SWIG doesn't know what to
- do with it.
-
- This file allows a different approach :
-
- def foo(arg1,arg2,*args):
- proxyc.__call_defarg(proxyc.foo,(arg1,arg2,)+args)
-
- Basically, we form a new tuple from the object, call this special
- __call_defarg method and it passes control to the real wrapper function.
- An ugly hack, but it works.
-*/
-
-SWIGINTERN PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
- PyObject *func;
- PyObject *parms;
-
- if (!PyArg_ParseTuple(args, "OO", &func, &parms))
- return NULL;
-
- if (!PyCallable_Check(func)) {
- SWIG_PYTHON_THREAD_BEGIN_BLOCK;
- PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
- SWIG_PYTHON_THREAD_END_BLOCK;
- return NULL;
- }
- return PyEval_CallObject(func,parms);
-}
diff --git a/Lib/python/director.swg b/Lib/python/director.swg
index 9694c6233..a1dd00f6d 100644
--- a/Lib/python/director.swg
+++ b/Lib/python/director.swg
@@ -14,6 +14,24 @@
#include <vector>
#include <map>
+#if defined(SWIG_PYTHON_THREADS)
+/* __THREAD__ is the old macro to activate some thread support */
+# if !defined(__THREAD__)
+# define __THREAD__ 1
+# endif
+#endif
+
+#ifdef __THREAD__
+#ifndef Py_LIMITED_API
+# include "pythread.h"
+#else
+# if defined(_WIN32)
+# include <windows.h>
+# else
+# include <pthread.h>
+# endif
+#endif
+#endif
/*
Use -DSWIG_PYTHON_DIRECTOR_NO_VTABLE if you don't want to generate a 'virtual
@@ -173,7 +191,7 @@ namespace Swig {
swig_msg += msg;
}
if (!PyErr_Occurred()) {
- PyErr_SetString(error, what());
+ PyErr_SetString(error, swig_msg.c_str());
}
SWIG_PYTHON_THREAD_END_BLOCK;
}
@@ -244,25 +262,89 @@ namespace Swig {
};
-#if defined(SWIG_PYTHON_THREADS)
-/* __THREAD__ is the old macro to activate some thread support */
-# if !defined(__THREAD__)
-# define __THREAD__ 1
-# endif
-#endif
-
#ifdef __THREAD__
-# include "pythread.h"
+#ifndef Py_LIMITED_API
+ class Mutex
+ {
+ public:
+ Mutex() {
+ mutex_ = PyThread_allocate_lock();
+ }
+
+ ~Mutex() {
+ PyThread_release_lock(mutex_);
+ }
+
+ private:
+ void Lock() {
+ PyThread_acquire_lock(mutex_, WAIT_LOCK);
+ }
+
+ void Unlock() {
+ PyThread_free_lock(mutex_);
+ }
+
+ PyThread_type_lock mutex_;
+
+ friend class Guard;
+ };
+#elif defined(_WIN32)
+ class Mutex : private CRITICAL_SECTION {
+ public:
+ Mutex() {
+ InitializeCriticalSection(this);
+ }
+
+ ~Mutex() {
+ DeleteCriticalSection(this);
+ }
+
+ private:
+ void Lock() {
+ EnterCriticalSection(this);
+ }
+
+ void Unlock() {
+ LeaveCriticalSection(this);
+ }
+
+ friend class Guard;
+ };
+#else
+ class Mutex {
+ public:
+ Mutex() {
+ pthread_mutex_init(&mutex_, NULL);
+ }
+
+ ~Mutex() {
+ pthread_mutex_destroy(&mutex_);
+ }
+
+ private:
+ void Lock() {
+ pthread_mutex_lock(&mutex_);
+ }
+
+ void Unlock() {
+ pthread_mutex_unlock(&mutex_);
+ }
+
+ friend class Guard;
+
+ pthread_mutex_t mutex_;
+ };
+#endif
class Guard {
- PyThread_type_lock &mutex_;
+ Mutex &mutex_;
public:
- Guard(PyThread_type_lock & mutex) : mutex_(mutex) {
- PyThread_acquire_lock(mutex_, WAIT_LOCK);
+ Guard(Mutex & mutex) : mutex_(mutex) {
+ mutex_.Lock();
}
~Guard() {
- PyThread_release_lock(mutex_);
+ mutex_.Unlock();
}
};
# define SWIG_GUARD(mutex) Guard _guard(mutex)
@@ -330,7 +412,7 @@ namespace Swig {
typedef std::map<void *, GCItem_var> swig_ownership_map;
mutable swig_ownership_map swig_owner;
#ifdef __THREAD__
- static PyThread_type_lock swig_mutex_own;
+ static Mutex swig_mutex_own;
#endif
public:
@@ -382,7 +464,7 @@ namespace Swig {
};
#ifdef __THREAD__
- PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock();
+ Mutex Director::swig_mutex_own;
#endif
}
diff --git a/Lib/python/embed.i b/Lib/python/embed.i
index efd048789..e5ee601d9 100644
--- a/Lib/python/embed.i
+++ b/Lib/python/embed.i
@@ -2,36 +2,43 @@
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is deprecated and no longer actively maintained, but it still
-// seems to work with Python 2.7. Status with Python 3 is unknown.
+// seems to work with Python 2.7. It doesn't work with Python 3.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack its setup script.
//
+// This module provides support for building a new version of the
+// Python executable. This will be necessary on systems that do
+// not support shared libraries and may be necessary with C++
+// extensions. This file contains everything you need to build
+// a new version of Python from include files and libraries normally
+// installed with the Python language.
+//
+// This module will automatically grab all of the Python modules
+// present in your current Python executable (including any special
+// purpose modules you have enabled such as Tkinter). Thus, you
+// may need to provide additional link libraries when compiling.
+//
+// As far as I know, this module is C++ safe.
-
-#ifdef AUTODOC
-%subsection "embed.i"
-%text %{
-This module provides support for building a new version of the
-Python executable. This will be necessary on systems that do
-not support shared libraries and may be necessary with C++
-extensions. This file contains everything you need to build
-a new version of Python from include files and libraries normally
-installed with the Python language.
-
-This module will automatically grab all of the Python modules
-present in your current Python executable (including any special
-purpose modules you have enabled such as Tkinter). Thus, you
-may need to provide additional link libraries when compiling.
-
-As far as I know, this module is C++ safe.
-%}
+%wrapper %{
+#if !defined(PY_SSIZE_T_CLEAN) && !defined(SWIG_NO_PY_SSIZE_T_CLEAN)
+#define PY_SSIZE_T_CLEAN
#endif
-%wrapper %{
+#if __GNUC__ >= 7
+#pragma GCC diagnostic push
+#if defined(__cplusplus) && __cplusplus >=201703L
+#pragma GCC diagnostic ignored "-Wregister" /* For python-2.7 headers that use register */
+#endif
+#endif
#include <Python.h>
+#if __GNUC__ >= 7
+#pragma GCC diagnostic pop
+#endif
+
#ifdef __cplusplus
extern "C"
#endif
diff --git a/Lib/python/pyabc.i b/Lib/python/pyabc.i
index fbd91dce4..cae1e7032 100644
--- a/Lib/python/pyabc.i
+++ b/Lib/python/pyabc.i
@@ -1,10 +1,14 @@
%define %pythonabc(Type, Abc)
- %feature("python:abc", #Abc) Type;
+ %feature("python:abc", Abc) Type;
%enddef
-%pythoncode %{import collections.abc%}
-%pythonabc(std::vector, collections.abc.MutableSequence);
-%pythonabc(std::list, collections.abc.MutableSequence);
-%pythonabc(std::map, collections.abc.MutableMapping);
-%pythonabc(std::multimap, collections.abc.MutableMapping);
-%pythonabc(std::set, collections.abc.MutableSet);
-%pythonabc(std::multiset, collections.abc.MutableSet);
+%pythoncode %{if _swig_python_version_info[0:2] >= (3, 3):
+ import collections.abc
+else:
+ import collections
+%}
+%pythonabc(std::vector, "collections.abc.MutableSequence if _swig_python_version_info >= (3, 3) else collections.MutableSequence");
+%pythonabc(std::list, "collections.abc.MutableSequence if _swig_python_version_info >= (3, 3) else collections.MutableSequence");
+%pythonabc(std::map, "collections.abc.MutableMapping if _swig_python_version_info >= (3, 3) else collections.MutableMapping");
+%pythonabc(std::multimap, "collections.abc.MutableMapping if _swig_python_version_info >= (3, 3) else collections.MutableMapping");
+%pythonabc(std::set, "collections.abc.MutableSet if _swig_python_version_info >= (3, 3) else collections.MutableSet");
+%pythonabc(std::multiset, "collections.abc.MutableSet if _swig_python_version_info >= (3, 3) else collections.MutableSet");
diff --git a/Lib/python/pybuffer.i b/Lib/python/pybuffer.i
index 577eb69c8..9ebc36a8c 100644
--- a/Lib/python/pybuffer.i
+++ b/Lib/python/pybuffer.i
@@ -12,18 +12,43 @@
* }
*/
+/* Note that in Py_LIMITED_API case we have no choice, but to use deprecated
+ * functions, as they provides the only way to access buffer data with limited
+ * API, which doesn't include Py_buffer definition. We also disable the
+ * warnings about doing this because they're not useful in our case.
+ */
+
%define %pybuffer_mutable_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
- size = view.len;
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ size = view.len;
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size/sizeof($*1_type));
}
@@ -45,14 +70,34 @@
%define %pybuffer_mutable_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE);
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ Py_ssize_t size;
+ res = PyObject_AsWriteBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
}
%enddef
@@ -74,15 +119,34 @@
%define %pybuffer_binary(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int res; Py_ssize_t size = 0; const void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
- size = view.len;
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
PyErr_Clear();
%argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ size = view.len;
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
$2 = ($2_ltype) (size / sizeof($*1_type));
}
@@ -106,16 +170,34 @@
%define %pybuffer_string(TYPEMAP)
%typemap(in) (TYPEMAP) {
int res; const void *buf = 0;
+%#ifndef Py_LIMITED_API
Py_buffer view;
res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO);
- buf = view.buf;
- PyBuffer_Release(&view);
+%#else
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic push
+ %#pragma GCC diagnostic ignored "-Wdeprecated"
+ %#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+ %#elif defined(_MSC_VER)
+ %#pragma warning(push)
+ %#pragma warning(disable: 4996)
+ %#endif
+ Py_ssize_t size;
+ res = PyObject_AsReadBuffer($input, &buf, &size);
+ %#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+ %#pragma GCC diagnostic pop
+ %#elif defined(_MSC_VER)
+ %#pragma warning(pop)
+ %#endif
+%#endif
if (res < 0) {
+ PyErr_Clear();
%argument_fail(res, "(TYPEMAP)", $symname, $argnum);
}
+%#ifndef Py_LIMITED_API
+ buf = view.buf;
+ PyBuffer_Release(&view);
+%#endif
$1 = ($1_ltype) buf;
}
%enddef
-
-
-
diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg
index 9d6299ff1..39c4e0316 100644
--- a/Lib/python/pyclasses.swg
+++ b/Lib/python/pyclasses.swg
@@ -11,7 +11,7 @@
or as a member variable:
struct A {
- SwigPtr_PyObject obj;
+ SwigPtr_PyObject _obj;
A(PyObject *o) : _obj(o) {
}
};
@@ -43,7 +43,7 @@ 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);";
+ %typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);"
/* For output */
diff --git a/Lib/python/pycomplex.swg b/Lib/python/pycomplex.swg
index 087c50f90..28c963617 100644
--- a/Lib/python/pycomplex.swg
+++ b/Lib/python/pycomplex.swg
@@ -65,7 +65,7 @@ SWIG_AsVal(Type)(PyObject *o, Type *val)
float re;
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
if (SWIG_IsOK(res)) {
- if (val) *val = Constructor(re, 0.0);
+ if (val) *val = Constructor(re, 0.0f);
return res;
}
}
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index fef4e9b3b..6916c618e 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -15,9 +15,9 @@
#include <iostream>
#if PY_VERSION_HEX >= 0x03020000
-# define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj))
+# define SWIGPY_SLICEOBJECT PyObject
#else
-# define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj))
+# define SWIGPY_SLICEOBJECT PySliceObject
#endif
%}
@@ -52,7 +52,7 @@ namespace swig {
struct container_owner {
// By default, do not add the back-reference (for value types)
// Specialization below will check the reference for pointer types.
- static bool back_reference(PyObject* child, PyObject* owner) {
+ static bool back_reference(PyObject* /*child*/, PyObject* /*owner*/) {
return false;
}
};
@@ -69,8 +69,7 @@ namespace swig {
static bool back_reference(PyObject* child, PyObject* owner) {
SwigPyObject* swigThis = SWIG_Python_GetSwigThis(child);
if (swigThis && (swigThis->own & SWIG_POINTER_OWN) != SWIG_POINTER_OWN) {
- PyObject_SetAttr(child, container_owner_attribute(), owner);
- return true;
+ return PyObject_SetAttr(child, container_owner_attribute(), owner) != -1;
}
return false;
}
@@ -387,7 +386,7 @@ namespace swig {
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);
+ PyOS_snprintf(msg, sizeof(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();
@@ -403,7 +402,7 @@ namespace swig {
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);
+ PyOS_snprintf(msg, sizeof(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();
@@ -457,239 +456,6 @@ namespace swig {
}
}
-%fragment("SwigPySequence_Cont","header",
- fragment="StdTraits",
- fragment="SwigPySequence_Base",
- fragment="SwigPyIterator_T")
-{
-namespace swig
-{
- template <class T>
- struct SwigPySequence_Ref
- {
- SwigPySequence_Ref(PyObject* seq, Py_ssize_t index)
- : _seq(seq), _index(index)
- {
- }
-
- operator T () const
- {
- swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
- try {
- return swig::as<T>(item);
- } catch (const std::invalid_argument& e) {
- char msg[1024];
- sprintf(msg, "in sequence element %d ", (int)_index);
- if (!PyErr_Occurred()) {
- ::%type_error(swig::type_name<T>());
- }
- SWIG_Python_AddErrorMsg(msg);
- SWIG_Python_AddErrorMsg(e.what());
- throw;
- }
- }
-
- SwigPySequence_Ref& operator=(const T& v)
- {
- PySequence_SetItem(_seq, _index, swig::from<T>(v));
- return *this;
- }
-
- private:
- PyObject* _seq;
- Py_ssize_t _index;
- };
-
- template <class T>
- struct SwigPySequence_ArrowProxy
- {
- SwigPySequence_ArrowProxy(const T& x): m_value(x) {}
- const T* operator->() const { return &m_value; }
- operator const T*() const { return &m_value; }
- T m_value;
- };
-
- template <class T, class Reference >
- struct SwigPySequence_InputIterator
- {
- typedef SwigPySequence_InputIterator<T, Reference > self;
-
- typedef std::random_access_iterator_tag iterator_category;
- typedef Reference reference;
- typedef T value_type;
- typedef T* pointer;
- typedef Py_ssize_t difference_type;
-
- SwigPySequence_InputIterator()
- {
- }
-
- SwigPySequence_InputIterator(PyObject* seq, Py_ssize_t index)
- : _seq(seq), _index(index)
- {
- }
-
- reference operator*() const
- {
- return reference(_seq, _index);
- }
-
- SwigPySequence_ArrowProxy<T>
- operator->() const {
- return SwigPySequence_ArrowProxy<T>(operator*());
- }
-
- bool operator==(const self& ri) const
- {
- return (_index == ri._index) && (_seq == ri._seq);
- }
-
- bool operator!=(const self& ri) const
- {
- return !(operator==(ri));
- }
-
- self& operator ++ ()
- {
- ++_index;
- return *this;
- }
-
- self& operator -- ()
- {
- --_index;
- return *this;
- }
-
- self& operator += (difference_type n)
- {
- _index += n;
- return *this;
- }
-
- self operator +(difference_type n) const
- {
- return self(_seq, _index + n);
- }
-
- self& operator -= (difference_type n)
- {
- _index -= n;
- return *this;
- }
-
- self operator -(difference_type n) const
- {
- return self(_seq, _index - n);
- }
-
- difference_type operator - (const self& ri) const
- {
- return _index - ri._index;
- }
-
- bool operator < (const self& ri) const
- {
- return _index < ri._index;
- }
-
- reference
- operator[](difference_type n) const
- {
- return reference(_seq, _index + n);
- }
-
- private:
- PyObject* _seq;
- difference_type _index;
- };
-
- // STL container wrapper around a Python sequence
- template <class T>
- struct SwigPySequence_Cont
- {
- typedef SwigPySequence_Ref<T> reference;
- typedef const SwigPySequence_Ref<T> const_reference;
- typedef T value_type;
- typedef T* pointer;
- typedef Py_ssize_t difference_type;
- typedef size_t size_type;
- typedef const pointer const_pointer;
- typedef SwigPySequence_InputIterator<T, reference> iterator;
- typedef SwigPySequence_InputIterator<T, const_reference> const_iterator;
-
- SwigPySequence_Cont(PyObject* seq) : _seq(0)
- {
- if (!PySequence_Check(seq)) {
- throw std::invalid_argument("a sequence is expected");
- }
- _seq = seq;
- Py_INCREF(_seq);
- }
-
- ~SwigPySequence_Cont()
- {
- Py_XDECREF(_seq);
- }
-
- size_type size() const
- {
- return static_cast<size_type>(PySequence_Size(_seq));
- }
-
- bool empty() const
- {
- return size() == 0;
- }
-
- iterator begin()
- {
- return iterator(_seq, 0);
- }
-
- const_iterator begin() const
- {
- return const_iterator(_seq, 0);
- }
-
- iterator end()
- {
- return iterator(_seq, size());
- }
-
- const_iterator end() const
- {
- return const_iterator(_seq, size());
- }
-
- reference operator[](difference_type n)
- {
- return reference(_seq, n);
- }
-
- const_reference operator[](difference_type n) const
- {
- return const_reference(_seq, n);
- }
-
- bool check() const
- {
- Py_ssize_t s = size();
- for (Py_ssize_t i = 0; i < s; ++i) {
- swig::SwigVar_PyObject item = PySequence_GetItem(_seq, i);
- if (!swig::check<value_type>(item))
- return false;
- }
- return true;
- }
-
- private:
- PyObject* _seq;
- };
-
-}
-}
-
%define %swig_sequence_iterator(Sequence...)
%swig_sequence_iterator_with_making_function(swig::make_output_iterator,Sequence...)
%enddef
@@ -705,12 +471,12 @@ namespace swig
class const_iterator;
class const_reverse_iterator;
- %typemap(out,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(out,noblock=1,fragment="SwigPyIterator_T")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
$result = SWIG_NewPointerObj(Make_output_iterator(%static_cast($1,const $type &)),
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
}
- %typemap(out,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(out,noblock=1,fragment="SwigPyIterator_T")
std::pair<iterator, iterator>, std::pair<const_iterator, const_iterator> {
$result = PyTuple_New(2);
PyTuple_SetItem($result,0,SWIG_NewPointerObj(Make_output_iterator(%static_cast($1,const $type &).first),
@@ -719,7 +485,7 @@ namespace swig
swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN));
}
- %fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPySequence_Cont") {}
+ %fragment("SwigPyPairBoolOutputIterator","header",fragment=SWIG_From_frag(bool),fragment="SwigPyIterator_T") {}
%typemap(out,noblock=1,fragment="SwigPyPairBoolOutputIterator")
std::pair<iterator, bool>, std::pair<const_iterator, bool> {
@@ -729,7 +495,7 @@ namespace swig
PyTuple_SetItem($result,1,SWIG_From(bool)(%static_cast($1,const $type &).second));
}
- %typemap(in,noblock=1,fragment="SwigPySequence_Cont")
+ %typemap(in,noblock=1,fragment="SwigPyIterator_T")
iterator(swig::SwigPyIterator *iter = 0, int res),
reverse_iterator(swig::SwigPyIterator *iter = 0, int res),
const_iterator(swig::SwigPyIterator *iter = 0, int res),
@@ -747,14 +513,14 @@ namespace swig
}
}
- %typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPySequence_Cont")
+ %typecheck(%checkcode(ITERATOR),noblock=1,fragment="SwigPyIterator_T")
iterator, reverse_iterator, const_iterator, const_reverse_iterator {
swig::SwigPyIterator *iter = 0;
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::SwigPyIterator::descriptor(), 0);
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::SwigPyIterator_T<$type > *>(iter) != 0));
}
- %fragment("SwigPySequence_Cont");
+ %fragment("SwigPyIterator_T");
%newobject iterator(PyObject **PYTHON_SELF);
%extend {
@@ -782,7 +548,7 @@ namespace swig
#if 1
%newobject __getslice__;
#endif
- %newobject __getitem__(PySliceObject *slice);
+ %newobject __getitem__(SWIGPY_SLICEOBJECT *slice);
#if defined(SWIGPYTHON_BUILTIN)
%feature("python:slot", "nb_nonzero", functype="inquiry") __nonzero__;
@@ -830,13 +596,13 @@ namespace swig
%extend {
/* typemap for slice object support */
- %typemap(in) PySliceObject* {
+ %typemap(in) SWIGPY_SLICEOBJECT* {
if (!PySlice_Check($input)) {
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
}
- $1 = (PySliceObject *) $input;
+ $1 = (SWIGPY_SLICEOBJECT *) $input;
}
- %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
+ %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) SWIGPY_SLICEOBJECT* {
$1 = PySlice_Check($input);
}
@@ -866,49 +632,49 @@ namespace swig
/* Overloaded methods for Python 3 compatibility
* (Also useful in Python 2.x)
*/
- Sequence* __getitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
+ Sequence* __getitem__(SWIGPY_SLICEOBJECT *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(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
+ PySlice_GetIndices(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__(SWIGPY_SLICEOBJECT *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(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
+ PySlice_GetIndices(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 __setitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
+ void __setitem__(SWIGPY_SLICEOBJECT *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);
+ PySlice_GetIndices(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) {
+ void __delitem__(SWIGPY_SLICEOBJECT *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);
+ PySlice_GetIndices(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);
@@ -1000,26 +766,50 @@ namespace swig
%fragment("StdSequenceTraits","header",
fragment="StdTraits",
- fragment="SwigPySequence_Cont")
+ fragment="SwigPySequence_Base")
{
namespace swig {
- template <class SwigPySeq, class Seq>
- inline void
- assign(const SwigPySeq& swigpyseq, Seq* seq) {
- // seq->assign(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
- typedef typename SwigPySeq::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- seq->insert(seq->end(),(value_type)(*it));
+ template <class Seq, class T = typename Seq::value_type >
+ struct IteratorProtocol {
+ static void assign(PyObject *obj, Seq *seq) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ while (item) {
+ seq->insert(seq->end(), swig::as<T>(item));
+ item = PyIter_Next(iter);
+ }
+ }
}
- }
+
+ static bool check(PyObject *obj) {
+ bool ret = false;
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ ret = true;
+ while (item) {
+ ret = swig::check<T>(item);
+ item = ret ? PyIter_Next(iter) : 0;
+ }
+ }
+ return ret;
+ }
+ };
template <class Seq, class T = typename Seq::value_type >
struct traits_asptr_stdseq {
typedef Seq sequence;
typedef T value_type;
+ static bool is_iterable(PyObject *obj) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ PyErr_Clear();
+ return iter != 0;
+ }
+
static int asptr(PyObject *obj, sequence **seq) {
+ int ret = SWIG_ERROR;
if (obj == Py_None || SWIG_Python_GetSwigThis(obj)) {
sequence *p;
swig_type_info *descriptor = swig::type_info<sequence>();
@@ -1027,27 +817,25 @@ namespace swig {
if (seq) *seq = p;
return SWIG_OLDOBJ;
}
- } else if (PySequence_Check(obj)) {
+ } else if (is_iterable(obj)) {
try {
- SwigPySequence_Cont<value_type> swigpyseq(obj);
if (seq) {
- sequence *pseq = new sequence();
- assign(swigpyseq, pseq);
- *seq = pseq;
- return SWIG_NEWOBJ;
+ *seq = new sequence();
+ IteratorProtocol<Seq, T>::assign(obj, *seq);
+ if (!PyErr_Occurred())
+ return SWIG_NEWOBJ;
} else {
- return swigpyseq.check() ? SWIG_OK : SWIG_ERROR;
+ return IteratorProtocol<Seq, T>::check(obj) ? SWIG_OK : SWIG_ERROR;
}
} catch (std::exception& e) {
- if (seq) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, e.what());
- }
- }
- return SWIG_ERROR;
+ if (seq && !PyErr_Occurred())
+ PyErr_SetString(PyExc_TypeError, e.what());
}
+ if (seq)
+ delete *seq;
+ return SWIG_ERROR;
}
- return SWIG_ERROR;
+ return ret;
}
};
diff --git a/Lib/python/pydocs.swg b/Lib/python/pydocs.swg
index 1eea41b8d..5a25423d4 100644
--- a/Lib/python/pydocs.swg
+++ b/Lib/python/pydocs.swg
@@ -2,43 +2,43 @@
// Documentation for use with the autodoc feature.
#ifdef SWIG_DOC_DOXYGEN_STYLE
-%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, 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)";
+%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, 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)";
+%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
// Types to use in Python documentation for the parameters of the given C++ type.
-%typemap(doctype) bool "boolean";
+%typemap(doctype) bool "boolean"
%define int_doctype_for_cppint_type(cppint_type)
- %typemap(doctype) cppint_type, unsigned cppint_type "int";
+ %typemap(doctype) cppint_type, unsigned cppint_type "int"
%enddef
%formacro(int_doctype_for_cppint_type, short, int, long, long long)
-%typemap(doctype) size_t "int";
+%typemap(doctype) size_t "int"
-%typemap(doctype) enum SWIGTYPE "int";
+%typemap(doctype) enum SWIGTYPE "int"
-%typemap(doctype) float, double, long double "float";
+%typemap(doctype) float, double, long double "float"
-%typemap(doctype) char*, std::string "string";
+%typemap(doctype) char*, std::string "string"
%typemap(doctype) SWIGTYPE "$1_basetype"
%typemap(doctype) SWIGTYPE * "$typemap(doctype, $*1_ltype)"
diff --git a/Lib/python/pyerrors.swg b/Lib/python/pyerrors.swg
index dcd99c939..dfa55e061 100644
--- a/Lib/python/pyerrors.swg
+++ b/Lib/python/pyerrors.swg
@@ -57,14 +57,15 @@ SWIG_Python_AddErrorMsg(const char* mesg)
PyErr_Fetch(&type, &value, &traceback);
if (value) {
PyObject *old_str = PyObject_Str(value);
- const char *tmp = SWIG_Python_str_AsChar(old_str);
+ PyObject *bytes = NULL;
+ const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes);
PyErr_Clear();
Py_XINCREF(type);
if (tmp)
PyErr_Format(type, "%s %s", tmp, mesg);
else
PyErr_Format(type, "%s", mesg);
- SWIG_Python_str_DelForPy3(tmp);
+ Py_XDECREF(bytes);
Py_DECREF(old_str);
Py_DECREF(value);
} else {
@@ -95,8 +96,12 @@ SWIG_Python_RaiseOrModifyTypeError(const char *message)
#else
newvalue = PyString_FromFormat("%s\nAdditional information:\n%s", PyString_AsString(value), message);
#endif
- Py_XDECREF(value);
- PyErr_Restore(type, newvalue, traceback);
+ if (newvalue) {
+ Py_XDECREF(value);
+ PyErr_Restore(type, newvalue, traceback);
+ } else {
+ PyErr_Restore(type, value, traceback);
+ }
} else {
/* Raise TypeError using given message */
PyErr_SetString(PyExc_TypeError, message);
diff --git a/Lib/python/pyhead.swg b/Lib/python/pyhead.swg
index c820f9016..46891d9e8 100644
--- a/Lib/python/pyhead.swg
+++ b/Lib/python/pyhead.swg
@@ -13,7 +13,6 @@
#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
@@ -31,36 +30,29 @@
#endif
-/* Warning: This function will allocate a new string in Python 3,
- * so please call SWIG_Python_str_DelForPy3(x) to free the space.
- */
-SWIGINTERN char*
-SWIG_Python_str_AsChar(PyObject *str)
+/* Wrapper around PyUnicode_AsUTF8AndSize - call Py_XDECREF on the returned pbytes when finished with the returned string */
+SWIGINTERN const char *
+SWIG_PyUnicode_AsUTF8AndSize(PyObject *str, Py_ssize_t *psize, PyObject **pbytes)
{
-#if PY_VERSION_HEX >= 0x03000000
- char *newstr = 0;
- str = PyUnicode_AsUTF8String(str);
- if (str) {
- char *cstr;
- Py_ssize_t len;
- PyBytes_AsStringAndSize(str, &cstr, &len);
- newstr = (char *) malloc(len+1);
- memcpy(newstr, cstr, len+1);
- Py_XDECREF(str);
- }
- return newstr;
+#if PY_VERSION_HEX >= 0x03030000
+# if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
+ *pbytes = NULL;
+ return PyUnicode_AsUTF8AndSize(str, psize);
+# else
+ *pbytes = PyUnicode_AsUTF8String(str);
+ const char *chars = *pbytes ? PyBytes_AsString(*pbytes) : NULL;
+ if (chars && psize)
+ *psize = PyBytes_Size(*pbytes);
+ return chars;
+# endif
#else
- return PyString_AsString(str);
+ char *chars = NULL;
+ *pbytes = NULL;
+ PyString_AsStringAndSize(str, &chars, psize);
+ return chars;
#endif
}
-#if PY_VERSION_HEX >= 0x03000000
-# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
-#else
-# define SWIG_Python_str_DelForPy3(x)
-#endif
-
-
SWIGINTERN PyObject*
SWIG_Python_str_FromChar(const char *c)
{
@@ -75,13 +67,31 @@ SWIG_Python_str_FromChar(const char *c)
# define PyObject_DEL PyObject_Del
#endif
-// SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user
-// interface files check for it.
+/* SWIGPY_USE_CAPSULE is no longer used within SWIG itself, but some user interface files check for it. */
# define SWIGPY_USE_CAPSULE
-# define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
+#ifdef SWIGPYTHON_BUILTIN
+# define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule_builtin" SWIG_TYPE_TABLE_NAME
+#else
+# define SWIGPY_CAPSULE_ATTR_NAME "type_pointer_capsule" SWIG_TYPE_TABLE_NAME
+#endif
+# define SWIGPY_CAPSULE_NAME ("swig_runtime_data" SWIG_RUNTIME_VERSION "." SWIGPY_CAPSULE_ATTR_NAME)
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
#define Py_hash_t long
#endif
+
+#ifdef Py_LIMITED_API
+# define PyTuple_GET_ITEM PyTuple_GetItem
+/* Note that PyTuple_SetItem() has different semantics from PyTuple_SET_ITEM as it decref's the original tuple item, so in general they cannot be used
+ interchangeably. However in SWIG-generated code PyTuple_SET_ITEM is only used with newly initialized tuples without any items and for them this does work. */
+# define PyTuple_SET_ITEM PyTuple_SetItem
+# define PyTuple_GET_SIZE PyTuple_Size
+# define PyCFunction_GET_FLAGS PyCFunction_GetFlags
+# define PyCFunction_GET_FUNCTION PyCFunction_GetFunction
+# define PyCFunction_GET_SELF PyCFunction_GetSelf
+# define PyList_GET_ITEM PyList_GetItem
+# define PyList_SET_ITEM PyList_SetItem
+# define PySliceObject PyObject
+#endif
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index dfbf40b34..6833b455a 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -8,6 +8,8 @@
%fragment("<stddef.h>"); // For offsetof
#endif
+#if defined SWIGPYTHON_FASTPROXY && !defined SWIGPYTHON_BUILTIN
+
%insert(runtime) %{
#ifdef __cplusplus
extern "C" {
@@ -24,220 +26,14 @@ SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyO
#endif
%}
+#endif
+
%init %{
#ifdef __cplusplus
extern "C" {
#endif
-/* Python-specific SWIG API */
-#define SWIG_newvarlink() SWIG_Python_newvarlink()
-#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr)
-#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
-
-/* -----------------------------------------------------------------------------
- * global variable support code.
- * ----------------------------------------------------------------------------- */
-
-typedef struct swig_globalvar {
- char *name; /* Name of global variable */
- PyObject *(*get_attr)(void); /* Return the current value */
- int (*set_attr)(PyObject *); /* Set the value */
- struct swig_globalvar *next;
-} swig_globalvar;
-
-typedef struct swig_varlinkobject {
- PyObject_HEAD
- swig_globalvar *vars;
-} swig_varlinkobject;
-
-SWIGINTERN PyObject *
-swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) {
-#if PY_VERSION_HEX >= 0x03000000
- return PyUnicode_InternFromString("<Swig global variables>");
-#else
- return PyString_FromString("<Swig global variables>");
-#endif
-}
-
-SWIGINTERN PyObject *
-swig_varlink_str(swig_varlinkobject *v) {
-#if PY_VERSION_HEX >= 0x03000000
- PyObject *str = PyUnicode_InternFromString("(");
- PyObject *tail;
- PyObject *joined;
- swig_globalvar *var;
- for (var = v->vars; var; var=var->next) {
- tail = PyUnicode_FromString(var->name);
- joined = PyUnicode_Concat(str, tail);
- Py_DecRef(str);
- Py_DecRef(tail);
- str = joined;
- if (var->next) {
- tail = PyUnicode_InternFromString(", ");
- joined = PyUnicode_Concat(str, tail);
- Py_DecRef(str);
- Py_DecRef(tail);
- str = joined;
- }
- }
- tail = PyUnicode_InternFromString(")");
- joined = PyUnicode_Concat(str, tail);
- Py_DecRef(str);
- Py_DecRef(tail);
- str = joined;
-#else
- PyObject *str = PyString_FromString("(");
- swig_globalvar *var;
- for (var = v->vars; var; var=var->next) {
- PyString_ConcatAndDel(&str,PyString_FromString(var->name));
- if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", "));
- }
- PyString_ConcatAndDel(&str,PyString_FromString(")"));
-#endif
- return str;
-}
-
-SWIGINTERN void
-swig_varlink_dealloc(swig_varlinkobject *v) {
- swig_globalvar *var = v->vars;
- while (var) {
- swig_globalvar *n = var->next;
- free(var->name);
- free(var);
- var = n;
- }
-}
-
-SWIGINTERN PyObject *
-swig_varlink_getattr(swig_varlinkobject *v, char *n) {
- PyObject *res = NULL;
- swig_globalvar *var = v->vars;
- while (var) {
- if (strcmp(var->name,n) == 0) {
- res = (*var->get_attr)();
- break;
- }
- var = var->next;
- }
- if (res == NULL && !PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
- }
- return res;
-}
-
-SWIGINTERN int
-swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
- int res = 1;
- swig_globalvar *var = v->vars;
- while (var) {
- if (strcmp(var->name,n) == 0) {
- res = (*var->set_attr)(p);
- break;
- }
- var = var->next;
- }
- if (res == 1 && !PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
- }
- return res;
-}
-
-SWIGINTERN PyTypeObject*
-swig_varlink_type(void) {
- static char varlink__doc__[] = "Swig var link object";
- static PyTypeObject varlink_type;
- static int type_init = 0;
- if (!type_init) {
- const PyTypeObject tmp = {
-#if PY_VERSION_HEX >= 0x03000000
- PyVarObject_HEAD_INIT(NULL, 0)
-#else
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
-#endif
- "swigvarlink", /* tp_name */
- sizeof(swig_varlinkobject), /* tp_basicsize */
- 0, /* tp_itemsize */
- (destructor) swig_varlink_dealloc, /* tp_dealloc */
- 0, /* 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 */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- (reprfunc) swig_varlink_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- varlink__doc__, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
- 0, /* tp_del */
- 0, /* tp_version_tag */
-#if PY_VERSION_HEX >= 0x03040000
- 0, /* tp_finalize */
-#endif
-#ifdef COUNT_ALLOCS
- 0, /* tp_allocs */
- 0, /* tp_frees */
- 0, /* tp_maxalloc */
- 0, /* tp_prev */
- 0 /* tp_next */
-#endif
- };
- varlink_type = tmp;
- type_init = 1;
- if (PyType_Ready(&varlink_type) < 0)
- return NULL;
- }
- return &varlink_type;
-}
-
-/* Create a variable linking object for use later */
-SWIGINTERN PyObject *
-SWIG_Python_newvarlink(void) {
- swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type());
- if (result) {
- result->vars = 0;
- }
- return ((PyObject*) result);
-}
-
-SWIGINTERN void
-SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
- swig_varlinkobject *v = (swig_varlinkobject *) p;
- swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
- if (gv) {
- size_t size = strlen(name)+1;
- gv->name = (char *)malloc(size);
- if (gv->name) {
- memcpy(gv->name, name, size);
- gv->get_attr = get_attr;
- gv->set_attr = set_attr;
- gv->next = v->vars;
- }
- }
- v->vars = gv;
-}
-
-SWIGINTERN PyObject *
-SWIG_globals(void) {
- static PyObject *globals = 0;
- if (!globals) {
- globals = SWIG_newvarlink();
- }
- return globals;
-}
-
/* -----------------------------------------------------------------------------
* constants/methods manipulation
* ----------------------------------------------------------------------------- */
@@ -266,15 +62,12 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
}
}
-/* -----------------------------------------------------------------------------*/
-/* Fix SwigMethods to carry the callback ptrs when needed */
-/* -----------------------------------------------------------------------------*/
+/* -----------------------------------------------------------------------------
+ * Patch %callback methods' docstrings to hold the callback ptrs
+ * -----------------------------------------------------------------------------*/
SWIGINTERN void
-SWIG_Python_FixMethods(PyMethodDef *methods,
- swig_const_info *const_table,
- swig_type_info **types,
- swig_type_info **types_initial) {
+SWIG_Python_FixMethods(PyMethodDef *methods, const swig_const_info *const_table, swig_type_info **types, swig_type_info **types_initial) {
size_t i;
for (i = 0; methods[i].ml_name; ++i) {
const char *c = methods[i].ml_doc;
@@ -282,7 +75,7 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
c = strstr(c, "swig_ptr: ");
if (c) {
int j;
- swig_const_info *ci = 0;
+ const swig_const_info *ci = 0;
const char *name = c + 10;
for (j = 0; const_table[j].type; ++j) {
if (strncmp(const_table[j].name, name,
@@ -314,6 +107,20 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
}
}
+#ifdef __cplusplus
+}
+#endif
+
+%}
+
+#if defined SWIGPYTHON_FASTPROXY && !defined SWIGPYTHON_BUILTIN
+
+%init %{
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* -----------------------------------------------------------------------------
* Method creation and docstring support functions
* ----------------------------------------------------------------------------- */
@@ -376,6 +183,12 @@ SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyO
}
#endif
+%}
+
+#endif
+
+%init %{
+
/* -----------------------------------------------------------------------------*
* Partial Init method
* -----------------------------------------------------------------------------*/
diff --git a/Lib/python/pyname_compat.i b/Lib/python/pyname_compat.i
index a9630dbe7..789b28443 100644
--- a/Lib/python/pyname_compat.i
+++ b/Lib/python/pyname_compat.i
@@ -25,7 +25,6 @@
*/
%fragment("PySequence_Base", "header", fragment="SwigPySequence_Base") {}
-%fragment("PySequence_Cont", "header", fragment="SwigPySequence_Cont") {}
%fragment("PySwigIterator_T", "header", fragment="SwigPyIterator_T") {}
%fragment("PyPairBoolOutputIterator", "header", fragment="SwigPyPairBoolOutputIterator") {}
%fragment("PySwigIterator", "header", fragment="SwigPyIterator") {}
@@ -38,11 +37,6 @@
#define PyObject_ptr SwigPtr_PyObject
#define PyObject_var SwigVar_PyObject
#define PyOper SwigPyOper
-#define PySeq SwigPySeq
-#define PySequence_ArrowProxy SwigPySequence_ArrowProxy
-#define PySequence_Cont SwigPySequence_Cont
-#define PySequence_InputIterator SwigPySequence_InputIterator
-#define PySequence_Ref SwigPySequence_Ref
#define PySwigClientData SwigPyClientData
#define PySwigClientData_Del SwigPyClientData_Del
#define PySwigClientData_New SwigPyClientData_New
@@ -79,7 +73,6 @@
#define PySwigPacked_repr SwigPyPacked_repr
#define PySwigPacked_str SwigPyPacked_str
#define PySwigPacked_type SwigPyPacked_type
-#define pyseq swigpyseq
#define pyswigobject_type swigpyobject_type
#define pyswigpacked_type swigpypacked_type
%}
diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg
index 6a01af17c..7f372753f 100644
--- a/Lib/python/pyprimtypes.swg
+++ b/Lib/python/pyprimtypes.swg
@@ -104,7 +104,12 @@ SWIG_AsVal_dec(long)(PyObject *obj, long* val)
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
- if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
+ // Largest double not larger than LONG_MAX (not portably calculated easily)
+ // Note that double(LONG_MAX) is stored in a double rounded up by one (for 64-bit long)
+ // 0x7ffffffffffffc00LL == (int64_t)std::nextafter(double(__uint128_t(LONG_MAX)+1), double(0))
+ const double long_max = sizeof(long) == 8 ? 0x7ffffffffffffc00LL : LONG_MAX;
+ // No equivalent needed for 64-bit double(LONG_MIN) is exactly LONG_MIN
+ if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, long_max)) {
if (val) *val = (long)(d);
return res;
}
@@ -166,7 +171,11 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
if (!dispatch) {
double d;
int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
- if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
+ // Largest double not larger than ULONG_MAX (not portably calculated easily)
+ // Note that double(ULONG_MAX) is stored in a double rounded up by one (for 64-bit unsigned long)
+ // 0xfffffffffffff800ULL == (uint64_t)std::nextafter(double(__uint128_t(ULONG_MAX)+1), double(0))
+ const double ulong_max = sizeof(unsigned long) == 8 ? 0xfffffffffffff800ULL : ULONG_MAX;
+ if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ulong_max)) {
if (val) *val = (unsigned long)(d);
return res;
}
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 445a1e324..af60c2b08 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -11,8 +11,8 @@
# error "This version of SWIG only supports Python >= 2.7"
#endif
-#if PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03020000
-# error "This version of SWIG only supports Python 3 >= 3.2"
+#if PY_VERSION_HEX >= 0x03000000 && PY_VERSION_HEX < 0x03030000
+# error "This version of SWIG only supports Python 3 >= 3.3"
#endif
/* Common SWIG API */
@@ -127,7 +127,12 @@ SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
if (!PyList_Check(result)) {
PyObject *o2 = result;
result = PyList_New(1);
- PyList_SetItem(result, 0, o2);
+ if (result) {
+ PyList_SET_ITEM(result, 0, o2);
+ } else {
+ Py_DECREF(obj);
+ return o2;
+ }
}
PyList_Append(result,obj);
Py_DECREF(obj);
@@ -183,6 +188,19 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
}
}
+SWIGINTERN int
+SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) {
+ int no_kwargs = 1;
+ if (kwargs) {
+ assert(PyDict_Check(kwargs));
+ if (PyDict_Size(kwargs) > 0) {
+ PyErr_Format(PyExc_TypeError, "%s() does not take keyword arguments", name);
+ no_kwargs = 0;
+ }
+ }
+ return no_kwargs;
+}
+
/* A functor is a function object with one single object argument */
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL);
@@ -196,6 +214,261 @@ SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssi
#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var
#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Python-specific SWIG API */
+#define SWIG_newvarlink() SWIG_Python_newvarlink()
+#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr)
+#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
+
+/* -----------------------------------------------------------------------------
+ * global variable support code.
+ * ----------------------------------------------------------------------------- */
+
+typedef struct swig_globalvar {
+ char *name; /* Name of global variable */
+ PyObject *(*get_attr)(void); /* Return the current value */
+ int (*set_attr)(PyObject *); /* Set the value */
+ struct swig_globalvar *next;
+} swig_globalvar;
+
+typedef struct swig_varlinkobject {
+ PyObject_HEAD
+ swig_globalvar *vars;
+} swig_varlinkobject;
+
+SWIGINTERN PyObject *
+swig_varlink_repr(PyObject *SWIGUNUSEDPARM(v)) {
+#if PY_VERSION_HEX >= 0x03000000
+ return PyUnicode_InternFromString("<Swig global variables>");
+#else
+ return PyString_FromString("<Swig global variables>");
+#endif
+}
+
+SWIGINTERN PyObject *
+swig_varlink_str(PyObject *o) {
+ swig_varlinkobject *v = (swig_varlinkobject *) o;
+#if PY_VERSION_HEX >= 0x03000000
+ PyObject *str = PyUnicode_InternFromString("(");
+ PyObject *tail;
+ PyObject *joined;
+ swig_globalvar *var;
+ for (var = v->vars; var; var=var->next) {
+ tail = PyUnicode_FromString(var->name);
+ joined = PyUnicode_Concat(str, tail);
+ Py_DecRef(str);
+ Py_DecRef(tail);
+ str = joined;
+ if (var->next) {
+ tail = PyUnicode_InternFromString(", ");
+ joined = PyUnicode_Concat(str, tail);
+ Py_DecRef(str);
+ Py_DecRef(tail);
+ str = joined;
+ }
+ }
+ tail = PyUnicode_InternFromString(")");
+ joined = PyUnicode_Concat(str, tail);
+ Py_DecRef(str);
+ Py_DecRef(tail);
+ str = joined;
+#else
+ PyObject *str = PyString_FromString("(");
+ swig_globalvar *var;
+ for (var = v->vars; var; var=var->next) {
+ PyString_ConcatAndDel(&str,PyString_FromString(var->name));
+ if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", "));
+ }
+ PyString_ConcatAndDel(&str,PyString_FromString(")"));
+#endif
+ return str;
+}
+
+SWIGINTERN void
+swig_varlink_dealloc(PyObject *o) {
+ swig_varlinkobject *v = (swig_varlinkobject *) o;
+ swig_globalvar *var = v->vars;
+ while (var) {
+ swig_globalvar *n = var->next;
+ free(var->name);
+ free(var);
+ var = n;
+ }
+}
+
+SWIGINTERN PyObject *
+swig_varlink_getattr(PyObject *o, char *n) {
+ swig_varlinkobject *v = (swig_varlinkobject *) o;
+ PyObject *res = NULL;
+ swig_globalvar *var = v->vars;
+ while (var) {
+ if (strcmp(var->name,n) == 0) {
+ res = (*var->get_attr)();
+ break;
+ }
+ var = var->next;
+ }
+ if (res == NULL && !PyErr_Occurred()) {
+ PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
+ }
+ return res;
+}
+
+SWIGINTERN int
+swig_varlink_setattr(PyObject *o, char *n, PyObject *p) {
+ swig_varlinkobject *v = (swig_varlinkobject *) o;
+ int res = 1;
+ swig_globalvar *var = v->vars;
+ while (var) {
+ if (strcmp(var->name,n) == 0) {
+ res = (*var->set_attr)(p);
+ break;
+ }
+ var = var->next;
+ }
+ if (res == 1 && !PyErr_Occurred()) {
+ PyErr_Format(PyExc_AttributeError, "Unknown C global variable '%s'", n);
+ }
+ return res;
+}
+
+SWIGINTERN PyTypeObject*
+swig_varlink_type(void) {
+ static char varlink__doc__[] = "Swig var link object";
+#ifndef Py_LIMITED_API
+ static PyTypeObject varlink_type;
+ static int type_init = 0;
+ if (!type_init) {
+ const PyTypeObject tmp = {
+#if PY_VERSION_HEX >= 0x03000000
+ PyVarObject_HEAD_INIT(NULL, 0)
+#else
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+#endif
+ "swigvarlink", /* tp_name */
+ sizeof(swig_varlinkobject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor) swig_varlink_dealloc, /* tp_dealloc */
+#if PY_VERSION_HEX < 0x030800b4
+ (printfunc)0, /*tp_print*/
+#else
+ (Py_ssize_t)0, /*tp_vectorcall_offset*/
+#endif
+ (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 */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ (reprfunc) swig_varlink_str, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ 0, /* tp_flags */
+ varlink__doc__, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+ 0, /* tp_del */
+ 0, /* tp_version_tag */
+#if PY_VERSION_HEX >= 0x03040000
+ 0, /* tp_finalize */
+#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
+#if PY_VERSION_HEX >= 0x030C0000
+ 0, /* tp_watched */
+#endif
+#ifdef COUNT_ALLOCS
+ 0, /* tp_allocs */
+ 0, /* tp_frees */
+ 0, /* tp_maxalloc */
+ 0, /* tp_prev */
+ 0 /* tp_next */
+#endif
+ };
+ varlink_type = tmp;
+ type_init = 1;
+ if (PyType_Ready(&varlink_type) < 0)
+ return NULL;
+ }
+ return &varlink_type;
+#else
+ PyType_Slot slots[] = {
+ { Py_tp_dealloc, (void *)swig_varlink_dealloc },
+ { Py_tp_repr, (void *)swig_varlink_repr },
+ { Py_tp_getattr, (void *)swig_varlink_getattr },
+ { Py_tp_setattr, (void *)swig_varlink_setattr },
+ { Py_tp_str, (void *)swig_varlink_str },
+ { Py_tp_doc, (void *)varlink__doc__ },
+ { 0, NULL }
+ };
+ PyType_Spec spec = {
+ "swigvarlink",
+ sizeof(swig_varlinkobject),
+ 0,
+ Py_TPFLAGS_DEFAULT,
+ slots
+ };
+ return (PyTypeObject *)PyType_FromSpec(&spec);
+#endif
+}
+
+/* Create a variable linking object for use later */
+SWIGINTERN PyObject *
+SWIG_Python_newvarlink(void) {
+ swig_varlinkobject *result = PyObject_New(swig_varlinkobject, swig_varlink_type());
+ if (result) {
+ result->vars = 0;
+ }
+ return ((PyObject*) result);
+}
+
+SWIGINTERN void
+SWIG_Python_addvarlink(PyObject *p, const char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
+ swig_varlinkobject *v = (swig_varlinkobject *) p;
+ swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
+ if (gv) {
+ size_t size = strlen(name)+1;
+ gv->name = (char *)malloc(size);
+ if (gv->name) {
+ memcpy(gv->name, name, size);
+ gv->get_attr = get_attr;
+ gv->set_attr = set_attr;
+ gv->next = v->vars;
+ }
+ }
+ v->vars = gv;
+}
+
+
+static PyObject *Swig_Globals_global = NULL;
+
+SWIGINTERN PyObject *
+SWIG_globals(void) {
+ if (Swig_Globals_global == NULL) {
+ Swig_Globals_global = SWIG_newvarlink();
+ }
+ return Swig_Globals_global;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
/* -----------------------------------------------------------------------------
* Pointer declarations
* ----------------------------------------------------------------------------- */
@@ -266,18 +539,25 @@ SwigPyClientData_New(PyObject* obj)
/* the newraw method and newargs arguments used to create a new raw instance */
if (PyClass_Check(obj)) {
data->newraw = 0;
- data->newargs = obj;
Py_INCREF(obj);
+ data->newargs = obj;
} else {
data->newraw = PyObject_GetAttrString(data->klass, "__new__");
if (data->newraw) {
- Py_INCREF(data->newraw);
- data->newargs = PyTuple_New(1);
- PyTuple_SetItem(data->newargs, 0, obj);
+ data->newargs = PyTuple_New(1);
+ if (data->newargs) {
+ Py_INCREF(obj);
+ PyTuple_SET_ITEM(data->newargs, 0, obj);
+ } else {
+ Py_DECREF(data->newraw);
+ Py_DECREF(data->klass);
+ free(data);
+ return 0;
+ }
} else {
- data->newargs = obj;
+ Py_INCREF(obj);
+ data->newargs = obj;
}
- Py_INCREF(data->newargs);
}
/* the destroy method, aka as the C++ delete method */
data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__");
@@ -286,10 +566,7 @@ SwigPyClientData_New(PyObject* obj)
data->destroy = 0;
}
if (data->destroy) {
- int flags;
- Py_INCREF(data->destroy);
- flags = PyCFunction_GET_FLAGS(data->destroy);
- data->delargs = !(flags & (METH_O));
+ data->delargs = !(PyCFunction_GET_FLAGS(data->destroy) & METH_O);
} else {
data->delargs = 0;
}
@@ -300,10 +577,13 @@ SwigPyClientData_New(PyObject* obj)
}
SWIGRUNTIME void
-SwigPyClientData_Del(SwigPyClientData *data) {
+SwigPyClientData_Del(SwigPyClientData *data)
+{
+ Py_XDECREF(data->klass);
Py_XDECREF(data->newraw);
Py_XDECREF(data->newargs);
Py_XDECREF(data->destroy);
+ free(data);
}
/* =============== SwigPyObject =====================*/
@@ -330,7 +610,7 @@ SwigPyObject_get___dict__(PyObject *v, PyObject *SWIGUNUSEDPARM(args))
if (!sobj->dict)
sobj->dict = PyDict_New();
- Py_INCREF(sobj->dict);
+ Py_XINCREF(sobj->dict);
return sobj->dict;
}
@@ -348,18 +628,21 @@ SwigPyObject_format(const char* fmt, SwigPyObject *v)
PyObject *res = NULL;
PyObject *args = PyTuple_New(1);
if (args) {
- if (PyTuple_SetItem(args, 0, SwigPyObject_long(v)) == 0) {
- PyObject *ofmt = SWIG_Python_str_FromChar(fmt);
+ PyObject *val = SwigPyObject_long(v);
+ if (val) {
+ PyObject *ofmt;
+ PyTuple_SET_ITEM(args, 0, val);
+ ofmt = SWIG_Python_str_FromChar(fmt);
if (ofmt) {
#if PY_VERSION_HEX >= 0x03000000
- res = PyUnicode_Format(ofmt,args);
+ res = PyUnicode_Format(ofmt,args);
#else
- res = PyString_Format(ofmt,args);
+ res = PyString_Format(ofmt,args);
#endif
- Py_DECREF(ofmt);
+ Py_DECREF(ofmt);
}
- Py_DECREF(args);
}
+ Py_DECREF(args);
}
return res;
}
@@ -381,18 +664,23 @@ SwigPyObject_repr(SwigPyObject *v)
{
const char *name = SWIG_TypePrettyName(v->ty);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", (name ? name : "unknown"), (void *)v);
- if (v->next) {
+ if (repr && v->next) {
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
+ if (nrep) {
# if PY_VERSION_HEX >= 0x03000000
- PyObject *joined = PyUnicode_Concat(repr, nrep);
- Py_DecRef(repr);
- Py_DecRef(nrep);
- repr = joined;
+ PyObject *joined = PyUnicode_Concat(repr, nrep);
+ Py_DecRef(repr);
+ Py_DecRef(nrep);
+ repr = joined;
# else
- PyString_ConcatAndDel(&repr,nrep);
+ PyString_ConcatAndDel(&repr,nrep);
# endif
+ } else {
+ Py_DecRef(repr);
+ repr = NULL;
+ }
}
- return repr;
+ return repr;
}
/* We need a version taking two PyObject* parameters so it's a valid
@@ -415,12 +703,14 @@ SwigPyObject_compare(SwigPyObject *v, SwigPyObject *w)
SWIGRUNTIME PyObject*
SwigPyObject_richcompare(SwigPyObject *v, SwigPyObject *w, int op)
{
- PyObject* res;
- if( op != Py_EQ && op != Py_NE ) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
+ PyObject* res = NULL;
+ if (!PyErr_Occurred()) {
+ if (op != Py_EQ && op != Py_NE) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0);
}
- res = PyBool_FromLong( (SwigPyObject_compare(v, w)==0) == (op == Py_EQ) ? 1 : 0);
return res;
}
@@ -448,20 +738,34 @@ SwigPyObject_type(void) {
SWIGRUNTIMEINLINE int
SwigPyObject_Check(PyObject *op) {
-#ifdef SWIGPYTHON_BUILTIN
PyTypeObject *target_tp = SwigPyObject_type();
- if (PyType_IsSubtype(op->ob_type, target_tp))
+ PyTypeObject *op_type = Py_TYPE(op);
+#ifdef SWIGPYTHON_BUILTIN
+ if (PyType_IsSubtype(op_type, target_tp))
return 1;
- return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
+ return (strcmp(op_type->tp_name, "SwigPyObject") == 0);
#else
- return (Py_TYPE(op) == SwigPyObject_type())
- || (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0);
+ if (op_type == target_tp)
+ return 1;
+# ifdef Py_LIMITED_API
+ int cmp;
+ PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__");
+ if (!tp_name)
+ return 0;
+ cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyObject");
+ Py_DECREF(tp_name);
+ return cmp == 0;
+# else
+ return (strcmp(op_type->tp_name, "SwigPyObject") == 0);
+# endif
#endif
}
SWIGRUNTIME PyObject *
SwigPyObject_New(void *ptr, swig_type_info *ty, int own);
+static PyObject* Swig_Capsule_global = NULL;
+
SWIGRUNTIME void
SwigPyObject_dealloc(PyObject *v)
{
@@ -488,8 +792,12 @@ SwigPyObject_dealloc(PyObject *v)
if (data->delargs) {
/* we need to create a temporary object to carry the destroy operation */
PyObject *tmp = SwigPyObject_New(sobj->ptr, ty, 0);
- res = SWIG_Python_CallFunctor(destroy, tmp);
- Py_DECREF(tmp);
+ if (tmp) {
+ res = SWIG_Python_CallFunctor(destroy, tmp);
+ } else {
+ res = 0;
+ }
+ Py_XDECREF(tmp);
} else {
PyCFunction meth = PyCFunction_GET_FUNCTION(destroy);
PyObject *mself = PyCFunction_GET_SELF(destroy);
@@ -508,8 +816,12 @@ SwigPyObject_dealloc(PyObject *v)
printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown"));
}
#endif
- }
+ Py_XDECREF(Swig_Capsule_global);
+ }
Py_XDECREF(next);
+#ifdef SWIGPYTHON_BUILTIN
+ Py_XDECREF(sobj->dict);
+#endif
PyObject_DEL(v);
}
@@ -521,6 +833,7 @@ SwigPyObject_append(PyObject* v, PyObject* next)
PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject");
return NULL;
}
+ ((SwigPyObject *)next)->next = sobj->next;
sobj->next = next;
Py_INCREF(next);
return SWIG_Py_Void();
@@ -565,9 +878,9 @@ SwigPyObject_own(PyObject *v, PyObject *args)
PyObject *obj = PyBool_FromLong(sobj->own);
if (val) {
if (PyObject_IsTrue(val)) {
- SwigPyObject_acquire(v,args);
+ Py_DECREF(SwigPyObject_acquire(v,args));
} else {
- SwigPyObject_disown(v,args);
+ Py_DECREF(SwigPyObject_disown(v,args));
}
}
return obj;
@@ -588,7 +901,7 @@ swigobject_methods[] = {
SWIGRUNTIME PyTypeObject*
SwigPyObject_TypeOnce(void) {
static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
-
+#ifndef Py_LIMITED_API
static PyNumberMethods SwigPyObject_as_number = {
(binaryfunc)0, /*nb_add*/
(binaryfunc)0, /*nb_subtract*/
@@ -647,7 +960,11 @@ SwigPyObject_TypeOnce(void) {
sizeof(SwigPyObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyObject_dealloc, /* tp_dealloc */
- 0, /* tp_print */
+#if PY_VERSION_HEX < 0x030800b4
+ (printfunc)0, /*tp_print*/
+#else
+ (Py_ssize_t)0, /*tp_vectorcall_offset*/
+#endif
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
#if PY_VERSION_HEX >= 0x03000000
@@ -696,6 +1013,15 @@ SwigPyObject_TypeOnce(void) {
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
+#if PY_VERSION_HEX >= 0x030C0000
+ 0, /* tp_watched */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -706,21 +1032,50 @@ SwigPyObject_TypeOnce(void) {
};
swigpyobject_type = tmp;
type_init = 1;
- if (PyType_Ready(&swigpyobject_type) < 0)
+ if (PyType_Ready(&swigpyobject_type) != 0)
return NULL;
}
return &swigpyobject_type;
+#else
+ PyType_Slot slots[] = {
+ { Py_tp_dealloc, (void *)SwigPyObject_dealloc },
+ { Py_tp_repr, (void *)SwigPyObject_repr },
+ { Py_tp_getattro, (void *)PyObject_GenericGetAttr },
+ { Py_tp_doc, (void *)swigobject_doc },
+ { Py_tp_richcompare, (void *)SwigPyObject_richcompare },
+ { Py_tp_methods, (void *)swigobject_methods },
+ { Py_nb_int, (void *)SwigPyObject_long },
+ { 0, NULL }
+ };
+ PyType_Spec spec = {
+ "SwigPyObject",
+ sizeof(SwigPyObject),
+ 0,
+ Py_TPFLAGS_DEFAULT,
+ slots
+ };
+ return (PyTypeObject *)PyType_FromSpec(&spec);
+#endif
}
SWIGRUNTIME PyObject *
SwigPyObject_New(void *ptr, swig_type_info *ty, int own)
{
- SwigPyObject *sobj = PyObject_NEW(SwigPyObject, SwigPyObject_type());
+ SwigPyObject *sobj = PyObject_New(SwigPyObject, SwigPyObject_type());
if (sobj) {
sobj->ptr = ptr;
sobj->ty = ty;
sobj->own = own;
sobj->next = 0;
+#ifdef SWIGPYTHON_BUILTIN
+ sobj->dict = 0;
+#endif
+ if (own == SWIG_POINTER_OWN) {
+ /* Obtain a reference to the Python capsule wrapping the module information, so that the
+ * module information is correctly destroyed after all SWIG python objects have been freed
+ * by the GC (and corresponding destructors invoked) */
+ Py_XINCREF(Swig_Capsule_global);
+ }
}
return (PyObject *)sobj;
}
@@ -777,8 +1132,20 @@ SwigPyPacked_type(void) {
SWIGRUNTIMEINLINE int
SwigPyPacked_Check(PyObject *op) {
- return ((op)->ob_type == SwigPyPacked_TypeOnce())
- || (strcmp((op)->ob_type->tp_name,"SwigPyPacked") == 0);
+ PyTypeObject* op_type = Py_TYPE(op);
+ if (op_type == SwigPyPacked_TypeOnce())
+ return 1;
+#ifdef Py_LIMITED_API
+ int cmp;
+ PyObject *tp_name = PyObject_GetAttrString((PyObject *)op_type, "__name__");
+ if (!tp_name)
+ return 0;
+ cmp = PyUnicode_CompareWithASCIIString(tp_name, "SwigPyPacked");
+ Py_DECREF(tp_name);
+ return cmp == 0;
+#else
+ return (strcmp(op_type->tp_name, "SwigPyPacked") == 0);
+#endif
}
SWIGRUNTIME void
@@ -794,6 +1161,7 @@ SwigPyPacked_dealloc(PyObject *v)
SWIGRUNTIME PyTypeObject*
SwigPyPacked_TypeOnce(void) {
static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
+#ifndef Py_LIMITED_API
static PyTypeObject swigpypacked_type;
static int type_init = 0;
if (!type_init) {
@@ -808,7 +1176,11 @@ SwigPyPacked_TypeOnce(void) {
sizeof(SwigPyPacked), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)SwigPyPacked_dealloc, /* tp_dealloc */
- 0, /* tp_print */
+#if PY_VERSION_HEX < 0x030800b4
+ (printfunc)0, /*tp_print*/
+#else
+ (Py_ssize_t)0, /*tp_vectorcall_offset*/
+#endif
(getattrfunc)0, /* tp_getattr */
(setattrfunc)0, /* tp_setattr */
#if PY_VERSION_HEX>=0x03000000
@@ -857,6 +1229,15 @@ SwigPyPacked_TypeOnce(void) {
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
+#if PY_VERSION_HEX >= 0x030C0000
+ 0, /* tp_watched */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -867,16 +1248,34 @@ SwigPyPacked_TypeOnce(void) {
};
swigpypacked_type = tmp;
type_init = 1;
- if (PyType_Ready(&swigpypacked_type) < 0)
+ if (PyType_Ready(&swigpypacked_type) != 0)
return NULL;
}
return &swigpypacked_type;
+#else
+ PyType_Slot slots[] = {
+ { Py_tp_dealloc, (void *)SwigPyPacked_dealloc },
+ { Py_tp_repr, (void *)SwigPyPacked_repr },
+ { Py_tp_str, (void *)SwigPyPacked_str },
+ { Py_tp_getattro, (void *)PyObject_GenericGetAttr },
+ { Py_tp_doc, (void *)swigpacked_doc },
+ { 0, NULL }
+ };
+ PyType_Spec spec = {
+ "SwigPyPacked",
+ sizeof(SwigPyPacked),
+ 0,
+ Py_TPFLAGS_DEFAULT,
+ slots
+ };
+ return (PyTypeObject *)PyType_FromSpec(&spec);
+#endif
}
SWIGRUNTIME PyObject *
SwigPyPacked_New(void *ptr, size_t size, swig_type_info *ty)
{
- SwigPyPacked *sobj = PyObject_NEW(SwigPyPacked, SwigPyPacked_type());
+ SwigPyPacked *sobj = PyObject_New(SwigPyPacked, SwigPyPacked_type());
if (sobj) {
void *pack = malloc(size);
if (pack) {
@@ -1057,12 +1456,19 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
}
}
if (sobj) {
- if (own)
- *own = *own | sobj->own;
- if (flags & SWIG_POINTER_DISOWN) {
- sobj->own = 0;
+ if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !sobj->own) {
+ res = SWIG_ERROR_RELEASE_NOT_OWNED;
+ } else {
+ if (own)
+ *own = *own | sobj->own;
+ if (flags & SWIG_POINTER_DISOWN) {
+ sobj->own = 0;
+ }
+ if (flags & SWIG_POINTER_CLEAR) {
+ sobj->ptr = 0;
+ }
+ res = SWIG_OK;
}
- res = SWIG_OK;
} else {
if (implicit_conv) {
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
@@ -1121,10 +1527,20 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
swig_cast_info *tc;
/* here we get the method pointer for callbacks */
+#ifndef Py_LIMITED_API
const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
+#else
+ PyObject* pystr_doc = PyObject_GetAttrString(obj, "__doc__");
+ PyObject *bytes = NULL;
+ const char *doc = pystr_doc ? SWIG_PyUnicode_AsUTF8AndSize(pystr_doc, NULL, &bytes) : 0;
+#endif
const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (desc)
desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
+#ifdef Py_LIMITED_API
+ Py_XDECREF(bytes);
+ Py_XDECREF(pystr_doc);
+#endif
if (!desc)
return SWIG_ERROR;
tc = SWIG_TypeCheck(desc,ty);
@@ -1175,16 +1591,23 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
PyObject **dictptr = _PyObject_GetDictPtr(inst);
if (dictptr != NULL) {
- PyObject *dict = *dictptr;
- if (dict == NULL) {
- dict = PyDict_New();
- *dictptr = dict;
- PyDict_SetItem(dict, SWIG_This(), swig_this);
- }
+ PyObject *dict = *dictptr;
+ if (dict == NULL) {
+ dict = PyDict_New();
+ *dictptr = dict;
+ }
+ if (dict) {
+ PyDict_SetItem(dict, SWIG_This(), swig_this);
+ } else{
+ Py_DECREF(inst);
+ inst = 0;
+ }
}
#else
- PyObject *key = SWIG_This();
- PyObject_SetAttr(inst, key, swig_this);
+ if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) {
+ Py_DECREF(inst);
+ inst = 0;
+ }
#endif
}
} else {
@@ -1193,11 +1616,20 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
if (empty_args) {
PyObject *empty_kwargs = PyDict_New();
if (empty_kwargs) {
- inst = ((PyTypeObject *)data->newargs)->tp_new((PyTypeObject *)data->newargs, empty_args, empty_kwargs);
+#ifndef Py_LIMITED_API
+ newfunc newfn = ((PyTypeObject *)data->newargs)->tp_new;
+#else
+ newfunc newfn = (newfunc)PyType_GetSlot((PyTypeObject *)data->newargs, Py_tp_new);
+#endif
+ inst = newfn((PyTypeObject *)data->newargs, empty_args, empty_kwargs);
Py_DECREF(empty_kwargs);
if (inst) {
- PyObject_SetAttr(inst, SWIG_This(), swig_this);
- Py_TYPE(inst)->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
+ if (PyObject_SetAttr(inst, SWIG_This(), swig_this) == -1) {
+ Py_DECREF(inst);
+ inst = 0;
+ } else {
+ PyType_Modified(Py_TYPE(inst));
+ }
}
}
Py_DECREF(empty_args);
@@ -1214,25 +1646,25 @@ SWIG_Python_NewShadowInstance(SwigPyClientData *data, PyObject *swig_this)
return inst;
}
-SWIGRUNTIME void
+SWIGRUNTIME int
SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
{
- PyObject *dict;
#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
- PyObject **dictptr = _PyObject_GetDictPtr(inst);
- if (dictptr != NULL) {
- dict = *dictptr;
- if (dict == NULL) {
- dict = PyDict_New();
- *dictptr = dict;
- }
- PyDict_SetItem(dict, SWIG_This(), swig_this);
- return;
- }
-#endif
- dict = PyObject_GetAttrString(inst, "__dict__");
- PyDict_SetItem(dict, SWIG_This(), swig_this);
- Py_DECREF(dict);
+ PyObject **dictptr = _PyObject_GetDictPtr(inst);
+ if (dictptr != NULL) {
+ PyObject *dict = *dictptr;
+ if (dict == NULL) {
+ dict = PyDict_New();
+ *dictptr = dict;
+ }
+ if (dict) {
+ return PyDict_SetItem(dict, SWIG_This(), swig_this);
+ } else{
+ return -1;
+ }
+ }
+#endif
+ return PyObject_SetAttr(inst, SWIG_This(), swig_this);
}
@@ -1244,9 +1676,10 @@ SWIG_Python_InitShadowInstance(PyObject *args) {
} else {
SwigPyObject *sthis = SWIG_Python_GetSwigThis(obj[0]);
if (sthis) {
- SwigPyObject_append((PyObject*) sthis, obj[1]);
+ Py_DECREF(SwigPyObject_append((PyObject*) sthis, obj[1]));
} else {
- SWIG_Python_SetSwigThis(obj[0], obj[1]);
+ if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0)
+ return NULL;
}
return SWIG_Py_Void();
}
@@ -1270,7 +1703,12 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f
if (flags & SWIG_BUILTIN_TP_INIT) {
newobj = (SwigPyObject*) self;
if (newobj->ptr) {
- PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0);
+#ifndef Py_LIMITED_API
+ allocfunc alloc = clientdata->pytype->tp_alloc;
+#else
+ allocfunc alloc = (allocfunc)PyType_GetSlot(clientdata->pytype, Py_tp_alloc);
+#endif
+ PyObject *next_self = alloc(clientdata->pytype, 0);
while (newobj->next)
newobj = (SwigPyObject *) newobj->next;
newobj->next = next_self;
@@ -1282,7 +1720,9 @@ SWIG_Python_NewPointerObj(PyObject *self, void *ptr, swig_type_info *type, int f
} else {
newobj = PyObject_New(SwigPyObject, clientdata->pytype);
#ifdef SWIGPYTHON_BUILTIN
- newobj->dict = 0;
+ if (newobj) {
+ newobj->dict = 0;
+ }
#endif
}
if (newobj) {
@@ -1321,39 +1761,61 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
void *SWIG_ReturnGlobalTypeList(void *);
#endif
+static PyObject *Swig_TypeCache_global = NULL;
+
+/* The python cached type query */
+SWIGRUNTIME PyObject *
+SWIG_Python_TypeCache(void) {
+ if (Swig_TypeCache_global == NULL) {
+ Swig_TypeCache_global = PyDict_New();
+ }
+ return Swig_TypeCache_global;
+}
+
SWIGRUNTIME swig_module_info *
SWIG_Python_GetModule(void *SWIGUNUSEDPARM(clientdata)) {
+#ifdef SWIG_LINK_RUNTIME
static void *type_pointer = (void *)0;
/* first check if module already created */
if (!type_pointer) {
-#ifdef SWIG_LINK_RUNTIME
type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
+ }
#else
- type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0);
- if (PyErr_Occurred()) {
- PyErr_Clear();
- type_pointer = (void *)0;
- }
-#endif
+ void *type_pointer = PyCapsule_Import(SWIGPY_CAPSULE_NAME, 0);
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ type_pointer = (void *)0;
}
+#endif
return (swig_module_info *) type_pointer;
}
+
+static int interpreter_counter = 0; /* how many (sub-)interpreters are using swig_module's types */
+
SWIGRUNTIME void
SWIG_Python_DestroyModule(PyObject *obj)
{
swig_module_info *swig_module = (swig_module_info *) PyCapsule_GetPointer(obj, SWIGPY_CAPSULE_NAME);
swig_type_info **types = swig_module->types;
size_t i;
+ if (--interpreter_counter != 0) /* another sub-interpreter may still be using the swig_module's types */
+ return;
for (i =0; i < swig_module->size; ++i) {
swig_type_info *ty = types[i];
if (ty->owndata) {
SwigPyClientData *data = (SwigPyClientData *) ty->clientdata;
+ ty->clientdata = 0;
if (data) SwigPyClientData_Del(data);
}
}
Py_DECREF(SWIG_This());
Swig_This_global = NULL;
+ Py_DECREF(SWIG_globals());
+ Swig_Globals_global = NULL;
+ Py_DECREF(SWIG_Python_TypeCache());
+ Swig_TypeCache_global = NULL;
+ Swig_Capsule_global = NULL;
}
SWIGRUNTIME void
@@ -1367,19 +1829,17 @@ SWIG_Python_SetModule(swig_module_info *swig_module) {
#endif
PyObject *pointer = PyCapsule_New((void *) swig_module, SWIGPY_CAPSULE_NAME, SWIG_Python_DestroyModule);
if (pointer && module) {
- PyModule_AddObject(module, "type_pointer_capsule" SWIG_TYPE_TABLE_NAME, pointer);
+ if (PyModule_AddObject(module, SWIGPY_CAPSULE_ATTR_NAME, pointer) == 0) {
+ ++interpreter_counter;
+ Swig_Capsule_global = pointer;
+ } else {
+ Py_DECREF(pointer);
+ }
} else {
Py_XDECREF(pointer);
}
}
-/* The python cached type query */
-SWIGRUNTIME PyObject *
-SWIG_Python_TypeCache(void) {
- static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New();
- return cache;
-}
-
SWIGRUNTIME swig_type_info *
SWIG_Python_TypeQuery(const char *type)
{
@@ -1394,8 +1854,10 @@ SWIG_Python_TypeQuery(const char *type)
descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type);
if (descriptor) {
obj = PyCapsule_New((void*) descriptor, NULL, NULL);
- PyDict_SetItem(cache, key, obj);
- Py_DECREF(obj);
+ if (obj) {
+ PyDict_SetItem(cache, key, obj);
+ Py_DECREF(obj);
+ }
}
}
Py_DECREF(key);
@@ -1419,7 +1881,8 @@ SWIG_Python_AddErrMesg(const char* mesg, int infront)
PyErr_Fetch(&type, &value, &traceback);
if (value) {
PyObject *old_str = PyObject_Str(value);
- const char *tmp = SWIG_Python_str_AsChar(old_str);
+ PyObject *bytes = NULL;
+ const char *tmp = SWIG_PyUnicode_AsUTF8AndSize(old_str, NULL, &bytes);
const char *errmesg = tmp ? tmp : "Invalid error message";
Py_XINCREF(type);
PyErr_Clear();
@@ -1428,7 +1891,7 @@ SWIG_Python_AddErrMesg(const char* mesg, int infront)
} else {
PyErr_Format(type, "%s %s", errmesg, mesg);
}
- SWIG_Python_str_DelForPy3(tmp);
+ Py_XDECREF(bytes);
Py_DECREF(old_str);
}
return 1;
@@ -1473,21 +1936,25 @@ SWIG_Python_TypeError(const char *type, PyObject *obj)
} else
#endif
{
+#ifndef Py_LIMITED_API
+ /* tp_name is not accessible */
const char *otype = (obj ? obj->ob_type->tp_name : 0);
if (otype) {
PyObject *str = PyObject_Str(obj);
- const char *cstr = str ? SWIG_Python_str_AsChar(str) : 0;
+ PyObject *bytes = NULL;
+ const char *cstr = str ? SWIG_PyUnicode_AsUTF8AndSize(str, NULL, &bytes) : 0;
if (cstr) {
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
type, otype, cstr);
- SWIG_Python_str_DelForPy3(cstr);
} else {
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
type, otype);
}
+ Py_XDECREF(bytes);
Py_XDECREF(str);
return;
}
+#endif
}
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
} else {
@@ -1502,12 +1969,6 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int SWIGUNUSEDPARM(arg
void *result;
if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
PyErr_Clear();
-#if SWIG_POINTER_EXCEPTION
- if (flags) {
- SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
- SWIG_Python_ArgFail(argnum);
- }
-#endif
}
return result;
}
@@ -1538,7 +1999,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
}
if (!tp->tp_dict) {
- if (PyType_Ready(tp) < 0)
+ if (PyType_Ready(tp) != 0)
goto done;
}
@@ -1553,7 +2014,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
} else {
encoded_name = PyUnicode_AsUTF8String(name);
if (!encoded_name)
- return -1;
+ goto done;
}
PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name));
Py_DECREF(encoded_name);
diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg
index 751bc8d5f..3f45af890 100644
--- a/Lib/python/pyruntime.swg
+++ b/Lib/python/pyruntime.swg
@@ -4,14 +4,38 @@
# include <math.h>
#endif
+#if !defined(PY_SSIZE_T_CLEAN) && !defined(SWIG_NO_PY_SSIZE_T_CLEAN)
+#define PY_SSIZE_T_CLEAN
+#endif
+
+#if __GNUC__ >= 7
+#pragma GCC diagnostic push
+#if defined(__cplusplus) && __cplusplus >=201703L
+#pragma GCC diagnostic ignored "-Wregister" /* For python-2.7 headers that use register */
+#endif
+#endif
+
#if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)
/* Use debug wrappers with the Python release dll */
+
+#if defined(_MSC_VER) && _MSC_VER >= 1929
+/* Workaround compilation errors when redefining _DEBUG in MSVC 2019 version 16.10 and later
+ * See https://github.com/swig/swig/issues/2090 */
+# include <corecrt.h>
+#endif
+
# undef _DEBUG
# include <Python.h>
# define _DEBUG 1
#else
# include <Python.h>
#endif
+
+#if __GNUC__ >= 7
+#pragma GCC diagnostic pop
+#endif
+
+#include <stdio.h>
%}
%insert(runtime) "swigrun.swg"; /* SWIG API */
diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg
index 0242e4d35..afa71350a 100644
--- a/Lib/python/pystdcommon.swg
+++ b/Lib/python/pystdcommon.swg
@@ -45,11 +45,20 @@ namespace swig {
template <class Type>
struct traits_asptr {
static int asptr(PyObject *obj, Type **val) {
- Type *p = 0;
+ int res = SWIG_ERROR;
swig_type_info *descriptor = type_info<Type>();
- int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
- if (SWIG_IsOK(res)) {
- if (val) *val = p;
+ if (val) {
+ Type *p = 0;
+ int newmem = 0;
+ res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR;
+ if (SWIG_IsOK(res)) {
+ if (newmem & SWIG_CAST_NEW_MEMORY) {
+ res |= SWIG_NEWOBJMASK;
+ }
+ *val = p;
+ }
+ } else {
+ res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR;
}
return res;
}
diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg
index 93f48acfa..1cb4e993a 100644
--- a/Lib/python/pystrings.swg
+++ b/Lib/python/pystrings.swg
@@ -2,8 +2,10 @@
* utility methods for char strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
+/* Return string from Python obj. NOTE: obj must remain in scope in order
+ to use the returned cptr (but only when alloc is set to SWIG_OLDOBJ) */
SWIGINTERN int
-SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
+SWIG_AsCharPtrAndSize(PyObject *obj, char **cptr, size_t *psize, int *alloc)
{
%#if PY_VERSION_HEX>=0x03000000
%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
@@ -16,53 +18,31 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
%#endif
{
char *cstr; Py_ssize_t len;
+ PyObject *bytes = NULL;
int ret = SWIG_OK;
-%#if PY_VERSION_HEX>=0x03000000
-%#if !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
- if (!alloc && cptr) {
- /* We can't allow converting without allocation, since the internal
- representation of string in Python 3 is UCS-2/UCS-4 but we require
- a UTF-8 representation.
- TODO(bhy) More detailed explanation */
- return SWIG_RuntimeError;
- }
- obj = PyUnicode_AsUTF8String(obj);
- if (!obj)
- return SWIG_TypeError;
if (alloc)
- *alloc = SWIG_NEWOBJ;
-%#endif
- PyBytes_AsStringAndSize(obj, &cstr, &len);
+ *alloc = SWIG_OLDOBJ;
+%#if PY_VERSION_HEX>=0x03000000 && defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
+ if (PyBytes_AsStringAndSize(obj, &cstr, &len) == -1)
+ return SWIG_TypeError;
%#else
- PyString_AsStringAndSize(obj, &cstr, &len);
-%#endif
- if (cptr) {
+ cstr = (char *)SWIG_PyUnicode_AsUTF8AndSize(obj, &len, &bytes);
+ if (!cstr)
+ return SWIG_TypeError;
+ /* The returned string is only duplicated if the char * returned is not owned and memory managed by obj */
+ if (bytes && cptr) {
if (alloc) {
- if (*alloc == SWIG_NEWOBJ) {
- *cptr = %new_copy_array(cstr, len + 1, char);
- *alloc = SWIG_NEWOBJ;
- } else {
- *cptr = cstr;
- *alloc = SWIG_OLDOBJ;
- }
+ cstr = %new_copy_array(cstr, len + 1, char);
+ *alloc = SWIG_NEWOBJ;
} else {
-%#if PY_VERSION_HEX>=0x03000000
-%#if defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
- *cptr = PyBytes_AsString(obj);
-%#else
- assert(0); /* Should never reach here with Unicode strings in Python 3 */
-%#endif
-%#else
- *cptr = SWIG_Python_str_AsChar(obj);
- if (!*cptr)
- ret = SWIG_TypeError;
-%#endif
+ /* alloc must be set in order to clean up allocated memory */
+ return SWIG_RuntimeError;
}
}
- if (psize) *psize = len + 1;
-%#if PY_VERSION_HEX>=0x03000000 && !defined(SWIG_PYTHON_STRICT_BYTE_CHAR)
- Py_XDECREF(obj);
%#endif
+ if (cptr) *cptr = cstr;
+ if (psize) *psize = len + 1;
+ Py_XDECREF(bytes);
return ret;
} else {
%#if defined(SWIG_PYTHON_2_UNICODE)
diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg
index 0138e40e4..a21034524 100644
--- a/Lib/python/pythonkw.swg
+++ b/Lib/python/pythonkw.swg
@@ -2,7 +2,7 @@
Warnings for Python keywords, built-in names and bad names.
*/
-#define PYTHONKW(x) %keywordwarn("'" `x` "' is a python keyword, renaming to '_" `x` "'", rename="_%s") `x`
+#define PYTHONKW(x) %keywordwarn("'" `x` "' is a python keyword", rename="_%s") `x`
#define PYTHONBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in python") `x`
diff --git a/Lib/python/pythreads.swg b/Lib/python/pythreads.swg
index d8797e659..96a64710c 100644
--- a/Lib/python/pythreads.swg
+++ b/Lib/python/pythreads.swg
@@ -8,8 +8,12 @@
# define SWIG_PYTHON_USE_GIL
# endif
# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
-# ifndef SWIG_PYTHON_INITIALIZE_THREADS
-# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads()
+# if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
+# if PY_VERSION_HEX < 0x03070000
+# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads()
+# else
+# define SWIG_PYTHON_INITIALIZE_THREADS
+# endif
# endif
# ifdef __cplusplus /* C++ code */
class SWIG_Python_Thread_Block {
@@ -24,7 +28,7 @@
bool status;
PyThreadState *save;
public:
- void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
+ void end() { if (status) { status = false; PyEval_RestoreThread(save); }}
SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {}
~SWIG_Python_Thread_Allow() { end(); }
};
diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg
index 0eda17cda..0ae25a686 100644
--- a/Lib/python/pytypemaps.swg
+++ b/Lib/python/pytypemaps.swg
@@ -83,7 +83,7 @@
{ SWIG_PY_POINTER, "$symname", 0, 0, (void *)($value), &$descriptor }
%typemap(consttab) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY));
-%typemap(constcode) SWIGTYPE ((*)(ANY)) "";
+%typemap(constcode) SWIGTYPE ((*)(ANY)) ""
%typemap(constcode) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY));
diff --git a/Lib/python/std_array.i b/Lib/python/std_array.i
index a3de3125b..707b35475 100644
--- a/Lib/python/std_array.i
+++ b/Lib/python/std_array.i
@@ -19,15 +19,43 @@
}
};
- template <class SwigPySeq, class T, size_t N>
- inline void
- assign(const SwigPySeq& swigpyseq, std::array<T, N>* seq) {
- if (swigpyseq.size() < seq->size())
- throw std::invalid_argument("std::array cannot be expanded in size");
- else if (swigpyseq.size() > seq->size())
- throw std::invalid_argument("std::array cannot be reduced in size");
- std::copy(swigpyseq.begin(), swigpyseq.end(), seq->begin());
- }
+ template <class T, size_t N>
+ struct IteratorProtocol<std::array<T, N>, T> {
+
+ static void assign(PyObject *obj, std::array<T, N> *seq) {
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ size_t count = 0;
+ typename std::array<T, N>::iterator array_iter = seq->begin();
+ while (item && (count < N)) {
+ ++count;
+ *array_iter++ = swig::as<T>(item);
+ item = PyIter_Next(iter);
+ }
+ if (count != N || item)
+ throw std::invalid_argument("std::array size does not match source container size");
+ }
+ }
+
+ static bool check(PyObject *obj) {
+ bool ret = false;
+ SwigVar_PyObject iter = PyObject_GetIter(obj);
+ if (iter) {
+ SwigVar_PyObject item = PyIter_Next(iter);
+ size_t count = 0;
+ ret = true;
+ while (item && (count < N)) {
+ ++count;
+ ret = swig::check<T>(item);
+ item = ret ? PyIter_Next(iter) : 0;
+ }
+ if (count != N || item)
+ ret = false;
+ }
+ return ret;
+ }
+ };
template <class T, size_t N>
inline void
diff --git a/Lib/python/std_auto_ptr.i b/Lib/python/std_auto_ptr.i
index e310e00c8..3d7ae8ba1 100644
--- a/Lib/python/std_auto_ptr.i
+++ b/Lib/python/std_auto_ptr.i
@@ -1,17 +1,39 @@
-/*
- The typemaps here allow to handle functions returning std::auto_ptr<>,
- which is the most common use of this type. If you have functions taking it
- as parameter, these typemaps can't be used for them and you need to do
- something else (e.g. use shared_ptr<> which SWIG supports fully).
- */
+/* -----------------------------------------------------------------------------
+ * std_auto_ptr.i
+ *
+ * SWIG library file for handling std::auto_ptr.
+ * Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
+ * class when returning a std::auto_ptr from a function.
+ * Memory ownership is passed from the proxy class to the std::auto_ptr in the
+ * C++ layer when passed as a parameter to a wrapped function.
+ * ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
-%typemap (out) std::auto_ptr<TYPE > %{
- %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
+%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
+ res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
+ if (!SWIG_IsOK(res)) {
+ if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
+ %releasenotowned_fail(res, "TYPE *", $symname, $argnum);
+ } else {
+ %argument_fail(res, "TYPE *", $symname, $argnum);
+ }
+ }
+ $1.reset((TYPE *)argp);
+}
+
+%typemap (out) std::auto_ptr< TYPE > %{
+ %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
-%template() std::auto_ptr<TYPE >;
+
+%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
+ $1 = SWIG_CheckState(res);
+}
+
+%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
- template <class T> class auto_ptr {};
-}
+ template <class T> class auto_ptr {};
+}
diff --git a/Lib/python/std_carray.i b/Lib/python/std_carray.i
deleted file mode 100644
index 680d67115..000000000
--- a/Lib/python/std_carray.i
+++ /dev/null
@@ -1,54 +0,0 @@
-%include <pycontainer.swg>
-
-
-%fragment("StdCarrayTraits","header",fragment="StdSequenceTraits")
-{
-namespace swig {
- template <class T, size_t S>
- struct traits_asptr<std::carray<T, S> > {
- static int asptr(PyObject *obj, std::carray<T, S> **array) {
- return traits_asptr_stdseq<std::carray<T, S> >::asptr(obj, array);
- }
- };
-}
-}
-
-%warnfilter(SWIGWARN_IGNORE_OPERATOR_INDEX) std::carray::operator[];
-
-%extend std::carray {
- %fragment(SWIG_Traits_frag(std::carray<_Type, _Size >), "header",
- fragment="SwigPyIterator_T",
- fragment=SWIG_Traits_frag(_Type),
- fragment="StdCarrayTraits") {
- namespace swig {
- template <> struct traits<std::carray<_Type, _Size > > {
- typedef pointer_category category;
- static const char* type_name() {
- return "std::carray<" #_Type "," #_Size " >";
- }
- };
- }
- }
-
- %typemaps_asptr(SWIG_TYPECHECK_VECTOR, swig::asptr,
- SWIG_Traits_frag(std::carray<_Type, _Size >),
- std::carray<_Type, _Size >);
-
- %typemap(out,noblock=1) iterator, const_iterator {
- $result = SWIG_NewPointerObj(swig::make_output_iterator((const $type &)$1),
- swig::SwigPyIterator::descriptor(),SWIG_POINTER_OWN);
- }
-
- inline size_t __len__() const { return self->size(); }
-
- inline const _Type& __getitem__(size_t i) const { return (*self)[i]; }
-
- inline void __setitem__(size_t i, const _Type& v) { (*self)[i] = v; }
-
-
- swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF) {
- return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
- }
-}
-
-%include <std/std_carray.swg>
diff --git a/Lib/python/std_filesystem.i b/Lib/python/std_filesystem.i
new file mode 100644
index 000000000..5b9f33589
--- /dev/null
+++ b/Lib/python/std_filesystem.i
@@ -0,0 +1,121 @@
+/* -----------------------------------------------------------------------------
+ * std_filesystem.i
+ *
+ * SWIG typemaps for std::filesystem::path
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include <filesystem>
+%}
+
+%fragment("SWIG_std_filesystem", "header") {
+SWIGINTERN PyObject *SWIG_std_filesystem_importPathClass() {
+ PyObject *module = PyImport_ImportModule("pathlib");
+ PyObject *cls = PyObject_GetAttrString(module, "Path");
+ Py_DECREF(module);
+ return cls;
+}
+
+SWIGINTERN bool SWIG_std_filesystem_isPathInstance(PyObject *obj) {
+ PyObject *cls = SWIG_std_filesystem_importPathClass();
+ bool is_instance = PyObject_IsInstance(obj, cls);
+ Py_DECREF(cls);
+ return is_instance;
+}
+}
+
+%typemap(in, fragment="SWIG_std_filesystem", fragment="<type_traits>") std::filesystem::path {
+ if (PyUnicode_Check($input)) {
+ PyObject *bytes = NULL;
+ const char *s = SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &bytes);
+ $1 = std::filesystem::path(s);
+ Py_XDECREF(bytes);
+ } else if (SWIG_std_filesystem_isPathInstance($input)) {
+ PyObject *str_obj = PyObject_Str($input);
+ if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
+ Py_ssize_t size = 0;
+ wchar_t *ws = PyUnicode_AsWideCharString(str_obj, &size);
+ if (!ws) SWIG_fail;
+ $1 = std::filesystem::path(std::wstring(ws, static_cast<size_t>(size)));
+ PyMem_Free(ws);
+ } else {
+ PyObject *bytes = NULL;
+ const char *s = SWIG_PyUnicode_AsUTF8AndSize(str_obj, NULL, &bytes);
+ $1 = std::filesystem::path(s);
+ Py_XDECREF(bytes);
+ }
+ Py_DECREF(str_obj);
+ } else {
+ void *argp = 0;
+ int res = SWIG_ConvertPtr($input, &argp, $descriptor(std::filesystem::path *), $disown | 0);
+ if (!SWIG_IsOK(res)) {
+ %argument_fail(res, "$type", $symname, $argnum);
+ }
+ std::filesystem::path *temp = %reinterpret_cast(argp, $1_ltype*);
+ $1 = *temp;
+ }
+}
+
+%typemap(in, fragment="SWIG_std_filesystem", fragment="<type_traits>") const std::filesystem::path &(std::filesystem::path temp_path) {
+ if (PyUnicode_Check($input)) {
+ PyObject *bytes = NULL;
+ const char *s = SWIG_PyUnicode_AsUTF8AndSize($input, NULL, &bytes);
+ temp_path = std::filesystem::path(s);
+ $1 = &temp_path;
+ Py_XDECREF(bytes);
+ } else if (SWIG_std_filesystem_isPathInstance($input)) {
+ PyObject *str_obj = PyObject_Str($input);
+ if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
+ Py_ssize_t size = 0;
+ wchar_t *ws = PyUnicode_AsWideCharString(str_obj, &size);
+ if (!ws) SWIG_fail;
+ temp_path = std::filesystem::path(std::wstring(ws, static_cast<size_t>(size)));
+ $1 = &temp_path;
+ PyMem_Free(ws);
+ } else {
+ PyObject *bytes = NULL;
+ const char *s = SWIG_PyUnicode_AsUTF8AndSize(str_obj, NULL, &bytes);
+ temp_path = std::filesystem::path(s);
+ $1 = &temp_path;
+ Py_XDECREF(bytes);
+ }
+ Py_DECREF(str_obj);
+ } else {
+ void *argp = 0;
+ int res = SWIG_ConvertPtr($input, &argp, $descriptor, $disown | 0);
+ if (!SWIG_IsOK(res)) {
+ %argument_fail(res, "$type", $symname, $argnum);
+ }
+ $1 = %reinterpret_cast(argp, $1_ltype);
+ }
+}
+
+%typemap(out, fragment="SWIG_std_filesystem", fragment="<type_traits>") std::filesystem::path {
+ PyObject *args;
+ if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
+ std::wstring s = $1.generic_wstring();
+ args = Py_BuildValue("(u)", s.data());
+ } else {
+ std::string s = $1.generic_string();
+ args = Py_BuildValue("(s)", s.data());
+ }
+ PyObject *cls = SWIG_std_filesystem_importPathClass();
+ $result = PyObject_CallObject(cls, args);
+ Py_DECREF(cls);
+ Py_DECREF(args);
+}
+
+%typemap(out, fragment="SWIG_std_filesystem", fragment="<type_traits>") const std::filesystem::path & {
+ PyObject *args;
+ if constexpr (std::is_same_v<typename std::filesystem::path::value_type, wchar_t>) {
+ std::wstring s = $1->generic_wstring();
+ args = Py_BuildValue("(u)", s.data());
+ } else {
+ std::string s = $1->generic_string();
+ args = Py_BuildValue("(s)", s.data());
+ }
+ PyObject *cls = SWIG_std_filesystem_importPathClass();
+ $result = PyObject_CallObject(cls, args);
+ Py_DECREF(cls);
+ Py_DECREF(args);
+}
diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i
index 8ae483cef..954e7eb2d 100644
--- a/Lib/python/std_map.i
+++ b/Lib/python/std_map.i
@@ -2,7 +2,7 @@
Maps
*/
-%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits")
+%fragment("StdMapCommonTraits","header",fragment="StdSequenceTraits",fragment="SwigPyIterator_T")
{
namespace swig {
template <class ValueType>
@@ -77,16 +77,6 @@
%fragment("StdMapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Compare, class Alloc >
- inline void
- 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, class Compare, class Alloc>
struct traits_asptr<std::map<K,T,Compare,Alloc > > {
typedef std::map<K,T,Compare,Alloc > map_type;
@@ -101,7 +91,7 @@
%#endif
res = traits_asptr_stdseq<map_type, std::pair<K, T> >::asptr(items, val);
} else {
- map_type *p;
+ map_type *p = 0;
swig_type_info *descriptor = swig::type_info<map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
@@ -295,7 +285,11 @@
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
+%#ifdef __cpp_lib_map_try_emplace
+ (*self).insert_or_assign(key, x);
+%#else
(*self)[key] = x;
+%#endif
}
PyObject* asdict() {
diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i
index f78a5277c..75b4d7fcf 100644
--- a/Lib/python/std_multimap.i
+++ b/Lib/python/std_multimap.i
@@ -6,16 +6,6 @@
%fragment("StdMultimapTraits","header",fragment="StdMapCommonTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T >
- inline void
- assign(const SwigPySeq& swigpyseq, std::multimap<K,T > *multimap) {
- typedef typename std::multimap<K,T>::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- multimap->insert(value_type(it->first, it->second));
- }
- }
-
template <class K, class T>
struct traits_asptr<std::multimap<K,T> > {
typedef std::multimap<K,T> multimap_type;
@@ -29,7 +19,7 @@
%#endif
res = traits_asptr_stdseq<std::multimap<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
- multimap_type *p;
+ multimap_type *p = 0;
swig_type_info *descriptor = swig::type_info<multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
diff --git a/Lib/python/std_multiset.i b/Lib/python/std_multiset.i
index ac430334c..b79f64e5a 100644
--- a/Lib/python/std_multiset.i
+++ b/Lib/python/std_multiset.i
@@ -7,17 +7,6 @@
%fragment("StdMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class T>
- inline void
- assign(const SwigPySeq& swigpyseq, std::multiset<T>* seq) {
- // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
- typedef typename SwigPySeq::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- seq->insert(seq->end(),(value_type)(*it));
- }
- }
-
template <class T>
struct traits_asptr<std::multiset<T> > {
static int asptr(PyObject *obj, std::multiset<T> **m) {
diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i
index 172572bff..cf463cb8f 100644
--- a/Lib/python/std_pair.i
+++ b/Lib/python/std_pair.i
@@ -47,7 +47,7 @@
res = get_pair(first, second, val);
}
} else {
- value_type *p;
+ value_type *p = 0;
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = *p;
@@ -104,7 +104,7 @@
res = get_pair(first, second, val);
}
} else {
- value_type *p;
+ value_type *p = 0;
swig_type_info *descriptor = swig::type_info<value_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i
index 0ef011998..3f80daff6 100644
--- a/Lib/python/std_set.i
+++ b/Lib/python/std_set.i
@@ -5,17 +5,6 @@
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class T>
- inline void
- assign(const SwigPySeq& swigpyseq, std::set<T>* seq) {
- // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
- typedef typename SwigPySeq::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- seq->insert(seq->end(),(value_type)(*it));
- }
- }
-
template <class T>
struct traits_asptr<std::set<T> > {
static int asptr(PyObject *obj, std::set<T> **s) {
diff --git a/Lib/python/std_string_view.i b/Lib/python/std_string_view.i
new file mode 100644
index 000000000..a3069f839
--- /dev/null
+++ b/Lib/python/std_string_view.i
@@ -0,0 +1,135 @@
+/* -----------------------------------------------------------------------------
+ * std_string_view.i
+ *
+ * SWIG typemaps for std::string_view types
+ * ----------------------------------------------------------------------------- */
+
+%include <exception.i>
+
+%{
+#include <string_view>
+
+#if PY_VERSION_HEX < 0x03000000
+# error std_string_view.i not supported for Python 2
+#endif
+%}
+
+namespace std {
+
+ %naturalvar string_view;
+
+ class string_view;
+
+ %typemap(typecheck,precedence=SWIG_TYPECHECK_STRINGVIEW) string_view, const string_view & %{
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ $1 = PyBytes_Check($input);
+#else
+ $1 = PyUnicode_Check($input) || PyBytes_Check($input);
+#endif
+ %}
+
+ %typemap(in) string_view (PyObject *bytes = NULL) %{
+ Py_ssize_t len;
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ const char *p = PyBytes_AsString($input);
+ if (!p) SWIG_fail;
+ len = PyBytes_Size($input);
+#else
+ const char *p;
+ if (PyUnicode_Check($input)) {
+ p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
+ if (!p) SWIG_fail;
+ } else {
+ p = PyBytes_AsString($input);
+ if (!p) SWIG_fail;
+ len = PyBytes_Size($input);
+ }
+#endif
+ $1 = std::string_view(p, len);
+ %}
+
+ %typemap(freearg) string_view %{
+ Py_XDECREF(bytes$argnum);
+ %}
+
+ %typemap(in) const string_view & ($*1_ltype temp, PyObject *bytes = NULL) %{
+ Py_ssize_t len;
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ const char *p = PyBytes_AsString($input);
+ if (!p) SWIG_fail;
+ len = PyBytes_Size($input);
+#else
+ const char *p;
+ if (PyUnicode_Check($input)) {
+ p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
+ if (!p) SWIG_fail;
+ } else {
+ p = PyBytes_AsString($input);
+ if (!p) SWIG_fail;
+ len = PyBytes_Size($input);
+ }
+#endif
+ temp = std::string_view(p, len);
+ $1 = &temp;
+ %}
+
+ %typemap(freearg) const string_view & %{
+ Py_XDECREF(bytes$argnum);
+ %}
+
+ %typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) string_view {
+ Py_ssize_t len;
+%#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ const char *p = PyBytes_AsString($input);
+ if (p) len = PyBytes_Size($input);
+%#else
+ const char *p;
+ PyObject *bytes = NULL;
+ if (PyUnicode_Check($input)) {
+ p = SWIG_PyUnicode_AsUTF8AndSize($input, &len, &bytes);
+ // Avoid undefined behaviour (p will be pointing to a temporary
+ // if bytes is not NULL which happens when Py_LIMITED_API is defined
+ // and < 0x030A0000) and just leak by not calling Py_XDECREF.
+ // Py_XDECREF(bytes);
+ } else {
+ p = PyBytes_AsString($input);
+ if (p) len = PyBytes_Size($input);
+ }
+%#endif
+ if (p) $result = std::string_view(p, len);
+ }
+
+
+ %typemap(out) string_view %{
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ $result = PyBytes_FromStringAndSize($1.data(), $1.size());
+#else
+ $result = PyUnicode_FromStringAndSize($1.data(), $1.size());
+#endif
+ %}
+
+ %typemap(varout) string_view %{
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ $result = PyBytes_FromStringAndSize($1.data(), $1.size());
+#else
+ $result = PyUnicode_FromStringAndSize($1.data(), $1.size());
+#endif
+ %}
+
+ %typemap(directorin) string_view, const string_view & %{
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ $input = PyBytes_FromStringAndSize($1.data(), $1.size());
+#else
+ $input = PyUnicode_FromStringAndSize($1.data(), $1.size());
+#endif
+ %}
+
+ %typemap(out) const string_view & %{
+#ifdef SWIG_PYTHON_STRICT_BYTE_CHAR
+ $result = PyBytes_FromStringAndSize($1->data(), $1->size());
+#else
+ $result = PyUnicode_FromStringAndSize($1->data(), $1->size());
+#endif
+ %}
+
+}
diff --git a/Lib/python/std_unique_ptr.i b/Lib/python/std_unique_ptr.i
new file mode 100644
index 000000000..f988714df
--- /dev/null
+++ b/Lib/python/std_unique_ptr.i
@@ -0,0 +1,39 @@
+/* -----------------------------------------------------------------------------
+ * std_unique_ptr.i
+ *
+ * SWIG library file for handling std::unique_ptr.
+ * Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
+ * class when returning a std::unique_ptr from a function.
+ * Memory ownership is passed from the proxy class to the std::unique_ptr in the
+ * C++ layer when passed as a parameter to a wrapped function.
+ * ----------------------------------------------------------------------------- */
+
+%define %unique_ptr(TYPE)
+%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
+ res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
+ if (!SWIG_IsOK(res)) {
+ if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
+ %releasenotowned_fail(res, "TYPE *", $symname, $argnum);
+ } else {
+ %argument_fail(res, "TYPE *", $symname, $argnum);
+ }
+ }
+ $1.reset((TYPE *)argp);
+}
+
+%typemap (out) std::unique_ptr< TYPE > %{
+ %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
+%}
+
+%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
+ void *vptr = 0;
+ int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
+ $1 = SWIG_CheckState(res);
+}
+
+%template() std::unique_ptr< TYPE >;
+%enddef
+
+namespace std {
+ template <class T> class unique_ptr {};
+}
diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i
index 042d5b671..432173556 100644
--- a/Lib/python/std_unordered_map.i
+++ b/Lib/python/std_unordered_map.i
@@ -56,16 +56,6 @@
%fragment("StdUnorderedMapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_map<K,T,Hash,Compare,Alloc> *unordered_map) {
- typedef typename std::unordered_map<K,T,Hash,Compare,Alloc>::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- unordered_map->insert(value_type(it->first, it->second));
- }
- }
-
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_map<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_map<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_map<K,T,Hash,Compare,Alloc>::size_type n) {
@@ -87,7 +77,7 @@
%#endif
res = traits_asptr_stdseq<std::unordered_map<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val);
} else {
- unordered_map_type *p;
+ unordered_map_type *p = 0;
swig_type_info *descriptor = swig::type_info<unordered_map_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
@@ -281,7 +271,11 @@
}
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
+%#ifdef __cpp_lib_unordered_map_try_emplace
+ (*self).insert_or_assign(key, x);
+%#else
(*self)[key] = x;
+%#endif
}
PyObject* asdict() {
diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i
index 281140445..816ec0933 100644
--- a/Lib/python/std_unordered_multimap.i
+++ b/Lib/python/std_unordered_multimap.i
@@ -6,16 +6,6 @@
%fragment("StdUnorderedMultimapTraits","header",fragment="StdMapCommonTraits",fragment="StdUnorderedMapForwardIteratorTraits")
{
namespace swig {
- template <class SwigPySeq, class K, class T, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_multimap<K,T,Hash,Compare,Alloc> *unordered_multimap) {
- typedef typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- unordered_multimap->insert(value_type(it->first, it->second));
- }
- }
-
template <class K, class T, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multimap<K,T,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multimap<K,T,Hash,Compare,Alloc> &seq, typename std::unordered_multimap<K,T,Hash,Compare,Alloc>::size_type n) {
@@ -36,7 +26,7 @@
%#endif
res = traits_asptr_stdseq<std::unordered_multimap<K,T,Hash,Compare,Alloc>, std::pair<K, T> >::asptr(items, val);
} else {
- unordered_multimap_type *p;
+ unordered_multimap_type *p = 0;
swig_type_info *descriptor = swig::type_info<unordered_multimap_type>();
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
if (SWIG_IsOK(res) && val) *val = p;
diff --git a/Lib/python/std_unordered_multiset.i b/Lib/python/std_unordered_multiset.i
index b0f3f096b..0542247b2 100644
--- a/Lib/python/std_unordered_multiset.i
+++ b/Lib/python/std_unordered_multiset.i
@@ -7,17 +7,6 @@
%fragment("StdUnorderedMultisetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_multiset<Key,Hash,Compare,Alloc>* seq) {
- // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
- typedef typename SwigPySeq::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- seq->insert(seq->end(),(value_type)(*it));
- }
- }
-
template <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_multiset<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_multiset<Key,Hash,Compare,Alloc> &seq, typename std::unordered_multiset<Key,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/python/std_unordered_set.i b/Lib/python/std_unordered_set.i
index 79fca6c2f..fd866b14a 100644
--- a/Lib/python/std_unordered_set.i
+++ b/Lib/python/std_unordered_set.i
@@ -5,17 +5,6 @@
%fragment("StdUnorderedSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
- template <class SwigPySeq, class Key, class Hash, class Compare, class Alloc>
- inline void
- assign(const SwigPySeq& swigpyseq, std::unordered_set<Key,Hash,Compare,Alloc>* seq) {
- // seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
- typedef typename SwigPySeq::value_type value_type;
- typename SwigPySeq::const_iterator it = swigpyseq.begin();
- for (;it != swigpyseq.end(); ++it) {
- seq->insert(seq->end(),(value_type)(*it));
- }
- }
-
template <class Key, class Hash, class Compare, class Alloc>
struct traits_reserve<std::unordered_set<Key,Hash,Compare,Alloc> > {
static void reserve(std::unordered_set<Key,Hash,Compare,Alloc> &seq, typename std::unordered_set<Key,Hash,Compare,Alloc>::size_type n) {
diff --git a/Lib/python/swigmove.i b/Lib/python/swigmove.i
new file mode 100644
index 000000000..62ecca768
--- /dev/null
+++ b/Lib/python/swigmove.i
@@ -0,0 +1 @@
+%include <typemaps/swigmove.swg>
diff --git a/Lib/python/typemaps.i b/Lib/python/typemaps.i
index 5d438ecab..75592036b 100644
--- a/Lib/python/typemaps.i
+++ b/Lib/python/typemaps.i
@@ -72,7 +72,7 @@ multiple output values, they are returned in the form of a Python tuple.
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
-returns the integer part in one of its parameters).K:
+returns the integer part in one of its parameters) :
double modf(double x, double *ip);
@@ -139,10 +139,6 @@ to a Python variable you might do this :
x = neg(x)
-Note : previous versions of SWIG used the symbol 'BOTH' to mark
-input/output arguments. This is still supported, but will be slowly
-phased out in future releases.
-
*/
%include <typemaps/typemaps.swg>