diff options
Diffstat (limited to 'siplib/voidptr.c')
-rw-r--r-- | siplib/voidptr.c | 169 |
1 files changed, 3 insertions, 166 deletions
diff --git a/siplib/voidptr.c b/siplib/voidptr.c index 50cafb2..ef19f31 100644 --- a/siplib/voidptr.c +++ b/siplib/voidptr.c @@ -60,11 +60,7 @@ static PyObject *sipVoidPtr_new(PyTypeObject *subtype, PyObject *args, PyObject *obj; if (!PyArg_ParseTupleAndKeywords(args, kw, -#if PY_VERSION_HEX >= 0x02050000 "O&|ni:voidptr", -#else - "O&|ii:voidptr", -#endif kwlist, vp_convertor, &vp_conversion, &size, &rw)) return NULL; @@ -89,7 +85,6 @@ static PyObject *sipVoidPtr_new(PyTypeObject *subtype, PyObject *args, } -#if PY_MAJOR_VERSION >= 3 /* * The read buffer implementation for Python v3. */ @@ -99,64 +94,6 @@ static int sipVoidPtr_getbuffer(PyObject *self, Py_buffer *buf, int flags) return PyBuffer_FillInfo(buf, self, v->voidptr, v->size, !v->rw, flags); } -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The read buffer implementation for Python v2. - */ -static SIP_SSIZE_T sipVoidPtr_getbuffer(PyObject *self, SIP_SSIZE_T seg, - void **ptr) -{ - SIP_SSIZE_T size = ((sipVoidPtrObject *)self)->size; - - if (size < 0 || seg != 0) - { - PyErr_SetString(PyExc_SystemError, "invalid buffer segment"); - return -1; - } - - *ptr = ((sipVoidPtrObject *)self)->voidptr; - - return size; -} -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The write buffer implementation for Python v2. - */ -static SIP_SSIZE_T sipVoidPtr_getwritebuffer(PyObject *self, SIP_SSIZE_T seg, - void **ptr) -{ - if (((sipVoidPtrObject *)self)->rw) - return sipVoidPtr_getbuffer(self, seg, ptr); - - PyErr_SetString(PyExc_TypeError, "the sip_tqt.voidptr is not writeable"); - return -1; -} -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The segment count implementation for Python v2. - */ -static SIP_SSIZE_T sipVoidPtr_getsegcount(PyObject *self, SIP_SSIZE_T *lenp) -{ - SIP_SSIZE_T segs, len; - - len = ((sipVoidPtrObject *)self)->size; - segs = (len < 0 ? 0 : 1); - - if (lenp != NULL) - *lenp = len; - - return segs; -} -#endif /* @@ -168,23 +105,6 @@ static PyObject *sipVoidPtr_int(sipVoidPtrObject *v) } -#if PY_MAJOR_VERSION < 3 -/* - * Implement hex() for the type. - */ -static PyObject *sipVoidPtr_hex(sipVoidPtrObject *v) -{ - char buf[2 + 16 + 1]; - - PyOS_snprintf(buf, sizeof (buf), "0x%.*lx", (int)(sizeof (void *) * 2), - (unsigned long)v->voidptr); - - return PyString_FromString(buf); -} -#endif - - -#if defined(SIP_USE_PYCAPSULE) /* * Implement ascapsule() for the type. */ @@ -192,18 +112,6 @@ static PyObject *sipVoidPtr_ascapsule(sipVoidPtrObject *v, PyObject *arg) { return PyCapsule_New(v->voidptr, NULL, NULL); } -#endif - - -#if defined(SIP_SUPPORT_PYCOBJECT) -/* - * Implement ascobject() for the type. - */ -static PyObject *sipVoidPtr_ascobject(sipVoidPtrObject *v, PyObject *arg) -{ - return PyCObject_FromVoidPtr(v->voidptr, NULL); -} -#endif /* @@ -217,11 +125,7 @@ static PyObject *sipVoidPtr_asstring(sipVoidPtrObject *v, PyObject *args, SIP_SSIZE_T size = -1; if (!PyArg_ParseTupleAndKeywords(args, kw, -#if PY_VERSION_HEX >= 0x02050000 "|n:asstring", -#else - "|i:asstring", -#endif kwlist, &size)) return NULL; @@ -236,7 +140,7 @@ static PyObject *sipVoidPtr_asstring(sipVoidPtrObject *v, PyObject *args, return NULL; } - return SIPBytes_FromStringAndSize(v->voidptr, size); + return PyBytes_FromStringAndSize(v->voidptr, size); } @@ -245,13 +149,7 @@ static PyObject *sipVoidPtr_asstring(sipVoidPtrObject *v, PyObject *args, */ static PyObject *sipVoidPtr_getsize(sipVoidPtrObject *v, PyObject *arg) { -#if PY_MAJOR_VERSION >= 3 return PyLong_FromSsize_t(v->size); -#elif PY_VERSION_HEX >= 0x02050000 - return PyInt_FromSsize_t(v->size); -#else - return PyInt_FromLong(v->size); -#endif } @@ -262,13 +160,7 @@ static PyObject *sipVoidPtr_setsize(sipVoidPtrObject *v, PyObject *arg) { SIP_SSIZE_T size; -#if PY_MAJOR_VERSION >= 3 size = PyLong_AsSsize_t(arg); -#elif PY_VERSION_HEX >= 0x02050000 - size = PyInt_AsSsize_t(arg); -#else - size = (int)PyInt_AsLong(arg); -#endif if (PyErr_Occurred()) return NULL; @@ -296,7 +188,7 @@ static PyObject *sipVoidPtr_setwriteable(sipVoidPtrObject *v, PyObject *arg) { int rw; - rw = (int)SIPLong_AsLong(arg); + rw = (int)PyLong_AsLong(arg); if (PyErr_Occurred()) return NULL; @@ -310,12 +202,7 @@ static PyObject *sipVoidPtr_setwriteable(sipVoidPtrObject *v, PyObject *arg) /* The methods data structure. */ 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}, -#endif {"asstring", (PyCFunction)sipVoidPtr_asstring, METH_VARARGS|METH_KEYWORDS, NULL}, {"getsize", (PyCFunction)sipVoidPtr_getsize, METH_NOARGS, NULL}, {"setsize", (PyCFunction)sipVoidPtr_setsize, METH_O, NULL}, @@ -330,9 +217,6 @@ static PyNumberMethods sipVoidPtr_NumberMethods = { 0, /* nb_add */ 0, /* nb_subtract */ 0, /* nb_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_divide */ -#endif 0, /* nb_remainder */ 0, /* nb_divmod */ 0, /* nb_power */ @@ -346,22 +230,12 @@ static PyNumberMethods sipVoidPtr_NumberMethods = { 0, /* nb_and */ 0, /* nb_xor */ 0, /* nb_or */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_coerce */ -#endif (unaryfunc)sipVoidPtr_int, /* nb_int */ - 0, /* nb_reserved (Python v3), nb_long (Python v2) */ + 0, /* nb_reserved */ 0, /* nb_float */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_oct */ - (unaryfunc)sipVoidPtr_hex, /* nb_hex */ -#endif 0, /* nb_inplace_add */ 0, /* nb_inplace_subtract */ 0, /* nb_inplace_multiply */ -#if PY_MAJOR_VERSION < 3 - 0, /* nb_inplace_divide */ -#endif 0, /* nb_inplace_remainder */ 0, /* nb_inplace_power */ 0, /* nb_inplace_lshift */ @@ -373,26 +247,14 @@ static PyNumberMethods sipVoidPtr_NumberMethods = { 0, /* nb_true_divide */ 0, /* nb_inplace_floor_divide */ 0, /* nb_inplace_true_divide */ -#if PY_VERSION_HEX >= 0x02050000 0 /* nb_index */ -#endif }; /* The buffer methods data structure. */ static PyBufferProcs sipVoidPtr_BufferProcs = { sipVoidPtr_getbuffer, -#if PY_MAJOR_VERSION >= 3 NULL, -#else - sipVoidPtr_getwritebuffer, - sipVoidPtr_getsegcount, -#if PY_VERSION_HEX >= 0x02050000 - (charbufferproc)sipVoidPtr_getbuffer -#else - (getcharbufferproc)sipVoidPtr_getbuffer -#endif -#endif }; @@ -456,21 +318,10 @@ void *sip_api_convert_to_void_ptr(PyObject *obj) if (PyObject_TypeCheck(obj, &sipVoidPtr_Type)) return ((sipVoidPtrObject *)obj)->voidptr; -#if defined(SIP_USE_PYCAPSULE) 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); -#else - return (void *)PyInt_AsLong(obj); -#endif } @@ -546,14 +397,8 @@ static int vp_convertor(PyObject *arg, struct vp_values *vp) if (arg == Py_None) ptr = NULL; -#if defined(SIP_USE_PYCAPSULE) 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; @@ -562,19 +407,11 @@ static int vp_convertor(PyObject *arg, struct vp_values *vp) } else { -#if PY_MAJOR_VERSION >= 3 ptr = PyLong_AsVoidPtr(arg); -#else - ptr = (void *)PyInt_AsLong(arg); -#endif if (PyErr_Occurred()) { -#if PY_VERSION_HEX >= 0x03010000 PyErr_SetString(PyExc_TypeError, "a single integer, CObject, None or another voidptr is required"); -#else - PyErr_SetString(PyExc_TypeError, "a single integer, Capsule, CObject, None or another voidptr is required"); -#endif return 0; } } |