Skip to content

Commit 62b0e26

Browse files
committed
fix: create const for default cStr size
1 parent 0925e6b commit 62b0e26

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/_libs/src/vendored/ujson/python/objToJSON.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Numeric decoder derived from TCL library
5151
#include <numpy/ndarraytypes.h>
5252
#include <numpy/npy_math.h>
5353

54+
static const int CSTR_SIZE = 20;
55+
5456
npy_int64 get_nat(void) { return NPY_MIN_INT64; }
5557

5658
typedef const char *(*PFN_PyTypeToUTF8)(JSOBJ obj, JSONTypeContext *ti,
@@ -1008,7 +1010,7 @@ static const char *List_iterGetName(JSOBJ Py_UNUSED(obj),
10081010
//=============================================================================
10091011
static void Index_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10101012
GET_TC(tc)->index = 0;
1011-
GET_TC(tc)->cStr = PyMem_Malloc(20);
1013+
GET_TC(tc)->cStr = PyMem_Malloc(CSTR_SIZE);
10121014
if (!GET_TC(tc)->cStr) {
10131015
PyErr_NoMemory();
10141016
}
@@ -1058,7 +1060,7 @@ static void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10581060
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
10591061
GET_TC(tc)->index = 0;
10601062
enc->outputFormat = VALUES; // for contained series
1061-
GET_TC(tc)->cStr = PyMem_Malloc(20);
1063+
GET_TC(tc)->cStr = PyMem_Malloc(CSTR_SIZE);
10621064
if (!GET_TC(tc)->cStr) {
10631065
PyErr_NoMemory();
10641066
}
@@ -1113,7 +1115,7 @@ static void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
11131115
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
11141116
GET_TC(tc)->index = 0;
11151117
enc->outputFormat = VALUES; // for contained series & index
1116-
GET_TC(tc)->cStr = PyMem_Malloc(20);
1118+
GET_TC(tc)->cStr = PyMem_Malloc(CSTR_SIZE);
11171119
if (!GET_TC(tc)->cStr) {
11181120
PyErr_NoMemory();
11191121
}

0 commit comments

Comments
 (0)