Skip to content

Commit 221ad46

Browse files
authored
Remove sizeof(char) uses (pandas-dev#60717)
1 parent f787764 commit 221ad46

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

pandas/_libs/src/parser/tokenizer.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int parser_init(parser_t *self) {
148148
self->warn_msg = NULL;
149149

150150
// token stream
151-
self->stream = malloc(STREAM_INIT_SIZE * sizeof(char));
151+
self->stream = malloc(STREAM_INIT_SIZE);
152152
if (self->stream == NULL) {
153153
parser_cleanup(self);
154154
return PARSER_OUT_OF_MEMORY;
@@ -221,9 +221,8 @@ static int make_stream_space(parser_t *self, size_t nbytes) {
221221
char *orig_ptr = (void *)self->stream;
222222
TRACE(("\n\nmake_stream_space: nbytes = %zu. grow_buffer(self->stream...)\n",
223223
nbytes))
224-
self->stream =
225-
(char *)grow_buffer((void *)self->stream, self->stream_len,
226-
&self->stream_cap, nbytes * 2, sizeof(char), &status);
224+
self->stream = (char *)grow_buffer((void *)self->stream, self->stream_len,
225+
&self->stream_cap, nbytes * 2, 1, &status);
227226
TRACE(("make_stream_space: self->stream=%p, self->stream_len = %zu, "
228227
"self->stream_cap=%zu, status=%zu\n",
229228
self->stream, self->stream_len, self->stream_cap, status))

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ static char *List_iterGetName(JSOBJ Py_UNUSED(obj),
984984
//=============================================================================
985985
static void Index_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
986986
GET_TC(tc)->index = 0;
987-
GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char));
987+
GET_TC(tc)->cStr = PyObject_Malloc(20);
988988
if (!GET_TC(tc)->cStr) {
989989
PyErr_NoMemory();
990990
}
@@ -998,10 +998,10 @@ static int Index_iterNext(JSOBJ obj, JSONTypeContext *tc) {
998998
const Py_ssize_t index = GET_TC(tc)->index;
999999
Py_XDECREF(GET_TC(tc)->itemValue);
10001000
if (index == 0) {
1001-
memcpy(GET_TC(tc)->cStr, "name", sizeof(char) * 5);
1001+
memcpy(GET_TC(tc)->cStr, "name", 5);
10021002
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "name");
10031003
} else if (index == 1) {
1004-
memcpy(GET_TC(tc)->cStr, "data", sizeof(char) * 5);
1004+
memcpy(GET_TC(tc)->cStr, "data", 5);
10051005
GET_TC(tc)->itemValue = get_values(obj);
10061006
if (!GET_TC(tc)->itemValue) {
10071007
return 0;
@@ -1033,7 +1033,7 @@ static char *Index_iterGetName(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc,
10331033
static void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10341034
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
10351035
GET_TC(tc)->index = 0;
1036-
GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char));
1036+
GET_TC(tc)->cStr = PyObject_Malloc(20);
10371037
enc->outputFormat = VALUES; // for contained series
10381038
if (!GET_TC(tc)->cStr) {
10391039
PyErr_NoMemory();
@@ -1048,13 +1048,13 @@ static int Series_iterNext(JSOBJ obj, JSONTypeContext *tc) {
10481048
const Py_ssize_t index = GET_TC(tc)->index;
10491049
Py_XDECREF(GET_TC(tc)->itemValue);
10501050
if (index == 0) {
1051-
memcpy(GET_TC(tc)->cStr, "name", sizeof(char) * 5);
1051+
memcpy(GET_TC(tc)->cStr, "name", 5);
10521052
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "name");
10531053
} else if (index == 1) {
1054-
memcpy(GET_TC(tc)->cStr, "index", sizeof(char) * 6);
1054+
memcpy(GET_TC(tc)->cStr, "index", 6);
10551055
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "index");
10561056
} else if (index == 2) {
1057-
memcpy(GET_TC(tc)->cStr, "data", sizeof(char) * 5);
1057+
memcpy(GET_TC(tc)->cStr, "data", 5);
10581058
GET_TC(tc)->itemValue = get_values(obj);
10591059
if (!GET_TC(tc)->itemValue) {
10601060
return 0;
@@ -1088,7 +1088,7 @@ static char *Series_iterGetName(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc,
10881088
static void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
10891089
PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder;
10901090
GET_TC(tc)->index = 0;
1091-
GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char));
1091+
GET_TC(tc)->cStr = PyObject_Malloc(20);
10921092
enc->outputFormat = VALUES; // for contained series & index
10931093
if (!GET_TC(tc)->cStr) {
10941094
PyErr_NoMemory();
@@ -1103,13 +1103,13 @@ static int DataFrame_iterNext(JSOBJ obj, JSONTypeContext *tc) {
11031103
const Py_ssize_t index = GET_TC(tc)->index;
11041104
Py_XDECREF(GET_TC(tc)->itemValue);
11051105
if (index == 0) {
1106-
memcpy(GET_TC(tc)->cStr, "columns", sizeof(char) * 8);
1106+
memcpy(GET_TC(tc)->cStr, "columns", 8);
11071107
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "columns");
11081108
} else if (index == 1) {
1109-
memcpy(GET_TC(tc)->cStr, "index", sizeof(char) * 6);
1109+
memcpy(GET_TC(tc)->cStr, "index", 6);
11101110
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "index");
11111111
} else if (index == 2) {
1112-
memcpy(GET_TC(tc)->cStr, "data", sizeof(char) * 5);
1112+
memcpy(GET_TC(tc)->cStr, "data", 5);
11131113
Py_INCREF(obj);
11141114
GET_TC(tc)->itemValue = obj;
11151115
} else {

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ cdef char* c_strftime(npy_datetimestruct *dts, char *fmt):
679679
c_date.tm_yday = get_day_of_year(dts.year, dts.month, dts.day) - 1
680680
c_date.tm_isdst = -1
681681

682-
result = <char*>malloc(result_len * sizeof(char))
682+
result = <char*>malloc(result_len)
683683
if result is NULL:
684684
raise MemoryError()
685685

0 commit comments

Comments
 (0)