Skip to content

Commit a5ba8d3

Browse files
committed
Fix compilation with Python 3.12
Python 3.12 finally removed PyUnicode_GET_SIZE, which we were still using unaware of its deprecation. This commit defines a macro that uses PyUnicode_GET_SIZE for Python 2.7, or PyUnicode_GET_LENGTH (the function we should be using) for Python 3. This addresses the original issue reported in #98. Signed-off-by: Rodrigo Tobar <[email protected]>
1 parent d5e6eae commit a5ba8d3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ijson/backends/yajl2_c/parse_basecoro.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include "kvitems_basecoro.h"
1414
#include "parse_basecoro.h"
1515

16+
#if PY_MAJOR_VERSION >= 3
17+
#define ijson_unicode_length PyUnicode_GET_LENGTH
18+
#else
19+
#define ijson_unicode_length PyUnicode_GET_SIZE
20+
#endif
1621

1722
/*
1823
* __init__, destructor, __iter__ and __next__
@@ -90,7 +95,7 @@ PyObject* parse_basecoro_send_impl(PyObject *self, PyObject *event, PyObject *va
9095
PyObject *last_path;
9196
N_N(last_path = PySequence_GetItem(gen->path, npaths - 1));
9297

93-
if (PyUnicode_GET_SIZE(last_path) > 0) {
98+
if (ijson_unicode_length(last_path) > 0) {
9499
PyObject *new_path;
95100
CONCAT(new_path, last_path, dotitem);
96101
N_M1(PyList_Append(gen->path, new_path));

0 commit comments

Comments
 (0)