diff options
Diffstat (limited to 'siplib')
-rw-r--r-- | siplib/apiversions.c | 4 | ||||
-rw-r--r-- | siplib/descriptors.c | 8 | ||||
-rw-r--r-- | siplib/sip-tqt.h | 94 | ||||
-rw-r--r-- | siplib/siplib.c | 671 | ||||
-rw-r--r-- | siplib/tqtlib.c | 7 | ||||
-rw-r--r-- | siplib/voidptr.c | 169 |
6 files changed, 40 insertions, 913 deletions
diff --git a/siplib/apiversions.c b/siplib/apiversions.c index f278c6b..cb2aaa6 100644 --- a/siplib/apiversions.c +++ b/siplib/apiversions.c @@ -194,11 +194,7 @@ PyObject *sipGetAPI(PyObject *self, PyObject *args) return NULL; } -#if PY_MAJOR_VERSION >= 3 return PyLong_FromLong(avd->version_nr); -#else - return PyInt_FromLong(avd->version_nr); -#endif } diff --git a/siplib/descriptors.c b/siplib/descriptors.c index 009a03e..1498c44 100644 --- a/siplib/descriptors.c +++ b/siplib/descriptors.c @@ -123,13 +123,7 @@ static PyObject *sipMethodDescr_repr(PyObject *self) { sipMethodDescr *md = (sipMethodDescr *)self; - return -#if PY_MAJOR_VERSION >= 3 - PyUnicode_FromFormat -#else - PyString_FromFormat -#endif - ("<built-in method %s>", md->pmd->ml_name); + return PyUnicode_FromFormat("<built-in method %s>", md->pmd->ml_name); } diff --git a/siplib/sip-tqt.h b/siplib/sip-tqt.h index e3a306f..7fb0bb5 100644 --- a/siplib/sip-tqt.h +++ b/siplib/sip-tqt.h @@ -46,8 +46,8 @@ extern "C" { /* Sanity check on the Python version. */ -#if PY_VERSION_HEX < 0x02030000 -#error "This version of SIP-TQt requires Python v2.3 or later" +#if PY_VERSION_HEX < 0x03020000 +#error "This version of SIP-TQt requires Python v3.2 or later" #endif @@ -178,63 +178,12 @@ extern "C" { #endif -/* Some Python compatibility stuff. */ -#if PY_VERSION_HEX >= 0x02050000 - #define SIP_SSIZE_T Py_ssize_t #define SIP_MLNAME_CAST(s) (s) #define SIP_MLDOC_CAST(s) (s) #define SIP_TPNAME_CAST(s) (s) -#else - -#define SIP_SSIZE_T int - -#define SIP_MLNAME_CAST(s) ((char *)(s)) -#define SIP_MLDOC_CAST(s) ((char *)(s)) -#define SIP_TPNAME_CAST(s) ((char *)(s)) - -#endif - -#if PY_MAJOR_VERSION >= 3 - -#define SIPLong_FromLong PyLong_FromLong -#define SIPLong_AsLong PyLong_AsLong - -#define SIPBytes_Check PyBytes_Check -#define SIPBytes_FromString PyBytes_FromString -#define SIPBytes_FromStringAndSize PyBytes_FromStringAndSize -#define SIPBytes_AS_STRING PyBytes_AS_STRING -#define SIPBytes_GET_SIZE PyBytes_GET_SIZE - -#if (PY_MAJOR_VERSION > 3) || ((PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >= 1)) -#define SIP_USE_PYCAPSULE -#endif - -#if (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION < 2) -#define SIP_SUPPORT_PYCOBJECT -#endif - -#else - -#define SIPLong_FromLong PyInt_FromLong -#define SIPLong_AsLong PyInt_AsLong - -#define SIPBytes_Check PyString_Check -#define SIPBytes_FromString PyString_FromString -#define SIPBytes_FromStringAndSize PyString_FromStringAndSize -#define SIPBytes_AS_STRING PyString_AS_STRING -#define SIPBytes_GET_SIZE PyString_GET_SIZE - -#if PY_MINOR_VERSION >= 7 -#define SIP_USE_PYCAPSULE -#endif - -#define SIP_SUPPORT_PYCOBJECT - -#endif - #if !defined(Py_REFCNT) #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #endif @@ -371,13 +320,8 @@ typedef void *(*sipInitFunc)(sipSimpleWrapper *, PyObject *, PyObject *, PyObject **, PyObject **, PyObject **); typedef int (*sipTraverseFunc)(void *, visitproc, void *); typedef int (*sipClearFunc)(void *); -#if PY_MAJOR_VERSION >= 3 typedef int (*sipGetBufferFunc)(PyObject *, void *, Py_buffer *, int); typedef void (*sipReleaseBufferFunc)(PyObject *, void *, Py_buffer *); -#else -typedef SIP_SSIZE_T (*sipBufferFunc)(PyObject *, void *, SIP_SSIZE_T, void **); -typedef SIP_SSIZE_T (*sipSegCountFunc)(PyObject *, void *, SIP_SSIZE_T *); -#endif typedef void (*sipDeallocFunc)(sipSimpleWrapper *); typedef void *(*sipCastFunc)(void *, const struct _sipTypeDef *); typedef const struct _sipTypeDef *(*sipSubClassConvertFunc)(void **); @@ -509,9 +453,6 @@ typedef enum { typedef enum { str_slot, /* __str__ */ int_slot, /* __int__ */ -#if PY_MAJOR_VERSION < 3 - long_slot, /* __long__ */ -#endif float_slot, /* __float__ */ len_slot, /* __len__ */ contains_slot, /* __contains__ */ @@ -554,18 +495,13 @@ typedef enum { ne_slot, /* __ne__ */ gt_slot, /* __gt__ */ ge_slot, /* __ge__ */ -#if PY_MAJOR_VERSION < 3 - cmp_slot, /* __cmp__ */ -#endif bool_slot, /* __bool__, __nonzero__ */ neg_slot, /* __neg__ */ repr_slot, /* __repr__ */ hash_slot, /* __hash__ */ pos_slot, /* __pos__ */ abs_slot, /* __abs__ */ -#if PY_VERSION_HEX >= 0x02050000 index_slot, /* __index__ */ -#endif iter_slot, /* __iter__ */ next_slot, /* __next__ */ } sipPySlotType; @@ -736,25 +672,11 @@ typedef struct _sipClassTypeDef { /* The clear function. */ sipClearFunc ctd_clear; -#if PY_MAJOR_VERSION >= 3 /* The get buffer function. */ sipGetBufferFunc ctd_getbuffer; /* The release buffer function. */ sipReleaseBufferFunc ctd_releasebuffer; -#else - /* The read buffer function. */ - sipBufferFunc ctd_readbuffer; - - /* The write buffer function. */ - sipBufferFunc ctd_writebuffer; - - /* The segment count function. */ - sipSegCountFunc ctd_segcount; - - /* The char buffer function. */ - sipBufferFunc ctd_charbuffer; -#endif /* The deallocation function. */ sipDeallocFunc ctd_dealloc; @@ -1196,11 +1118,6 @@ typedef struct _sipPyMethod { /* Self if it is a bound method. */ PyObject *mself; - -#if PY_MAJOR_VERSION < 3 - /* The class. */ - PyObject *mclass; -#endif } sipPyMethod; @@ -1474,16 +1391,9 @@ typedef struct _sipTQtAPI { #define sipIsExactWrappedType(wt) (sipTypeAsPyTypeObject((wt)->type) == (PyTypeObject *)(wt)) -#if PY_VERSION_HEX >= 0x03020000 #define sipConvertFromSliceObject(o,len,start,stop,step,slen) \ PySlice_GetIndicesEx((o), (len), (start), (stop), \ (step), (slen)) -#else -#define sipConvertFromSliceObject(o,len,start,stop,step,slen) \ - PySlice_GetIndicesEx((PySliceObject *)(o), (len), (start), (stop), \ - (step), (slen)) -#endif - /* * The following are deprecated parts of the public API. diff --git a/siplib/siplib.c b/siplib/siplib.c index 242a1cb..ea9bbd1 100644 --- a/siplib/siplib.c +++ b/siplib/siplib.c @@ -656,19 +656,11 @@ static sipExportedModuleDef *isModuleLoaded(sipExportedModuleDef *table, /* * The Python module initialisation function. */ -#if PY_MAJOR_VERSION >= 3 #define SIP_MODULE_ENTRY PyInit_sip_tqt #define SIP_MODULE_TYPE PyObject * #define SIP_MODULE_DISCARD(m) Py_DECREF(m) #define SIP_FATAL(s) return NULL #define SIP_MODULE_RETURN(m) return (m) -#else -#define SIP_MODULE_ENTRY initsip_tqt -#define SIP_MODULE_TYPE void -#define SIP_MODULE_DISCARD(m) -#define SIP_FATAL(s) Py_FatalError(s) -#define SIP_MODULE_RETURN(m) -#endif #if defined(SIP_STATIC_MODULE) SIP_MODULE_TYPE SIP_MODULE_ENTRY(void) @@ -695,7 +687,6 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) {NULL, NULL, 0, NULL} }; -#if PY_MAJOR_VERSION >= 3 static PyModuleDef module_def = { PyModuleDef_HEAD_INIT, "sip_tqt", /* m_name */ @@ -707,7 +698,6 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) NULL, /* m_clear */ NULL, /* m_free */ }; -#endif int rc; PyObject *mod, *mod_dict, *obj; @@ -730,10 +720,8 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) #if defined(STACKLESS) sipWrapper_Type.super.tp_base = (PyTypeObject *)&sipSimpleWrapper_Type; -#elif PY_VERSION_HEX >= 0x02050000 - sipWrapper_Type.super.ht_type.tp_base = (PyTypeObject *)&sipSimpleWrapper_Type; #else - sipWrapper_Type.super.type.tp_base = (PyTypeObject *)&sipSimpleWrapper_Type; + sipWrapper_Type.super.ht_type.tp_base = (PyTypeObject *)&sipSimpleWrapper_Type; #endif if (PyType_Ready((PyTypeObject *)&sipWrapper_Type) < 0) @@ -753,11 +741,7 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) if (PyType_Ready(&sipVoidPtr_Type) < 0) SIP_FATAL("sip-tqt: Failed to initialise sip_tqt.voidptr type"); -#if PY_MAJOR_VERSION >= 3 mod = PyModule_Create(&module_def); -#else - mod = Py_InitModule("sip_tqt", methods); -#endif if (mod == NULL) SIP_FATAL("sip-tqt: Failed to intialise sip_tqt module"); @@ -775,11 +759,7 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) } /* Publish the SIP-TQt API. */ -#if defined(SIP_USE_PYCAPSULE) obj = PyCapsule_New((void *)&sip_api, "sip_tqt._C_API", NULL); -#else - obj = PyCObject_FromVoidPtr((void *)&sip_api, NULL); -#endif if (obj == NULL) { @@ -797,11 +777,7 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) } /* Add the SIP-TQt version number, but don't worry about errors. */ -#if PY_MAJOR_VERSION >= 3 obj = PyLong_FromLong(SIP_TQT_VERSION); -#else - obj = PyInt_FromLong(SIP_TQT_VERSION); -#endif if (obj != NULL) { @@ -809,11 +785,7 @@ PyMODINIT_FUNC SIP_MODULE_ENTRY(void) Py_DECREF(obj); } -#if PY_MAJOR_VERSION >= 3 obj = PyUnicode_FromString(SIP_TQT_VERSION_STR); -#else - obj = PyString_FromString(SIP_TQT_VERSION_STR); -#endif if (obj != NULL) { @@ -897,11 +869,7 @@ static PyObject *dumpWrapper(PyObject *self, PyObject *args) { print_object(NULL, (PyObject *)sw); -#if PY_VERSION_HEX >= 0x02050000 printf(" Reference count: %" PY_FORMAT_SIZE_T "d\n", Py_REFCNT(sw)); -#else - printf(" Reference count: %d\n", Py_REFCNT(sw)); -#endif printf(" Address of wrapped object: %p\n", sip_api_get_address(sw)); printf(" To be destroyed by: %s\n", (sipIsPyOwned(sw) ? "Python" : "C/C++")); printf(" Derived class?: %s\n", (sipIsDerived(sw) ? "yes" : "no")); @@ -1264,11 +1232,7 @@ static int sip_api_export_module(sipExportedModuleDef *client, } /* Convert the module name to an object. */ -#if PY_MAJOR_VERSION >= 3 client->em_nameobj = PyUnicode_FromString(full_name); -#else - client->em_nameobj = PyString_FromString(full_name); -#endif if (client->em_nameobj == NULL) return -1; @@ -1825,7 +1789,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) if (s != NULL) { - el = SIPBytes_FromStringAndSize(s, l); + el = PyBytes_FromStringAndSize(s, l); } else { @@ -1868,7 +1832,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) { char c = va_arg(va, int); - el = SIPBytes_FromStringAndSize(&c, 1); + el = PyBytes_FromStringAndSize(&c, 1); } break; @@ -1876,12 +1840,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) case 'a': { char c = va_arg(va, int); - -#if PY_MAJOR_VERSION >= 3 el = PyUnicode_FromStringAndSize(&c, 1); -#else - el = PyString_FromStringAndSize(&c, 1); -#endif } break; @@ -1931,11 +1890,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) case 'e': case 'h': case 'i': -#if PY_MAJOR_VERSION >= 3 el = PyLong_FromLong(va_arg(va, int)); -#else - el = PyInt_FromLong(va_arg(va, int)); -#endif break; case 'l': @@ -1968,7 +1923,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) if (s != NULL) { - el = SIPBytes_FromString(s); + el = PyBytes_FromString(s); } else { @@ -1984,11 +1939,7 @@ static PyObject *buildObject(PyObject *obj, const char *fmt, va_list va) char *s = va_arg(va, char *); if (s != NULL) -#if PY_MAJOR_VERSION >= 3 el = PyUnicode_FromString(s); -#else - el = PyString_FromString(s); -#endif else { Py_INCREF(Py_None); @@ -2221,7 +2172,7 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, case 'b': { - int v = SIPLong_AsLong(arg); + int v = PyLong_AsLong(arg); if (PyErr_Occurred()) invalid = TRUE; @@ -2305,7 +2256,7 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, int *p = va_arg(va, int *); if (sip_api_can_convert_to_enum(arg, ((sipEnumTypeObject *)et)->type)) - *p = SIPLong_AsLong(arg); + *p = PyLong_AsLong(arg); else invalid = TRUE; } @@ -2318,7 +2269,7 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, int *p = va_arg(va, int *); if (sip_api_can_convert_to_enum(arg, td)) - *p = SIPLong_AsLong(arg); + *p = PyLong_AsLong(arg); else invalid = TRUE; } @@ -2339,7 +2290,7 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, case 'h': { - short v = SIPLong_AsLong(arg); + short v = PyLong_AsLong(arg); if (PyErr_Occurred()) invalid = TRUE; @@ -2364,7 +2315,7 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, case 'e': case 'i': { - int v = SIPLong_AsLong(arg); + int v = PyLong_AsLong(arg); if (PyErr_Occurred()) invalid = TRUE; @@ -2717,23 +2668,6 @@ static int sip_api_parse_result(int *isErr, PyObject *method, PyObject *res, */ static unsigned long sip_api_long_as_unsigned_long(PyObject *o) { -#if PY_VERSION_HEX < 0x02040000 - if (o != NULL && !PyLong_Check(o) && PyInt_Check(o)) - { - long v = PyInt_AsLong(o); - - if (v < 0) - { - PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to unsigned long"); - - return (unsigned long)-1; - } - - return v; - } -#endif - return PyLong_AsUnsignedLong(o); } @@ -2881,13 +2815,8 @@ static int parseKwdArgs(PyObject **parseErrp, PyObject *sipArgs, */ static PyObject *bad_type_str(int arg_nr, PyObject *arg) { -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromFormat("argument %d has unexpected type '%s'", arg_nr, Py_TYPE(arg)->tp_name); -#else - return PyString_FromFormat("argument %d has unexpected type '%s'", arg_nr, - Py_TYPE(arg)->tp_name); -#endif } @@ -2950,7 +2879,6 @@ static void sip_api_add_exception(sipErrorState es, PyObject **parseErrp) /* * The dtor for parse failure wrapped in a Python object. */ -#if defined(SIP_USE_PYCAPSULE) static void failure_dtor(PyObject *capsule) { sipParseFailure *failure = (sipParseFailure *)PyCapsule_GetPointer(capsule, NULL); @@ -2959,16 +2887,6 @@ static void failure_dtor(PyObject *capsule) sip_api_free(failure); } -#else -static void failure_dtor(void *ptr) -{ - sipParseFailure *failure = (sipParseFailure *)ptr; - - Py_XDECREF(failure->detail_obj); - - sip_api_free(failure); -} -#endif /* @@ -2998,11 +2916,7 @@ static void add_failure(PyObject **parseErrp, sipParseFailure *failure) *failure_copy = *failure; -#if defined(SIP_USE_PYCAPSULE) failure_obj = PyCapsule_New(failure_copy, NULL, failure_dtor); -#else - failure_obj = PyCObject_FromVoidPtr(failure_copy, failure_dtor); -#endif if (failure_obj == NULL) { @@ -3218,11 +3132,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, { int a; -#if PY_MAJOR_VERSION >= 3 if (!PyUnicode_Check(key)) -#else - if (!PyString_Check(key)) -#endif { failure.reason = KeywordNotString; failure.detail_obj = key; @@ -3240,11 +3150,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (name == NULL) continue; -#if PY_MAJOR_VERSION >= 3 if (PyUnicode_CompareWithASCIIString(key, name) == 0) -#else - if (strcmp(PyString_AS_STRING(key), name) == 0) -#endif break; } } @@ -3368,11 +3274,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, { int a; -#if PY_MAJOR_VERSION >= 3 if (!PyUnicode_Check(key)) -#else - if (!PyString_Check(key)) -#endif { failure.reason = KeywordNotString; failure.detail_obj = key; @@ -3390,11 +3292,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (name == NULL) continue; -#if PY_MAJOR_VERSION >= 3 if (PyUnicode_CompareWithASCIIString(key, name) == 0) -#else - if (strcmp(PyString_AS_STRING(key), name) == 0) -#endif break; } } @@ -3535,9 +3433,9 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, *sname = NULL; *scall = NULL; - if (SIPBytes_Check(arg)) + if (PyBytes_Check(arg)) { - char *s = SIPBytes_AS_STRING(arg); + char *s = PyBytes_AS_STRING(arg); if (*s == '1' || *s == '2' || *s == '9') { @@ -3573,9 +3471,9 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { - if (SIPBytes_Check(arg)) + if (PyBytes_Check(arg)) { - char *s = SIPBytes_AS_STRING(arg); + char *s = PyBytes_AS_STRING(arg); if (*s == '1' || *s == '2' || *s == '9') { @@ -3607,9 +3505,9 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { - if (SIPBytes_Check(arg)) + if (PyBytes_Check(arg)) { - char *s = SIPBytes_AS_STRING(arg); + char *s = PyBytes_AS_STRING(arg); if (*s == '2' || *s == '9') { @@ -4011,7 +3909,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { - int v = SIPLong_AsLong(arg); + int v = PyLong_AsLong(arg); if (PyErr_Occurred()) { @@ -4055,7 +3953,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { - int v = SIPLong_AsLong(arg); + int v = PyLong_AsLong(arg); if (PyErr_Occurred()) { @@ -4105,7 +4003,7 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, if (arg != NULL) { - short v = SIPLong_AsLong(arg); + short v = PyLong_AsLong(arg); if (PyErr_Occurred()) { @@ -4375,17 +4273,10 @@ static int parsePass1(PyObject **parseErrp, sipSimpleWrapper **selfp, { /* Integer. */ -#if PY_MAJOR_VERSION >= 3 if (PyLong_Check(arg)) { *(int *)p = PyLong_AS_LONG(arg); } -#else - if (PyInt_Check(arg)) - { - *(int *)p = PyInt_AS_LONG(arg); - } -#endif else { failure.reason = WrongType; @@ -4788,7 +4679,7 @@ static int parsePass2(sipSimpleWrapper *self, int selfarg, PyObject *sipArgs, int *p = va_arg(va, int *); if (arg != NULL) - *p = SIPLong_AsLong(arg); + *p = PyLong_AsLong(arg); } break; @@ -4804,7 +4695,7 @@ static int parsePass2(sipSimpleWrapper *self, int selfarg, PyObject *sipArgs, p = va_arg(va, int *); if (arg != NULL) - *p = SIPLong_AsLong(arg); + *p = PyLong_AsLong(arg); break; } @@ -5161,12 +5052,7 @@ static PyObject *getDefaultBases(void) /* Only do this once. */ if (default_bases == NULL) { -#if PY_VERSION_HEX >= 0x02040000 default_bases = PyTuple_Pack(1, (PyObject *)&sipWrapper_Type); -#else - default_bases = Py_BuildValue("(O)", &sipWrapper_Type); -#endif - if (default_bases == NULL) return NULL; } @@ -5227,21 +5113,13 @@ static PyObject *createContainerType(sipContainerDef *cod, sipTypeDef *td, goto reterr; /* Create an object corresponding to the type name. */ -#if PY_MAJOR_VERSION >= 3 name = PyUnicode_FromString(sipPyNameOfContainer(cod, td)); -#else - name = PyString_FromString(sipPyNameOfContainer(cod, td)); -#endif if (name == NULL) goto reldict; /* Create the type by calling the metatype. */ -#if PY_VERSION_HEX >= 0x02040000 args = PyTuple_Pack(3, name, bases, typedict); -#else - args = Py_BuildValue("OOO", name, bases, typedict); -#endif if (args == NULL) goto relname; @@ -5314,11 +5192,7 @@ static int createClassType(sipExportedModuleDef *client, sipClassTypeDef *ctd, if ((supertype = findPyType(supertype_name)) == NULL) goto reterr; -#if PY_VERSION_HEX >= 0x02040000 bases = PyTuple_Pack(1, supertype); -#else - bases = Py_BuildValue("(O)", supertype); -#endif } if (bases == NULL) @@ -5453,24 +5327,15 @@ static sipExportedModuleDef *getModule(PyObject *mname_obj) /* Find the module definition. */ for (em = moduleList; em != NULL; em = em->em_next) -#if PY_MAJOR_VERSION >= 3 if (PyUnicode_Compare(mname_obj, em->em_nameobj) == 0) -#else - if (strcmp(PyString_AS_STRING(mname_obj), sipNameOfModule(em)) == 0) -#endif break; Py_DECREF(mod); if (em == NULL) { -#if PY_MAJOR_VERSION >= 3 PyErr_Format(PyExc_SystemError, "unable to find to find module: %U", mname_obj); -#else - PyErr_Format(PyExc_SystemError, "unable to find to find module: %s", - PyString_AS_STRING(mname_obj)); -#endif } return em; @@ -5488,11 +5353,7 @@ static PyObject *unpickle_type(PyObject *ignore, PyObject *args) int i; if (!PyArg_ParseTuple(args, -#if PY_MAJOR_VERSION >= 3 "UsO!:_unpickle_type", -#else - "SsO!:_unpickle_type", -#endif &mname_obj, &tname, &PyTuple_Type, &init_args)) return NULL; @@ -5584,11 +5445,7 @@ static PyObject *unpickle_enum(PyObject *ignore, PyObject *args) int i; if (!PyArg_ParseTuple(args, -#if PY_MAJOR_VERSION >= 3 "UsO:_unpickle_enum", -#else - "SsO:_unpickle_enum", -#endif &mname_obj, &ename, &evalue_obj)) return NULL; @@ -5621,12 +5478,7 @@ static PyObject *pickle_enum(PyObject *obj, PyObject *ignore) return Py_BuildValue("O(Osi)", enum_unpickler, td->td_module->em_nameobj, sipPyNameOfEnum((sipEnumTypeDef *)td), -#if PY_MAJOR_VERSION >= 3 - (int)PyLong_AS_LONG(obj) -#else - (int)PyInt_AS_LONG(obj) -#endif - ); + (int)PyLong_AS_LONG(obj)); } @@ -5679,24 +5531,14 @@ static int createEnumType(sipExportedModuleDef *client, sipEnumTypeDef *etd, /* Create the base type tuple if it hasn't already been done. */ if (bases == NULL) { -#if PY_MAJOR_VERSION >= 3 bases = PyTuple_Pack(1, (PyObject *)&PyLong_Type); -#elif PY_VERSION_HEX >= 0x02040000 - bases = PyTuple_Pack(1, (PyObject *)&PyInt_Type); -#else - bases = Py_BuildValue("(O)", &PyInt_Type); -#endif if (bases == NULL) goto reterr; } /* Create an object corresponding to the type name. */ -#if PY_MAJOR_VERSION >= 3 name = PyUnicode_FromString(sipPyNameOfEnum(etd)); -#else - name = PyString_FromString(sipPyNameOfEnum(etd)); -#endif if (name == NULL) goto reterr; @@ -5706,11 +5548,7 @@ static int createEnumType(sipExportedModuleDef *client, sipEnumTypeDef *etd, goto relname; /* Create the type by calling the metatype. */ -#if PY_VERSION_HEX >= 0x02040000 args = PyTuple_Pack(3, name, bases, typedict); -#else - args = Py_BuildValue("OOO", name, bases, typedict); -#endif Py_DECREF(typedict); @@ -5784,11 +5622,7 @@ static int objectify(const char *s, PyObject **objp) { if (*objp == NULL) { -#if PY_MAJOR_VERSION >= 3 *objp = PyUnicode_FromString(s); -#else - *objp = PyString_FromString(s); -#endif if (*objp == NULL) return -1; @@ -6074,11 +5908,7 @@ static int sip_api_can_convert_to_enum(PyObject *obj, const sipTypeDef *td) if (PyObject_TypeCheck((PyObject *)Py_TYPE(obj), &sipEnumType_Type)) return (PyObject_TypeCheck(obj, sipTypeAsPyTypeObject(td))); -#if PY_MAJOR_VERSION >= 3 return PyLong_Check(obj); -#else - return PyInt_Check(obj); -#endif } @@ -6088,11 +5918,7 @@ static int sip_api_can_convert_to_enum(PyObject *obj, const sipTypeDef *td) static PyObject *createEnumMember(sipTypeDef *td, sipEnumMemberDef *enm) { if (enm->em_enum < 0) -#if PY_MAJOR_VERSION >= 3 return PyLong_FromLong(enm->em_val); -#else - return PyInt_FromLong(enm->em_val); -#endif return sip_api_convert_from_enum(enm->em_val, td->td_module->em_types[enm->em_enum]); @@ -6180,13 +6006,7 @@ static void sip_api_no_method(PyObject *parseErr, const char *scope, if (doc_obj != NULL) { -#if PY_MAJOR_VERSION >= 3 exc = PyUnicode_FromFormat("%U: %U", doc_obj, detail); -#else - exc = PyString_FromFormat("%s: %s", - PyString_AS_STRING(doc_obj), - PyString_AS_STRING(detail)); -#endif Py_DECREF(doc_obj); } @@ -6197,13 +6017,8 @@ static void sip_api_no_method(PyObject *parseErr, const char *scope, } else { -#if PY_MAJOR_VERSION >= 3 exc = PyUnicode_FromFormat("%s%s%s(): %U", scope, sep, method, detail); -#else - exc = PyString_FromFormat("%s%s%s(): %s", scope, sep, - method, PyString_AS_STRING(detail)); -#endif } Py_DECREF(detail); @@ -6221,21 +6036,12 @@ static void sip_api_no_method(PyObject *parseErr, const char *scope, if (doc != NULL) { -#if PY_MAJOR_VERSION >= 3 exc = PyUnicode_FromString(summary); -#else - exc = PyString_FromString(summary); -#endif } else { -#if PY_MAJOR_VERSION >= 3 exc = PyUnicode_FromFormat("%s%s%s(): %s", scope, sep, method, summary); -#else - exc = PyString_FromFormat("%s%s%s(): %s", scope, sep, method, - summary); -#endif } for (i = 0; i < PyList_GET_SIZE(parseErr); ++i) @@ -6252,14 +6058,8 @@ static void sip_api_no_method(PyObject *parseErr, const char *scope, if (doc_obj != NULL) { -#if PY_MAJOR_VERSION >= 3 failure = PyUnicode_FromFormat("\n %U: %U", doc_obj, detail); -#else - failure = PyString_FromFormat("\n %s: %s", - PyString_AS_STRING(doc_obj), - PyString_AS_STRING(detail)); -#endif Py_DECREF(doc_obj); } @@ -6272,25 +6072,13 @@ static void sip_api_no_method(PyObject *parseErr, const char *scope, } else { -#if PY_MAJOR_VERSION >= 3 failure = PyUnicode_FromFormat("\n overload %zd: %U", i + 1, detail); -#elif PY_VERSION_HEX >= 0x02050000 - failure = PyString_FromFormat("\n overload %zd: %s", - i + 1, PyString_AS_STRING(detail)); -#else - failure = PyString_FromFormat("\n overload %d: %s", - i + 1, PyString_AS_STRING(detail)); -#endif } Py_DECREF(detail); -#if PY_MAJOR_VERSION >= 3 PyUnicode_AppendAndDel(&exc, failure); -#else - PyString_ConcatAndDel(&exc, failure); -#endif } else { @@ -6351,11 +6139,7 @@ static PyObject *signature_FromDocstring(const char *doc, SIP_SSIZE_T line) if (*eol == ')') size = eol - doc + 1; -#if PY_MAJOR_VERSION >= 3 return PyUnicode_FromStringAndSize(doc, size); -#else - return PyString_FromStringAndSize(doc, size); -#endif } @@ -6367,87 +6151,39 @@ static PyObject *detail_FromFailure(PyObject *failure_obj) sipParseFailure *failure; PyObject *detail; -#if defined(SIP_USE_PYCAPSULE) failure = (sipParseFailure *)PyCapsule_GetPointer(failure_obj, NULL); -#else - failure = (sipParseFailure *)PyCObject_AsVoidPtr(failure_obj); -#endif switch (failure->reason) { case Unbound: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat( "first argument of unbound method must have type '%s'", failure->detail_str); -#else - detail = PyString_FromFormat( - "first argument of unbound method must have type '%s'", - failure->detail_str); -#endif break; case TooFew: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromString("not enough arguments"); -#else - detail = PyString_FromString("not enough arguments"); -#endif break; case TooMany: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromString("too many arguments"); -#else - detail = PyString_FromString("too many arguments"); -#endif break; case KeywordNotString: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat( "%S keyword argument name is not a string", failure->detail_obj); -#else - { - PyObject *str = PyObject_Str(failure->detail_obj); - - if (str != NULL) - { - detail = PyString_FromFormat( - "%s keyword argument name is not a string", - PyString_AsString(str)); - - Py_DECREF(str); - } - else - { - detail = NULL; - } - } -#endif break; case UnknownKeyword: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat("'%U' is not a valid keyword argument", failure->detail_obj); -#else - detail = PyString_FromFormat("'%s' is not a valid keyword argument", - PyString_AS_STRING(failure->detail_obj)); -#endif break; case Duplicate: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat( "'%U' has already been given as a positional argument", failure->detail_obj); -#else - detail = PyString_FromFormat( - "'%s' has already been given as a positional argument", - PyString_AS_STRING(failure->detail_obj)); -#endif break; case WrongType: @@ -6457,15 +6193,9 @@ static PyObject *detail_FromFailure(PyObject *failure_obj) } else { -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromFormat( "keyword argument '%s' has unexpected type '%s'", failure->arg_name, Py_TYPE(failure->detail_obj)->tp_name); -#else - detail = PyString_FromFormat( - "keyword argument '%s' has unexpected type '%s'", - failure->arg_name, Py_TYPE(failure->detail_obj)->tp_name); -#endif } break; @@ -6482,11 +6212,7 @@ static PyObject *detail_FromFailure(PyObject *failure_obj) /* Drop through. */ default: -#if PY_MAJOR_VERSION >= 3 detail = PyUnicode_FromString("unknown reason"); -#else - detail = PyString_FromString("unknown reason"); -#endif } return detail; @@ -6520,11 +6246,7 @@ static int sip_api_deprecated(const char *classname, const char *method) PyOS_snprintf(buf, sizeof (buf), "%s.%s() is deprecated", classname, method); -#if PY_VERSION_HEX >= 0x02050000 return PyErr_WarnEx(PyExc_DeprecationWarning, buf, 1); -#else - return PyErr_Warn(PyExc_DeprecationWarning, buf); -#endif } @@ -6574,11 +6296,7 @@ static void sip_api_bad_length_for_slice(SIP_SSIZE_T seqlen, SIP_SSIZE_T slicelen) { PyErr_Format(PyExc_ValueError, -#if PY_VERSION_HEX >= 0x02050000 "attempt to assign sequence of size %zd to slice of size %zd", -#else - "attempt to assign sequence of size %d to slice of size %d", -#endif seqlen, slicelen); } @@ -6616,14 +6334,8 @@ static void sip_api_bad_catcher_result(PyObject *method) mname = ((PyFunctionObject *)PyMethod_GET_FUNCTION(method))->func_name; -#if PY_MAJOR_VERSION >= 3 PyErr_Format(PyExc_TypeError, "invalid result type from %s.%U()", Py_TYPE(PyMethod_GET_SELF(method))->tp_name, mname); -#else - PyErr_Format(PyExc_TypeError, "invalid result type from %s.%s()", - Py_TYPE(PyMethod_GET_SELF(method))->tp_name, - PyString_AsString(mname)); -#endif } @@ -6746,11 +6458,7 @@ static int addLicense(PyObject *dict,sipLicenseDef *lc) if (lc->lc_type == NULL) goto deldict; -#if PY_MAJOR_VERSION >= 3 o = PyUnicode_FromString(lc->lc_type); -#else - o = PyString_FromString(lc->lc_type); -#endif if (o == NULL) goto deldict; @@ -6763,11 +6471,7 @@ static int addLicense(PyObject *dict,sipLicenseDef *lc) if (lc->lc_licensee != NULL) { -#if PY_MAJOR_VERSION >= 3 o = PyUnicode_FromString(lc->lc_licensee); -#else - o = PyString_FromString(lc->lc_licensee); -#endif if (o == NULL) goto deldict; @@ -6781,11 +6485,7 @@ static int addLicense(PyObject *dict,sipLicenseDef *lc) if (lc->lc_timestamp != NULL) { -#if PY_MAJOR_VERSION >= 3 o = PyUnicode_FromString(lc->lc_timestamp); -#else - o = PyString_FromString(lc->lc_timestamp); -#endif if (o == NULL) goto deldict; @@ -6799,11 +6499,7 @@ static int addLicense(PyObject *dict,sipLicenseDef *lc) if (lc->lc_signature != NULL) { -#if PY_MAJOR_VERSION >= 3 o = PyUnicode_FromString(lc->lc_signature); -#else - o = PyString_FromString(lc->lc_signature); -#endif if (o == NULL) goto deldict; @@ -6880,15 +6576,11 @@ static int addCharInstances(PyObject *dict, sipCharInstanceDef *ci) break; case '8': -#if PY_MAJOR_VERSION >= 3 w = PyUnicode_FromStringAndSize(&ci->ci_val, 1); -#else - w = PyUnicode_DecodeUTF8(&ci->ci_val, 1, NULL); -#endif break; default: - w = SIPBytes_FromStringAndSize(&ci->ci_val, 1); + w = PyBytes_FromStringAndSize(&ci->ci_val, 1); } if (w == NULL) @@ -6928,15 +6620,11 @@ static int addStringInstances(PyObject *dict, sipStringInstanceDef *si) break; case '8': -#if PY_MAJOR_VERSION >= 3 w = PyUnicode_FromString(si->si_val); -#else - w = PyUnicode_DecodeUTF8(si->si_val, strlen(si->si_val), NULL); -#endif break; default: - w = SIPBytes_FromString(si->si_val); + w = PyBytes_FromString(si->si_val); } if (w == NULL) @@ -6965,11 +6653,7 @@ static int addIntInstances(PyObject *dict, sipIntInstanceDef *ii) int rc; PyObject *w; -#if PY_MAJOR_VERSION >= 3 w = PyLong_FromLong(ii->ii_val); -#else - w = PyInt_FromLong(ii->ii_val); -#endif if (w == NULL) return -1; @@ -7237,11 +6921,7 @@ static PyObject *sip_api_is_py_method(sip_gilstate_t *gil, char *pymc, *gil = PyGILState_Ensure(); #endif -#if PY_MAJOR_VERSION >= 3 mname_obj = PyUnicode_FromString(mname); -#else - mname_obj = PyString_FromString(mname); -#endif if (mname_obj == NULL) { @@ -7280,16 +6960,7 @@ static PyObject *sip_api_is_py_method(sip_gilstate_t *gil, char *pymc, PyObject *cls_dict; cls = PyTuple_GET_ITEM(mro, i); - -#if PY_MAJOR_VERSION >= 3 cls_dict = ((PyTypeObject *)cls)->tp_dict; -#else - // Allow for classic classes as mixins. - if (PyClass_Check(cls)) - cls_dict = ((PyClassObject *)cls)->cl_dict; - else - cls_dict = ((PyTypeObject *)cls)->tp_dict; -#endif if (cls_dict != NULL && (reimp = PyDict_GetItem(cls_dict, mname_obj)) != NULL) { @@ -7306,13 +6977,8 @@ static PyObject *sip_api_is_py_method(sip_gilstate_t *gil, char *pymc, } else { -#if PY_MAJOR_VERSION >= 3 reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), (PyObject *)sipSelf); -#else - reimp = PyMethod_New(PyMethod_GET_FUNCTION(reimp), - (PyObject *)sipSelf, PyMethod_GET_CLASS(reimp)); -#endif } break; @@ -7320,12 +6986,7 @@ static PyObject *sip_api_is_py_method(sip_gilstate_t *gil, char *pymc, if (PyFunction_Check(reimp)) { -#if PY_MAJOR_VERSION >= 3 reimp = PyMethod_New(reimp, (PyObject *)sipSelf); -#else - reimp = PyMethod_New(reimp, (PyObject *)sipSelf, cls); -#endif - break; } @@ -7498,11 +7159,7 @@ static void sip_api_keep_reference(PyObject *self, int key, PyObject *obj) ((sipSimpleWrapper *)self)->extra_refs = dict; } -#if PY_MAJOR_VERSION >= 3 key_obj = PyLong_FromLong(key); -#else - key_obj = PyInt_FromLong(key); -#endif if (key_obj != NULL) { @@ -7949,9 +7606,6 @@ void sipSaveMethod(sipPyMethod *pm, PyObject *meth) { pm->mfunc = PyMethod_GET_FUNCTION(meth); pm->mself = PyMethod_GET_SELF(meth); -#if PY_MAJOR_VERSION < 3 - pm->mclass = PyMethod_GET_CLASS(meth); -#endif } @@ -8299,11 +7953,7 @@ static int objobjargprocSlot(PyObject *self, PyObject *arg1, PyObject *arg2, } else { -#if PY_VERSION_HEX >= 0x02040000 args = PyTuple_Pack(2, arg1, arg2); -#else - args = Py_BuildValue("(OO)", arg1, arg2); -#endif if (args == NULL) return -1; @@ -8342,19 +7992,9 @@ static int ssizeobjargprocSlot(PyObject *self, SIP_SSIZE_T arg1, * optional. */ if (arg2 == NULL) -#if PY_MAJOR_VERSION >= 3 args = PyLong_FromSsize_t(arg1); -#elif PY_VERSION_HEX >= 0x02050000 - args = PyInt_FromSsize_t(arg1); -#else - args = PyInt_FromLong(arg1); -#endif - else -#if PY_VERSION_HEX >= 0x02050000 + else args = Py_BuildValue("(nO)", arg1, arg2); -#else - args = Py_BuildValue("(iO)", arg1, arg2); -#endif if (args == NULL) return -1; @@ -8819,7 +8459,6 @@ static int sipSimpleWrapper_clear(sipSimpleWrapper *self) } -#if PY_MAJOR_VERSION >= 3 /* * The instance get buffer slot for Python v3. */ @@ -8834,10 +8473,8 @@ static int sipSimpleWrapper_getbuffer(sipSimpleWrapper *self, Py_buffer *buf, return ctd->ctd_getbuffer((PyObject *)self, ptr, buf, flags); } -#endif -#if PY_MAJOR_VERSION >= 3 /* * The instance release buffer slot for Python v3. */ @@ -8852,79 +8489,6 @@ static void sipSimpleWrapper_releasebuffer(sipSimpleWrapper *self, return ctd->ctd_releasebuffer((PyObject *)self, ptr, buf); } -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The instance read buffer slot for Python v2. - */ -static SIP_SSIZE_T sipSimpleWrapper_getreadbuffer(sipSimpleWrapper *self, - SIP_SSIZE_T segment, void **ptrptr) -{ - void *ptr; - const sipClassTypeDef *ctd; - - if ((ptr = getPtrTypeDef(self, &ctd)) == NULL) - return -1; - - return ctd->ctd_readbuffer((PyObject *)self, ptr, segment, ptrptr); -} -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The instance write buffer slot for Python v2. - */ -static SIP_SSIZE_T sipSimpleWrapper_getwritebuffer(sipSimpleWrapper *self, - SIP_SSIZE_T segment, void **ptrptr) -{ - void *ptr; - const sipClassTypeDef *ctd; - - if ((ptr = getPtrTypeDef(self, &ctd)) == NULL) - return -1; - - return ctd->ctd_writebuffer((PyObject *)self, ptr, segment, ptrptr); -} -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The instance segment count slot for Python v2. - */ -static SIP_SSIZE_T sipSimpleWrapper_getsegcount(sipSimpleWrapper *self, - SIP_SSIZE_T *lenp) -{ - void *ptr; - const sipClassTypeDef *ctd; - - if ((ptr = getPtrTypeDef(self, &ctd)) == NULL) - return 0; - - return ctd->ctd_segcount((PyObject *)self, ptr, lenp); -} -#endif - - -#if PY_MAJOR_VERSION < 3 -/* - * The instance char buffer slot for Python v2. - */ -static SIP_SSIZE_T sipSimpleWrapper_getcharbuffer(sipSimpleWrapper *self, - SIP_SSIZE_T segment, void **ptrptr) -{ - void *ptr; - const sipClassTypeDef *ctd; - - if ((ptr = getPtrTypeDef(self, &ctd)) == NULL) - return -1; - - return ctd->ctd_charbuffer((PyObject *)self, ptr, segment, ptrptr); -} -#endif /* @@ -8969,14 +8533,7 @@ static PyObject *slot_sq_item(PyObject *self, SIP_SSIZE_T n) PyObject *(*f)(PyObject *,PyObject *); PyObject *arg, *res; -#if PY_MAJOR_VERSION >= 3 arg = PyLong_FromSsize_t(n); -#elif PY_VERSION_HEX >= 0x02050000 - arg = PyInt_FromSsize_t(n); -#else - arg = PyInt_FromLong(n); -#endif - if (arg == NULL) return NULL; @@ -9323,41 +8880,11 @@ static int sipWrapper_traverse(sipWrapper *self, visitproc visit, void *arg) static void addClassSlots(sipWrapperType *wt, sipClassTypeDef *ctd) { /* Add the buffer interface. */ -#if PY_MAJOR_VERSION >= 3 if (ctd->ctd_getbuffer != NULL) wt->super.as_buffer.bf_getbuffer = (getbufferproc)sipSimpleWrapper_getbuffer; if (ctd->ctd_releasebuffer != NULL) wt->super.as_buffer.bf_releasebuffer = (releasebufferproc)sipSimpleWrapper_releasebuffer; -#else - if (ctd->ctd_readbuffer != NULL) -#if PY_VERSION_HEX >= 0x02050000 - wt->super.as_buffer.bf_getreadbuffer = (readbufferproc)sipSimpleWrapper_getreadbuffer; -#else - wt->super.as_buffer.bf_getreadbuffer = (getreadbufferproc)sipSimpleWrapper_getreadbuffer; -#endif - - if (ctd->ctd_writebuffer != NULL) -#if PY_VERSION_HEX >= 0x02050000 - wt->super.as_buffer.bf_getwritebuffer = (writebufferproc)sipSimpleWrapper_getwritebuffer; -#else - wt->super.as_buffer.bf_getwritebuffer = (getwritebufferproc)sipSimpleWrapper_getwritebuffer; -#endif - - if (ctd->ctd_segcount != NULL) -#if PY_VERSION_HEX >= 0x02050000 - wt->super.as_buffer.bf_getsegcount = (segcountproc)sipSimpleWrapper_getsegcount; -#else - wt->super.as_buffer.bf_getsegcount = (getsegcountproc)sipSimpleWrapper_getsegcount; -#endif - - if (ctd->ctd_charbuffer != NULL) -#if PY_VERSION_HEX >= 0x02050000 - wt->super.as_buffer.bf_getcharbuffer = (charbufferproc)sipSimpleWrapper_getcharbuffer; -#else - wt->super.as_buffer.bf_getcharbuffer = (getcharbufferproc)sipSimpleWrapper_getcharbuffer; -#endif -#endif /* Add the slots for this type. */ if (ctd->ctd_pyslots != NULL) @@ -9393,13 +8920,6 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) nb->nb_int = (unaryfunc)f; break; -#if PY_MAJOR_VERSION < 3 - case long_slot: - if (nb != NULL) - nb->nb_long = (unaryfunc)f; - break; -#endif - case float_slot: if (nb != NULL) nb->nb_float = (unaryfunc)f; @@ -9407,17 +8927,9 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) case len_slot: if (mp != NULL) -#if PY_VERSION_HEX >= 0x02050000 mp->mp_length = (lenfunc)f; -#else - mp->mp_length = (inquiry)f; -#endif if (sq != NULL) -#if PY_VERSION_HEX >= 0x02050000 sq->sq_length = (lenfunc)f; -#else - sq->sq_length = (inquiry)f; -#endif break; case contains_slot: @@ -9447,20 +8959,13 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) case repeat_slot: if (sq != NULL) -#if PY_VERSION_HEX >= 0x02050000 sq->sq_repeat = (ssizeargfunc)f; -#else - sq->sq_repeat = (intargfunc)f; -#endif break; case div_slot: if (nb != NULL) { nb->nb_true_divide = (binaryfunc)f; -#if PY_MAJOR_VERSION < 3 - nb->nb_divide = (binaryfunc)f; -#endif } break; @@ -9526,20 +9031,13 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) case irepeat_slot: if (sq != NULL) -#if PY_VERSION_HEX >= 0x02050000 sq->sq_inplace_repeat = (ssizeargfunc)f; -#else - sq->sq_inplace_repeat = (intargfunc)f; -#endif break; case idiv_slot: if (nb != NULL) { nb->nb_inplace_true_divide = (binaryfunc)f; -#if PY_MAJOR_VERSION < 3 - nb->nb_inplace_divide = (binaryfunc)f; -#endif } break; @@ -9616,19 +9114,9 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) to->tp_richcompare = slot_richcompare; break; -#if PY_MAJOR_VERSION < 3 - case cmp_slot: - to->tp_compare = (cmpfunc)f; - break; -#endif - case bool_slot: if (nb != NULL) -#if PY_MAJOR_VERSION >= 3 nb->nb_bool = (inquiry)f; -#else - nb->nb_nonzero = (inquiry)f; -#endif break; case neg_slot: @@ -9654,12 +9142,10 @@ static void addTypeSlots(PyHeapTypeObject *heap_to, sipPySlotDef *slots) nb->nb_absolute = (unaryfunc)f; break; -#if PY_VERSION_HEX >= 0x02050000 case index_slot: if (nb != NULL) nb->nb_index = (unaryfunc)f; break; -#endif case iter_slot: to->tp_iter = (getiterfunc)f; @@ -9856,11 +9342,7 @@ static char sip_api_bytes_as_char(PyObject *obj) if (parseBytes_AsChar(obj, &ch) < 0) { PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes of length 1 expected not '%s'", -#else - "string of length 1 expected not '%s'", -#endif Py_TYPE(obj)->tp_name); return '\0'; @@ -9881,11 +9363,7 @@ static const char *sip_api_bytes_as_string(PyObject *obj) if (parseBytes_AsString(obj, &a) < 0) { PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes expected not '%s'", -#else - "string expected not '%s'", -#endif Py_TYPE(obj)->tp_name); return NULL; @@ -9908,11 +9386,7 @@ static char sip_api_string_as_ascii_char(PyObject *obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(obj) || PyUnicode_GET_SIZE(obj) != 1) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or ASCII string of length 1 expected not '%s'", -#else - "string or ASCII unicode of length 1 expected not '%s'", -#endif Py_TYPE(obj)->tp_name); return '\0'; @@ -9944,11 +9418,7 @@ static char sip_api_string_as_latin1_char(PyObject *obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(obj) || PyUnicode_GET_SIZE(obj) != 1) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or Latin-1 string of length 1 expected not '%s'", -#else - "string or Latin-1 unicode of length 1 expected not '%s'", -#endif Py_TYPE(obj)->tp_name); return '\0'; @@ -9980,11 +9450,7 @@ static char sip_api_string_as_utf8_char(PyObject *obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(obj) || PyUnicode_GET_SIZE(obj) != 1) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or UTF-8 string of length 1 expected not '%s'", -#else - "string or UTF-8 unicode of length 1 expected not '%s'", -#endif Py_TYPE(obj)->tp_name); return '\0'; @@ -10017,7 +9483,7 @@ static int parseString_AsEncodedChar(PyObject *bytes, PyObject *obj, char *ap) return parseBytes_AsChar(obj, ap); } - size = SIPBytes_GET_SIZE(bytes); + size = PyBytes_GET_SIZE(bytes); if (size != 1) { @@ -10025,7 +9491,7 @@ static int parseString_AsEncodedChar(PyObject *bytes, PyObject *obj, char *ap) return -1; } - *ap = *SIPBytes_AS_STRING(bytes); + *ap = *PyBytes_AS_STRING(bytes); Py_DECREF(bytes); @@ -10048,11 +9514,7 @@ static const char *sip_api_string_as_ascii_string(PyObject **obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(s)) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or ASCII string expected not '%s'", -#else - "string or ASCII unicode expected not '%s'", -#endif Py_TYPE(s)->tp_name); return NULL; @@ -10087,11 +9549,7 @@ static const char *sip_api_string_as_latin1_string(PyObject **obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(s)) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or Latin-1 string expected not '%s'", -#else - "string or Latin-1 unicode expected not '%s'", -#endif Py_TYPE(s)->tp_name); return NULL; @@ -10126,11 +9584,7 @@ static const char *sip_api_string_as_utf8_string(PyObject **obj) /* Use the exception set if it was an encoding error. */ if (!PyUnicode_Check(s)) PyErr_Format(PyExc_TypeError, -#if PY_MAJOR_VERSION >= 3 "bytes or UTF-8 string expected not '%s'", -#else - "string or UTF-8 unicode expected not '%s'", -#endif Py_TYPE(s)->tp_name); return NULL; @@ -10159,7 +9613,7 @@ static PyObject *parseString_AsEncodedString(PyObject *bytes, PyObject *obj, { if (bytes != NULL) { - *ap = SIPBytes_AS_STRING(bytes); + *ap = PyBytes_AS_STRING(bytes); return bytes; } @@ -10186,10 +9640,10 @@ static int parseBytes_AsCharArray(PyObject *obj, const char **ap, *ap = NULL; *aszp = 0; } - else if (SIPBytes_Check(obj)) + else if (PyBytes_Check(obj)) { - *ap = SIPBytes_AS_STRING(obj); - *aszp = SIPBytes_GET_SIZE(obj); + *ap = PyBytes_AS_STRING(obj); + *aszp = PyBytes_GET_SIZE(obj); } else if (PyObject_AsCharBuffer(obj, ap, aszp) < 0) return -1; @@ -10206,10 +9660,10 @@ static int parseBytes_AsChar(PyObject *obj, char *ap) const char *chp; SIP_SSIZE_T sz; - if (SIPBytes_Check(obj)) + if (PyBytes_Check(obj)) { - chp = SIPBytes_AS_STRING(obj); - sz = SIPBytes_GET_SIZE(obj); + chp = PyBytes_AS_STRING(obj); + sz = PyBytes_GET_SIZE(obj); } else if (PyObject_AsCharBuffer(obj, &chp, &sz) < 0) return -1; @@ -10245,11 +9699,7 @@ static wchar_t sip_api_unicode_as_wchar(PyObject *obj) if (parseWChar(obj, &ch) < 0) { PyErr_Format(PyExc_ValueError, -#if PY_MAJOR_VERSION >= 3 "string" -#else - "unicode string" -#endif " of length 1 expected, not %s", Py_TYPE(obj)->tp_name); return L'\0'; @@ -10269,12 +9719,7 @@ static wchar_t *sip_api_unicode_as_wstring(PyObject *obj) if (parseWCharString(obj, &p) < 0) { PyErr_Format(PyExc_ValueError, -#if PY_MAJOR_VERSION >= 3 - "string" -#else - "unicode string" -#endif - " expected, not %s", Py_TYPE(obj)->tp_name); + "string expected, not %s", Py_TYPE(obj)->tp_name); return NULL; } @@ -10299,22 +9744,6 @@ static int parseWCharArray(PyObject *obj, wchar_t **ap, SIP_SSIZE_T *aszp) if (PyUnicode_Check(obj)) return convertToWCharArray(obj, ap, aszp); -#if PY_MAJOR_VERSION < 3 - if (PyString_Check(obj)) - { - int rc; - PyObject *uobj; - - if ((uobj = PyUnicode_FromObject(obj)) == NULL) - return -1; - - rc = convertToWCharArray(uobj, ap, aszp); - Py_DECREF(uobj); - - return rc; - } -#endif - return -1; } @@ -10356,22 +9785,6 @@ static int parseWChar(PyObject *obj, wchar_t *ap) if (PyUnicode_Check(obj)) return convertToWChar(obj, ap); -#if PY_MAJOR_VERSION < 3 - if (PyString_Check(obj)) - { - int rc; - PyObject *uobj; - - if ((uobj = PyUnicode_FromObject(obj)) == NULL) - return -1; - - rc = convertToWChar(uobj, ap); - Py_DECREF(uobj); - - return rc; - } -#endif - return -1; } @@ -10406,22 +9819,6 @@ static int parseWCharString(PyObject *obj, wchar_t **ap) if (PyUnicode_Check(obj)) return convertToWCharString(obj, ap); -#if PY_MAJOR_VERSION < 3 - if (PyString_Check(obj)) - { - int rc; - PyObject *uobj; - - if ((uobj = PyUnicode_FromObject(obj)) == NULL) - return -1; - - rc = convertToWCharString(uobj, ap); - Py_DECREF(uobj); - - return rc; - } -#endif - return -1; } diff --git a/siplib/tqtlib.c b/siplib/tqtlib.c index 1628c83..702b679 100644 --- a/siplib/tqtlib.c +++ b/siplib/tqtlib.c @@ -151,11 +151,7 @@ PyObject *sip_api_invoke_slot(const sipSlot *slot, PyObject *sigargs) return Py_None; } -#if PY_MAJOR_VERSION >= 3 sfunc = PyMethod_New(slot->meth.mfunc, self); -#else - sfunc = PyMethod_New(slot->meth.mfunc, self, slot->meth.mclass); -#endif if (sfunc == NULL) { @@ -324,9 +320,6 @@ int sip_api_same_slot(const sipSlot *sp, PyObject *rxObj, const char *slot) return (sp->meth.mfunc == PyMethod_GET_FUNCTION(rxObj) && sp->meth.mself == PyMethod_GET_SELF(rxObj) -#if PY_MAJOR_VERSION < 3 - && sp->meth.mclass == PyMethod_GET_CLASS(rxObj) -#endif ); } 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; } } |