From 07f04c5e8694ddd5ecfcc516ff28f0e99918b587 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sat, 23 Jan 2021 15:21:53 -0300 Subject: [PATCH 01/15] STYLE: Fix incorrect path to ujson directory --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index d2f20a91cc654..597aced96eb18 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -64,7 +64,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then # this particular codebase (e.g. src/headers, src/klib). However, # we can lint all header files since they aren't "generated" like C files are. MSG='Linting .c and .h' ; echo $MSG - cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp + cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp RET=$(($RET + $?)) ; echo $MSG "DONE" fi From daa988827087a492075b63af57ff1ccc6fa28b8f Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 10:56:08 -0300 Subject: [PATCH 02/15] STYLE: Remove extra spaces and redundant blank line --- pandas/_libs/src/ujson/lib/ultrajsonenc.c | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/pandas/_libs/src/ujson/lib/ultrajsonenc.c b/pandas/_libs/src/ujson/lib/ultrajsonenc.c index 2af10a5b72d33..4469631b7b3f7 100644 --- a/pandas/_libs/src/ujson/lib/ultrajsonenc.c +++ b/pandas/_libs/src/ujson/lib/ultrajsonenc.c @@ -728,20 +728,19 @@ INLINE_PREFIX void FASTCALL_MSVC strreverse(char *begin, while (end > begin) aux = *end, *end-- = *begin, *begin++ = aux; } -void Buffer_AppendIndentNewlineUnchecked(JSONObjectEncoder *enc) -{ +void Buffer_AppendIndentNewlineUnchecked(JSONObjectEncoder *enc) { if (enc->indent > 0) Buffer_AppendCharUnchecked(enc, '\n'); } // This function could be refactored to only accept enc as an argument, // but this is a straight vendor from ujson source -void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value) -{ +void Buffer_AppendIndentUnchecked(JSONObjectEncoder *enc, JSINT32 value) { int i; - if (enc->indent > 0) + if (enc->indent > 0) { while (value-- > 0) for (i = 0; i < enc->indent; i++) Buffer_AppendCharUnchecked(enc, ' '); + } } void Buffer_AppendIntUnchecked(JSONObjectEncoder *enc, JSINT32 value) { @@ -976,7 +975,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, enc->iterBegin(obj, &tc); Buffer_AppendCharUnchecked(enc, '['); - Buffer_AppendIndentNewlineUnchecked (enc); + Buffer_AppendIndentNewlineUnchecked(enc); while (enc->iterNext(obj, &tc)) { if (count > 0) { @@ -984,20 +983,20 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, #ifndef JSON_NO_EXTRA_WHITESPACE Buffer_AppendCharUnchecked(buffer, ' '); #endif - Buffer_AppendIndentNewlineUnchecked (enc); + Buffer_AppendIndentNewlineUnchecked(enc); } iterObj = enc->iterGetValue(obj, &tc); enc->level++; - Buffer_AppendIndentUnchecked (enc, enc->level); + Buffer_AppendIndentUnchecked(enc, enc->level); encode(iterObj, enc, NULL, 0); count++; } enc->iterEnd(obj, &tc); - Buffer_AppendIndentNewlineUnchecked (enc); - Buffer_AppendIndentUnchecked (enc, enc->level); + Buffer_AppendIndentNewlineUnchecked(enc); + Buffer_AppendIndentUnchecked(enc, enc->level); Buffer_AppendCharUnchecked(enc, ']'); break; } @@ -1007,7 +1006,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, enc->iterBegin(obj, &tc); Buffer_AppendCharUnchecked(enc, '{'); - Buffer_AppendIndentNewlineUnchecked (enc); + Buffer_AppendIndentNewlineUnchecked(enc); while (enc->iterNext(obj, &tc)) { if (count > 0) { @@ -1015,21 +1014,21 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, #ifndef JSON_NO_EXTRA_WHITESPACE Buffer_AppendCharUnchecked(enc, ' '); #endif - Buffer_AppendIndentNewlineUnchecked (enc); + Buffer_AppendIndentNewlineUnchecked(enc); } iterObj = enc->iterGetValue(obj, &tc); objName = enc->iterGetName(obj, &tc, &szlen); enc->level++; - Buffer_AppendIndentUnchecked (enc, enc->level); + Buffer_AppendIndentUnchecked(enc, enc->level); encode(iterObj, enc, objName, szlen); count++; } enc->iterEnd(obj, &tc); - Buffer_AppendIndentNewlineUnchecked (enc); - Buffer_AppendIndentUnchecked (enc, enc->level); + Buffer_AppendIndentNewlineUnchecked(enc); + Buffer_AppendIndentUnchecked(enc, enc->level); Buffer_AppendCharUnchecked(enc, '}'); break; } @@ -1134,7 +1133,6 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, } break; - } } From dfd71ebae929d755e4e05a469d73b9be672c438b Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 11:45:49 -0300 Subject: [PATCH 03/15] STYLE: Add at least two spaces between code and comments --- pandas/_libs/src/ujson/python/objToJSON.c | 34 +++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 59298522d86d1..a86dcec1e12a0 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -64,9 +64,9 @@ typedef char *(*PFN_PyTypeToUTF8)(JSOBJ obj, JSONTypeContext *ti, typedef struct __NpyArrContext { PyObject *array; char *dataptr; - int curdim; // current dimension in array's order - int stridedim; // dimension we are striding over - int inc; // stride dimension increment (+/- 1) + int curdim; // current dimension in array's order + int stridedim; // dimension we are striding over + int inc; // stride dimension increment (+/- 1) npy_intp dim; npy_intp stride; npy_intp ndim; @@ -83,8 +83,8 @@ typedef struct __PdBlockContext { int ncols; int transpose; - int *cindices; // frame column -> block column map - NpyArrContext **npyCtxts; // NpyArrContext for each column + int *cindices; // frame column -> block column map + NpyArrContext **npyCtxts; // NpyArrContext for each column } PdBlockContext; typedef struct __TypeContext { @@ -346,7 +346,6 @@ static char *NpyTimeDeltaToIsoCallback(JSOBJ Py_UNUSED(unused), /* JSON callback */ static char *PyDateTimeToIsoCallback(JSOBJ obj, JSONTypeContext *tc, size_t *len) { - if (!PyDate_Check(obj)) { PyErr_SetString(PyExc_TypeError, "Expected date object"); return NULL; @@ -1108,7 +1107,7 @@ void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) { PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder; GET_TC(tc)->index = 0; GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char)); - enc->outputFormat = VALUES; // for contained series + enc->outputFormat = VALUES; // for contained series if (!GET_TC(tc)->cStr) { PyErr_NoMemory(); } @@ -1164,7 +1163,7 @@ void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) { PyObjectEncoder *enc = (PyObjectEncoder *)tc->encoder; GET_TC(tc)->index = 0; GET_TC(tc)->cStr = PyObject_Malloc(20 * sizeof(char)); - enc->outputFormat = VALUES; // for contained series & index + enc->outputFormat = VALUES; // for contained series & index if (!GET_TC(tc)->cStr) { PyErr_NoMemory(); } @@ -1364,7 +1363,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc, } else { if (PyDelta_Check(item)) { nanosecVal = total_seconds(item) * - 1000000000LL; // nanoseconds per second + 1000000000LL; // nanoseconds per second } else { // datetime.* objects don't follow above rules nanosecVal = PyDateTimeToEpoch(item, NPY_FR_ns); @@ -1395,13 +1394,13 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc, break; } } else { - cLabel = PyObject_Malloc(21); // 21 chars for int64 + cLabel = PyObject_Malloc(21); // 21 chars for int64 sprintf(cLabel, "%" NPY_DATETIME_FMT, NpyDateTimeToEpoch(nanosecVal, base)); len = strlen(cLabel); } } - } else { // Fallback to string representation + } else { // Fallback to string representation // Replace item with the string to keep it alive. Py_SETREF(item, PyObject_Str(item)); if (item == NULL) { @@ -1502,7 +1501,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { if (longVal == get_nat()) { tc->type = JT_NULL; } else { - if (enc->datetimeIso) { if (enc->npyType == NPY_TIMEDELTA) { pc->PyTypeToUTF8 = NpyTimeDeltaToIsoCallback; @@ -2039,7 +2037,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args, PyObject *newobj; PyObject *oinput = NULL; PyObject *oensureAscii = NULL; - int idoublePrecision = 10; // default double precision setting + int idoublePrecision = 10; // default double precision setting PyObject *oencodeHTMLChars = NULL; char *sOrient = NULL; char *sdateFormat = NULL; @@ -2052,7 +2050,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args, Object_endTypeContext, Object_getStringValue, Object_getLongValue, - NULL, // getIntValue is unused + NULL, // getIntValue is unused Object_getDoubleValue, Object_getBigNumStringValue, Object_iterBegin, @@ -2064,11 +2062,11 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args, PyObject_Malloc, PyObject_Realloc, PyObject_Free, - -1, // recursionMax + -1, // recursionMax idoublePrecision, - 1, // forceAscii - 0, // encodeHTMLChars - 0, // indent + 1, // forceAscii + 0, // encodeHTMLChars + 0, // indent }}; JSONObjectEncoder *encoder = (JSONObjectEncoder *)&pyEncoder; From 39292c5d8bbf9ad03cb36d660cfb2f836a28c34f Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 11:51:17 -0300 Subject: [PATCH 04/15] STYLE: Replace sprinf with snprinf --- pandas/_libs/src/ujson/python/objToJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index a86dcec1e12a0..890ad94bbfc5c 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -1395,7 +1395,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc, } } else { cLabel = PyObject_Malloc(21); // 21 chars for int64 - sprintf(cLabel, "%" NPY_DATETIME_FMT, + snprintf(cLabel, "%" NPY_DATETIME_FMT, NpyDateTimeToEpoch(nanosecVal, base)); len = strlen(cLabel); } From b0ed1b303a72a6b209cf9dc30b567751dce0b679 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 12:02:12 -0300 Subject: [PATCH 05/15] STYLE: Remove redundant blank line at the end of code block --- pandas/_libs/src/ujson/python/ujson.c | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/ujson.c b/pandas/_libs/src/ujson/python/ujson.c index a40f2709c0c61..4710c86f2c6a1 100644 --- a/pandas/_libs/src/ujson/python/ujson.c +++ b/pandas/_libs/src/ujson/python/ujson.c @@ -75,5 +75,4 @@ static PyModuleDef moduledef = { PyMODINIT_FUNC PyInit_json(void) { initObjToJSON(); // TODO: clean up, maybe via tp_free? return PyModuleDef_Init(&moduledef); - } From 932a43af918e74a775c9eca9261eccf6a87e05c0 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 12:30:07 -0300 Subject: [PATCH 06/15] STYLE: Fix header guard --- pandas/_libs/src/ujson/python/date_conversions.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/src/ujson/python/date_conversions.h b/pandas/_libs/src/ujson/python/date_conversions.h index 23e36999be43f..c872fdeca1a15 100644 --- a/pandas/_libs/src/ujson/python/date_conversions.h +++ b/pandas/_libs/src/ujson/python/date_conversions.h @@ -1,5 +1,5 @@ -#ifndef PANDAS__LIBS_SRC_UJSON_DATE_CONVERSIONS -#define PANDAS__LIBS_SRC_UJSON_DATE_CONVERSIONS +#ifndef PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_ +#define PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_ #define PY_SSIZE_T_CLEAN #include @@ -29,4 +29,4 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base); char *int64ToIsoDuration(int64_t value, size_t *len); -#endif +#endif // PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_ From a52960bf4d28d12a0ebe279c47049b73847f67fc Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 12:41:56 -0300 Subject: [PATCH 07/15] STYLE: Add a space between // and comment --- pandas/_libs/src/ujson/python/date_conversions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/date_conversions.c b/pandas/_libs/src/ujson/python/date_conversions.c index 4c25ab572bebe..62eb5ffb00771 100644 --- a/pandas/_libs/src/ujson/python/date_conversions.c +++ b/pandas/_libs/src/ujson/python/date_conversions.c @@ -109,7 +109,7 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) { "Could not convert PyDateTime to numpy datetime"); } // TODO: is setting errMsg required? - //((JSONObjectEncoder *)tc->encoder)->errorMsg = ""; + // ((JSONObjectEncoder *)tc->encoder)->errorMsg = ""; // return NULL; } From 10384372b6cfa581921e210f205fd2aa1df61443 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 14:23:02 -0300 Subject: [PATCH 08/15] STYLE: Add two spaces between code and comment --- pandas/_libs/src/ujson/python/objToJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 890ad94bbfc5c..b9ae177b32cc6 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -1606,7 +1606,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { if (PyObject_HasAttrString(obj, "value")) { value = get_long_attr(obj, "value"); } else { - value = total_seconds(obj) * 1000000000LL; // nanoseconds per second + value = total_seconds(obj) * 1000000000LL; // nanoseconds per sec } if (value == get_nat()) { From 2475c47c90655bf64a8d4f6cc13da7482777fc81 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 17:22:43 -0300 Subject: [PATCH 09/15] STYLE: Add copyright notice --- pandas/_libs/src/ujson/python/date_conversions.c | 9 ++++++++- pandas/_libs/src/ujson/python/date_conversions.h | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/src/ujson/python/date_conversions.c b/pandas/_libs/src/ujson/python/date_conversions.c index 62eb5ffb00771..0744c6af74480 100644 --- a/pandas/_libs/src/ujson/python/date_conversions.c +++ b/pandas/_libs/src/ujson/python/date_conversions.c @@ -1,3 +1,10 @@ +/* +Copyright (c) 2020, PyData Development Team +All rights reserved. +Distributed under the terms of the BSD Simplified License. +The full license is in the LICENSE file, distributed with this software. +*/ + // Conversion routines that are useful for serialization, // but which don't interact with JSON objects directly @@ -108,7 +115,7 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) { PyErr_SetString(PyExc_ValueError, "Could not convert PyDateTime to numpy datetime"); } - // TODO: is setting errMsg required? + // TODO(username): is setting errMsg required? // ((JSONObjectEncoder *)tc->encoder)->errorMsg = ""; // return NULL; } diff --git a/pandas/_libs/src/ujson/python/date_conversions.h b/pandas/_libs/src/ujson/python/date_conversions.h index c872fdeca1a15..efd707f04197c 100644 --- a/pandas/_libs/src/ujson/python/date_conversions.h +++ b/pandas/_libs/src/ujson/python/date_conversions.h @@ -1,3 +1,10 @@ +/* +Copyright (c) 2020, PyData Development Team +All rights reserved. +Distributed under the terms of the BSD Simplified License. +The full license is in the LICENSE file, distributed with this software. +*/ + #ifndef PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_ #define PANDAS__LIBS_SRC_UJSON_PYTHON_DATE_CONVERSIONS_H_ @@ -14,8 +21,8 @@ int scaleNanosecToUnit(npy_int64 *value, NPY_DATETIMEUNIT unit); // len is mutated to save the length of the returned string char *int64ToIso(int64_t value, NPY_DATETIMEUNIT base, size_t *len); -// TODO: this function doesn't do a lot; should augment or replace with -// scaleNanosecToUnit +// TODO(username): this function doesn't do a lot; should augment or +// replace with scaleNanosecToUnit npy_datetime NpyDateTimeToEpoch(npy_datetime dt, NPY_DATETIMEUNIT base); // Converts a Python object representing a Date / Datetime to ISO format From faff6f7b70b79afc277ae242cf9c35790db8d3e7 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 17:26:55 -0300 Subject: [PATCH 10/15] STYLE: Add missing username in TODO --- pandas/_libs/src/ujson/python/objToJSON.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index b9ae177b32cc6..457c9e9d15fe4 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -1519,7 +1519,8 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { } } - // TODO: this prevents infinite loop with mixed-type DataFrames; + // TODO(username): this prevents infinite loop with + // mixed-type DataFrames; // refactor enc->npyCtxtPassthru = NULL; enc->npyType = -1; @@ -1618,7 +1619,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) { } else { unit = ((PyObjectEncoder *)tc->encoder)->datetimeUnit; if (scaleNanosecToUnit(&value, unit) != 0) { - // TODO: Add some kind of error handling here + // TODO(username): Add some kind of error handling here } exc = PyErr_Occurred(); From fed2290bc05337174671ac5ea0e2a4826c9e6b9d Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Sun, 24 Jan 2021 17:30:03 -0300 Subject: [PATCH 11/15] STYLE: Add missing username in TODO --- pandas/_libs/src/ujson/python/ujson.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/ujson.c b/pandas/_libs/src/ujson/python/ujson.c index 4710c86f2c6a1..32011cb9cb92c 100644 --- a/pandas/_libs/src/ujson/python/ujson.c +++ b/pandas/_libs/src/ujson/python/ujson.c @@ -73,6 +73,6 @@ static PyModuleDef moduledef = { PyMODINIT_FUNC PyInit_json(void) { - initObjToJSON(); // TODO: clean up, maybe via tp_free? + initObjToJSON(); // TODO(username): clean up, maybe via tp_free? return PyModuleDef_Init(&moduledef); } From badb0a46bca441d03d28f83c12187fbf8d9dfab1 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Mon, 25 Jan 2021 11:35:19 -0300 Subject: [PATCH 12/15] STYLE: Replace snprintf with sprintf --- pandas/_libs/src/ujson/python/objToJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 457c9e9d15fe4..426b7993e7c25 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -1395,7 +1395,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc, } } else { cLabel = PyObject_Malloc(21); // 21 chars for int64 - snprintf(cLabel, "%" NPY_DATETIME_FMT, + sprintf(cLabel, "%" NPY_DATETIME_FMT, NpyDateTimeToEpoch(nanosecVal, base)); len = strlen(cLabel); } From e8a9d74b94820b01faea804623543fe730114afe Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Mon, 25 Jan 2021 11:51:08 -0300 Subject: [PATCH 13/15] STYLE: Add -runtime/printf to list of filters --- ci/code_checks.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 597aced96eb18..269181b58e502 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -58,13 +58,14 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then # readability/casting: Warnings about C casting instead of C++ casting # runtime/int: Warnings about using C number types instead of C++ ones # build/include_subdir: Warnings about prefacing included header files with directory + # runtime/printf: Warnings about using sprintf instead of snprintf # We don't lint all C files because we don't want to lint any that are built # from Cython files nor do we want to lint C files that we didn't modify for # this particular codebase (e.g. src/headers, src/klib). However, # we can lint all header files since they aren't "generated" like C files are. MSG='Linting .c and .h' ; echo $MSG - cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp + cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir,-runtime/printf pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp RET=$(($RET + $?)) ; echo $MSG "DONE" fi From 2bc49d2059b25c29efaabe1bcc1b67e5dd8c9c17 Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Tue, 26 Jan 2021 09:31:34 -0300 Subject: [PATCH 14/15] Remove -runtime/printf from list of filters --- ci/code_checks.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 269181b58e502..597aced96eb18 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -58,14 +58,13 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then # readability/casting: Warnings about C casting instead of C++ casting # runtime/int: Warnings about using C number types instead of C++ ones # build/include_subdir: Warnings about prefacing included header files with directory - # runtime/printf: Warnings about using sprintf instead of snprintf # We don't lint all C files because we don't want to lint any that are built # from Cython files nor do we want to lint C files that we didn't modify for # this particular codebase (e.g. src/headers, src/klib). However, # we can lint all header files since they aren't "generated" like C files are. MSG='Linting .c and .h' ; echo $MSG - cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir,-runtime/printf pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp + cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/src/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp RET=$(($RET + $?)) ; echo $MSG "DONE" fi From becb16d32027c0ad8e801676f124fec233fc582f Mon Sep 17 00:00:00 2001 From: gcmaciel Date: Tue, 26 Jan 2021 09:57:07 -0300 Subject: [PATCH 15/15] STYLE: Use snprintf instead of sprintf --- pandas/_libs/src/ujson/python/objToJSON.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/src/ujson/python/objToJSON.c b/pandas/_libs/src/ujson/python/objToJSON.c index 426b7993e7c25..f9fc5c301b3b2 100644 --- a/pandas/_libs/src/ujson/python/objToJSON.c +++ b/pandas/_libs/src/ujson/python/objToJSON.c @@ -1394,8 +1394,9 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc, break; } } else { - cLabel = PyObject_Malloc(21); // 21 chars for int64 - sprintf(cLabel, "%" NPY_DATETIME_FMT, + int size_of_cLabel = 21; // 21 chars for int 64 + cLabel = PyObject_Malloc(size_of_cLabel); + snprintf(cLabel, size_of_cLabel, "%" NPY_DATETIME_FMT, NpyDateTimeToEpoch(nanosecVal, base)); len = strlen(cLabel); }