From 5b12d262dc940b6fe9e2766988917665c970318d Mon Sep 17 00:00:00 2001 From: aneejit1 Date: Tue, 19 Apr 2022 00:17:45 +0000 Subject: Updates for Python 3 Support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following changes have been made to support Python 3: - in sip-tqt.h, remove the cast in the "sipConvertFromSliceObject" macro in versions 3.2+ as the API changed causing a compile error; - in voidptr.h, alter the precompile conditions to remove the PyCObject API cals for version 3.2+ (causes runtime symbol resolution error) and amend the flags for "asstring"; - alter module import process in siplib.c to avoid re-loading an already loaded module. Signed-off-by: aneejit1 Signed-off-by: Slávek Banko --- siplib/voidptr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'siplib/voidptr.c') diff --git a/siplib/voidptr.c b/siplib/voidptr.c index 65d4fe9..50cafb2 100644 --- a/siplib/voidptr.c +++ b/siplib/voidptr.c @@ -195,6 +195,7 @@ static PyObject *sipVoidPtr_ascapsule(sipVoidPtrObject *v, PyObject *arg) #endif +#if defined(SIP_SUPPORT_PYCOBJECT) /* * Implement ascobject() for the type. */ @@ -202,6 +203,7 @@ static PyObject *sipVoidPtr_ascobject(sipVoidPtrObject *v, PyObject *arg) { return PyCObject_FromVoidPtr(v->voidptr, NULL); } +#endif /* @@ -311,8 +313,10 @@ static PyMethodDef sipVoidPtr_Methods[] = { #if defined(SIP_USE_PYCAPSULE) {"ascapsule", (PyCFunction)sipVoidPtr_ascapsule, METH_NOARGS, NULL}, #endif +#if defined(SIP_SUPPORT_PYCOBJECT) {"ascobject", (PyCFunction)sipVoidPtr_ascobject, METH_NOARGS, NULL}, - {"asstring", (PyCFunction)sipVoidPtr_asstring, METH_KEYWORDS, NULL}, +#endif + {"asstring", (PyCFunction)sipVoidPtr_asstring, METH_VARARGS|METH_KEYWORDS, NULL}, {"getsize", (PyCFunction)sipVoidPtr_getsize, METH_NOARGS, NULL}, {"setsize", (PyCFunction)sipVoidPtr_setsize, METH_O, NULL}, {"getwriteable", (PyCFunction)sipVoidPtr_getwriteable, METH_NOARGS, NULL}, @@ -456,9 +460,11 @@ void *sip_api_convert_to_void_ptr(PyObject *obj) if (PyCapsule_CheckExact(obj)) return PyCapsule_GetPointer(obj, NULL); #endif - +#if defined(SIP_SUPPORT_PYCOBJECT) if (PyCObject_Check(obj)) return PyCObject_AsVoidPtr(obj); +#endif + #if PY_MAJOR_VERSION >= 3 return PyLong_AsVoidPtr(obj); @@ -544,8 +550,10 @@ static int vp_convertor(PyObject *arg, struct vp_values *vp) else if (PyCapsule_CheckExact(arg)) ptr = PyCapsule_GetPointer(arg, NULL); #endif +#if defined(SIP_SUPPORT_PYCOBJECT) else if (PyCObject_Check(arg)) ptr = PyCObject_AsVoidPtr(arg); +#endif else if (PyObject_TypeCheck(arg, &sipVoidPtr_Type)) { ptr = ((sipVoidPtrObject *)arg)->voidptr; -- cgit v1.2.3