Skip to content

Commit

Permalink
Remove 2/3 compatibility leftover
Browse files Browse the repository at this point in the history
This macro was previously used to select different functions between
python 2 and 3, but those days are gone. While removing it I also
simplified a few calling places that didn't require passing a length,
or where casting was necessary.

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Dec 25, 2024
1 parent 0f089d4 commit 829655e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
around correct error handling.
* Pointing to our own fork of yajl (for when we build it ourselves)
that contains fixes for all known CVEs (#126).
* Removed leftover compatibility bits in the C backend.
* Fixed potential issue with `yajl` and `yajl2` backends
where crashes could occur at interpreter shutdown.
* Removed tox.
Expand Down
4 changes: 2 additions & 2 deletions src/ijson/backends/ext/_yajl2/basic_parse_basecoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int number(void * ctx, const char *numberVal, size_t numberLen) {

static int string_cb(void * ctx, const unsigned char *stringVal, size_t stringLen) {
PyObject *val;
Z_N(val = PyUnicode_FromStringAndSize((char *)stringVal, stringLen))
Z_N(val = PyUnicode_FromStringAndSize((const char *)stringVal, stringLen))
return add_event_and_value(ctx, get_enames(ctx).string_ename, val);
}

Expand All @@ -111,7 +111,7 @@ static int start_map(void *ctx) {

static int map_key(void *ctx, const unsigned char *key, size_t stringLen) {
PyObject *val;
Z_N(val = STRING_FROM_UTF8(key, stringLen))
Z_N(val = PyUnicode_FromStringAndSize((const char *)key, stringLen))
return add_event_and_value(ctx, get_enames(ctx).map_key_ename, val);
}

Expand Down
2 changes: 0 additions & 2 deletions src/ijson/backends/ext/_yajl2/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

#define STRING_FROM_UTF8(val, len) PyUnicode_FromStringAndSize((const char *)val, len)

/*
* Error-handling macros to help reducing clutter in the code.
* N: NULL, M1: -1, Z: zero, NZ: not-zero, LZ: less-than-zero
Expand Down
8 changes: 4 additions & 4 deletions src/ijson/backends/ext/_yajl2/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ static int _yajl2_mod_exec(PyObject *m)

yajl2_state *state;
M1_N(state = get_state(m));
state->dot = STRING_FROM_UTF8(".", 1);
state->item = STRING_FROM_UTF8("item", 4);
state->dotitem = STRING_FROM_UTF8(".item", 5);
state->dot = PyUnicode_FromString(".");
state->item = PyUnicode_FromString("item");
state->dotitem = PyUnicode_FromString(".item");

#define INIT_ENAME(x) state->enames.x##_ename = STRING_FROM_UTF8(#x, strlen(#x))
#define INIT_ENAME(x) state->enames.x##_ename = PyUnicode_FromString(#x)
INIT_ENAME(null);
INIT_ENAME(boolean);
INIT_ENAME(integer);
Expand Down
2 changes: 1 addition & 1 deletion src/ijson/backends/ext/_yajl2/parse_basecoro.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int parse_basecoro_init(ParseBasecoro *self, PyObject *args, PyObject *kw
M1_N(self->module_state = get_state_from_imported_module());

PyObject *empty;
M1_N(empty = STRING_FROM_UTF8("", 0));
M1_N(empty = PyUnicode_FromString(""));
int res = PyList_Append(self->path, empty);
Py_DECREF(empty);
M1_M1(res);
Expand Down

0 comments on commit 829655e

Please sign in to comment.