summaryrefslogtreecommitdiffstats
path: root/siplib/siplib.c
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2023-01-22 13:41:16 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2023-01-22 21:16:37 +0900
commit3e5815bce63e9e476bdeb58cbe230239622e1ba5 (patch)
tree8fd8d6fe17a2a0d3dd78560c5114331a6c93b616 /siplib/siplib.c
parent1d30924b9dd0740b726ae10b0aa4e6b6a6ea213a (diff)
downloadsip4-tqt-3e5815bce63e9e476bdeb58cbe230239622e1ba5.tar.gz
sip4-tqt-3e5815bce63e9e476bdeb58cbe230239622e1ba5.zip
Remove old conditional python code.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'siplib/siplib.c')
-rw-r--r--siplib/siplib.c671
1 files changed, 34 insertions, 637 deletions
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;
}