From ec6ed34118d4a771ad358979c2de1379f25ce9e8 Mon Sep 17 00:00:00 2001 From: Rene Hopf Date: Thu, 26 Aug 2021 12:49:35 +0200 Subject: [PATCH] cleanup python modules, remove py3c --- src/emc/pythonplugin/python_plugin.cc | 28 +--- src/emc/rs274ngc/gcodemodule.cc | 53 ++----- src/emc/rs274ngc/interp_namedparams.cc | 7 +- src/emc/rs274ngc/interp_python.cc | 15 +- src/emc/rs274ngc/pyparamclass.cc | 6 +- src/emc/task/taskclass.cc | 32 ---- .../usr_intf/axis/extensions/_toglmodule.c | 4 +- src/emc/usr_intf/axis/extensions/emcmodule.cc | 36 ++--- src/emc/usr_intf/axis/extensions/minigl.c | 6 +- src/hal/components/panelui.c | 10 +- src/hal/halmodule.cc | 105 +++---------- src/py3c/capsulethunk.h | 141 ------------------ src/py3c/comparison.h | 45 ------ src/py3c/compat.h | 139 ----------------- src/py3c/fileshim.h | 49 ------ src/py3c/py3c.h | 34 ----- src/py3c/py3shims.h | 44 ------ src/py3c/tpflags.h | 52 ------- tests/interp/compile/use-rs274.cc | 13 -- 19 files changed, 76 insertions(+), 743 deletions(-) delete mode 100644 src/py3c/capsulethunk.h delete mode 100644 src/py3c/comparison.h delete mode 100644 src/py3c/compat.h delete mode 100644 src/py3c/fileshim.h delete mode 100644 src/py3c/py3c.h delete mode 100644 src/py3c/py3shims.h delete mode 100644 src/py3c/tpflags.h diff --git a/src/emc/pythonplugin/python_plugin.cc b/src/emc/pythonplugin/python_plugin.cc index 62bc9059d69..05042a707d2 100644 --- a/src/emc/pythonplugin/python_plugin.cc +++ b/src/emc/pythonplugin/python_plugin.cc @@ -55,25 +55,12 @@ namespace bp = boost::python; static const char *strstore(const char *s); -// boost python versions from 1.58 to 1.61 (the latest at the time of -// writing) all have a bug in boost::python::execfile that results in a -// double free. Work around it by using the Python implementation of -// execfile instead. -// The bug was introduced at https://github.com/boostorg/python/commit/fe24ab9dd5440562e27422cd38f7de03356bfd16 -bp::object working_execfile(const char *filename, bp::object globals, bp::object locals) { - #if PY_MAJOR_VERSION >=3 - return bp::exec_file(filename,globals,locals); - #else - return bp::import("__builtin__").attr("execfile")(filename, globals, locals); - #endif -} - int PythonPlugin::run_string(const char *cmd, bp::object &retval, bool as_file) { reload(); try { if (as_file) - retval = working_execfile(cmd, main_namespace, main_namespace); + retval = bp::exec_file(cmd, main_namespace, main_namespace); else retval = bp::exec(cmd, main_namespace, main_namespace); status = PLUGIN_OK; @@ -273,9 +260,7 @@ int PythonPlugin::initialize() main_namespace[inittab_entries[i]] = bp::import(inittab_entries[i].c_str()); } if (toplevel) // only execute a file if there's one configured. - bp::object result = working_execfile(abs_path, - main_namespace, - main_namespace); + bp::object result = bp::exec_file(abs_path, main_namespace, main_namespace); status = PLUGIN_OK; } catch (bp::error_already_set &) { @@ -306,7 +291,6 @@ PythonPlugin::PythonPlugin(struct _inittab *inittab) : abs_path(0), log_level(0) { -#if PY_MAJOR_VERSION >= 3 if (abs_path) { wchar_t *program = Py_DecodeLocale(abs_path, NULL); Py_SetProgramName(program); @@ -338,14 +322,6 @@ PythonPlugin::PythonPlugin(struct _inittab *inittab) : } } Py_UnbufferedStdioFlag = 1; -#else - Py_SetProgramName((char *) abs_path); - if ((inittab != NULL) && PyImport_ExtendInittab(inittab)) { - logPP(-1, "cant extend inittab"); - status = PLUGIN_INITTAB_FAILED; - return; - } -#endif Py_Initialize(); initialize(); } diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc index 5696ba2f93e..c8de64cd6f6 100644 --- a/src/emc/rs274ngc/gcodemodule.cc +++ b/src/emc/rs274ngc/gcodemodule.cc @@ -17,7 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "py3c/py3c.h" #include #include "rs274ngc.hh" @@ -30,8 +29,6 @@ int _task = 0; // control preview behaviour when remapping char _parameter_file_name[LINELEN]; -#if PY_MAJOR_VERSION >=3 - extern "C" PyObject* PyInit_emctask(void); extern "C" PyObject* PyInit_interpreter(void); extern "C" PyObject* PyInit_emccanon(void); @@ -42,23 +39,11 @@ struct _inittab builtin_modules[] = { { NULL, NULL } }; -#else - -extern "C" void initinterpreter(); -extern "C" void initemccanon(); -extern "C" struct _inittab builtin_modules[]; -struct _inittab builtin_modules[] = { - { (char *) "interpreter", initinterpreter }, - { (char *) "emccanon", initemccanon }, - // any others... - { NULL, NULL } -}; -#endif static PyObject *int_array(int *arr, int sz) { PyObject *res = PyTuple_New(sz); for(int i = 0; i < sz; i++) { - PyTuple_SET_ITEM(res, i, PyInt_FromLong(arr[i])); + PyTuple_SET_ITEM(res, i, PyLong_FromLong(arr[i])); } return res; } @@ -544,7 +529,7 @@ void SET_PARAMETER_FILE_NAME(const char *name) void GET_EXTERNAL_PARAMETER_FILE_NAME(char *name, int max_size) { PyObject *result = PyObject_GetAttrString(callback, "parameter_file"); if(!result) { name[0] = 0; return; } - char *s = (char*)PyStr_AsString(result); + char *s = (char*)PyUnicode_AsUTF8(result); if(!s) { name[0] = 0; return; } memset(name, 0, max_size); strncpy(name, s, max_size - 1); @@ -622,8 +607,8 @@ int GET_EXTERNAL_AXIS_MASK() { PyObject *result = callmethod(callback, "get_axis_mask", ""); if(!result) { interp_error ++; return 7 /* XYZABC */; } - if(!PyInt_Check(result)) { interp_error ++; return 7 /* XYZABC */; } - int mask = PyInt_AsLong(result); + if(!PyLong_Check(result)) { interp_error ++; return 7 /* XYZABC */; } + int mask = PyLong_AsLong(result); Py_DECREF(result); return mask; } @@ -656,8 +641,8 @@ double GET_EXTERNAL_TOOL_LENGTH_WOFFSET() { return tool_offset.w; } -static bool PyInt_CheckAndError(const char *func, PyObject *p) { - if(PyInt_Check(p)) return true; +static bool PyLong_CheckAndError(const char *func, PyObject *p) { + if(PyLong_Check(p)) return true; PyErr_Format(PyExc_TypeError, "%s: Expected int, got %s", func, Py_TYPE(p)->tp_name); return false; @@ -773,7 +758,7 @@ static PyObject *parse_file(PyObject *self, PyObject *args) { { PyObject *item = PyList_GetItem(initcodes, i); if(!item) return NULL; - const char *code = PyStr_AsString(item); + const char *code = PyUnicode_AsUTF8(item); if(!code) return NULL; result = pinterp->read(code); if(!RESULT_OK) goto out_error; @@ -827,8 +812,8 @@ static PyObject *parse_file(PyObject *self, PyObject *args) { maybe_new_line(); if(PyErr_Occurred()) { interp_error = 1; goto out_error; } PyObject *retval = PyTuple_New(2); - PyTuple_SetItem(retval, 0, PyInt_FromLong(result)); - PyTuple_SetItem(retval, 1, PyInt_FromLong(last_sequence_number + error_line_offset)); + PyTuple_SetItem(retval, 0, PyLong_FromLong(result)); + PyTuple_SetItem(retval, 1, PyLong_FromLong(last_sequence_number + error_line_offset)); return retval; } @@ -840,7 +825,7 @@ static PyObject *rs274_strerror(PyObject *s, PyObject *o) { int err; if(!PyArg_ParseTuple(o, "i", &err)) return nullptr; pinterp->error_text(err, savedError, LINELEN); - return PyStr_FromString(savedError); + return PyUnicode_FromString(savedError); } static PyObject *rs274_calc_extents(PyObject *self, PyObject *args) { @@ -906,17 +891,10 @@ static PyObject *rs274_calc_extents(PyObject *self, PyObject *args) { min_xt, min_yt, min_zt, max_xt, max_yt, max_zt); } -#if PY_VERSION_HEX < 0x02050000 -#define PyObject_GetAttrString(o,s) \ - PyObject_GetAttrString((o),const_cast((s))) -#define PyArg_VaParse(o,f,a) \ - PyArg_VaParse((o),const_cast((f)),(a)) -#endif - static bool get_attr(PyObject *o, const char *attr_name, int *v) { PyObject *attr = PyObject_GetAttrString(o, attr_name); - if(attr && PyInt_CheckAndError(attr_name, attr)) { - *v = PyInt_AsLong(attr); + if(attr && PyLong_CheckAndError(attr_name, attr)) { + *v = PyLong_AsLong(attr); Py_DECREF(attr); return true; } @@ -1082,15 +1060,16 @@ static struct PyModuleDef gcode_moduledef = { gcode_methods /* m_methods */ }; -MODULE_INIT_FUNC(gcode) +PyMODINIT_FUNC PyInit_gcode(void); +PyMODINIT_FUNC PyInit_gcode(void) { PyObject *m = PyModule_Create(&gcode_moduledef); PyType_Ready(&LineCodeType); PyModule_AddObject(m, "linecode", (PyObject*)&LineCodeType); - PyObject_SetAttrString(m, "MAX_ERROR", PyInt_FromLong(maxerror)); + PyObject_SetAttrString(m, "MAX_ERROR", PyLong_FromLong(maxerror)); PyObject_SetAttrString(m, "MIN_ERROR", - PyInt_FromLong(INTERP_MIN_ERROR)); + PyLong_FromLong(INTERP_MIN_ERROR)); return m; } // vim:ts=8:sts=4:sw=4:et: diff --git a/src/emc/rs274ngc/interp_namedparams.cc b/src/emc/rs274ngc/interp_namedparams.cc index a8519287b43..49d166a0f95 100644 --- a/src/emc/rs274ngc/interp_namedparams.cc +++ b/src/emc/rs274ngc/interp_namedparams.cc @@ -21,7 +21,6 @@ #define _GNU_SOURCE #endif -#include "py3c/py3c.h" #define BOOST_PYTHON_MAX_ARITY 4 #include "python_plugin.hh" #include @@ -369,13 +368,13 @@ int Interp::find_named_param( "named param - pycall(%s):\n%s", nameBuf, python_plugin->last_exception().c_str()); CHKS(retval.ptr() == Py_None, "Python namedparams.%s returns no value", nameBuf); - if (PyStr_Check(retval.ptr())) { + if (PyUnicode_Check(retval.ptr())) { // returning a string sets the interpreter error message and aborts *status = 0; char *msg = bp::extract(retval); ERS("%s", msg); } - if (PyInt_Check(retval.ptr())) { // widen + if (PyLong_Check(retval.ptr())) { // widen *value = (double) bp::extract(retval); *status = 1; return INTERP_OK; @@ -391,7 +390,7 @@ int Interp::find_named_param( Py_XDECREF(res_str); ERS("Python call %s.%s returned '%s' - expected double, int or string, got %s", NAMEDPARAMS_MODULE, nameBuf, - PyStr_AsString(res_str), + PyUnicode_AsUTF8(res_str), retval.ptr()->ob_type->tp_name); } else { *value = pv->value; diff --git a/src/emc/rs274ngc/interp_python.cc b/src/emc/rs274ngc/interp_python.cc index 0e1418bd0e8..8dd7595abac 100644 --- a/src/emc/rs274ngc/interp_python.cc +++ b/src/emc/rs274ngc/interp_python.cc @@ -16,7 +16,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "py3c/py3c.h" #define BOOST_PYTHON_MAX_ARITY 4 #include "python_plugin.hh" #include "interp_python.hh" @@ -195,22 +194,18 @@ int Interp::pycall(setup_pointer settings, // a generator was returned. This must have been the first time call to a handler // which contains a yield. Extract next() method. - #if PY_MAJOR_VERSION >=3 frame->pystuff.impl->generator_next = bp::getattr(retval, "__next__"); - #else - frame->pystuff.impl->generator_next = bp::getattr(retval, "next"); - #endif // and call it for the first time. // Expect execution up to first 'yield INTERP_EXECUTE_FINISH'. frame->pystuff.impl->py_returned_int = bp::extract(frame->pystuff.impl->generator_next()); frame->pystuff.impl->py_return_type = RET_YIELD; - } else if (PyStr_Check(retval.ptr())) { + } else if (PyUnicode_Check(retval.ptr())) { // returning a string sets the interpreter error message and aborts char *msg = bp::extract(retval); ERM("%s", msg); frame->pystuff.impl->py_return_type = RET_ERRORMSG; status = INTERP_ERROR; - } else if (PyInt_Check(retval.ptr())) { + } else if (PyLong_Check(retval.ptr())) { frame->pystuff.impl->py_returned_int = bp::extract(retval); frame->pystuff.impl->py_return_type = RET_INT; logPy("Python call %s.%s returned int: %d", module, funcname, frame->pystuff.impl->py_returned_int); @@ -224,7 +219,7 @@ int Interp::pycall(setup_pointer settings, Py_XDECREF(res_str); ERM("Python call %s.%s returned '%s' - expected generator, int, or float value, got %s", module, funcname, - PyStr_AsString(res_str), + PyUnicode_AsUTF8(res_str), Py_TYPE(retval.ptr())->tp_name); status = INTERP_ERROR; } @@ -239,7 +234,7 @@ int Interp::pycall(setup_pointer settings, // a plain int (INTERP_OK, INTERP_ERROR, INTERP_EXECUTE_FINISH...) is expected // must have returned an int if ((retval.ptr() != Py_None) && - (PyInt_Check(retval.ptr()))) { + (PyLong_Check(retval.ptr()))) { // FIXME check new return value convention status = frame->pystuff.impl->py_returned_int = bp::extract(retval); @@ -250,7 +245,7 @@ int Interp::pycall(setup_pointer settings, res_str = PyObject_Str(retval.ptr()); ERM("Python internal function '%s' expected tuple or int return value, got '%s' (%s)", funcname, - PyStr_AsString(res_str), + PyUnicode_AsUTF8(res_str), Py_TYPE(retval.ptr())->tp_name); Py_XDECREF(res_str); status = INTERP_ERROR; diff --git a/src/emc/rs274ngc/pyparamclass.cc b/src/emc/rs274ngc/pyparamclass.cc index 7cafaba99f9..3bb747ffd62 100644 --- a/src/emc/rs274ngc/pyparamclass.cc +++ b/src/emc/rs274ngc/pyparamclass.cc @@ -18,7 +18,7 @@ // Interpreter internals - Python bindings // Michael Haberler 7/2011 // -#include "py3c/py3c.h" + #define BOOST_PYTHON_MAX_ARITY 4 #include #include @@ -40,8 +40,8 @@ extern int _task; // zero in gcodemodule, 1 in milltask #include using namespace interp_param_global; -#define IS_STRING(x) (PyStr_Check(x.ptr())) -#define IS_INT(x) (PyInt_Check(x.ptr())) +#define IS_STRING(x) (PyUnicode_Check(x.ptr())) +#define IS_INT(x) (PyLong_Check(x.ptr())) // access to named and numbered parameters via a pseudo-dictionary // either params["paramname"] or params[5400] is valid diff --git a/src/emc/task/taskclass.cc b/src/emc/task/taskclass.cc index c7641543a40..70e38bb6fc5 100644 --- a/src/emc/task/taskclass.cc +++ b/src/emc/task/taskclass.cc @@ -31,8 +31,6 @@ #include "emc_nml.hh" #include "emcglb.h" // EMC_INIFILE - -#include "py3c/py3c.h" #include "python_plugin.hh" #include "taskclass.hh" #include @@ -397,21 +395,12 @@ int return_int(const char *funcname, PyObject *retval) return -1; } if ((retval != Py_None) && -#if PY_MAJOR_VERSION >=3 (PyLong_Check(retval))) { return PyLong_AsLong(retval); -#else - (PyInt_Check(retval))) { - return PyInt_AS_LONG(retval); -#endif } else { emcOperatorError(0, "return_int(%s): expected int return value, got '%s' (%s)", funcname, -#if PY_MAJOR_VERSION >=3 PyBytes_AsString(retval), -#else - PyString_AsString(retval), -#endif Py_TYPE(retval)->tp_name); Py_XDECREF(retval); return -1; @@ -434,14 +423,6 @@ int emcPluginCall(EMC_EXEC_PLUGIN_CALL *call_msg) } } -// int emcAbortCleanup(int reason, const char *message) -// { -// int status = interp.on_abort(reason,message); -// if (status > INTERP_MIN_ERROR) -// print_interp_error(status); -// return status; -// } -#if PY_MAJOR_VERSION >=3 extern "C" PyObject* PyInit_emctask(void); extern "C" PyObject* PyInit_interpreter(void); extern "C" PyObject* PyInit_emccanon(void); @@ -452,19 +433,6 @@ struct _inittab builtin_modules[] = { // any others... { NULL, NULL } }; -#else -extern "C" void initemctask(); -extern "C" void initinterpreter(); -extern "C" void initemccanon(); -struct _inittab builtin_modules[] = { - { (char *) "interpreter", initinterpreter }, - { (char *) "emccanon", initemccanon }, - { (char *) "emctask", initemctask }, - // any others... - { NULL, NULL } -}; -#endif - Task::Task() : use_iocontrol(0), random_toolchanger(0) { diff --git a/src/emc/usr_intf/axis/extensions/_toglmodule.c b/src/emc/usr_intf/axis/extensions/_toglmodule.c index 3fc52390fd9..32b5582d3aa 100644 --- a/src/emc/usr_intf/axis/extensions/_toglmodule.c +++ b/src/emc/usr_intf/axis/extensions/_toglmodule.c @@ -14,7 +14,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "py3c/py3c.h" #include static int first_time = 1; @@ -77,7 +76,8 @@ static struct PyModuleDef togl_moduledef = { togl_methods }; -MODULE_INIT_FUNC(_togl) +PyMODINIT_FUNC PyInit__togl(void); +PyMODINIT_FUNC PyInit__togl(void) { PyObject *m = PyModule_Create(&togl_moduledef); return m; diff --git a/src/emc/usr_intf/axis/extensions/emcmodule.cc b/src/emc/usr_intf/axis/extensions/emcmodule.cc index 1b5821e2489..2ce6e2437c8 100644 --- a/src/emc/usr_intf/axis/extensions/emcmodule.cc +++ b/src/emc/usr_intf/axis/extensions/emcmodule.cc @@ -19,7 +19,6 @@ #define PY_SSIZE_T_CLEAN #define __STDC_FORMAT_MACROS #include -#include "py3c/py3c.h" #include #include #include @@ -123,7 +122,7 @@ static PyObject *Ini_find(pyIniFile *self, PyObject *args) { Py_INCREF(Py_None); return Py_None; } - return PyStr_FromString(const_cast(out)); + return PyUnicode_FromString(const_cast(out)); } static PyObject *Ini_findall(pyIniFile *self, PyObject *args) { @@ -137,7 +136,7 @@ static PyObject *Ini_findall(pyIniFile *self, PyObject *args) { if(out == NULL) { break; } - PyList_Append(result, PyStr_FromString(const_cast(out))); + PyList_Append(result, PyUnicode_FromString(const_cast(out))); num++; } return result; @@ -250,7 +249,7 @@ static int emcSendCommand(pyCommandChannel *s, RCS_CMD_MSG & cmd) { static const char *get_nmlfile(void) { PyObject *fileobj = PyObject_GetAttrString(m, "nmlfile"); if(fileobj == NULL) return NULL; - return PyStr_AsString(fileobj); + return PyUnicode_AsUTF8(fileobj); } static int Stat_init(pyStatChannel *self, PyObject *a, PyObject *k) { @@ -416,7 +415,7 @@ static PyMemberDef Stat_members[] = { static PyObject *int_array(int *arr, int sz) { PyObject *res = PyTuple_New(sz); for(int i = 0; i < sz; i++) { - PyTuple_SET_ITEM(res, i, PyInt_FromLong(arr[i])); + PyTuple_SET_ITEM(res, i, PyLong_FromLong(arr[i])); } return res; } @@ -444,7 +443,7 @@ static PyObject *pose(const EmcPose &p) { } static PyObject *Stat_g5x_index(pyStatChannel *s) { - return PyInt_FromLong(s->status.task.g5x_index); + return PyLong_FromLong(s->status.task.g5x_index); } static PyObject *Stat_g5x_offset(pyStatChannel *s) { @@ -521,7 +520,7 @@ static PyObject *Stat_limit(pyStatChannel *s) { if(s->status.motion.joint[i].maxHardLimit) v |= 2; if(s->status.motion.joint[i].minSoftLimit) v |= 4; if(s->status.motion.joint[i].maxSoftLimit) v |= 8; - PyTuple_SET_ITEM(res, i, PyInt_FromLong(v)); + PyTuple_SET_ITEM(res, i, PyLong_FromLong(v)); } return res; } @@ -529,7 +528,7 @@ static PyObject *Stat_limit(pyStatChannel *s) { static PyObject *Stat_homed(pyStatChannel *s) { PyObject *res = PyTuple_New(EMCMOT_MAX_JOINTS); for(int i = 0; i < EMCMOT_MAX_JOINTS; i++) { - PyTuple_SET_ITEM(res, i, PyInt_FromLong(s->status.motion.joint[i].homed)); + PyTuple_SET_ITEM(res, i, PyLong_FromLong(s->status.motion.joint[i].homed)); } return res; } @@ -544,7 +543,7 @@ static PyObject *Stat_aout(pyStatChannel *s) { static void dict_add(PyObject *d, const char *name, unsigned char v) { PyObject *o; - PyDict_SetItemString(d, name, o = PyInt_FromLong(v)); + PyDict_SetItemString(d, name, o = PyLong_FromLong(v)); Py_XDECREF(o); } static void dict_add(PyObject *d, const char *name, double v) { @@ -694,7 +693,7 @@ static PyObject *Stat_tool_table(pyStatChannel *s) { } struct CANON_TOOL_TABLE &t = tdata; PyObject *tool = PyStructSequence_New(&ToolResultType); - PyStructSequence_SET_ITEM(tool, 0, PyInt_FromLong(t.toolno)); + PyStructSequence_SET_ITEM(tool, 0, PyLong_FromLong(t.toolno)); PyStructSequence_SET_ITEM(tool, 1, PyFloat_FromDouble(t.offset.tran.x)); PyStructSequence_SET_ITEM(tool, 2, PyFloat_FromDouble(t.offset.tran.y)); PyStructSequence_SET_ITEM(tool, 3, PyFloat_FromDouble(t.offset.tran.z)); @@ -707,7 +706,7 @@ static PyObject *Stat_tool_table(pyStatChannel *s) { PyStructSequence_SET_ITEM(tool, 10, PyFloat_FromDouble(t.diameter)); PyStructSequence_SET_ITEM(tool, 11, PyFloat_FromDouble(t.frontangle)); PyStructSequence_SET_ITEM(tool, 12, PyFloat_FromDouble(t.backangle)); - PyStructSequence_SET_ITEM(tool, 13, PyInt_FromLong(t.orientation)); + PyStructSequence_SET_ITEM(tool, 13, PyLong_FromLong(t.orientation)); PyTuple_SetItem(res, j, tool); j++; } @@ -717,7 +716,7 @@ static PyObject *Stat_tool_table(pyStatChannel *s) { static PyObject *Stat_axes(pyStatChannel *s) { PyErr_WarnEx(PyExc_DeprecationWarning, "stat.axes is deprecated and will be removed in the future", 0); - return PyInt_FromLong(s->status.motion.traj.deprecated_axes); + return PyLong_FromLong(s->status.motion.traj.deprecated_axes); } // XXX io.tool.toolTable @@ -1369,7 +1368,7 @@ static PyObject *wait_complete(pyCommandChannel *s, PyObject *o) { double timeout = EMC_COMMAND_TIMEOUT; if (!PyArg_ParseTuple(o, "|d:emc.command.wait_complete", &timeout)) return NULL; - return PyInt_FromLong(emcWaitCommandComplete(s, timeout)); + return PyLong_FromLong(emcWaitCommandComplete(s, timeout)); } static PyObject *error_msg(pyCommandChannel *s, PyObject *args ) { @@ -1545,14 +1544,14 @@ static PyObject* Error_poll(pyErrorChannel *s) { return Py_None; } PyObject *r = PyTuple_New(2); - PyTuple_SET_ITEM(r, 0, PyInt_FromLong(type)); + PyTuple_SET_ITEM(r, 0, PyLong_FromLong(type)); #define PASTE(a,b) a ## b #define _TYPECASE(tag, type, f) \ case tag: { \ char error_string[LINELEN]; \ strncpy(error_string, ((type*)s->c->get_address())->f, LINELEN-1); \ error_string[LINELEN-1] = 0; \ - PyTuple_SET_ITEM(r, 1, PyStr_FromString(error_string)); \ + PyTuple_SET_ITEM(r, 1, PyUnicode_FromString(error_string)); \ break; \ } #define TYPECASE(x, f) _TYPECASE(PASTE(x, _TYPE), x, f) @@ -1567,7 +1566,7 @@ static PyObject* Error_poll(pyErrorChannel *s) { { char error_string[256]; snprintf(error_string, sizeof(error_string), "unrecognized error %" PRId32, type); - PyTuple_SET_ITEM(r, 1, PyStr_FromString(error_string)); + PyTuple_SET_ITEM(r, 1, PyUnicode_FromString(error_string)); break; } } @@ -2362,7 +2361,8 @@ static struct PyModuleDef linuxcnc_moduledef = { emc_methods /* m_methods */ }; -MODULE_INIT_FUNC(linuxcnc) +PyMODINIT_FUNC PyInit_linuxcnc(void); +PyMODINIT_FUNC PyInit_linuxcnc(void) { verbose_nml_error_messages = 0; @@ -2398,7 +2398,7 @@ MODULE_INIT_FUNC(linuxcnc) PyStructSequence_InitType(&ToolResultType, &tool_result_desc); PyModule_AddObject(m, "tool", (PyObject*)&ToolResultType); - PyModule_AddObject(m, "version", PyStr_FromString(PACKAGE_VERSION)); + PyModule_AddObject(m, "version", PyUnicode_FromString(PACKAGE_VERSION)); ENUMX(4, EMC_LINEAR); ENUMX(4, EMC_ANGULAR); diff --git a/src/emc/usr_intf/axis/extensions/minigl.c b/src/emc/usr_intf/axis/extensions/minigl.c index 1c4354e7495..cbf0cc9d9f6 100644 --- a/src/emc/usr_intf/axis/extensions/minigl.c +++ b/src/emc/usr_intf/axis/extensions/minigl.c @@ -17,7 +17,6 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include -#include "py3c/py3c.h" #define GL_GLEXT_PROTOTYPES #include #include @@ -372,7 +371,7 @@ static PyObject *pyglReadPixels(PyObject *s, PyObject *o) { sz = width * height * 4; buf = malloc(sz); glReadPixels(x,y,width,height,format,type,buf); - res = PyStr_FromStringAndSize(buf, sz); + res = PyUnicode_FromStringAndSize(buf, sz); free(buf); return res; } @@ -790,7 +789,8 @@ static struct PyModuleDef minigl_moduledef = { //extern "C" //void init_hal(void) { -MODULE_INIT_FUNC(minigl) +PyMODINIT_FUNC PyInit_minigl(void); +PyMODINIT_FUNC PyInit_minigl(void) { PyObject *m = PyModule_Create(&minigl_moduledef); glerror = PyErr_NewException("minigl.error", PyExc_RuntimeError, NULL); diff --git a/src/hal/components/panelui.c b/src/hal/components/panelui.c index 18aad6ebaba..b0f5a85e5bc 100644 --- a/src/hal/components/panelui.c +++ b/src/hal/components/panelui.c @@ -206,13 +206,9 @@ int main(int argc, char **argv) /* import the python module and get references for needed function */ PyObject *pModule, *pFunc, *pPeriodicFunc, *pClass; - char name[] = "panelui"; - #if PY_MAJOR_VERSION >=3 - wchar_t *wname = Py_DecodeLocale(name, NULL); - Py_SetProgramName(wname); - #else - Py_SetProgramName(name); - #endif + char name[] = "panelui"; + wchar_t *wname = Py_DecodeLocale(name, NULL); + Py_SetProgramName(wname); Py_Initialize(); PyRun_SimpleString("import pyui\n" "pyui.instance = pyui.master.keyboard()\n" diff --git a/src/hal/halmodule.cc b/src/hal/halmodule.cc index 498ec97a2c7..2c354ae61fa 100644 --- a/src/hal/halmodule.cc +++ b/src/hal/halmodule.cc @@ -16,7 +16,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -#include "py3c/py3c.h" #include #include #include @@ -29,12 +28,6 @@ using namespace std; #include "hal.h" #include "hal_priv.h" -#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) -typedef int Py_ssize_t; -#define PY_SSIZE_T_MAX INT_MAX -#define PY_SSIZE_T_MIN INT_MIN -#endif - #define EXCEPTION_IF_NOT_LIVE(retval) do { \ if(self->hal_id <= 0) { \ PyErr_SetString(PyExc_RuntimeError, "Invalid operation on closed HAL component"); \ @@ -47,12 +40,12 @@ PyObject *to_python(bool b) { } PyObject *to_python(unsigned u) { - if(u < LONG_MAX) return PyInt_FromLong(u); + if(u < LONG_MAX) return PyLong_FromLong(u); return PyLong_FromUnsignedLong(u); } PyObject *to_python(int u) { - return PyInt_FromLong(u); + return PyLong_FromLong(u); } PyObject *to_python(double d) { @@ -63,14 +56,9 @@ bool from_python(PyObject *o, double *d) { if(PyFloat_Check(o)) { *d = PyFloat_AsDouble(o); return true; - } else if(PyInt_Check(o)) { - #if PY_MAJOR_VERSION >= 3 + } else if(PyLong_Check(o)) { *d = PyLong_AsDouble(o); return !PyErr_Occurred(); - #else - *d = PyInt_AsLong(o); - #endif - return true; } else if(PyLong_Check(o)) { *d = PyLong_AsDouble(o); return !PyErr_Occurred(); @@ -90,22 +78,11 @@ bool from_python(PyObject *o, double *d) { bool from_python(PyObject *o, uint32_t *u) { PyObject *tmp = 0; long long l; -#if !IS_PY3 - if(PyInt_Check(o)) { - l = PyInt_AsLong(o); - goto got_value; - } -#endif - tmp = PyLong_Check(o) ? o : PyNumber_Long(o); if(!tmp) goto fail; l = PyLong_AsLongLong(tmp); if(PyErr_Occurred()) goto fail; - -#if !IS_PY3 -got_value: -#endif if(l < 0 || l != (uint32_t)l) { PyErr_Format(PyExc_OverflowError, "Value %lld out of range", l); goto fail; @@ -122,22 +99,11 @@ bool from_python(PyObject *o, uint32_t *u) { bool from_python(PyObject *o, int32_t *i) { PyObject *tmp = 0; long long l; -#if !IS_PY3 - if(PyInt_Check(o)) { - l = PyInt_AsLong(o); - goto got_value; - } -#endif - tmp = PyLong_Check(o) ? o : PyNumber_Long(o); if(!tmp) goto fail; l = PyLong_AsLongLong(tmp); if(PyErr_Occurred()) goto fail; - -#if !IS_PY3 -got_value: -#endif if(l != (int32_t)l) { PyErr_Format(PyExc_OverflowError, "Value %lld out of range", l); goto fail; @@ -489,7 +455,7 @@ static PyObject *pyhal_exit(PyObject *_self, PyObject *o) { static PyObject *pyhal_repr(PyObject *_self) { halobject *self = (halobject *)_self; - return PyStr_FromFormat("", + return PyUnicode_FromFormat("", self->name, self->hal_id, (int)self->items->size()); } @@ -502,13 +468,13 @@ static PyObject *pyhal_getattro(PyObject *_self, PyObject *attro) { if(result) return result; PyErr_Clear(); - return pyhal_read_common(find_item(self, PyStr_AsString(attro))); + return pyhal_read_common(find_item(self, PyUnicode_AsUTF8(attro))); } static int pyhal_setattro(PyObject *_self, PyObject *attro, PyObject *v) { halobject *self = (halobject *)_self; EXCEPTION_IF_NOT_LIVE(-1); - return pyhal_write_common(find_item(self, PyStr_AsString(attro)), v); + return pyhal_write_common(find_item(self, PyUnicode_AsUTF8(attro)), v); } static Py_ssize_t pyhal_len(PyObject *_self) { @@ -525,7 +491,7 @@ static PyObject *pyhal_get_prefix(PyObject *_self, PyObject *args) { if(!self->prefix) Py_RETURN_NONE; - return PyStr_FromString(self->prefix); + return PyUnicode_FromString(self->prefix); } @@ -650,9 +616,9 @@ static PyObject *pyhalpin_repr(PyObject *_self) { if (pyself->name) name = pyself->name; if (!self->is_pin) - return PyStr_FromFormat("", name, + return PyUnicode_FromFormat("", name, pin_type2name(self->type), param_dir2name(self->dir.paramdir)); - return PyStr_FromFormat("", name, + return PyUnicode_FromFormat("", name, pin_type2name(self->type), pin_dir2name(self->dir.pindir)); } @@ -684,15 +650,15 @@ static PyObject * pyhal_pin_get(PyObject * _self, PyObject *) { static PyObject * pyhal_pin_get_type(PyObject * _self, PyObject *) { pyhalitem * self = (pyhalitem *) _self; - return PyInt_FromLong(self->pin.type); + return PyLong_FromLong(self->pin.type); } static PyObject * pyhal_pin_get_dir(PyObject * _self, PyObject *) { pyhalitem * self = (pyhalitem *) _self; if (self->pin.is_pin) - return PyInt_FromLong(self->pin.dir.pindir); + return PyLong_FromLong(self->pin.dir.pindir); else - return PyInt_FromLong(self->pin.dir.paramdir); + return PyLong_FromLong(self->pin.dir.paramdir); } static PyObject * pyhal_pin_is_pin(PyObject * _self, PyObject *) { @@ -704,7 +670,7 @@ static PyObject * pyhal_pin_get_name(PyObject * _self, PyObject *) { pyhalitem * self = (pyhalitem *) _self; if (!self->name) Py_RETURN_NONE; - return PyStr_FromString(self->name); + return PyUnicode_FromString(self->name); } static PyMethodDef halpin_methods[] = { @@ -1335,11 +1301,9 @@ static void pyshm_delete(PyObject *_self) { rtapi_shmem_delete(self->shm_id, self->comp->hal_id); Py_XDECREF(self->comp); } -#if PY_MAJOR_VERSION >=3 -static int -shm_buffer_getbuffer(PyObject *obj, Py_buffer *view, int flags) -{ -if (view == NULL) { + +static int shm_buffer_getbuffer(PyObject *obj, Py_buffer *view, int flags) { + if (view == NULL) { PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer"); return -1; } @@ -1351,23 +1315,10 @@ if (view == NULL) { Py_INCREF(self); // need to increase the reference count return 0; } -#else - -static Py_ssize_t shm_buffer(PyObject *_self, Py_ssize_t segment, void **ptrptr){ - shmobject *self = (shmobject *)_self; - if(ptrptr) *ptrptr = self->buf; - return self->size; -} -static Py_ssize_t shm_segcount(PyObject *_self, Py_ssize_t *lenp) { - shmobject *self = (shmobject *)_self; - if(lenp) *lenp = self->size; - return 1; -} -#endif static PyObject *pyshm_repr(PyObject *_self) { shmobject *self = (shmobject *)_self; - return PyStr_FromFormat("", + return PyUnicode_FromFormat("", self->key, self->shm_id, (unsigned long)self->size); } @@ -1393,29 +1344,14 @@ static PyObject *set_msg_level(PyObject *_self, PyObject *args) { } static PyObject *get_msg_level(PyObject *_self, PyObject *args) { - return PyInt_FromLong(rtapi_get_msg_level()); + return PyLong_FromLong(rtapi_get_msg_level()); } - -#if PY_MAJOR_VERSION >=3 - static PyBufferProcs shmbuffer_procs = { (getbufferproc)shm_buffer_getbuffer, /* bf_getbuffer */ (releasebufferproc)NULL, //(releasebufferproc)shm_buffer_releasebuffer, /* bf_releasebuffer */ }; -#else - -static -PyBufferProcs shmbuffer_procs = { - shm_buffer, - shm_buffer, - shm_segcount, - NULL -}; - -#endif - static PyMethodDef shm_methods[] = { {"getbuffer", shm_getbuffer, METH_NOARGS, "Get a writable buffer object for the shared memory segment"}, @@ -1655,7 +1591,7 @@ static void pystream_delete(PyObject *_self) { static PyObject *pystream_repr(PyObject *_self) { streamobj *self = reinterpret_cast(_self); - return PyStr_FromFormat("", self->key, + return PyUnicode_FromFormat("", self->key, self->creator ? " creator" : ""); } @@ -1766,7 +1702,8 @@ static struct PyModuleDef hal_moduledef = { module_methods /* m_methods */ }; -MODULE_INIT_FUNC(_hal) +PyMODINIT_FUNC PyInit__hal(void); +PyMODINIT_FUNC PyInit__hal(void) { PyObject *m = PyModule_Create(&hal_moduledef); diff --git a/src/py3c/capsulethunk.h b/src/py3c/capsulethunk.h deleted file mode 100644 index 6ad70041334..00000000000 --- a/src/py3c/capsulethunk.h +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright (c) 2011, Larry Hastings - * Copyright (c) 2015, py3c contributors - * Licensed under the MIT license; see py3c.h - * - * (Note: Relicensed from PSF: http://bugs.python.org/issue24937#msg250191 ) - */ - -#ifndef __CAPSULETHUNK_H -#define __CAPSULETHUNK_H - -#if ( (PY_VERSION_HEX < 0x02070000) \ - || ((PY_VERSION_HEX >= 0x03000000) \ - && (PY_VERSION_HEX < 0x03010000)) ) - -#define __PyCapsule_GetField(capsule, field, error_value) \ - ( PyCapsule_CheckExact(capsule) \ - ? (((PyCObject *)capsule)->field) \ - : (PyErr_SetString(PyExc_TypeError, "CObject required"), (error_value)) \ - ) \ - -#define __PyCapsule_SetField(capsule, field, value) \ - ( PyCapsule_CheckExact(capsule) \ - ? (((PyCObject *)capsule)->field = value), 0 \ - : (PyErr_SetString(PyExc_TypeError, "CObject required"), 1) \ - ) \ - - -#define PyCapsule_Type PyCObject_Type - -#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) -#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule)) - - -#define PyCapsule_New(pointer, name, destructor) \ - (PyCObject_FromVoidPtr(pointer, (void (*)(void*)) (destructor))) - - -#define PyCapsule_GetPointer(capsule, name) \ - (PyCObject_AsVoidPtr(capsule)) - -/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */ -#define PyCapsule_SetPointer(capsule, pointer) \ - __PyCapsule_SetField(capsule, cobject, pointer) - - -#define PyCapsule_GetDestructor(capsule) \ - __PyCapsule_GetField(capsule, destructor, (void (*)(void*)) NULL) - -#define PyCapsule_SetDestructor(capsule, dtor) \ - __PyCapsule_SetField(capsule, destructor, (void (*)(void*)) dtor) - - -/* - * Sorry, there's simply no place - * to store a Capsule "name" in a CObject. - */ -#define PyCapsule_GetName(capsule) NULL - -static int -PyCapsule_SetName(PyObject *capsule, const char *unused) -{ - unused = unused; - PyErr_SetString(PyExc_NotImplementedError, - "can't use PyCapsule_SetName with CObjects"); - return 1; -} - - - -#define PyCapsule_GetContext(capsule) \ - __PyCapsule_GetField(capsule, desc, (void*) NULL) - -#define PyCapsule_SetContext(capsule, context) \ - __PyCapsule_SetField(capsule, desc, context) - - -static void * -PyCapsule_Import(const char *name, int no_block) -{ - PyObject *object = NULL; - void *return_value = NULL; - char *trace; - size_t name_length = (strlen(name) + 1) * sizeof(char); - char *name_dup = (char *)PyMem_MALLOC(name_length); - - if (!name_dup) { - return NULL; - } - - memcpy(name_dup, name, name_length); - - trace = name_dup; - while (trace) { - char *dot = strchr(trace, '.'); - if (dot) { - *dot++ = '\0'; - } - - if (object == NULL) { - if (no_block) { - object = PyImport_ImportModuleNoBlock(trace); - } else { - object = PyImport_ImportModule(trace); - if (!object) { - PyErr_Format(PyExc_ImportError, - "PyCapsule_Import could not " - "import module \"%s\"", trace); - } - } - } else { - PyObject *object2 = PyObject_GetAttrString(object, trace); - Py_DECREF(object); - object = object2; - } - if (!object) { - goto EXIT; - } - - trace = dot; - } - - if (PyCObject_Check(object)) { - PyCObject *cobject = (PyCObject *)object; - return_value = cobject->cobject; - } else { - PyErr_Format(PyExc_AttributeError, - "PyCapsule_Import \"%s\" is not valid", - name); - } - -EXIT: - Py_XDECREF(object); - if (name_dup) { - PyMem_FREE(name_dup); - } - return return_value; -} - -#endif /* #if PY_VERSION_HEX < 0x02070000 */ - -#endif /* __CAPSULETHUNK_H */ diff --git a/src/py3c/comparison.h b/src/py3c/comparison.h deleted file mode 100644 index 9d3765a4abd..00000000000 --- a/src/py3c/comparison.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates - * Licensed under the MIT license; see py3c.h - */ - -#ifndef _PY3C_COMPARISON_H_ -#define _PY3C_COMPARISON_H_ -#include - -/* Rich comparisons */ - -#ifndef Py_RETURN_NOTIMPLEMENTED -#define Py_RETURN_NOTIMPLEMENTED \ - return Py_INCREF(Py_NotImplemented), Py_NotImplemented -#endif - -#ifndef Py_UNREACHABLE -#define Py_UNREACHABLE() abort() -#endif - -#ifndef Py_RETURN_RICHCOMPARE -#define Py_RETURN_RICHCOMPARE(val1, val2, op) \ - do { \ - switch (op) { \ - case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \ - default: \ - Py_UNREACHABLE(); \ - } \ - } while (0) -#endif - -#define PY3C_RICHCMP(val1, val2, op) \ - ((op) == Py_EQ) ? PyBool_FromLong((val1) == (val2)) : \ - ((op) == Py_NE) ? PyBool_FromLong((val1) != (val2)) : \ - ((op) == Py_LT) ? PyBool_FromLong((val1) < (val2)) : \ - ((op) == Py_GT) ? PyBool_FromLong((val1) > (val2)) : \ - ((op) == Py_LE) ? PyBool_FromLong((val1) <= (val2)) : \ - ((op) == Py_GE) ? PyBool_FromLong((val1) >= (val2)) : \ - (Py_INCREF(Py_NotImplemented), Py_NotImplemented) - -#endif diff --git a/src/py3c/compat.h b/src/py3c/compat.h deleted file mode 100644 index 15d32def0b8..00000000000 --- a/src/py3c/compat.h +++ /dev/null @@ -1,139 +0,0 @@ -/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates - * Licensed under the MIT license; see py3c.h - */ - -#ifndef _PY3C_COMPAT_H_ -#define _PY3C_COMPAT_H_ -#include - -#if PY_MAJOR_VERSION >= 3 - -/***** Python 3 *****/ - -#define IS_PY3 1 - -/* Strings */ - -#define PyStr_Type PyUnicode_Type -#define PyStr_Check PyUnicode_Check -#define PyStr_CheckExact PyUnicode_CheckExact -#define PyStr_FromString PyUnicode_FromString -#define PyStr_FromStringAndSize PyUnicode_FromStringAndSize -#define PyStr_FromFormat PyUnicode_FromFormat -#define PyStr_FromFormatV PyUnicode_FromFormatV -#define PyStr_AsString PyUnicode_AsUTF8 -#define PyStr_Concat PyUnicode_Concat -#define PyStr_Format PyUnicode_Format -#define PyStr_InternInPlace PyUnicode_InternInPlace -#define PyStr_InternFromString PyUnicode_InternFromString -#define PyStr_Decode PyUnicode_Decode - -#define PyStr_AsUTF8String PyUnicode_AsUTF8String /* returns PyBytes */ -#define PyStr_AsUTF8 PyUnicode_AsUTF8 -#define PyStr_AsUTF8AndSize PyUnicode_AsUTF8AndSize - -/* Ints */ - -#define PyInt_Type PyLong_Type -#define PyInt_Check PyLong_Check -#define PyInt_CheckExact PyLong_CheckExact -#define PyInt_FromString PyLong_FromString -#define PyInt_FromLong PyLong_FromLong -#define PyInt_FromSsize_t PyLong_FromSsize_t -#define PyInt_FromSize_t PyLong_FromSize_t -#define PyInt_AsLong PyLong_AsLong -#define PyInt_AS_LONG PyLong_AS_LONG -#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask -#define PyInt_AsSsize_t PyLong_AsSsize_t - -/* Module init */ - -#define MODULE_INIT_FUNC(name) \ - PyMODINIT_FUNC PyInit_ ## name(void); \ - PyMODINIT_FUNC PyInit_ ## name(void) - -#else - -/***** Python 2 *****/ - -#define IS_PY3 0 - -/* Strings */ - -#define PyStr_Type PyString_Type -#define PyStr_Check PyString_Check -#define PyStr_CheckExact PyString_CheckExact -#define PyStr_FromString PyString_FromString -#define PyStr_FromStringAndSize PyString_FromStringAndSize -#define PyStr_FromFormat PyString_FromFormat -#define PyStr_FromFormatV PyString_FromFormatV -#define PyStr_AsString PyString_AsString -#define PyStr_Format PyString_Format -#define PyStr_InternInPlace PyString_InternInPlace -#define PyStr_InternFromString PyString_InternFromString -#define PyStr_Decode PyString_Decode - -#ifdef __GNUC__ -static PyObject *PyStr_Concat(PyObject *left, PyObject *right) __attribute__ ((unused)); -#endif -static PyObject *PyStr_Concat(PyObject *left, PyObject *right) { - PyObject *str = left; - Py_INCREF(left); /* reference to old left will be stolen */ - PyString_Concat(&str, right); - if (str) { - return str; - } else { - return NULL; - } -} - -#define PyStr_AsUTF8String(str) (Py_INCREF(str), (str)) -#define PyStr_AsUTF8 PyString_AsString -#define PyStr_AsUTF8AndSize(pystr, sizeptr) \ - ((*sizeptr=PyString_Size(pystr)), PyString_AsString(pystr)) - -#define PyBytes_Type PyString_Type -#define PyBytes_Check PyString_Check -#define PyBytes_CheckExact PyString_CheckExact -#define PyBytes_FromString PyString_FromString -#define PyBytes_FromStringAndSize PyString_FromStringAndSize -#define PyBytes_FromFormat PyString_FromFormat -#define PyBytes_FromFormatV PyString_FromFormatV -#define PyBytes_Size PyString_Size -#define PyBytes_GET_SIZE PyString_GET_SIZE -#define PyBytes_AsString PyString_AsString -#define PyBytes_AS_STRING PyString_AS_STRING -#define PyBytes_AsStringAndSize PyString_AsStringAndSize -#define PyBytes_Concat PyString_Concat -#define PyBytes_ConcatAndDel PyString_ConcatAndDel -#define _PyBytes_Resize _PyString_Resize - -/* Floats */ - -#define PyFloat_FromString(str) PyFloat_FromString(str, NULL) - -/* Module init */ - -#define PyModuleDef_HEAD_INIT 0 - -typedef struct PyModuleDef { - int m_base; - const char* m_name; - const char* m_doc; - Py_ssize_t m_size; - PyMethodDef *m_methods; -} PyModuleDef; - -#define PyModule_Create(def) \ - Py_InitModule3((def)->m_name, (def)->m_methods, (def)->m_doc) - -#define MODULE_INIT_FUNC(name) \ - static PyObject *PyInit_ ## name(void); \ - PyMODINIT_FUNC init ## name(void); \ - PyMODINIT_FUNC init ## name(void) { PyInit_ ## name(); } \ - static PyObject *PyInit_ ## name(void) - - -#endif - -#endif diff --git a/src/py3c/fileshim.h b/src/py3c/fileshim.h deleted file mode 100644 index ecf31f40677..00000000000 --- a/src/py3c/fileshim.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates - * Licensed under the MIT license; see py3c.h - */ - -#ifndef _PY3C_FILESHIM_H_ -#define _PY3C_FILESHIM_H_ -#include - -/* - -For debugging purposes only. -Caveats: - * Only works on file-like objects backed by an actual file - * All C-level writes should be done before additional - Python-level writes are allowed (e.g. by running Python code). - * Though the function tries to flush, there is no guarantee that - writes will be reordered due to different layers of buffering. - -*/ - -static char FLUSH[] = "flush"; -static char EMPTY_STRING[] = ""; - -static FILE* py3c_PyFile_AsFileWithMode(PyObject *py_file, const char *mode) { - FILE *f; - PyObject *ret; - int fd; - - ret = PyObject_CallMethod(py_file, FLUSH, EMPTY_STRING); - if (ret == NULL) { - return NULL; - } - Py_DECREF(ret); - - fd = PyObject_AsFileDescriptor(py_file); - if (fd == -1) { - return NULL; - } - - f = fdopen(fd, mode); - if (f == NULL) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - - return f; -} - -#endif /* _PY3C_FILESHIM_H_ */ diff --git a/src/py3c/py3c.h b/src/py3c/py3c.h deleted file mode 100644 index b86324b347d..00000000000 --- a/src/py3c/py3c.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2015, Red Hat, Inc. and/or its affiliates - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef _PY3COMPAT_H_ -#define _PY3COMPAT_H_ - -#include - -#include -#include -#include - -#endif diff --git a/src/py3c/py3shims.h b/src/py3c/py3shims.h deleted file mode 100644 index 947595e978d..00000000000 --- a/src/py3c/py3shims.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (c) 2016, Red Hat, Inc. and/or its affiliates - * Licensed under the MIT license; see py3c.h - */ - -/* - * Shims for new functionality from in Python 3.3+ - * - * See https://docs.python.org/3/c-api/memory.html#raw-memory-interface - */ - -#ifndef _PY3C_RAWMALLOC_H_ -#define _PY3C_RAWMALLOC_H_ -#include -#include - - -/* Py_UNUSED - added in Python 3.4, documneted in 3.7 */ - -#ifndef Py_UNUSED -#ifdef __GNUC__ -#define Py_UNUSED(name) _unused_ ## name __attribute__((unused)) -#else -#define Py_UNUSED(name) _unused_ ## name -#endif -#endif - - -/* PyMem_Raw{Malloc,Realloc,Free} - added in Python 3.4 */ - -#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 4) -#define PyMem_RawMalloc(n) malloc((n) || 1) -#define PyMem_RawRealloc(p, n) realloc(p, (n) || 1) -#define PyMem_RawFree(p) free(p) -#endif /* version < 3.4 */ - - -/* PyMem_RawCalloc - added in Python 3.5 */ - -#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 5) -#define PyMem_RawCalloc(n, s) calloc((n) || 1, (s) || 1) -#endif /* version < 3.5 */ - - -#endif /* _PY3C_RAWMALLOC_H_ */ diff --git a/src/py3c/tpflags.h b/src/py3c/tpflags.h deleted file mode 100644 index aa570352365..00000000000 --- a/src/py3c/tpflags.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates - * Licensed under the MIT license; see py3c.h - */ - -/* - * WARNING: These flags are only to be used in class definitions. - * - * Before including this header file, check that you do not use - * these flags with with PyType_HasFeature. Example command: - * grep -r PyType_HasFeature . - * - * In Python 3, *all objects* have the features corresponding to removed flags. - */ - -#ifndef _PY3C_TPFLAGS_H_ -#define _PY3C_TPFLAGS_H_ -#include - -#if PY_MAJOR_VERSION >= 3 - -#define Py_TPFLAGS_HAVE_GETCHARBUFFER 0 -#define Py_TPFLAGS_HAVE_SEQUENCE_IN 0 -#define Py_TPFLAGS_HAVE_INPLACEOPS 0 -#define Py_TPFLAGS_CHECKTYPES 0 -#define Py_TPFLAGS_HAVE_RICHCOMPARE 0 -#define Py_TPFLAGS_HAVE_WEAKREFS 0 -#define Py_TPFLAGS_HAVE_ITER 0 -#define Py_TPFLAGS_HAVE_CLASS 0 -/* Py_TPFLAGS_HEAPTYPE is still optional in py3 */ -/* Py_TPFLAGS_BASETYPE is still optional in py3 */ -/* Py_TPFLAGS_READY is still useful in py3 */ -/* Py_TPFLAGS_READYING is still useful in py3 */ -/* Py_TPFLAGS_HAVE_GC is still optional in py3 */ -/* Py_TPFLAGS_HAVE_STACKLESS_EXTENSION is still optional in py3 */ -#define Py_TPFLAGS_HAVE_INDEX 0 -/* Py_TPFLAGS_HAVE_VERSION_TAG is still optional in py3 */ -/* Py_TPFLAGS_VALID_VERSION_TAG is still optional in py3 */ -/* Py_TPFLAGS_IS_ABSTRACT is still optional in py3 */ -#define Py_TPFLAGS_HAVE_NEWBUFFER 0 -/* Py_TPFLAGS_INT_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_LONG_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_LIST_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_TUPLE_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_STRING_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_UNICODE_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_DICT_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_BASE_EXC_SUBCLASS is still optional in py3 */ -/* Py_TPFLAGS_TYPE_SUBCLASS is still optional in py3 */ - -/* py 3.4 adds Py_TPFLAGS_HAVE_FINALIZE */ -#endif -#endif /* _PY3C_TPFLAGS_H_ */ diff --git a/tests/interp/compile/use-rs274.cc b/tests/interp/compile/use-rs274.cc index e61ee2ae860..98d891d7ff8 100644 --- a/tests/interp/compile/use-rs274.cc +++ b/tests/interp/compile/use-rs274.cc @@ -45,7 +45,6 @@ int main() { // (and it needs Python.h for the definition of struct inttab) int _task = 0; char _parameter_file_name[LINELEN]; -#if PY_MAJOR_VERSION >=3 extern "C" PyObject* PyInit_emctask(void); extern "C" PyObject* PyInit_interpreter(void); @@ -57,18 +56,6 @@ struct _inittab builtin_modules[] = { { NULL, NULL } }; -#else - -extern "C" void initinterpreter(); -extern "C" void initemccanon(); -extern "C" struct _inittab builtin_modules[]; -struct _inittab builtin_modules[] = { - { (char *) "interpreter", initinterpreter }, - { (char *) "emccanon", initemccanon }, - { NULL, NULL } -}; -#endif - // everything below here is stuff that needs a real implementation, not a dummy // one void INIT_CANON() {}