summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorTimothy Redaelli <tredaelli@redhat.com>2022-07-18 12:40:01 +0200
committerIlya Maximets <i.maximets@ovn.org>2022-07-22 15:22:01 +0200
commit54ebc235ae4bc1aa76dfb3b44765a0a21926f26a (patch)
tree9d9eae9250818846dbaceb41432b156695bdc56c /python
parent2f4eb2d8c8a9b762a0b2dcf0c3f97fb994ffbef7 (diff)
downloadopenvswitch-54ebc235ae4bc1aa76dfb3b44765a0a21926f26a.tar.gz
python-c-ext: Remove Python 2 support.
Since Python 2 is not supported anymore, remove Python 2 support from C extension too Fixes: 1ca0323e7c29 ("Require Python 3 and remove support for Python 2.") Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'python')
-rw-r--r--python/ovs/_json.c34
1 files changed, 1 insertions, 33 deletions
diff --git a/python/ovs/_json.c b/python/ovs/_json.c
index ef7bb4b8e..80bf9dea3 100644
--- a/python/ovs/_json.c
+++ b/python/ovs/_json.c
@@ -2,10 +2,6 @@
#include <openvswitch/json.h>
#include "structmember.h"
-#if PY_MAJOR_VERSION >= 3
-#define IS_PY3K
-#endif
-
typedef struct {
PyObject_HEAD
struct json_parser *_parser;
@@ -63,21 +59,13 @@ Parser_feed(json_ParserObject * self, PyObject * args)
if (!PyArg_UnpackTuple(args, "input", 1, 1, &input)) {
return NULL;
}
-#ifdef IS_PY3K
if ((input_str = PyUnicode_AsUTF8AndSize(input, &input_sz)) == NULL) {
-#else
- if (PyString_AsStringAndSize(input, &input_str, &input_sz) < 0) {
-#endif
return NULL;
}
rd = json_parser_feed(self->_parser, input_str, (size_t) input_sz);
-#ifdef IS_PY3K
return PyLong_FromSize_t(rd);
-#else
- return PyInt_FromSize_t(rd);
-#endif
}
static PyObject *
@@ -144,11 +132,7 @@ json_to_python(struct json *json)
return PyFloat_FromDouble(json->real);
} /* fall through to treat 0 as int */
case JSON_INTEGER:
-#ifdef IS_PY3K
return PyLong_FromLong((long) json->integer);
-#else
- return PyInt_FromLong((long) json->integer);
-#endif
case JSON_STRING:
return PyUnicode_FromString(json->string);
@@ -225,7 +209,6 @@ static PyTypeObject json_ParserType = {
Parser_new, /* tp_new */
};
-#ifdef IS_PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"ovs._json", /* m_name */
@@ -238,32 +221,17 @@ static struct PyModuleDef moduledef = {
0, /* m_free */
};
-#define INITERROR return NULL
-#else /* !IS_PY3K */
-#define INITERROR return
-#endif
-
PyMODINIT_FUNC
-#ifdef IS_PY3K
PyInit__json(void)
-#else
-init_json(void)
-#endif
{
PyObject *m;
if (PyType_Ready(&json_ParserType) < 0) {
- INITERROR;
+ return NULL;
}
-#ifdef IS_PY3K
m = PyModule_Create(&moduledef);
-#else
- m = Py_InitModule3("ovs._json", NULL, "OVS JSON Parser module");
-#endif
Py_INCREF(&json_ParserType);
PyModule_AddObject(m, "Parser", (PyObject *) & json_ParserType);
-#ifdef IS_PY3K
return m;
-#endif
}