aboutsummaryrefslogtreecommitdiff
path: root/Lib/python/pyhead.swg
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/python/pyhead.swg')
-rw-r--r--Lib/python/pyhead.swg68
1 files changed, 39 insertions, 29 deletions
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