Skip to content

Commit

Permalink
Remove C code for compatibility with < 3.5
Browse files Browse the repository at this point in the history
Most of these were small macro checks to avoid compiling certain bits
and pieces, which can now be gone for a smaller, slightly easier to
maintain codebase.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Nov 25, 2023
1 parent 41a30e2 commit 087b8d5
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 142 deletions.
10 changes: 2 additions & 8 deletions ijson/backends/yajl2_c/async_reading_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "basic_parse_basecoro.h"
#include "common.h"

#if PY_VERSION_HEX >= 0x03050000
static int async_reading_generator_init(async_reading_generator *self, PyObject *args, PyObject *kwargs)
{
self->coro = NULL;
Expand Down Expand Up @@ -204,19 +203,14 @@ static PyAsyncMethods async_reading_generator_methods = {
};

PyTypeObject AsyncReadingGeneratorType = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(async_reading_generator),
.tp_name = "_yajl2.async_reading_generator",
.tp_doc = "The awaitable yielded by the asynchronous iterables",
.tp_init = (initproc)async_reading_generator_init,
.tp_dealloc = (destructor)async_reading_generator_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_async = &async_reading_generator_methods,
.tp_iter = ijson_return_self,
.tp_iternext = async_reading_generator_next,
};
#endif // PY_VERSION_HEX >= 0x03050000
};
2 changes: 0 additions & 2 deletions ijson/backends/yajl2_c/async_reading_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if PY_VERSION_HEX >= 0x03050000
#include "coro_utils.h"

/**
Expand All @@ -36,6 +35,5 @@ typedef struct {
void async_reading_generator_add_coro(async_reading_generator *self, pipeline_node *coro_pipeline);

extern PyTypeObject AsyncReadingGeneratorType;
#endif // PY_VERSION_HEX >= 0x03050000

#endif // ASYNC_READING_GENERATOR_H
6 changes: 1 addition & 5 deletions ijson/backends/yajl2_c/basic_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ static PyObject* basicparsegen_iternext(PyObject *self)


PyTypeObject BasicParseGen_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(BasicParseGen),
.tp_name = "_yajl2.basic_parse",
.tp_doc = "Generator of (evt,value)",
.tp_init = (initproc)basicparsegen_init,
.tp_dealloc = (destructor)basicparsegen_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = basicparsegen_iternext
};
9 changes: 1 addition & 8 deletions ijson/backends/yajl2_c/basic_parse_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "common.h"
#include "coro_utils.h"

#if PY_VERSION_HEX >= 0x03050000
/**
* basic_parse_async asynchronous iterable object structure
*/
Expand Down Expand Up @@ -56,18 +55,12 @@ static PyAsyncMethods basicparseasync_methods = {
};

PyTypeObject BasicParseAsync_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(BasicParseAsync),
.tp_name = "_yajl2.basic_parse_async",
.tp_doc = "Asynchronous iterable yielding (evt,value) tuples",
.tp_init = (initproc)basicparseasync_init,
.tp_dealloc = (destructor)basicparseasync_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_async = &basicparseasync_methods
};

#endif // PY_VERSION_HEX >= 0x03050000
};
2 changes: 0 additions & 2 deletions ijson/backends/yajl2_c/basic_parse_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if PY_VERSION_HEX >= 0x03050000
/**
* basic_parse_async asynchronous iterable object type
*/
extern PyTypeObject BasicParseAsync_Type;
#endif // PY_VERSION_HEX >= 0x03050000

#endif // BASIC_PARSE_H
25 changes: 2 additions & 23 deletions ijson/backends/yajl2_c/basic_parse_basecoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ static int boolean(void * ctx, int val) {
static int yajl_integer(void *ctx, long long val)
{
PyObject *ival;
#if PY_MAJOR_VERSION < 3
if (val <= 0xFFFFFFFF) {
Z_N(ival = PyInt_FromLong((long)val));
}
else
#endif
{
Z_N(ival = PyLong_FromLongLong(val))
}
Z_N(ival = PyLong_FromLongLong(val))
return add_event_and_value(ctx, enames.number_ename, ival);
}

Expand Down Expand Up @@ -90,12 +82,7 @@ static int number(void * ctx, const char *numberVal, size_t numberLen) {
memcpy(nval, numberVal, numberLen);
nval[numberLen] = 0;
char *endptr;
#if PY_MAJOR_VERSION >= 3
val = PyLong_FromString(nval, &endptr, 10);
#else
// returns either PyLong or PyInt
val = PyInt_FromString(nval, &endptr, 10);
#endif
free(nval);
assert(("string provided by yajl is not an integer",
val != NULL && endptr != nval));
Expand Down Expand Up @@ -168,11 +155,7 @@ PyObject* ijson_yajl_parse(yajl_handle handle, char *buffer, size_t length)
// automatically, so we show the bytes instead
if (!error_obj) {
PyErr_Clear();
#if PY_MAJOR_VERSION >= 3
error_obj = PyBytes_FromString((char *)perror);
#else
error_obj = PyString_FromString((char *)perror);
#endif
PyErr_Clear();
}
PyErr_SetObject(IncompleteJSONError, error_obj);
Expand Down Expand Up @@ -273,17 +256,13 @@ static PyMethodDef basic_parse_basecoro_methods[] = {
};

PyTypeObject BasicParseBasecoro_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(BasicParseBasecoro),
.tp_name = "_yajl2.basic_parse_basecoro",
.tp_doc = "Coroutine dispatching (evt,value) pairs",
.tp_init = (initproc)basic_parse_basecoro_init,
.tp_dealloc = (destructor)basic_parse_basecoro_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = ijson_return_none,
.tp_methods = basic_parse_basecoro_methods
Expand Down
3 changes: 0 additions & 3 deletions ijson/backends/yajl2_c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include <Python.h>

#define STRING_FROM_UTF8(val, len) PyUnicode_FromStringAndSize((const char *)val, len)
#if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_HAVE_ITER 0
#endif

/*
* Error-handling macros to help reducing clutter in the code.
Expand Down
6 changes: 1 addition & 5 deletions ijson/backends/yajl2_c/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,13 @@ static PyObject* itemsgen_iternext(PyObject *self)
* items generator object type
*/
PyTypeObject ItemsGen_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(ItemsGen),
.tp_name = "_yajl2.items",
.tp_doc = "Generates items",
.tp_init = (initproc)itemsgen_init,
.tp_dealloc = (destructor)itemsgen_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = itemsgen_iternext
};
9 changes: 1 addition & 8 deletions ijson/backends/yajl2_c/items_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "common.h"
#include "coro_utils.h"

#if PY_VERSION_HEX >= 0x03050000
/**
* items_async asynchronous iterable object structure
*/
Expand Down Expand Up @@ -64,18 +63,12 @@ static PyAsyncMethods itemsasync_methods = {
};

PyTypeObject ItemsAsync_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(ItemsAsync),
.tp_name = "_yajl2._items_async",
.tp_doc = "Asynchronous iterable yielding fully-built items",
.tp_init = (initproc)itemsasync_init,
.tp_dealloc = (destructor)itemsasync_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_async = &itemsasync_methods
};

#endif // PY_VERSION_HEX >= 0x03050000
};
2 changes: 0 additions & 2 deletions ijson/backends/yajl2_c/items_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if PY_VERSION_HEX >= 0x03050000
/**
* items_async asynchronous iterable object type
*/
extern PyTypeObject ItemsAsync_Type;
#endif // PY_VERSION_HEX >= 0x03050000

#endif // ITEMS_ASYNC_H
6 changes: 1 addition & 5 deletions ijson/backends/yajl2_c/items_basecoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,13 @@ static PyMethodDef items_basecoro_methods[] = {
* items generator object type
*/
PyTypeObject ItemsBasecoro_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(ItemsBasecoro),
.tp_name = "_yajl2.items_basecoro",
.tp_doc = "Coroutine dispatching fully-built objects for the given prefix",
.tp_init = (initproc)items_basecoro_init,
.tp_dealloc = (destructor)items_basecoro_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = ijson_return_none,
.tp_methods = items_basecoro_methods
Expand Down
6 changes: 1 addition & 5 deletions ijson/backends/yajl2_c/kvitems.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,13 @@ static PyObject* kvitemsgen_iternext(PyObject *self)
* kvitems generator object type
*/
PyTypeObject KVItemsGen_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(KVItemsGen),
.tp_name = "_yajl2.kvitems",
.tp_doc = "Generates key/value pairs",
.tp_init = (initproc)kvitemsgen_init,
.tp_dealloc = (destructor)kvitemsgen_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = kvitemsgen_iternext
};
9 changes: 1 addition & 8 deletions ijson/backends/yajl2_c/kvitems_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "common.h"
#include "coro_utils.h"

#if PY_VERSION_HEX >= 0x03050000
/**
* kvitems_async asynchronous iterable object structure
*/
Expand Down Expand Up @@ -64,18 +63,12 @@ static PyAsyncMethods kvitemsasync_methods = {
};

PyTypeObject KVItemsAsync_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(KVItemsAsync),
.tp_name = "_yajl2._kvitems_async",
.tp_doc = "Asynchronous iterable yielding key/value pairs",
.tp_init = (initproc)kvitemsasync_init,
.tp_dealloc = (destructor)kvitemsasync_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_as_async = &kvitemsasync_methods
};

#endif // PY_VERSION_HEX >= 0x03050000
};
2 changes: 0 additions & 2 deletions ijson/backends/yajl2_c/kvitems_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#if PY_VERSION_HEX >= 0x03050000
/**
* kvitems_async asynchronous iterable object type
*/
extern PyTypeObject KVItemsAsync_Type;
#endif // PY_VERSION_HEX >= 0x03050000

#endif // KVITEMS_ASYNC_H
6 changes: 1 addition & 5 deletions ijson/backends/yajl2_c/kvitems_basecoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,13 @@ static PyMethodDef kvitems_basecoro_methods[] = {
* kvitems generator object type
*/
PyTypeObject KVItemsBasecoro_Type = {
#if PY_MAJOR_VERSION >= 3
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
#endif
.tp_basicsize = sizeof(KVItemsBasecoro),
.tp_name = "_yajl2.kvitems_basecoro",
.tp_doc = "Coroutine dispatching (key, value) tuples",
.tp_init = (initproc)kvitems_basecoro_init,
.tp_dealloc = (destructor)kvitems_basecoro_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_iter = ijson_return_self,
.tp_iternext = ijson_return_none,
.tp_methods = kvitems_basecoro_methods
Expand Down
Loading

0 comments on commit 087b8d5

Please sign in to comment.