Skip to content

Commit 15c19c0

Browse files
committed
fix: replace PyObject_Malloc with PyMem_Malloc
1 parent f324bd8 commit 15c19c0

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pandas/_libs/src/datetime/date_conversions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ char *int64ToIso(int64_t value, NPY_DATETIMEUNIT valueUnit,
4949
pandas_datetime_to_datetimestruct(value, valueUnit, &dts);
5050

5151
*len = (size_t)get_datetime_iso_8601_strlen(0, base);
52-
char *result = PyObject_Malloc(*len);
52+
char *result = PyMem_Malloc(*len);
5353

5454
if (result == NULL) {
5555
PyErr_NoMemory();
@@ -78,7 +78,7 @@ char *int64ToIsoDuration(int64_t value, size_t *len) {
7878

7979
// Max theoretical length of ISO Duration with 64 bit day
8080
// as the largest unit is 70 characters + 1 for a null terminator
81-
char *result = PyObject_Malloc(71);
81+
char *result = PyMem_Malloc(71);
8282
if (result == NULL) {
8383
PyErr_NoMemory();
8484
return NULL;

pandas/_libs/src/datetime/pd_datetime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static char *PyDateTimeToIso(PyObject *obj, NPY_DATETIMEUNIT base,
170170
}
171171

172172
*len = (size_t)get_datetime_iso_8601_strlen(0, base);
173-
char *result = PyObject_Malloc(*len);
173+
char *result = PyMem_Malloc(*len);
174174
// Check to see if PyDateTime has a timezone.
175175
// Don't convert to UTC if it doesn't.
176176
int is_tz_aware = 0;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ static const char *List_iterGetName(JSOBJ Py_UNUSED(obj),
10081008
//=============================================================================
10091009
static void Index_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10101010
GET_TC(tc)->index = 0;
1011-
GET_TC(tc)->cStr = PyObject_Malloc(20);
1011+
GET_TC(tc)->cStr = PyMem_Malloc(20);
10121012
if (!GET_TC(tc)->cStr) {
10131013
PyErr_NoMemory();
10141014
}
@@ -1058,7 +1058,7 @@ static void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10581058
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
10591059
GET_TC(tc)->index = 0;
10601060
enc->outputFormat = VALUES; // for contained series
1061-
GET_TC(tc)->cStr = PyObject_Malloc(20);
1061+
GET_TC(tc)->cStr = PyMem_Malloc(20);
10621062
if (!GET_TC(tc)->cStr) {
10631063
PyErr_NoMemory();
10641064
}
@@ -1113,7 +1113,7 @@ static void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
11131113
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
11141114
GET_TC(tc)->index = 0;
11151115
enc->outputFormat = VALUES; // for contained series & index
1116-
GET_TC(tc)->cStr = PyObject_Malloc(20);
1116+
GET_TC(tc)->cStr = PyMem_Malloc(20);
11171117
if (!GET_TC(tc)->cStr) {
11181118
PyErr_NoMemory();
11191119
}
@@ -1905,7 +1905,7 @@ static void Object_endTypeContext(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
19051905
GET_TC(tc)->rowLabels = NULL;
19061906
NpyArr_freeLabels(GET_TC(tc)->columnLabels, GET_TC(tc)->columnLabelsLen);
19071907
GET_TC(tc)->columnLabels = NULL;
1908-
PyObject_Free((void *)GET_TC(tc)->cStr);
1908+
PyMem_Free((void *)GET_TC(tc)->cStr);
19091909
GET_TC(tc)->cStr = NULL;
19101910
PyObject_Free(tc->prv);
19111911
tc->prv = NULL;
@@ -1929,7 +1929,7 @@ static const char *Object_getBigNumStringValue(JSOBJ obj, JSONTypeContext *tc,
19291929
size_t *_outLen) {
19301930
PyObject *repr = PyObject_Str(obj);
19311931
const char *str = PyUnicode_AsUTF8AndSize(repr, (Py_ssize_t *)_outLen);
1932-
char *bytes = PyObject_Malloc(*_outLen + 1);
1932+
char *bytes = PyMem_Malloc(*_outLen + 1);
19331933
memcpy(bytes, str, *_outLen + 1);
19341934
GET_TC(tc)->cStr = bytes;
19351935

0 commit comments

Comments
 (0)