Base: remove Py2 code

This commit is contained in:
luz paz
2021-04-23 12:48:46 -04:00
committed by wwmayer
parent 31b0f25b6d
commit 142c2c2c4d
16 changed files with 0 additions and 546 deletions

View File

@@ -183,7 +183,6 @@ SystemExitException::SystemExitException()
value = code;
}
#if PY_MAJOR_VERSION >= 3
if (PyLong_Check(value)) {
errCode = PyLong_AsLong(value);
}
@@ -192,16 +191,6 @@ SystemExitException::SystemExitException()
if (str)
errMsg = errMsg + ": " + str;
}
#else
if (PyInt_Check(value)) {
errCode = PyInt_AsLong(value);
}
else {
const char *str = PyString_AsString(value);
if (str)
errMsg = errMsg + ": " + str;
}
#endif
}
_sErrMsg = errMsg;
@@ -279,11 +268,7 @@ std::string InterpreterSingleton::runString(const char *sCmd)
PyObject* repr = PyObject_Repr(presult);
Py_DECREF(presult);
if (repr) {
#if PY_MAJOR_VERSION >= 3
std::string ret(PyUnicode_AsUTF8(repr));
#else
std::string ret(PyString_AsString(repr));
#endif
Py_DECREF(repr);
return ret;
}
@@ -328,12 +313,8 @@ std::string InterpreterSingleton::runStringWithKey(const char *psCmd, const char
if (!key_return_value.isString())
key_return_value = key_return_value.str();
#if PY_MAJOR_VERSION >= 3
Py::Bytes str = Py::String(key_return_value).encode("utf-8", "~E~");
std::string result = static_cast<std::string>(str);
#else
std::string result = static_cast<std::string>(Py::String(key_return_value));
#endif
return result;
}
@@ -368,10 +349,6 @@ void InterpreterSingleton::systemExit(void)
int exitcode = 0;
PyErr_Fetch(&exception, &value, &tb);
#if PY_MAJOR_VERSION < 3
if (Py_FlushLine())
PyErr_Clear();
#endif
fflush(stdout);
if (value == NULL || value == Py_None)
goto done;
@@ -387,13 +364,8 @@ void InterpreterSingleton::systemExit(void)
/* If we failed to dig out the 'code' attribute,
just let the else clause below print the error. */
}
#if PY_MAJOR_VERSION < 3
if (PyInt_Check(value))
exitcode = (int)PyInt_AsLong(value);
#else
if (PyLong_Check(value))
exitcode = (int)PyLong_AsLong(value);
#endif
else {
PyObject_Print(value, stderr, Py_PRINT_RAW);
PySys_WriteStderr("\n");
@@ -435,13 +407,8 @@ void InterpreterSingleton::runInteractiveString(const char *sCmd)
RuntimeError exc(""); // do not use PyException since this clears the error indicator
if (errdata) {
#if PY_MAJOR_VERSION >= 3
if (PyUnicode_Check(errdata))
exc.setMessage(PyUnicode_AsUTF8(errdata));
#else
if (PyString_Check(errdata))
exc.setMessage(PyString_AsString(errdata));
#endif
}
PyErr_Restore(errobj, errdata, errtraceback);
if (PyErr_Occurred())
@@ -476,11 +443,7 @@ void InterpreterSingleton::runFile(const char*pxFileName, bool local)
}
if (PyDict_GetItemString(dict, "__file__") == NULL) {
#if PY_MAJOR_VERSION >= 3
PyObject *f = PyUnicode_FromString(pxFileName);
#else
PyObject *f = PyString_FromString(pxFileName);
#endif
if (f == NULL) {
fclose(fp);
Py_DECREF(dict);
@@ -585,7 +548,6 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
PyEval_InitThreads();
#endif
#if PY_MAJOR_VERSION >= 3
size_t size = argc;
static std::vector<wchar_t *> _argv(size);
for (int i = 0; i < argc; i++) {
@@ -596,22 +558,15 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
#endif
}
PySys_SetArgv(argc, _argv.data());
#else
PySys_SetArgv(argc, argv);
#endif
PythonStdOutput::init_type();
this->_global = PyEval_SaveThread();
}
#if PY_MAJOR_VERSION >= 3
PyGILStateLocker lock;
#if PY_MINOR_VERSION >= 5
return Py_EncodeLocale(Py_GetPath(),NULL);
#else
return _Py_wchar2char(Py_GetPath(),NULL);
#endif
#else
return Py_GetPath();
#endif
}
void InterpreterSingleton::replaceStdOutput()
@@ -873,42 +828,13 @@ int getSWIGVersionFromModule(const std::string& module)
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
namespace Swig_python { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
#endif
#if PY_MAJOR_VERSION < 3
namespace Swig_1_3_25 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
namespace Swig_1_3_33 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
namespace Swig_1_3_36 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
namespace Swig_1_3_38 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
namespace Swig_1_3_40 { extern int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int own); }
#endif
PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const char* TypeName, void* Pointer, int own)
{
int result = 0;
PyObject* proxy=0;
PyGILStateLocker locker;
#if PY_MAJOR_VERSION < 3
int version = getSWIGVersionFromModule(Module);
switch (version)
{
case 66329:
result = Swig_1_3_25::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
break;
case 66337:
result = Swig_1_3_33::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
break;
case 66340:
result = Swig_1_3_36::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
break;
case 66342:
result = Swig_1_3_38::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
break;
case 66344:
result = Swig_1_3_40::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
break;
default:
#else
(void)Module;
#endif
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
result = Swig_python::createSWIGPointerObj_T(TypeName, Pointer, &proxy, own);
#else
@@ -917,9 +843,6 @@ PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const c
(void)own;
result = -1; // indicates error
#endif
#if PY_MAJOR_VERSION < 3
}
#endif
if (result == 0)
return proxy;
@@ -931,41 +854,12 @@ PyObject* InterpreterSingleton::createSWIGPointerObj(const char* Module, const c
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
namespace Swig_python { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
#endif
#if PY_MAJOR_VERSION < 3
namespace Swig_1_3_25 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
namespace Swig_1_3_33 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
namespace Swig_1_3_36 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
namespace Swig_1_3_38 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
namespace Swig_1_3_40 { extern int convertSWIGPointerObj_T(const char* TypeName, PyObject* obj, void** ptr, int flags); }
#endif
bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char* TypeName, PyObject* obj, void** ptr, int flags)
{
int result = 0;
PyGILStateLocker locker;
#if PY_MAJOR_VERSION < 3
int version = getSWIGVersionFromModule(Module);
switch (version)
{
case 66329:
result = Swig_1_3_25::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
break;
case 66337:
result = Swig_1_3_33::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
break;
case 66340:
result = Swig_1_3_36::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
break;
case 66342:
result = Swig_1_3_38::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
break;
case 66344:
result = Swig_1_3_40::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
break;
default:
#else
(void)Module;
#endif
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
result = Swig_python::convertSWIGPointerObj_T(TypeName, obj, ptr, flags);
#else
@@ -975,9 +869,6 @@ bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char*
(void)flags;
result = -1; // indicates error
#endif
#if PY_MAJOR_VERSION < 3
}
#endif
if (result == 0)
return true;
@@ -989,13 +880,6 @@ bool InterpreterSingleton::convertSWIGPointerObj(const char* Module, const char*
#if (defined(HAVE_SWIG) && (HAVE_SWIG == 1))
namespace Swig_python { extern void cleanupSWIG_T(const char* TypeName); }
#endif
#if PY_MAJOR_VERSION < 3
namespace Swig_1_3_25 { extern void cleanupSWIG_T(const char* TypeName); }
namespace Swig_1_3_33 { extern void cleanupSWIG_T(const char* TypeName); }
namespace Swig_1_3_36 { extern void cleanupSWIG_T(const char* TypeName); }
namespace Swig_1_3_38 { extern void cleanupSWIG_T(const char* TypeName); }
namespace Swig_1_3_40 { extern void cleanupSWIG_T(const char* TypeName); }
#endif
void InterpreterSingleton::cleanupSWIG(const char* TypeName)
{
@@ -1005,11 +889,4 @@ void InterpreterSingleton::cleanupSWIG(const char* TypeName)
#else
(void)TypeName;
#endif
#if PY_MAJOR_VERSION < 3
Swig_1_3_25::cleanupSWIG_T(TypeName);
Swig_1_3_33::cleanupSWIG_T(TypeName);
Swig_1_3_36::cleanupSWIG_T(TypeName);
Swig_1_3_38::cleanupSWIG_T(TypeName);
Swig_1_3_40::cleanupSWIG_T(TypeName);
#endif
}