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 <tredae...@redhat.com>
---
 python/ovs/_json.c | 34 +---------------------------------
 1 file changed, 1 insertion(+), 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
 }
-- 
2.36.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to