Remove old conditional python code.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/12/head
Michele Calgaro 1 year ago
parent 1d30924b9d
commit 3e5815bce6
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -75,7 +75,6 @@ static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir,
static void generateComponentCpp(sipSpec *pt, const char *codeDir, static void generateComponentCpp(sipSpec *pt, const char *codeDir,
const char *consModule); const char *consModule);
static void generateSipImport(moduleDef *mod, FILE *fp); static void generateSipImport(moduleDef *mod, FILE *fp);
static void generateSipImportVariables(FILE *fp);
static void generateModInitStart(moduleDef *mod, int gen_c, FILE *fp); static void generateModInitStart(moduleDef *mod, int gen_c, FILE *fp);
static void generateModDefinition(moduleDef *mod, const char *methods, static void generateModDefinition(moduleDef *mod, const char *methods,
FILE *fp); FILE *fp);
@ -246,8 +245,6 @@ static void prCachedName(FILE *fp, nameDef *nd, const char *prefix);
static void generateSignalTableEntry(sipSpec *pt, classDef *cd, overDef *sig, static void generateSignalTableEntry(sipSpec *pt, classDef *cd, overDef *sig,
memberDef *md, int membernr, FILE *fp); memberDef *md, int membernr, FILE *fp);
static void generateTypesTable(sipSpec *pt, moduleDef *mod, FILE *fp); static void generateTypesTable(sipSpec *pt, moduleDef *mod, FILE *fp);
static int py2OnlySlot(slotType st);
static int py2_5LaterSlot(slotType st);
static int keepPyReference(argDef *ad); static int keepPyReference(argDef *ad);
static int isDuplicateProtected(classDef *cd, overDef *target); static int isDuplicateProtected(classDef *cd, overDef *target);
static char getEncoding(argType atype); static char getEncoding(argType atype);
@ -865,11 +862,7 @@ static void generateCompositeCpp(sipSpec *pt, const char *codeDir)
"\n" "\n"
"static void sip_import_component_module(PyObject *d, const char *name)\n" "static void sip_import_component_module(PyObject *d, const char *name)\n"
"{\n" "{\n"
"#if PY_VERSION_HEX >= 0x02050000\n"
" PyObject *mod = PyImport_ImportModule(name);\n" " PyObject *mod = PyImport_ImportModule(name);\n"
"#else\n"
" PyObject *mod = PyImport_ImportModule((char *)name);\n"
"#endif\n"
"\n" "\n"
" /*\n" " /*\n"
" * Note that we don't complain if the module can't be imported. This\n" " * Note that we don't complain if the module can't be imported. This\n"
@ -891,11 +884,7 @@ static void generateCompositeCpp(sipSpec *pt, const char *codeDir)
"\n" "\n"
" PyObject *sipModule, *sipModuleDict;\n" " PyObject *sipModule, *sipModuleDict;\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" sipModule = PyModule_Create(&sip_module_def);\n" " sipModule = PyModule_Create(&sip_module_def);\n"
"#else\n"
" sipModule = Py_InitModule(\"%s\", 0);\n"
"#endif\n"
"\n" "\n"
" if (sipModule == NULL)\n" " if (sipModule == NULL)\n"
" SIP_MODULE_RETURN(NULL);\n" " SIP_MODULE_RETURN(NULL);\n"
@ -956,11 +945,7 @@ static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir,
for (mod = pt->modules; mod != NULL; mod = mod->next) for (mod = pt->modules; mod != NULL; mod = mod->next)
if (mod->container == pt->module) if (mod->container == pt->module)
prcode(fp, prcode(fp,
"#if PY_MAJOR_VERSION >= 3\n" "extern PyObject *sip_init_%s(void);\n"
"extern PyObject *sip_init_%s(void);\n"
"#else\n"
"extern void sip_init_%s(void);\n"
"#endif\n"
, mod->name , mod->name
, mod->name); , mod->name);
@ -980,11 +965,7 @@ static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir,
"{\n" "{\n"
" struct component {\n" " struct component {\n"
" const char *name;\n" " const char *name;\n"
"#if PY_MAJOR_VERSION >= 3\n"
" PyObject *(*init)(void);\n" " PyObject *(*init)(void);\n"
"#else\n"
" void (*init)(void);\n"
"#endif\n"
" };\n" " };\n"
"\n" "\n"
" static struct component components[] = {\n" " static struct component components[] = {\n"
@ -1003,27 +984,14 @@ static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir,
" const char *name;\n" " const char *name;\n"
" struct component *scd;\n" " struct component *scd;\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" name = PyBytes_AsString(arg);\n" " name = PyBytes_AsString(arg);\n"
"#else\n"
" name = PyString_AsString(arg);\n"
"#endif\n"
"\n" "\n"
" if (name == NULL)\n" " if (name == NULL)\n"
" return NULL;\n" " return NULL;\n"
"\n" "\n"
" for (scd = components; scd->name != NULL; ++scd)\n" " for (scd = components; scd->name != NULL; ++scd)\n"
" if (strcmp(scd->name, name) == 0)\n" " if (strcmp(scd->name, name) == 0)\n"
"#if PY_MAJOR_VERSION >= 3\n"
" return (*scd->init)();\n" " return (*scd->init)();\n"
"#else\n"
" {\n"
" (*scd->init)();\n"
"\n"
" Py_INCREF(Py_None);\n"
" return Py_None;\n"
" }\n"
"#endif\n"
"\n" "\n"
" PyErr_Format(PyExc_ImportError, \"unknown component module %%s\", name);\n" " PyErr_Format(PyExc_ImportError, \"unknown component module %%s\", name);\n"
"\n" "\n"
@ -1044,13 +1012,9 @@ static void generateConsolidatedCpp(sipSpec *pt, const char *codeDir,
prcode(fp, prcode(fp,
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" return PyModule_Create(&sip_module_def);\n" " return PyModule_Create(&sip_module_def);\n"
"#else\n"
" Py_InitModule(\"%s\", sip_methods);\n"
"#endif\n"
"}\n" "}\n"
, mname); );
closeFile(fp); closeFile(fp);
free(cppfile); free(cppfile);
@ -1088,18 +1052,10 @@ static void generateComponentCpp(sipSpec *pt, const char *codeDir,
prcode(fp, prcode(fp,
" /* Ask the consolidated module to do the initialistion. */\n" " /* Ask the consolidated module to do the initialistion. */\n"
"#if PY_MAJOR_VERSION >= 3\n"
" sip_result = PyObject_CallMethod(sip_mod, \"init\", \"y\", \"%s\");\n" " sip_result = PyObject_CallMethod(sip_mod, \"init\", \"y\", \"%s\");\n"
"#else\n"
" sip_result = PyObject_CallMethod(sip_mod, \"init\", \"s\", \"%s\");\n"
"#endif\n"
" Py_DECREF(sip_mod);\n" " Py_DECREF(sip_mod);\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" return sip_result;\n" " return sip_result;\n"
"#else\n"
" Py_XDECREF(sip_result);\n"
"#endif\n"
"}\n" "}\n"
, pt->module->fullname->text , pt->module->fullname->text
, pt->module->fullname->text); , pt->module->fullname->text);
@ -1311,24 +1267,10 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
for (od = mod->overs; od != NULL; od = od->next) for (od = mod->overs; od != NULL; od = od->next)
if (od->common == md) if (od->common == md)
{ {
if (py2OnlySlot(md->slot))
prcode(fp,
"#if PY_MAJOR_VERSION < 3\n"
);
else if (py2_5LaterSlot(md->slot))
prcode(fp,
"#if PY_VERSION_HEX >= 0x02050000\n"
);
prcode(fp, prcode(fp,
" {(void *)slot_%s, %s, {0, 0, 0}},\n" " {(void *)slot_%s, %s, {0, 0, 0}},\n"
, md->pyname->text, slotName(md->slot)); , md->pyname->text, slotName(md->slot));
if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot))
prcode(fp,
"#endif\n"
);
break; break;
} }
} }
@ -1336,15 +1278,6 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
for (cd = mod->proxies; cd != NULL; cd = cd->next) for (cd = mod->proxies; cd != NULL; cd = cd->next)
for (md = cd->members; md != NULL; md = md->next) for (md = cd->members; md != NULL; md = md->next)
{ {
if (py2OnlySlot(md->slot))
prcode(fp,
"#if PY_MAJOR_VERSION < 3\n"
);
else if (py2_5LaterSlot(md->slot))
prcode(fp,
"#if PY_VERSION_HEX >= 0x02050000\n"
);
prcode(fp, prcode(fp,
" {(void *)slot_%L_%s, %s, ", cd->iff, md->pyname->text, slotName(md->slot)); " {(void *)slot_%L_%s, %s, ", cd->iff, md->pyname->text, slotName(md->slot));
@ -1352,11 +1285,6 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
prcode(fp, "},\n" prcode(fp, "},\n"
); );
if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot))
prcode(fp,
"#endif\n"
);
} }
prcode(fp, prcode(fp,
@ -1430,23 +1358,9 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
if ((stype = slotName(slot->slot)) != NULL) if ((stype = slotName(slot->slot)) != NULL)
{ {
if (py2OnlySlot(slot->slot))
prcode(fp,
"#if PY_MAJOR_VERSION < 3\n"
);
else if (py2_5LaterSlot(slot->slot))
prcode(fp,
"#if PY_VERSION_HEX >= 0x02050000\n"
);
prcode(fp, prcode(fp,
" {(void *)slot_%C_%s, %s},\n" " {(void *)slot_%C_%s, %s},\n"
, ed->fqcname, slot->pyname->text, stype); , ed->fqcname, slot->pyname->text, stype);
if (py2OnlySlot(slot->slot) || py2_5LaterSlot(slot->slot))
prcode(fp,
"#endif\n"
);
} }
} }
@ -1904,15 +1818,9 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
if (mod->container == pt->module) if (mod->container == pt->module)
prcode(fp, prcode(fp,
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
"#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n" "#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n"
"#define SIP_MODULE_RETURN(r) return (r)\n" "#define SIP_MODULE_RETURN(r) return (r)\n"
"PyObject *sip_init_%s()\n" "PyObject *sip_init_%s()\n"
"#else\n"
"#define SIP_MODULE_DISCARD(r)\n"
"#define SIP_MODULE_RETURN(r) return\n"
"void sip_init_%s()\n"
"#endif\n"
"{\n" "{\n"
, mname , mname
, mname); , mname);
@ -1966,31 +1874,12 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
" PyObject *sipModule, *sipModuleDict;\n" " PyObject *sipModule, *sipModuleDict;\n"
); );
generateSipImportVariables(fp);
/* Generate any pre-initialisation code. */ /* Generate any pre-initialisation code. */
generateCppCodeBlock(mod->preinitcode, fp); generateCppCodeBlock(mod->preinitcode, fp);
prcode(fp, prcode(fp,
" /* Initialise the module and get it's dictionary. */\n" " /* Initialise the module and get it's dictionary. */\n"
"#if PY_MAJOR_VERSION >= 3\n"
" sipModule = PyModule_Create(&sip_module_def);\n" " sipModule = PyModule_Create(&sip_module_def);\n"
"#elif PY_VERSION_HEX >= 0x02050000\n"
" sipModule = Py_InitModule(%N, sip_methods);\n"
"#else\n"
, mod->fullname);
if (generating_c)
prcode(fp,
" sipModule = Py_InitModule((char *)%N, sip_methods);\n"
, mod->fullname);
else
prcode(fp,
" sipModule = Py_InitModule(const_cast<char *>(%N), sip_methods);\n"
, mod->fullname);
prcode(fp,
"#endif\n"
"\n" "\n"
" if (sipModule == NULL)\n" " if (sipModule == NULL)\n"
" SIP_MODULE_RETURN(NULL);\n" " SIP_MODULE_RETURN(NULL);\n"
@ -2008,9 +1897,6 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
" /* Export the module and publish it's API. */\n" " /* Export the module and publish it's API. */\n"
" if (sipExportModule(&sipModuleAPI_%s,SIP_TQT_API_MAJOR_NR,SIP_TQT_API_MINOR_NR,0) < 0)\n" " if (sipExportModule(&sipModuleAPI_%s,SIP_TQT_API_MAJOR_NR,SIP_TQT_API_MINOR_NR,0) < 0)\n"
" {\n" " {\n"
"#if !defined(SIP_USE_PYCAPSULE)\n"
" Py_DECREF(sip_sipmod);\n"
"#endif\n"
" SIP_MODULE_DISCARD(sipModule);\n" " SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(0);\n" " SIP_MODULE_RETURN(0);\n"
" }\n" " }\n"
@ -2034,9 +1920,6 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
" /* Initialise the module now all its dependencies have been set up. */\n" " /* Initialise the module now all its dependencies have been set up. */\n"
" if (sipInitModule(&sipModuleAPI_%s,sipModuleDict) < 0)\n" " if (sipInitModule(&sipModuleAPI_%s,sipModuleDict) < 0)\n"
" {\n" " {\n"
"#if !defined(SIP_USE_PYCAPSULE)\n"
" Py_DECREF(sip_sipmod);\n"
"#endif\n"
" SIP_MODULE_DISCARD(sipModule);\n" " SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(0);\n" " SIP_MODULE_RETURN(0);\n"
" }\n" " }\n"
@ -2076,11 +1959,7 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
prcode(fp, prcode(fp,
"\n" "\n"
" if ((exceptionsTable[%d] = PyErr_NewException(\n" " if ((exceptionsTable[%d] = PyErr_NewException(\n"
"#if PY_MAJOR_VERSION >= 3\n"
" \"%s.%s\",\n" " \"%s.%s\",\n"
"#else\n"
" const_cast<char *>(\"%s.%s\"),\n"
"#endif\n"
" " " "
, xd->exceptionnr , xd->exceptionnr
, xd->iff->module->name, xd->pyname , xd->iff->module->name, xd->pyname
@ -2095,9 +1974,6 @@ static void generateCpp(sipSpec *pt, moduleDef *mod, const char *codeDir,
prcode(fp, ",NULL)) == NULL || PyDict_SetItemString(sipModuleDict,\"%s\",exceptionsTable[%d]) < 0)\n" prcode(fp, ",NULL)) == NULL || PyDict_SetItemString(sipModuleDict,\"%s\",exceptionsTable[%d]) < 0)\n"
" {\n" " {\n"
"#if !defined(SIP_USE_PYCAPSULE)\n"
" Py_DECREF(sip_sipmod);\n"
"#endif\n"
" SIP_MODULE_DISCARD(sipModule);\n" " SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(0);\n" " SIP_MODULE_RETURN(0);\n"
" }\n" " }\n"
@ -2215,8 +2091,6 @@ static void generateSipImport(moduleDef *mod, FILE *fp)
{ {
prcode(fp, prcode(fp,
" /* Get the SIP-TQt module's API. */\n" " /* Get the SIP-TQt module's API. */\n"
"#if defined(SIP_USE_PYCAPSULE)\n"
"\n"
); );
if (generating_c) if (generating_c)
@ -2235,71 +2109,7 @@ static void generateSipImport(moduleDef *mod, FILE *fp)
" SIP_MODULE_DISCARD(sipModule);\n" " SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(NULL);\n" " SIP_MODULE_RETURN(NULL);\n"
" }\n" " }\n"
"\n"
"#else\n"
"\n"
"#if PY_VERSION_HEX >= 0x02050000\n"
" sip_sipmod = PyImport_ImportModule(\"sip_tqt\");\n"
"#else\n"
, mod->name);
if (generating_c)
prcode(fp,
" sip_sipmod = PyImport_ImportModule((char *)\"sip_tqt\");\n"
);
else
prcode(fp,
" sip_sipmod = PyImport_ImportModule(const_cast<char *>(\"sip_tqt\"));\n"
);
prcode(fp,
"#endif\n"
"\n"
" if (sip_sipmod == NULL)\n"
" {\n"
" SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(NULL);\n"
" }\n"
"\n"
" sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), \"_C_API\");\n"
"\n"
" if (sip_capiobj == NULL || !PyCObject_Check(sip_capiobj))\n"
" {\n"
" Py_DECREF(sip_sipmod);\n"
" SIP_MODULE_DISCARD(sipModule);\n"
" SIP_MODULE_RETURN(NULL);\n"
" }\n"
"\n"
);
if (generating_c)
prcode(fp,
" sipAPI_%s = (const sipAPIDef *)PyCObject_AsVoidPtr(sip_capiobj);\n"
, mod->name); , mod->name);
else
prcode(fp,
" sipAPI_%s = reinterpret_cast<const sipAPIDef *>(PyCObject_AsVoidPtr(sip_capiobj));\n"
, mod->name);
prcode(fp,
"\n"
"#endif\n"
"\n"
);
}
/*
* Generate the variables needed by generateSipImport().
*/
static void generateSipImportVariables(FILE *fp)
{
prcode(fp,
"#if !defined(SIP_USE_PYCAPSULE)\n"
" PyObject *sip_sipmod, *sip_capiobj;\n"
"#endif\n"
"\n"
);
} }
@ -2312,17 +2122,10 @@ static void generateModInitStart(moduleDef *mod, int gen_c, FILE *fp)
"\n" "\n"
"\n" "\n"
"/* The Python module initialisation function. */\n" "/* The Python module initialisation function. */\n"
"#if PY_MAJOR_VERSION >= 3\n"
"#define SIP_MODULE_ENTRY PyInit_%s\n" "#define SIP_MODULE_ENTRY PyInit_%s\n"
"#define SIP_MODULE_TYPE PyObject *\n" "#define SIP_MODULE_TYPE PyObject *\n"
"#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n" "#define SIP_MODULE_DISCARD(r) Py_DECREF(r)\n"
"#define SIP_MODULE_RETURN(r) return (r)\n" "#define SIP_MODULE_RETURN(r) return (r)\n"
"#else\n"
"#define SIP_MODULE_ENTRY init%s\n"
"#define SIP_MODULE_TYPE void\n"
"#define SIP_MODULE_DISCARD(r)\n"
"#define SIP_MODULE_RETURN(r) return\n"
"#endif\n"
"\n" "\n"
"#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)\n" "#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)\n"
"#pragma GCC visibility push(default)\n" "#pragma GCC visibility push(default)\n"
@ -2350,7 +2153,6 @@ static void generateModDefinition(moduleDef *mod, const char *methods,
{ {
prcode(fp, prcode(fp,
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" static PyModuleDef sip_module_def = {\n" " static PyModuleDef sip_module_def = {\n"
" PyModuleDef_HEAD_INIT,\n" " PyModuleDef_HEAD_INIT,\n"
" \"%s\",\n" " \"%s\",\n"
@ -2362,7 +2164,6 @@ static void generateModDefinition(moduleDef *mod, const char *methods,
" NULL,\n" " NULL,\n"
" NULL\n" " NULL\n"
" };\n" " };\n"
"#endif\n"
, mod->fullname->text , mod->fullname->text
, methods); , methods);
} }
@ -4363,11 +4164,7 @@ static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp)
case utf8_string_type: case utf8_string_type:
if (vd->type.nrderefs == 0) if (vd->type.nrderefs == 0)
prcode(fp, prcode(fp,
"#if PY_MAJOR_VERSION >= 3\n"
" return PyUnicode_FromStringAndSize(&sipVal, 1);\n" " return PyUnicode_FromStringAndSize(&sipVal, 1);\n"
"#else\n"
" return PyUnicode_DecodeUTF8(&sipVal, 1, NULL);\n"
"#endif\n"
); );
else else
prcode(fp, prcode(fp,
@ -4377,11 +4174,7 @@ static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp)
" return Py_None;\n" " return Py_None;\n"
" }\n" " }\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" return PyUnicode_FromString(sipVal);\n" " return PyUnicode_FromString(sipVal);\n"
"#else\n"
" return PyUnicode_DecodeUTF8(sipVal, strlen(sipVal), NULL);\n"
"#endif\n"
); );
break; break;
@ -4394,7 +4187,7 @@ static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp)
if (vd->type.nrderefs == 0) if (vd->type.nrderefs == 0)
prcode(fp, prcode(fp,
" return SIPBytes_FromStringAndSize(%s&sipVal, 1);\n" " return PyBytes_FromStringAndSize(%s&sipVal, 1);\n"
, cast); , cast);
else else
prcode(fp, prcode(fp,
@ -4404,7 +4197,7 @@ static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp)
" return Py_None;\n" " return Py_None;\n"
" }\n" " }\n"
"\n" "\n"
" return SIPBytes_FromString(%ssipVal);\n" " return PyBytes_FromString(%ssipVal);\n"
, cast); , cast);
} }
@ -4458,7 +4251,7 @@ static void generateVariableGetter(ifaceFileDef *scope, varDef *vd, FILE *fp)
case cint_type: case cint_type:
case int_type: case int_type:
prcode(fp, prcode(fp,
" return SIPLong_FromLong(sipVal);\n" " return PyLong_FromLong(sipVal);\n"
); );
break; break;
@ -4789,7 +4582,7 @@ static int generateObjToCppConversion(argDef *ad,FILE *fp)
break; break;
case enum_type: case enum_type:
prcode(fp, "(%E)SIPLong_AsLong(sipPy);\n" prcode(fp, "(%E)PyLong_AsLong(sipPy);\n"
, ad->u.ed); , ad->u.ed);
break; break;
@ -4866,7 +4659,7 @@ static int generateObjToCppConversion(argDef *ad,FILE *fp)
case bool_type: case bool_type:
case cbool_type: case cbool_type:
rhs = "(bool)SIPLong_AsLong(sipPy)"; rhs = "(bool)PyLong_AsLong(sipPy)";
break; break;
case ushort_type: case ushort_type:
@ -4874,7 +4667,7 @@ static int generateObjToCppConversion(argDef *ad,FILE *fp)
break; break;
case short_type: case short_type:
rhs = "(short)SIPLong_AsLong(sipPy)"; rhs = "(short)PyLong_AsLong(sipPy)";
break; break;
case uint_type: case uint_type:
@ -4883,7 +4676,7 @@ static int generateObjToCppConversion(argDef *ad,FILE *fp)
case int_type: case int_type:
case cint_type: case cint_type:
rhs = "(int)SIPLong_AsLong(sipPy)"; rhs = "(int)PyLong_AsLong(sipPy)";
break; break;
case ulong_type: case ulong_type:
@ -5146,15 +4939,6 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
"\n" "\n"
); );
if (py2OnlySlot(md->slot))
prcode(fp,
"#if PY_MAJOR_VERSION < 3\n"
);
else if (py2_5LaterSlot(md->slot))
prcode(fp,
"#if PY_VERSION_HEX >= 0x02050000\n"
);
if (!generating_c) if (!generating_c)
{ {
prcode(fp, prcode(fp,
@ -5204,7 +4988,7 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
, (md->slot == cmp_slot ? "-2" : (ret_int ? "-1" : "0"))); , (md->slot == cmp_slot ? "-2" : (ret_int ? "-1" : "0")));
else else
prcode(fp, prcode(fp,
" %S sipCpp = static_cast<%S>(SIPLong_AsLong(sipSelf));\n" " %S sipCpp = static_cast<%S>(PyLong_AsLong(sipSelf));\n"
"\n" "\n"
, fqcname, fqcname); , fqcname, fqcname);
} }
@ -5311,11 +5095,6 @@ static void generateSlot(moduleDef *mod, classDef *cd, enumDef *ed,
prcode(fp, prcode(fp,
"}\n" "}\n"
); );
if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot))
prcode(fp,
"#endif\n"
);
} }
@ -5564,7 +5343,6 @@ static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd,
prcode(fp, prcode(fp,
"\n" "\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
); );
if (!generating_c) if (!generating_c)
@ -5596,7 +5374,6 @@ static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd,
"\n" "\n"
" return sipRes;\n" " return sipRes;\n"
"}\n" "}\n"
"#endif\n"
); );
} }
@ -5605,7 +5382,6 @@ static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd,
prcode(fp, prcode(fp,
"\n" "\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
); );
if (!generating_c) if (!generating_c)
@ -5629,158 +5405,6 @@ static void generateClassFunctions(sipSpec *pt, moduleDef *mod, classDef *cd,
prcode(fp, prcode(fp,
"}\n" "}\n"
"#endif\n"
);
}
if (cd->readbufcode != NULL)
{
prcode(fp,
"\n"
"\n"
"#if PY_MAJOR_VERSION < 3\n"
);
if (!generating_c)
prcode(fp,
"extern \"C\" {static SIP_SSIZE_T getreadbuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n"
, classFTQCName(cd));
prcode(fp,
"static SIP_SSIZE_T getreadbuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n"
"{\n"
" ", classFTQCName(cd)
, argName("sipSelf", cd->readbufcode)
, argName("sipSegment", cd->readbufcode)
, argName("sipPtrPtr", cd->readbufcode));
generateClassFromVoid(cd, "sipCpp", "sipCppV", fp);
prcode(fp, ";\n"
" SIP_SSIZE_T sipRes;\n"
"\n"
);
generateCppCodeBlock(cd->readbufcode, fp);
prcode(fp,
"\n"
" return sipRes;\n"
"}\n"
"#endif\n"
);
}
if (cd->writebufcode != NULL)
{
prcode(fp,
"\n"
"\n"
"#if PY_MAJOR_VERSION < 3\n"
);
if (!generating_c)
prcode(fp,
"extern \"C\" {static SIP_SSIZE_T getwritebuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n"
, classFTQCName(cd));
prcode(fp,
"static SIP_SSIZE_T getwritebuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n"
"{\n"
" ", classFTQCName(cd)
, argName("sipSelf", cd->writebufcode)
, argName("sipSegment", cd->writebufcode)
, argName("sipPtrPtr", cd->writebufcode));
generateClassFromVoid(cd, "sipCpp", "sipCppV", fp);
prcode(fp, ";\n"
" SIP_SSIZE_T sipRes;\n"
"\n"
);
generateCppCodeBlock(cd->writebufcode, fp);
prcode(fp,
"\n"
" return sipRes;\n"
"}\n"
"#endif\n"
);
}
if (cd->segcountcode != NULL)
{
prcode(fp,
"\n"
"\n"
"#if PY_MAJOR_VERSION < 3\n"
);
if (!generating_c)
prcode(fp,
"extern \"C\" {static SIP_SSIZE_T getsegcount_%C(PyObject *, void *, SIP_SSIZE_T *);}\n"
, classFTQCName(cd));
prcode(fp,
"static SIP_SSIZE_T getsegcount_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T *%s)\n"
"{\n"
" ", classFTQCName(cd)
, argName("sipSelf", cd->segcountcode)
, argName("sipLenPtr", cd->segcountcode));
generateClassFromVoid(cd, "sipCpp", "sipCppV", fp);
prcode(fp, ";\n"
" SIP_SSIZE_T sipRes;\n"
"\n"
);
generateCppCodeBlock(cd->segcountcode, fp);
prcode(fp,
"\n"
" return sipRes;\n"
"}\n"
"#endif\n"
);
}
if (cd->charbufcode != NULL)
{
prcode(fp,
"\n"
"\n"
"#if PY_MAJOR_VERSION < 3\n"
);
if (!generating_c)
prcode(fp,
"extern \"C\" {static SIP_SSIZE_T getcharbuffer_%C(PyObject *, void *, SIP_SSIZE_T, void **);}\n"
, classFTQCName(cd));
prcode(fp,
"static SIP_SSIZE_T getcharbuffer_%C(PyObject *%s, void *sipCppV, SIP_SSIZE_T %s, void **%s)\n"
"{\n"
" ", classFTQCName(cd)
, argName("sipSelf", cd->charbufcode)
, argName("sipSegment", cd->charbufcode)
, argName("sipPtrPtr", cd->charbufcode));
generateClassFromVoid(cd, "sipCpp", "sipCppV", fp);
prcode(fp, ";\n"
" SIP_SSIZE_T sipRes;\n"
"\n"
);
generateCppCodeBlock(cd->charbufcode, fp);
prcode(fp,
"\n"
" return sipRes;\n"
"}\n"
"#endif\n"
); );
} }
@ -8962,23 +8586,9 @@ static void generateTypeDefinition(sipSpec *pt, classDef *cd, FILE *fp)
if ((stype = slotName(md->slot)) != NULL) if ((stype = slotName(md->slot)) != NULL)
{ {
if (py2OnlySlot(md->slot))
prcode(fp,
"#if PY_MAJOR_VERSION < 3\n"
);
else if (py2_5LaterSlot(md->slot))
prcode(fp,
"#if PY_VERSION_HEX >= 0x02050000\n"
);
prcode(fp, prcode(fp,
" {(void *)slot_%L_%s, %s},\n" " {(void *)slot_%L_%s, %s},\n"
, cd->iff, md->pyname->text, stype); , cd->iff, md->pyname->text, stype);
if (py2OnlySlot(md->slot) || py2_5LaterSlot(md->slot))
prcode(fp,
"#endif\n"
);
} }
} }
@ -9398,10 +9008,6 @@ static void generateTypeDefinition(sipSpec *pt, classDef *cd, FILE *fp)
" 0,\n" " 0,\n"
); );
prcode(fp,
"#if PY_MAJOR_VERSION >= 3\n"
);
if (cd->getbufcode != NULL) if (cd->getbufcode != NULL)
prcode(fp, prcode(fp,
" getbuffer_%C,\n" " getbuffer_%C,\n"
@ -9420,50 +9026,6 @@ static void generateTypeDefinition(sipSpec *pt, classDef *cd, FILE *fp)
" 0,\n" " 0,\n"
); );
prcode(fp,
"#else\n"
);
if (cd->readbufcode != NULL)
prcode(fp,
" getreadbuffer_%C,\n"
, classFTQCName(cd));
else
prcode(fp,
" 0,\n"
);
if (cd->writebufcode != NULL)
prcode(fp,
" getwritebuffer_%C,\n"
, classFTQCName(cd));
else
prcode(fp,
" 0,\n"
);
if (cd->segcountcode != NULL)
prcode(fp,
" getsegcount_%C,\n"
, classFTQCName(cd));
else
prcode(fp,
" 0,\n"
);
if (cd->charbufcode != NULL)
prcode(fp,
" getcharbuffer_%C,\n"
, classFTQCName(cd));
else
prcode(fp,
" 0,\n"
);
prcode(fp,
"#endif\n"
);
if (needDealloc(cd)) if (needDealloc(cd))
prcode(fp, prcode(fp,
" dealloc_%L,\n" " dealloc_%L,\n"
@ -9614,28 +9176,6 @@ static void generateSignalTableEntry(sipSpec *pt, classDef *cd, overDef *sig,
} }
/*
* Return TRUE if the slot is specific to Python v2.
*/
static int py2OnlySlot(slotType st)
{
/*
* Note that we place interpretations on div_slot and idiv_slot for Python
* v3 so they are not included.
*/
return (st == long_slot || st == cmp_slot);
}
/*
* Return TRUE if the slot is specific to Python v2.5 and later.
*/
static int py2_5LaterSlot(slotType st)
{
return (st == index_slot);
}
/* /*
* Return the sip module's string equivalent of a slot. * Return the sip module's string equivalent of a slot.
*/ */
@ -10912,11 +10452,7 @@ static void generateHandleResult(overDef *od, int isNew, int result_size,
case utf8_string_type: case utf8_string_type:
if (ad->nrderefs == 0) if (ad->nrderefs == 0)
prcode(fp, prcode(fp,
"#if PY_MAJOR_VERSION >= 3\n"
" %s PyUnicode_FromStringAndSize(&%s, 1);\n" " %s PyUnicode_FromStringAndSize(&%s, 1);\n"
"#else\n"
" %s PyUnicode_DecodeUTF8(&%s, 1, NULL);\n"
"#endif\n"
, prefix, vname , prefix, vname
, prefix, vname); , prefix, vname);
else else
@ -10927,11 +10463,7 @@ static void generateHandleResult(overDef *od, int isNew, int result_size,
" return Py_None;\n" " return Py_None;\n"
" }\n" " }\n"
"\n" "\n"
"#if PY_MAJOR_VERSION >= 3\n"
" %s PyUnicode_FromString(%s);\n" " %s PyUnicode_FromString(%s);\n"
"#else\n"
" %s PyUnicode_DecodeUTF8(%s, strlen(%s), NULL);\n"
"#endif\n"
, vname , vname
, prefix, vname , prefix, vname
, prefix, vname, vname); , prefix, vname, vname);
@ -10943,7 +10475,7 @@ static void generateHandleResult(overDef *od, int isNew, int result_size,
case string_type: case string_type:
if (ad->nrderefs == 0) if (ad->nrderefs == 0)
prcode(fp, prcode(fp,
" %s SIPBytes_FromStringAndSize(%s&%s,1);\n" " %s PyBytes_FromStringAndSize(%s&%s,1);\n"
,prefix,(ad->atype != string_type) ? "(char *)" : "",vname); ,prefix,(ad->atype != string_type) ? "(char *)" : "",vname);
else else
prcode(fp, prcode(fp,
@ -10953,7 +10485,7 @@ static void generateHandleResult(overDef *od, int isNew, int result_size,
" return Py_None;\n" " return Py_None;\n"
" }\n" " }\n"
"\n" "\n"
" %s SIPBytes_FromString(%s%s);\n" " %s PyBytes_FromString(%s%s);\n"
,vname ,vname
,prefix,(ad->atype != string_type) ? "(char *)" : "",vname); ,prefix,(ad->atype != string_type) ? "(char *)" : "",vname);
@ -10994,7 +10526,7 @@ static void generateHandleResult(overDef *od, int isNew, int result_size,
case int_type: case int_type:
case cint_type: case cint_type:
prcode(fp, prcode(fp,
" %s SIPLong_FromLong(%s);\n" " %s PyLong_FromLong(%s);\n"
,prefix,vname); ,prefix,vname);
break; break;

@ -194,11 +194,7 @@ PyObject *sipGetAPI(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
#if PY_MAJOR_VERSION >= 3
return PyLong_FromLong(avd->version_nr); return PyLong_FromLong(avd->version_nr);
#else
return PyInt_FromLong(avd->version_nr);
#endif
} }

@ -123,13 +123,7 @@ static PyObject *sipMethodDescr_repr(PyObject *self)
{ {
sipMethodDescr *md = (sipMethodDescr *)self; sipMethodDescr *md = (sipMethodDescr *)self;
return return PyUnicode_FromFormat("<built-in method %s>", md->pmd->ml_name);
#if PY_MAJOR_VERSION >= 3
PyUnicode_FromFormat
#else
PyString_FromFormat
#endif
("<built-in method %s>", md->pmd->ml_name);
} }

@ -46,8 +46,8 @@ extern "C" {
/* Sanity check on the Python version. */ /* Sanity check on the Python version. */
#if PY_VERSION_HEX < 0x02030000 #if PY_VERSION_HEX < 0x03020000
#error "This version of SIP-TQt requires Python v2.3 or later" #error "This version of SIP-TQt requires Python v3.2 or later"
#endif #endif
@ -178,63 +178,12 @@ extern "C" {
#endif #endif
/* Some Python compatibility stuff. */
#if PY_VERSION_HEX >= 0x02050000
#define SIP_SSIZE_T Py_ssize_t #define SIP_SSIZE_T Py_ssize_t
#define SIP_MLNAME_CAST(s) (s) #define SIP_MLNAME_CAST(s) (s)
#define SIP_MLDOC_CAST(s) (s) #define SIP_MLDOC_CAST(s) (s)
#define SIP_TPNAME_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) #if !defined(Py_REFCNT)
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
#endif #endif
@ -371,13 +320,8 @@ typedef void *(*sipInitFunc)(sipSimpleWrapper *, PyObject *, PyObject *,
PyObject **, PyObject **, PyObject **); PyObject **, PyObject **, PyObject **);
typedef int (*sipTraverseFunc)(void *, visitproc, void *); typedef int (*sipTraverseFunc)(void *, visitproc, void *);
typedef int (*sipClearFunc)(void *); typedef int (*sipClearFunc)(void *);
#if PY_MAJOR_VERSION >= 3
typedef int (*sipGetBufferFunc)(PyObject *, void *, Py_buffer *, int); typedef int (*sipGetBufferFunc)(PyObject *, void *, Py_buffer *, int);
typedef void (*sipReleaseBufferFunc)(PyObject *, void *, Py_buffer *); 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 (*sipDeallocFunc)(sipSimpleWrapper *);
typedef void *(*sipCastFunc)(void *, const struct _sipTypeDef *); typedef void *(*sipCastFunc)(void *, const struct _sipTypeDef *);
typedef const struct _sipTypeDef *(*sipSubClassConvertFunc)(void **); typedef const struct _sipTypeDef *(*sipSubClassConvertFunc)(void **);
@ -509,9 +453,6 @@ typedef enum {
typedef enum { typedef enum {
str_slot, /* __str__ */ str_slot, /* __str__ */
int_slot, /* __int__ */ int_slot, /* __int__ */
#if PY_MAJOR_VERSION < 3
long_slot, /* __long__ */
#endif
float_slot, /* __float__ */ float_slot, /* __float__ */
len_slot, /* __len__ */ len_slot, /* __len__ */
contains_slot, /* __contains__ */ contains_slot, /* __contains__ */
@ -554,18 +495,13 @@ typedef enum {
ne_slot, /* __ne__ */ ne_slot, /* __ne__ */
gt_slot, /* __gt__ */ gt_slot, /* __gt__ */
ge_slot, /* __ge__ */ ge_slot, /* __ge__ */
#if PY_MAJOR_VERSION < 3
cmp_slot, /* __cmp__ */
#endif
bool_slot, /* __bool__, __nonzero__ */ bool_slot, /* __bool__, __nonzero__ */
neg_slot, /* __neg__ */ neg_slot, /* __neg__ */
repr_slot, /* __repr__ */ repr_slot, /* __repr__ */
hash_slot, /* __hash__ */ hash_slot, /* __hash__ */
pos_slot, /* __pos__ */ pos_slot, /* __pos__ */
abs_slot, /* __abs__ */ abs_slot, /* __abs__ */
#if PY_VERSION_HEX >= 0x02050000
index_slot, /* __index__ */ index_slot, /* __index__ */
#endif
iter_slot, /* __iter__ */ iter_slot, /* __iter__ */
next_slot, /* __next__ */ next_slot, /* __next__ */
} sipPySlotType; } sipPySlotType;
@ -736,25 +672,11 @@ typedef struct _sipClassTypeDef {
/* The clear function. */ /* The clear function. */
sipClearFunc ctd_clear; sipClearFunc ctd_clear;
#if PY_MAJOR_VERSION >= 3
/* The get buffer function. */ /* The get buffer function. */
sipGetBufferFunc ctd_getbuffer; sipGetBufferFunc ctd_getbuffer;
/* The release buffer function. */ /* The release buffer function. */
sipReleaseBufferFunc ctd_releasebuffer; 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. */ /* The deallocation function. */
sipDeallocFunc ctd_dealloc; sipDeallocFunc ctd_dealloc;
@ -1196,11 +1118,6 @@ typedef struct _sipPyMethod {
/* Self if it is a bound method. */ /* Self if it is a bound method. */
PyObject *mself; PyObject *mself;
#if PY_MAJOR_VERSION < 3
/* The class. */
PyObject *mclass;
#endif
} sipPyMethod; } sipPyMethod;
@ -1474,16 +1391,9 @@ typedef struct _sipTQtAPI {
#define sipIsExactWrappedType(wt) (sipTypeAsPyTypeObject((wt)->type) == (PyTypeObject *)(wt)) #define sipIsExactWrappedType(wt) (sipTypeAsPyTypeObject((wt)->type) == (PyTypeObject *)(wt))
#if PY_VERSION_HEX >= 0x03020000
#define sipConvertFromSliceObject(o,len,start,stop,step,slen) \ #define sipConvertFromSliceObject(o,len,start,stop,step,slen) \
PySlice_GetIndicesEx((o), (len), (start), (stop), \ PySlice_GetIndicesEx((o), (len), (start), (stop), \
(step), (slen)) (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. * The following are deprecated parts of the public API.

File diff suppressed because it is too large Load Diff

@ -151,11 +151,7 @@ PyObject *sip_api_invoke_slot(const sipSlot *slot, PyObject *sigargs)
return Py_None; return Py_None;
} }
#if PY_MAJOR_VERSION >= 3
sfunc = PyMethod_New(slot->meth.mfunc, self); sfunc = PyMethod_New(slot->meth.mfunc, self);
#else
sfunc = PyMethod_New(slot->meth.mfunc, self, slot->meth.mclass);
#endif
if (sfunc == NULL) 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) return (sp->meth.mfunc == PyMethod_GET_FUNCTION(rxObj)
&& sp->meth.mself == PyMethod_GET_SELF(rxObj) && sp->meth.mself == PyMethod_GET_SELF(rxObj)
#if PY_MAJOR_VERSION < 3
&& sp->meth.mclass == PyMethod_GET_CLASS(rxObj)
#endif
); );
} }

@ -60,11 +60,7 @@ static PyObject *sipVoidPtr_new(PyTypeObject *subtype, PyObject *args,
PyObject *obj; PyObject *obj;
if (!PyArg_ParseTupleAndKeywords(args, kw, if (!PyArg_ParseTupleAndKeywords(args, kw,
#if PY_VERSION_HEX >= 0x02050000
"O&|ni:voidptr", "O&|ni:voidptr",
#else
"O&|ii:voidptr",
#endif
kwlist, vp_convertor, &vp_conversion, &size, &rw)) kwlist, vp_convertor, &vp_conversion, &size, &rw))
return NULL; 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. * 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); 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. * Implement ascapsule() for the type.
*/ */
@ -192,18 +112,6 @@ static PyObject *sipVoidPtr_ascapsule(sipVoidPtrObject *v, PyObject *arg)
{ {
return PyCapsule_New(v->voidptr, NULL, NULL); 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; SIP_SSIZE_T size = -1;
if (!PyArg_ParseTupleAndKeywords(args, kw, if (!PyArg_ParseTupleAndKeywords(args, kw,
#if PY_VERSION_HEX >= 0x02050000
"|n:asstring", "|n:asstring",
#else
"|i:asstring",
#endif
kwlist, &size)) kwlist, &size))
return NULL; return NULL;
@ -236,7 +140,7 @@ static PyObject *sipVoidPtr_asstring(sipVoidPtrObject *v, PyObject *args,
return NULL; 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) static PyObject *sipVoidPtr_getsize(sipVoidPtrObject *v, PyObject *arg)
{ {
#if PY_MAJOR_VERSION >= 3
return PyLong_FromSsize_t(v->size); 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; SIP_SSIZE_T size;
#if PY_MAJOR_VERSION >= 3
size = PyLong_AsSsize_t(arg); 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()) if (PyErr_Occurred())
return NULL; return NULL;
@ -296,7 +188,7 @@ static PyObject *sipVoidPtr_setwriteable(sipVoidPtrObject *v, PyObject *arg)
{ {
int rw; int rw;
rw = (int)SIPLong_AsLong(arg); rw = (int)PyLong_AsLong(arg);
if (PyErr_Occurred()) if (PyErr_Occurred())
return NULL; return NULL;
@ -310,12 +202,7 @@ static PyObject *sipVoidPtr_setwriteable(sipVoidPtrObject *v, PyObject *arg)
/* The methods data structure. */ /* The methods data structure. */
static PyMethodDef sipVoidPtr_Methods[] = { static PyMethodDef sipVoidPtr_Methods[] = {
#if defined(SIP_USE_PYCAPSULE)
{"ascapsule", (PyCFunction)sipVoidPtr_ascapsule, METH_NOARGS, NULL}, {"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}, {"asstring", (PyCFunction)sipVoidPtr_asstring, METH_VARARGS|METH_KEYWORDS, NULL},
{"getsize", (PyCFunction)sipVoidPtr_getsize, METH_NOARGS, NULL}, {"getsize", (PyCFunction)sipVoidPtr_getsize, METH_NOARGS, NULL},
{"setsize", (PyCFunction)sipVoidPtr_setsize, METH_O, NULL}, {"setsize", (PyCFunction)sipVoidPtr_setsize, METH_O, NULL},
@ -330,9 +217,6 @@ static PyNumberMethods sipVoidPtr_NumberMethods = {
0, /* nb_add */ 0, /* nb_add */
0, /* nb_subtract */ 0, /* nb_subtract */
0, /* nb_multiply */ 0, /* nb_multiply */
#if PY_MAJOR_VERSION < 3
0, /* nb_divide */
#endif
0, /* nb_remainder */ 0, /* nb_remainder */
0, /* nb_divmod */ 0, /* nb_divmod */
0, /* nb_power */ 0, /* nb_power */
@ -346,22 +230,12 @@ static PyNumberMethods sipVoidPtr_NumberMethods = {
0, /* nb_and */ 0, /* nb_and */
0, /* nb_xor */ 0, /* nb_xor */
0, /* nb_or */ 0, /* nb_or */
#if PY_MAJOR_VERSION < 3
0, /* nb_coerce */
#endif
(unaryfunc)sipVoidPtr_int, /* nb_int */ (unaryfunc)sipVoidPtr_int, /* nb_int */
0, /* nb_reserved (Python v3), nb_long (Python v2) */ 0, /* nb_reserved */
0, /* nb_float */ 0, /* nb_float */
#if PY_MAJOR_VERSION < 3
0, /* nb_oct */
(unaryfunc)sipVoidPtr_hex, /* nb_hex */
#endif
0, /* nb_inplace_add */ 0, /* nb_inplace_add */
0, /* nb_inplace_subtract */ 0, /* nb_inplace_subtract */
0, /* nb_inplace_multiply */ 0, /* nb_inplace_multiply */
#if PY_MAJOR_VERSION < 3
0, /* nb_inplace_divide */
#endif
0, /* nb_inplace_remainder */ 0, /* nb_inplace_remainder */
0, /* nb_inplace_power */ 0, /* nb_inplace_power */
0, /* nb_inplace_lshift */ 0, /* nb_inplace_lshift */
@ -373,26 +247,14 @@ static PyNumberMethods sipVoidPtr_NumberMethods = {
0, /* nb_true_divide */ 0, /* nb_true_divide */
0, /* nb_inplace_floor_divide */ 0, /* nb_inplace_floor_divide */
0, /* nb_inplace_true_divide */ 0, /* nb_inplace_true_divide */
#if PY_VERSION_HEX >= 0x02050000
0 /* nb_index */ 0 /* nb_index */
#endif
}; };
/* The buffer methods data structure. */ /* The buffer methods data structure. */
static PyBufferProcs sipVoidPtr_BufferProcs = { static PyBufferProcs sipVoidPtr_BufferProcs = {
sipVoidPtr_getbuffer, sipVoidPtr_getbuffer,
#if PY_MAJOR_VERSION >= 3
NULL, 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)) if (PyObject_TypeCheck(obj, &sipVoidPtr_Type))
return ((sipVoidPtrObject *)obj)->voidptr; return ((sipVoidPtrObject *)obj)->voidptr;
#if defined(SIP_USE_PYCAPSULE)
if (PyCapsule_CheckExact(obj)) if (PyCapsule_CheckExact(obj))
return PyCapsule_GetPointer(obj, NULL); 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); 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) if (arg == Py_None)
ptr = NULL; ptr = NULL;
#if defined(SIP_USE_PYCAPSULE)
else if (PyCapsule_CheckExact(arg)) else if (PyCapsule_CheckExact(arg))
ptr = PyCapsule_GetPointer(arg, NULL); 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)) else if (PyObject_TypeCheck(arg, &sipVoidPtr_Type))
{ {
ptr = ((sipVoidPtrObject *)arg)->voidptr; ptr = ((sipVoidPtrObject *)arg)->voidptr;
@ -562,19 +407,11 @@ static int vp_convertor(PyObject *arg, struct vp_values *vp)
} }
else else
{ {
#if PY_MAJOR_VERSION >= 3
ptr = PyLong_AsVoidPtr(arg); ptr = PyLong_AsVoidPtr(arg);
#else
ptr = (void *)PyInt_AsLong(arg);
#endif
if (PyErr_Occurred()) if (PyErr_Occurred())
{ {
#if PY_VERSION_HEX >= 0x03010000
PyErr_SetString(PyExc_TypeError, "a single integer, CObject, None or another voidptr is required"); 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; return 0;
} }
} }

Loading…
Cancel
Save