From 67a43759686911f35d96b7e777c0e5f00888e2f5 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 4 Dec 2023 11:16:45 -0800 Subject: [PATCH 01/11] Compiled pandas with -Wextra --- meson.build | 3 +- pandas/_libs/include/pandas/portable.h | 10 +++ pandas/_libs/src/datetime/pd_datetime.c | 2 + pandas/_libs/src/parser/pd_parser.c | 1 + pandas/_libs/src/parser/tokenizer.c | 37 +++++---- .../numpy/datetime/np_datetime_strings.c | 11 +++ .../src/vendored/ujson/lib/ultrajsonenc.c | 3 + .../src/vendored/ujson/python/JSONtoObj.c | 80 +++++++++++++++---- .../src/vendored/ujson/python/objToJSON.c | 66 +++++++-------- .../_libs/src/vendored/ujson/python/ujson.c | 6 +- 10 files changed, 155 insertions(+), 64 deletions(-) diff --git a/meson.build b/meson.build index 0bc04c59d8716..06623a305ab54 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,8 @@ project( meson_version: '>=1.2.1', default_options: [ 'buildtype=release', - 'c_std=c11' + 'c_std=c11', + 'warning_level=2', ] ) diff --git a/pandas/_libs/include/pandas/portable.h b/pandas/_libs/include/pandas/portable.h index be9080172fe42..8f78d9b4e6175 100644 --- a/pandas/_libs/include/pandas/portable.h +++ b/pandas/_libs/include/pandas/portable.h @@ -23,3 +23,13 @@ The full license is in the LICENSE file, distributed with this software. #define isspace_ascii(c) (((c) == ' ') || (((unsigned)(c) - '\t') < 5)) #define toupper_ascii(c) ((((unsigned)(c) - 'a') < 26) ? ((c) & 0x5f) : (c)) #define tolower_ascii(c) ((((unsigned)(c) - 'A') < 26) ? ((c) | 0x20) : (c)) + +#define UNUSED(x) (void)(x) + +#if __has_attribute(__fallthrough__) +#define PD_FALLTHROUGH __attribute__((__fallthrough__)) +#else +#define PD_FALLTHROUGH \ + do { \ + } while (0) /* fallthrough */ +#endif diff --git a/pandas/_libs/src/datetime/pd_datetime.c b/pandas/_libs/src/datetime/pd_datetime.c index 030d734aeab21..cdb01f2977cc7 100644 --- a/pandas/_libs/src/datetime/pd_datetime.c +++ b/pandas/_libs/src/datetime/pd_datetime.c @@ -21,6 +21,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt #include "datetime.h" #include "pandas/datetime/pd_datetime.h" +#include "pandas/portable.h" static void pandas_datetime_destructor(PyObject *op) { void *ptr = PyCapsule_GetPointer(op, PandasDateTime_CAPSULE_NAME); @@ -189,6 +190,7 @@ static npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) { } static int pandas_datetime_exec(PyObject *module) { + UNUSED(module); PyDateTime_IMPORT; PandasDateTime_CAPI *capi = PyMem_Malloc(sizeof(PandasDateTime_CAPI)); if (capi == NULL) { diff --git a/pandas/_libs/src/parser/pd_parser.c b/pandas/_libs/src/parser/pd_parser.c index 88b6603c3c6f9..d9edd82bbf0b0 100644 --- a/pandas/_libs/src/parser/pd_parser.c +++ b/pandas/_libs/src/parser/pd_parser.c @@ -100,6 +100,7 @@ static void pandas_parser_destructor(PyObject *op) { } static int pandas_parser_exec(PyObject *module) { + UNUSED(module); PandasParser_CAPI *capi = PyMem_Malloc(sizeof(PandasParser_CAPI)); if (capi == NULL) { PyErr_NoMemory(); diff --git a/pandas/_libs/src/parser/tokenizer.c b/pandas/_libs/src/parser/tokenizer.c index f1de56c465e5f..6b32c4f289298 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -794,7 +794,7 @@ static int tokenize_bytes(parser_t *self, size_t line_limit, break; } else if (!isblank(c)) { self->state = START_FIELD; - // fall through to subsequent state + PD_FALLTHROUGH; // fall through to subsequent state } else { // if whitespace char, keep slurping break; @@ -848,12 +848,12 @@ static int tokenize_bytes(parser_t *self, size_t line_limit, self->state = WHITESPACE_LINE; break; } - // fall through } // normal character - fall through // to handle as START_FIELD self->state = START_FIELD; + PD_FALLTHROUGH; } case START_FIELD: // expecting field @@ -1129,10 +1129,10 @@ int parser_consume_rows(parser_t *self, size_t nrows) { /* if word_deletions == 0 (i.e. this case) then char_count must * be 0 too, as no data needs to be skipped */ - const int64_t char_count = word_deletions >= 1 - ? (self->word_starts[word_deletions - 1] + - strlen(self->words[word_deletions - 1]) + 1) - : 0; + const uint64_t char_count = + word_deletions >= 1 ? (self->word_starts[word_deletions - 1] + + strlen(self->words[word_deletions - 1]) + 1) + : 0; TRACE(("parser_consume_rows: Deleting %d words, %d chars\n", word_deletions, char_count)); @@ -1414,9 +1414,11 @@ double xstrtod(const char *str, char **endptr, char decimal, char sci, int negative = 0; switch (*p) { case '-': - negative = 1; // Fall through to increment position. + negative = 1; + PD_FALLTHROUGH; // Fall through to increment position. case '+': p++; + break; } int exponent = 0; @@ -1484,9 +1486,11 @@ double xstrtod(const char *str, char **endptr, char decimal, char sci, negative = 0; switch (*++p) { case '-': - negative = 1; // Fall through to increment pos. + negative = 1; + PD_FALLTHROUGH; // Fall through to increment position. case '+': p++; + break; } // Process string of digits. @@ -1594,9 +1598,11 @@ double precise_xstrtod(const char *str, char **endptr, char decimal, char sci, int negative = 0; switch (*p) { case '-': - negative = 1; // Fall through to increment position. + negative = 1; + PD_FALLTHROUGH; // Fall through to increment position. case '+': p++; + break; } double number = 0.; @@ -1655,9 +1661,11 @@ double precise_xstrtod(const char *str, char **endptr, char decimal, char sci, negative = 0; switch (*++p) { case '-': - negative = 1; // Fall through to increment pos. + negative = 1; + PD_FALLTHROUGH; // Fall through to increment position. case '+': p++; + break; } // Process string of digits. @@ -1763,6 +1771,7 @@ static char *_str_copy_decimal_str_c(const char *s, char **endpos, char decimal, double round_trip(const char *p, char **q, char decimal, char sci, char tsep, int skip_trailing, int *error, int *maybe_int) { + UNUSED(sci); // 'normalize' representation to C-locale; replace decimal with '.' and // remove thousands separator. char *endptr; @@ -1961,9 +1970,9 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, // can be processed without overflowing. // // Process the digits. - uint64_t number = 0; - const uint64_t pre_max = uint_max / 10; - const uint64_t dig_pre_max = uint_max % 10; + int64_t number = 0; + const int64_t pre_max = uint_max / 10; + const int64_t dig_pre_max = uint_max % 10; char d = *p; if (tsep != '\0') { while (1) { @@ -2008,7 +2017,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, return 0; } - if (number > (uint64_t)int_max) { + if (number > int_max) { state->seen_uint = 1; } diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c index 3a9a805a9ec45..0eb9f2afb081c 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -768,27 +768,38 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base) { /* return 4;*/ case NPY_FR_as: len += 3; /* "###" */ + break; case NPY_FR_fs: len += 3; /* "###" */ + break; case NPY_FR_ps: len += 3; /* "###" */ + break; case NPY_FR_ns: len += 3; /* "###" */ + break; case NPY_FR_us: len += 3; /* "###" */ + break; case NPY_FR_ms: len += 4; /* ".###" */ + break; case NPY_FR_s: len += 3; /* ":##" */ + break; case NPY_FR_m: len += 3; /* ":##" */ + break; case NPY_FR_h: len += 3; /* "T##" */ + break; case NPY_FR_D: case NPY_FR_W: len += 3; /* "-##" */ + break; case NPY_FR_M: len += 3; /* "-##" */ + break; case NPY_FR_Y: len += 21; /* 64-bit year */ break; diff --git a/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c b/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c index 42dfa113e6279..d0913b39ffc8c 100644 --- a/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c +++ b/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c @@ -40,6 +40,7 @@ Numeric decoder derived from TCL library // Licence at LICENSES/ULTRAJSON_LICENSE +#include "pandas/portable.h" #include "pandas/vendored/ujson/lib/ultrajson.h" #include #include @@ -463,6 +464,7 @@ int Buffer_EscapeStringUnvalidated(JSONObjectEncoder *enc, const char *io, { if (enc->encodeHTMLChars) { // Fall through to \u00XX case below. + PD_FALLTHROUGH; } else { // Same as default case below. (*of++) = (*io); @@ -647,6 +649,7 @@ int Buffer_EscapeStringValidated(JSOBJ obj, JSONObjectEncoder *enc, case 29: { if (enc->encodeHTMLChars) { // Fall through to \u00XX case 30 below. + PD_FALLTHROUGH; } else { // Same as case 1 above. *(of++) = (*io++); diff --git a/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c b/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c index e7c58d498f9be..cf97887833407 100644 --- a/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c +++ b/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c @@ -41,6 +41,7 @@ Numeric decoder derived from TCL library #define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY #define NO_IMPORT_ARRAY #define PY_SSIZE_T_CLEAN +#include "pandas/portable.h" #include "pandas/vendored/ujson/lib/ultrajson.h" #include #include @@ -77,6 +78,7 @@ void Npy_releaseContext(NpyArrContext *npyarr) { } static int Object_objectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) { + UNUSED(prv); int ret = PyDict_SetItem(obj, name, value); Py_DECREF((PyObject *)name); Py_DECREF((PyObject *)value); @@ -84,54 +86,86 @@ static int Object_objectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) { } static int Object_arrayAddItem(void *prv, JSOBJ obj, JSOBJ value) { + UNUSED(prv); int ret = PyList_Append(obj, value); Py_DECREF((PyObject *)value); return ret == 0 ? 1 : 0; } static JSOBJ Object_newString(void *prv, wchar_t *start, wchar_t *end) { + UNUSED(prv); return PyUnicode_FromWideChar(start, (end - start)); } -static JSOBJ Object_newTrue(void *prv) { Py_RETURN_TRUE; } +static JSOBJ Object_newTrue(void *prv) { + UNUSED(prv); + Py_RETURN_TRUE; +} -static JSOBJ Object_newFalse(void *prv) { Py_RETURN_FALSE; } +static JSOBJ Object_newFalse(void *prv) { + UNUSED(prv); + Py_RETURN_FALSE; +} -static JSOBJ Object_newNull(void *prv) { Py_RETURN_NONE; } +static JSOBJ Object_newNull(void *prv) { + UNUSED(prv); + Py_RETURN_NONE; +} static JSOBJ Object_newPosInf(void *prv) { + UNUSED(prv); return PyFloat_FromDouble(Py_HUGE_VAL); } static JSOBJ Object_newNegInf(void *prv) { + UNUSED(prv); return PyFloat_FromDouble(-Py_HUGE_VAL); } -static JSOBJ Object_newObject(void *prv, void *decoder) { return PyDict_New(); } +static JSOBJ Object_newObject(void *prv, void *decoder) { + UNUSED(prv); + UNUSED(decoder); + return PyDict_New(); +} -static JSOBJ Object_endObject(void *prv, JSOBJ obj) { return obj; } +static JSOBJ Object_endObject(void *prv, JSOBJ obj) { + UNUSED(prv); + return obj; +} -static JSOBJ Object_newArray(void *prv, void *decoder) { return PyList_New(0); } +static JSOBJ Object_newArray(void *prv, void *decoder) { + UNUSED(prv); + UNUSED(decoder); + return PyList_New(0); +} -static JSOBJ Object_endArray(void *prv, JSOBJ obj) { return obj; } +static JSOBJ Object_endArray(void *prv, JSOBJ obj) { + UNUSED(prv); + return obj; +} static JSOBJ Object_newInteger(void *prv, JSINT32 value) { - return PyLong_FromLong((long)value); + UNUSED(prv); + return PyLong_FromLong(value); } static JSOBJ Object_newLong(void *prv, JSINT64 value) { + UNUSED(prv); return PyLong_FromLongLong(value); } static JSOBJ Object_newUnsignedLong(void *prv, JSUINT64 value) { + UNUSED(prv); return PyLong_FromUnsignedLongLong(value); } static JSOBJ Object_newDouble(void *prv, double value) { + UNUSED(prv); return PyFloat_FromDouble(value); } static void Object_releaseObject(void *prv, JSOBJ obj, void *_decoder) { + UNUSED(prv); PyObjectDecoder *decoder = (PyObjectDecoder *)_decoder; if (obj != decoder->npyarr_addr) { Py_XDECREF(((PyObject *)obj)); @@ -141,6 +175,7 @@ static void Object_releaseObject(void *prv, JSOBJ obj, void *_decoder) { static char *g_kwlist[] = {"obj", "precise_float", "labelled", "dtype", NULL}; PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) { + UNUSED(self); PyObject *ret; PyObject *sarg; PyObject *arg; @@ -151,13 +186,28 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) { int labelled = 0; JSONObjectDecoder dec = { - Object_newString, Object_objectAddKey, Object_arrayAddItem, - Object_newTrue, Object_newFalse, Object_newNull, - Object_newPosInf, Object_newNegInf, Object_newObject, - Object_endObject, Object_newArray, Object_endArray, - Object_newInteger, Object_newLong, Object_newUnsignedLong, - Object_newDouble, Object_releaseObject, PyObject_Malloc, - PyObject_Free, PyObject_Realloc}; + .newString = Object_newString, + .objectAddKey = Object_objectAddKey, + .arrayAddItem = Object_arrayAddItem, + .newTrue = Object_newTrue, + .newFalse = Object_newFalse, + .newNull = Object_newNull, + .newPosInf = Object_newPosInf, + .newNegInf = Object_newNegInf, + .newObject = Object_newObject, + .endObject = Object_endObject, + .newArray = Object_newArray, + .endArray = Object_endArray, + .newInt = Object_newInteger, + .newLong = Object_newLong, + .newUnsignedLong = Object_newUnsignedLong, + .newDouble = Object_newDouble, + .releaseObject = Object_releaseObject, + .malloc = PyObject_Malloc, + .free = PyObject_Free, + .realloc = PyObject_Realloc, + .errorStr = NULL, + }; dec.preciseFloat = 0; dec.prv = NULL; diff --git a/pandas/_libs/src/vendored/ujson/python/objToJSON.c b/pandas/_libs/src/vendored/ujson/python/objToJSON.c index 9f1c1d3f857d1..3fec64e495569 100644 --- a/pandas/_libs/src/vendored/ujson/python/objToJSON.c +++ b/pandas/_libs/src/vendored/ujson/python/objToJSON.c @@ -1927,40 +1927,42 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args, PyObject *odefHandler = 0; int indent = 0; - PyObjectEncoder pyEncoder = {{ - Object_beginTypeContext, - Object_endTypeContext, - Object_getStringValue, - Object_getLongValue, - NULL, // getIntValue is unused - Object_getDoubleValue, - Object_getBigNumStringValue, - Object_iterBegin, - Object_iterNext, - Object_iterEnd, - Object_iterGetValue, - Object_iterGetName, - Object_releaseObject, - PyObject_Malloc, - PyObject_Realloc, - PyObject_Free, - -1, // recursionMax - idoublePrecision, - 1, // forceAscii - 0, // encodeHTMLChars - indent, // indent - }}; + PyObjectEncoder pyEncoder = { + { + .beginTypeContext = Object_beginTypeContext, + .endTypeContext = Object_endTypeContext, + .getStringValue = Object_getStringValue, + .getLongValue = Object_getLongValue, + .getIntValue = NULL, + .getDoubleValue = Object_getDoubleValue, + .getBigNumStringValue = Object_getBigNumStringValue, + .iterBegin = Object_iterBegin, + .iterNext = Object_iterNext, + .iterEnd = Object_iterEnd, + .iterGetValue = Object_iterGetValue, + .iterGetName = Object_iterGetName, + .releaseObject = Object_releaseObject, + .malloc = PyObject_Malloc, + .realloc = PyObject_Realloc, + .free = PyObject_Free, + .recursionMax = -1, + .doublePrecision = idoublePrecision, + .forceASCII = 1, + .encodeHTMLChars = 0, + .indent = indent, + .errorMsg = NULL, + }, + .npyCtxtPassthru = NULL, + .blkCtxtPassthru = NULL, + .npyType = -1, + .npyValue = NULL, + .datetimeIso = 0, + .datetimeUnit = NPY_FR_ms, + .outputFormat = COLUMNS, + .defaultHandler = NULL, + }; JSONObjectEncoder *encoder = (JSONObjectEncoder *)&pyEncoder; - pyEncoder.npyCtxtPassthru = NULL; - pyEncoder.blkCtxtPassthru = NULL; - pyEncoder.npyType = -1; - pyEncoder.npyValue = NULL; - pyEncoder.datetimeIso = 0; - pyEncoder.datetimeUnit = NPY_FR_ms; - pyEncoder.outputFormat = COLUMNS; - pyEncoder.defaultHandler = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OiOssOOi", kwlist, &oinput, &oensureAscii, &idoublePrecision, &oencodeHTMLChars, &sOrient, &sdateFormat, diff --git a/pandas/_libs/src/vendored/ujson/python/ujson.c b/pandas/_libs/src/vendored/ujson/python/ujson.c index 736089c48e3ee..bace54255ea85 100644 --- a/pandas/_libs/src/vendored/ujson/python/ujson.c +++ b/pandas/_libs/src/vendored/ujson/python/ujson.c @@ -57,9 +57,11 @@ PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs); "encode_html_chars=True to encode < > & as unicode escape sequences." static PyMethodDef ujsonMethods[] = { - {"ujson_dumps", (PyCFunction)objToJSON, METH_VARARGS | METH_KEYWORDS, + {"ujson_dumps", (PyCFunction)(void (*)(void))objToJSON, + METH_VARARGS | METH_KEYWORDS, "Converts arbitrary object recursively into JSON. " ENCODER_HELP_TEXT}, - {"ujson_loads", (PyCFunction)JSONToObj, METH_VARARGS | METH_KEYWORDS, + {"ujson_loads", (PyCFunction)(void (*)(void))JSONToObj, + METH_VARARGS | METH_KEYWORDS, "Converts JSON as string to dict object structure. Use precise_float=True " "to use high precision float decoder."}, {NULL, NULL, 0, NULL} /* Sentinel */ From ed23f964a30ae9d3f5c5d32db094258686ff8fe9 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 4 Dec 2023 11:47:20 -0800 Subject: [PATCH 02/11] np_datetime_strings.c fallthrough --- .../numpy/datetime/np_datetime_strings.c | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c index 0eb9f2afb081c..042a01a2f66c3 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -36,6 +36,7 @@ This file implements string parsing and creation for NumPy datetime. #include #include +#include "pandas/portable.h" #include "pandas/vendored/numpy/datetime/np_datetime.h" #include "pandas/vendored/numpy/datetime/np_datetime_strings.h" @@ -768,38 +769,38 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base) { /* return 4;*/ case NPY_FR_as: len += 3; /* "###" */ - break; + PD_FALLTHROUGH; case NPY_FR_fs: len += 3; /* "###" */ - break; + PD_FALLTHROUGH; case NPY_FR_ps: len += 3; /* "###" */ - break; + PD_FALLTHROUGH; case NPY_FR_ns: len += 3; /* "###" */ - break; + PD_FALLTHROUGH; case NPY_FR_us: len += 3; /* "###" */ - break; + PD_FALLTHROUGH; case NPY_FR_ms: len += 4; /* ".###" */ - break; + PD_FALLTHROUGH; case NPY_FR_s: len += 3; /* ":##" */ - break; + PD_FALLTHROUGH; case NPY_FR_m: len += 3; /* ":##" */ - break; + PD_FALLTHROUGH; case NPY_FR_h: len += 3; /* "T##" */ - break; + PD_FALLTHROUGH; case NPY_FR_D: case NPY_FR_W: len += 3; /* "-##" */ - break; + PD_FALLTHROUGH; case NPY_FR_M: len += 3; /* "-##" */ - break; + PD_FALLTHROUGH; case NPY_FR_Y: len += 21; /* 64-bit year */ break; From ce566f75dd1d834ad909c42292ad243151e79c4e Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 4 Dec 2023 13:10:00 -0800 Subject: [PATCH 03/11] test fixes --- pandas/_libs/src/parser/tokenizer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/src/parser/tokenizer.c b/pandas/_libs/src/parser/tokenizer.c index 6b32c4f289298..4cae184f1ddcc 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -1970,9 +1970,9 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, // can be processed without overflowing. // // Process the digits. - int64_t number = 0; - const int64_t pre_max = uint_max / 10; - const int64_t dig_pre_max = uint_max % 10; + uint64_t number = 0; + const uint64_t pre_max = uint_max / 10; + const uint64_t dig_pre_max = uint_max % 10; char d = *p; if (tsep != '\0') { while (1) { @@ -1983,7 +1983,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, break; } if ((number < pre_max) || - ((number == pre_max) && (d - '0' <= dig_pre_max))) { + ((number == pre_max) && ((uint64_t)(d - '0') <= dig_pre_max))) { number = number * 10 + (d - '0'); d = *++p; @@ -1995,7 +1995,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, } else { while (isdigit_ascii(d)) { if ((number < pre_max) || - ((number == pre_max) && (d - '0' <= dig_pre_max))) { + ((number == pre_max) && ((uint64_t)(d - '0') <= dig_pre_max))) { number = number * 10 + (d - '0'); d = *++p; @@ -2017,7 +2017,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max, return 0; } - if (number > int_max) { + if (number > (uint64_t)int_max) { state->seen_uint = 1; } From ddde8d7f56cec5f0949b7dda05498384b2869246 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 17:33:47 -0800 Subject: [PATCH 04/11] win compat --- pandas/_libs/include/pandas/portable.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/include/pandas/portable.h b/pandas/_libs/include/pandas/portable.h index 8f78d9b4e6175..66949b2eaee4f 100644 --- a/pandas/_libs/include/pandas/portable.h +++ b/pandas/_libs/include/pandas/portable.h @@ -26,7 +26,7 @@ The full license is in the LICENSE file, distributed with this software. #define UNUSED(x) (void)(x) -#if __has_attribute(__fallthrough__) +#if !defined(_WIN32) && __has_attribute(__fallthrough__) #define PD_FALLTHROUGH __attribute__((__fallthrough__)) #else #define PD_FALLTHROUGH \ From d5bb4ab0e8ef2b5c2089e83dc31bc3e386109f74 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 17:45:34 -0800 Subject: [PATCH 05/11] win compat again? --- pandas/_libs/include/pandas/portable.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/include/pandas/portable.h b/pandas/_libs/include/pandas/portable.h index 66949b2eaee4f..2d1142e31e47b 100644 --- a/pandas/_libs/include/pandas/portable.h +++ b/pandas/_libs/include/pandas/portable.h @@ -26,7 +26,11 @@ The full license is in the LICENSE file, distributed with this software. #define UNUSED(x) (void)(x) -#if !defined(_WIN32) && __has_attribute(__fallthrough__) +#if defined(_WIN32) +#define PD_FALLTHROUGH \ + do { \ + } while (0) /* fallthrough */ +#elif __has_attribute(__fallthrough__) #define PD_FALLTHROUGH __attribute__((__fallthrough__)) #else #define PD_FALLTHROUGH \ From 0419f7ae2f01e873a15799486cad909040d9ba66 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 20:19:16 -0800 Subject: [PATCH 06/11] size_t arg fixup --- pandas/_libs/include/pandas/datetime/pd_datetime.h | 2 +- .../pandas/vendored/numpy/datetime/np_datetime_strings.h | 2 +- pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/include/pandas/datetime/pd_datetime.h b/pandas/_libs/include/pandas/datetime/pd_datetime.h index a51f8cea71513..98e5521af2506 100644 --- a/pandas/_libs/include/pandas/datetime/pd_datetime.h +++ b/pandas/_libs/include/pandas/datetime/pd_datetime.h @@ -50,7 +50,7 @@ typedef struct { NPY_DATETIMEUNIT *, int *, int *, const char *, int, FormatRequirement); int (*get_datetime_iso_8601_strlen)(int, NPY_DATETIMEUNIT); - int (*make_iso_8601_datetime)(npy_datetimestruct *, char *, int, int, + int (*make_iso_8601_datetime)(npy_datetimestruct *, char *, size_t, int, NPY_DATETIMEUNIT); int (*make_iso_8601_timedelta)(pandas_timedeltastruct *, char *, size_t *); } PandasDateTime_CAPI; diff --git a/pandas/_libs/include/pandas/vendored/numpy/datetime/np_datetime_strings.h b/pandas/_libs/include/pandas/vendored/numpy/datetime/np_datetime_strings.h index d96ca79d70cb7..75e69f30ada1e 100644 --- a/pandas/_libs/include/pandas/vendored/numpy/datetime/np_datetime_strings.h +++ b/pandas/_libs/include/pandas/vendored/numpy/datetime/np_datetime_strings.h @@ -85,7 +85,7 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base); * Returns 0 on success, -1 on failure (for example if the output * string was too short). */ -int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int outlen, +int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, size_t outlen, int utc, NPY_DATETIMEUNIT base); /* diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c index 761e46e9bc929..4d23eaa7b2c0c 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -835,7 +835,7 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base) { * Returns 0 on success, -1 on failure (for example if the output * string was too short). */ -int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int outlen, +int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, size_t outlen, int utc, NPY_DATETIMEUNIT base) { char *substr = outstr; int sublen = outlen; From afa94f852a65ec7ebc0386d43565dd468976cd9a Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 20:34:39 -0800 Subject: [PATCH 07/11] casts --- .../src/vendored/numpy/datetime/np_datetime.c | 119 +++++++++--------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c index ab24752203c57..06e3251db8315 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c @@ -243,7 +243,7 @@ static void set_datetimestruct_days(npy_int64 days, npy_datetimestruct *dts) { for (i = 0; i < 12; ++i) { if (days < month_lengths[i]) { dts->month = i + 1; - dts->day = days + 1; + dts->day = (npy_int32)days + 1; return; } else { days -= month_lengths[i]; @@ -568,7 +568,7 @@ void pandas_datetime_to_datetimestruct(npy_datetime dt, NPY_DATETIMEUNIT base, case NPY_FR_M: out->year = 1970 + extract_unit(&dt, 12); - out->month = dt + 1; + out->month = (npy_int32)dt + 1; break; case NPY_FR_W: @@ -584,72 +584,72 @@ void pandas_datetime_to_datetimestruct(npy_datetime dt, NPY_DATETIMEUNIT base, perday = 24LL; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = dt; + out->hour = (npy_int32)dt; break; case NPY_FR_m: perday = 24LL * 60; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 60); - out->min = (int)dt; + out->hour = (npy_int32)extract_unit(&dt, 60); + out->min = (npy_int32)dt; break; case NPY_FR_s: perday = 24LL * 60 * 60; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 60 * 60); - out->min = (int)extract_unit(&dt, 60); - out->sec = (int)dt; + out->hour = (npy_int32)extract_unit(&dt, 60 * 60); + out->min = (npy_int32)extract_unit(&dt, 60); + out->sec = (npy_int32)dt; break; case NPY_FR_ms: perday = 24LL * 60 * 60 * 1000; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 1000LL * 60 * 60); - out->min = (int)extract_unit(&dt, 1000LL * 60); - out->sec = (int)extract_unit(&dt, 1000LL); - out->us = (int)(dt * 1000); + out->hour = (npy_int32)extract_unit(&dt, 1000LL * 60 * 60); + out->min = (npy_int32)extract_unit(&dt, 1000LL * 60); + out->sec = (npy_int32)extract_unit(&dt, 1000LL); + out->us = (npy_int32)(dt * 1000); break; case NPY_FR_us: perday = 24LL * 60LL * 60LL * 1000LL * 1000LL; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 1000LL * 1000 * 60 * 60); - out->min = (int)extract_unit(&dt, 1000LL * 1000 * 60); - out->sec = (int)extract_unit(&dt, 1000LL * 1000); - out->us = (int)dt; + out->hour = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 60 * 60); + out->min = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 60); + out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000); + out->us = (npy_int32)dt; break; case NPY_FR_ns: perday = 24LL * 60LL * 60LL * 1000LL * 1000LL * 1000LL; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 60 * 60); - out->min = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 60); - out->sec = (int)extract_unit(&dt, 1000LL * 1000 * 1000); - out->us = (int)extract_unit(&dt, 1000LL); - out->ps = (int)(dt * 1000); + out->hour = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60 * 60); + out->min = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60); + out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000); + out->us = (npy_int32)extract_unit(&dt, 1000LL); + out->ps = (npy_int32)(dt * 1000); break; case NPY_FR_ps: perday = 24LL * 60 * 60 * 1000 * 1000 * 1000 * 1000; set_datetimestruct_days(extract_unit(&dt, perday), out); - out->hour = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 60 * 60); - out->min = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 60); - out->sec = (int)extract_unit(&dt, 1000LL * 1000 * 1000); - out->us = (int)extract_unit(&dt, 1000LL); - out->ps = (int)(dt * 1000); + out->hour = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60 * 60); + out->min = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 60); + out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000); + out->us = (npy_int32)extract_unit(&dt, 1000LL); + out->ps = (npy_int32)(dt * 1000); break; case NPY_FR_fs: /* entire range is only +- 2.6 hours */ - out->hour = - (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000 * 60 * 60); + out->hour = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * + 1000 * 60 * 60); if (out->hour < 0) { out->year = 1969; out->month = 12; @@ -657,17 +657,18 @@ void pandas_datetime_to_datetimestruct(npy_datetime dt, NPY_DATETIMEUNIT base, out->hour += 24; assert(out->hour >= 0); } - out->min = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000 * 60); - out->sec = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000); - out->us = (int)extract_unit(&dt, 1000LL * 1000 * 1000); - out->ps = (int)extract_unit(&dt, 1000LL); - out->as = (int)(dt * 1000); + out->min = + (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000 * 60); + out->sec = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000); + out->us = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000); + out->ps = (npy_int32)extract_unit(&dt, 1000LL); + out->as = (npy_int32)(dt * 1000); break; case NPY_FR_as: /* entire range is only +- 9.2 seconds */ out->sec = - (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000 * 1000); + (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000 * 1000 * 1000); if (out->sec < 0) { out->year = 1969; out->month = 12; @@ -677,9 +678,9 @@ void pandas_datetime_to_datetimestruct(npy_datetime dt, NPY_DATETIMEUNIT base, out->sec += 60; assert(out->sec >= 0); } - out->us = (int)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000); - out->ps = (int)extract_unit(&dt, 1000LL * 1000); - out->as = (int)dt; + out->us = (npy_int32)extract_unit(&dt, 1000LL * 1000 * 1000 * 1000); + out->ps = (npy_int32)extract_unit(&dt, 1000LL * 1000); + out->as = (npy_int32)dt; break; default: @@ -741,21 +742,21 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, } if (frac >= 3600) { - out->hrs = frac / 3600LL; + out->hrs = (npy_int32)(frac / 3600LL); frac -= out->hrs * 3600LL; } else { out->hrs = 0; } if (frac >= 60) { - out->min = frac / 60LL; + out->min = (npy_int32)(frac / 60LL); frac -= out->min * 60LL; } else { out->min = 0; } if (frac >= 0) { - out->sec = frac; + out->sec = (npy_int32)frac; frac -= out->sec; } else { out->sec = 0; @@ -769,11 +770,11 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, ifrac = td - (out->days * per_day + sfrac); if (ifrac != 0) { - out->ms = ifrac / (1000LL * 1000LL); + out->ms = (npy_int32)(ifrac / (1000LL * 1000LL)); ifrac -= out->ms * 1000LL * 1000LL; - out->us = ifrac / 1000LL; + out->us = (npy_int32)(ifrac / 1000LL); ifrac -= out->us * 1000LL; - out->ns = ifrac; + out->ns = (npy_int32)ifrac; } else { out->ms = 0; out->us = 0; @@ -813,21 +814,21 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, } if (frac >= 3600) { - out->hrs = frac / 3600LL; + out->hrs = (npy_int32)(frac / 3600LL); frac -= out->hrs * 3600LL; } else { out->hrs = 0; } if (frac >= 60) { - out->min = frac / 60LL; + out->min = (npy_int32)(frac / 60LL); frac -= out->min * 60LL; } else { out->min = 0; } if (frac >= 0) { - out->sec = frac; + out->sec = (npy_int32)frac; frac -= out->sec; } else { out->sec = 0; @@ -841,11 +842,11 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, ifrac = td - (out->days * per_day + sfrac); if (ifrac != 0) { - out->ms = ifrac / 1000LL; + out->ms = (npy_int32)(ifrac / 1000LL); ifrac -= out->ms * 1000LL; - out->us = ifrac / 1L; + out->us = (npy_int32)(ifrac / 1L); ifrac -= out->us * 1L; - out->ns = ifrac; + out->ns = (npy_int32)ifrac; } else { out->ms = 0; out->us = 0; @@ -885,21 +886,21 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, } if (frac >= 3600) { - out->hrs = frac / 3600LL; + out->hrs = (npy_int32)(frac / 3600LL); frac -= out->hrs * 3600LL; } else { out->hrs = 0; } if (frac >= 60) { - out->min = frac / 60LL; + out->min = (npy_int32)(frac / 60LL); frac -= out->min * 60LL; } else { out->min = 0; } if (frac >= 0) { - out->sec = frac; + out->sec = (npy_int32)frac; frac -= out->sec; } else { out->sec = 0; @@ -913,7 +914,7 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, ifrac = td - (out->days * per_day + sfrac); if (ifrac != 0) { - out->ms = ifrac; + out->ms = (npy_int32)ifrac; out->us = 0; out->ns = 0; } else { @@ -956,21 +957,21 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, } if (frac >= 3600) { - out->hrs = frac / 3600LL; + out->hrs = (npy_int32)(frac / 3600LL); frac -= out->hrs * 3600LL; } else { out->hrs = 0; } if (frac >= 60) { - out->min = frac / 60LL; + out->min = (npy_int32)(frac / 60LL); frac -= out->min * 60LL; } else { out->min = 0; } if (frac >= 0) { - out->sec = frac; + out->sec = (npy_int32)frac; frac -= out->sec; } else { out->sec = 0; @@ -998,9 +999,9 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, out->days = td / 1440LL; td -= out->days * 1440LL; - out->hrs = td / 60LL; + out->hrs = (npy_int32)(td / 60LL); td -= out->hrs * 60LL; - out->min = td; + out->min = (npy_int32)td; out->sec = 0; out->ms = 0; @@ -1011,7 +1012,7 @@ void pandas_timedelta_to_timedeltastruct(npy_timedelta td, case NPY_FR_h: out->days = td / 24LL; td -= out->days * 24LL; - out->hrs = td; + out->hrs = (npy_int32)td; out->min = 0; out->sec = 0; From 23958e8048bff0e8a311c01cddd0dd7d7b073a00 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 21:12:43 -0800 Subject: [PATCH 08/11] size_t fixes --- pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c index 4d23eaa7b2c0c..42feb54a6ab6a 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -838,7 +838,7 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base) { int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, size_t outlen, int utc, NPY_DATETIMEUNIT base) { char *substr = outstr; - int sublen = outlen; + size_t sublen = outlen; int tmplen; /* From a73679ff91b638621b008f2761a030f6833aeceb Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 21:20:28 -0800 Subject: [PATCH 09/11] more size_t fix --- pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c index 42feb54a6ab6a..a46f5bc467c5d 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -863,7 +863,7 @@ int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, size_t outlen, tmplen = snprintf(substr, sublen, "%04" NPY_INT64_FMT, dts->year); #endif // _WIN32 /* If it ran out of space or there isn't space for the NULL terminator */ - if (tmplen < 0 || tmplen > sublen) { + if (tmplen < 0 || (size_t)tmplen > sublen) { goto string_too_short; } substr += tmplen; From 46ff7e5d6fa975adbc6e9ac3f9f8b6595f367698 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Tue, 5 Dec 2023 21:31:30 -0800 Subject: [PATCH 10/11] json fixes --- pandas/_libs/src/vendored/ujson/python/objToJSON.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/src/vendored/ujson/python/objToJSON.c b/pandas/_libs/src/vendored/ujson/python/objToJSON.c index 91cf62837a736..8bba95dd456de 100644 --- a/pandas/_libs/src/vendored/ujson/python/objToJSON.c +++ b/pandas/_libs/src/vendored/ujson/python/objToJSON.c @@ -66,9 +66,9 @@ int object_is_na_type(PyObject *obj); 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) + npy_intp curdim; // current dimension in array's order + npy_intp stridedim; // dimension we are striding over + int inc; // stride dimension increment (+/- 1) npy_intp dim; npy_intp stride; npy_intp ndim; @@ -81,8 +81,8 @@ typedef struct __NpyArrContext { } NpyArrContext; typedef struct __PdBlockContext { - int colIdx; - int ncols; + Py_ssize_t colIdx; + Py_ssize_t ncols; int transpose; NpyArrContext **npyCtxts; // NpyArrContext for each column From 5612e0dbfceb4fade4510d70416c6d746e2e54cf Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Thu, 7 Dec 2023 23:23:54 -0800 Subject: [PATCH 11/11] builtin Py_UNUSED --- pandas/_libs/include/pandas/portable.h | 2 - pandas/_libs/src/datetime/pd_datetime.c | 3 +- pandas/_libs/src/parser/pd_parser.c | 3 +- pandas/_libs/src/parser/tokenizer.c | 5 +- .../src/vendored/ujson/python/JSONtoObj.c | 71 ++++++------------- 5 files changed, 26 insertions(+), 58 deletions(-) diff --git a/pandas/_libs/include/pandas/portable.h b/pandas/_libs/include/pandas/portable.h index 2d1142e31e47b..1d0509d9e9724 100644 --- a/pandas/_libs/include/pandas/portable.h +++ b/pandas/_libs/include/pandas/portable.h @@ -24,8 +24,6 @@ The full license is in the LICENSE file, distributed with this software. #define toupper_ascii(c) ((((unsigned)(c) - 'a') < 26) ? ((c) & 0x5f) : (c)) #define tolower_ascii(c) ((((unsigned)(c) - 'A') < 26) ? ((c) | 0x20) : (c)) -#define UNUSED(x) (void)(x) - #if defined(_WIN32) #define PD_FALLTHROUGH \ do { \ diff --git a/pandas/_libs/src/datetime/pd_datetime.c b/pandas/_libs/src/datetime/pd_datetime.c index 939bfb6713f45..19de51be6e1b2 100644 --- a/pandas/_libs/src/datetime/pd_datetime.c +++ b/pandas/_libs/src/datetime/pd_datetime.c @@ -189,8 +189,7 @@ static npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) { return npy_dt; } -static int pandas_datetime_exec(PyObject *module) { - UNUSED(module); +static int pandas_datetime_exec(PyObject *Py_UNUSED(module)) { PyDateTime_IMPORT; PandasDateTime_CAPI *capi = PyMem_Malloc(sizeof(PandasDateTime_CAPI)); if (capi == NULL) { diff --git a/pandas/_libs/src/parser/pd_parser.c b/pandas/_libs/src/parser/pd_parser.c index 84fc25b9ae3fa..48f3cd14cbc30 100644 --- a/pandas/_libs/src/parser/pd_parser.c +++ b/pandas/_libs/src/parser/pd_parser.c @@ -100,8 +100,7 @@ static void pandas_parser_destructor(PyObject *op) { PyMem_Free(ptr); } -static int pandas_parser_exec(PyObject *module) { - UNUSED(module); +static int pandas_parser_exec(PyObject *Py_UNUSED(module)) { PandasParser_CAPI *capi = PyMem_Malloc(sizeof(PandasParser_CAPI)); if (capi == NULL) { PyErr_NoMemory(); diff --git a/pandas/_libs/src/parser/tokenizer.c b/pandas/_libs/src/parser/tokenizer.c index 19f80fa44637d..0e4188bea4dc7 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -1770,9 +1770,8 @@ static char *_str_copy_decimal_str_c(const char *s, char **endpos, char decimal, return s_copy; } -double round_trip(const char *p, char **q, char decimal, char sci, char tsep, - int skip_trailing, int *error, int *maybe_int) { - UNUSED(sci); +double round_trip(const char *p, char **q, char decimal, char Py_UNUSED(sci), + char tsep, int skip_trailing, int *error, int *maybe_int) { // 'normalize' representation to C-locale; replace decimal with '.' and // remove thousands separator. char *endptr; diff --git a/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c b/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c index eb6db810152cf..7cc20a52f1849 100644 --- a/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c +++ b/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c @@ -42,101 +42,74 @@ Numeric decoder derived from TCL library #define PY_SSIZE_T_CLEAN #include -static int Object_objectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) { - UNUSED(prv); +static int Object_objectAddKey(void *Py_UNUSED(prv), JSOBJ obj, JSOBJ name, + JSOBJ value) { int ret = PyDict_SetItem(obj, name, value); Py_DECREF((PyObject *)name); Py_DECREF((PyObject *)value); return ret == 0 ? 1 : 0; } -static int Object_arrayAddItem(void *prv, JSOBJ obj, JSOBJ value) { - UNUSED(prv); +static int Object_arrayAddItem(void *Py_UNUSED(prv), JSOBJ obj, JSOBJ value) { int ret = PyList_Append(obj, value); Py_DECREF((PyObject *)value); return ret == 0 ? 1 : 0; } -static JSOBJ Object_newString(void *prv, wchar_t *start, wchar_t *end) { - UNUSED(prv); +static JSOBJ Object_newString(void *Py_UNUSED(prv), wchar_t *start, + wchar_t *end) { return PyUnicode_FromWideChar(start, (end - start)); } -static JSOBJ Object_newTrue(void *prv) { - UNUSED(prv); - Py_RETURN_TRUE; -} +static JSOBJ Object_newTrue(void *Py_UNUSED(prv)) { Py_RETURN_TRUE; } -static JSOBJ Object_newFalse(void *prv) { - UNUSED(prv); - Py_RETURN_FALSE; -} +static JSOBJ Object_newFalse(void *Py_UNUSED(prv)) { Py_RETURN_FALSE; } -static JSOBJ Object_newNull(void *prv) { - UNUSED(prv); - Py_RETURN_NONE; -} +static JSOBJ Object_newNull(void *Py_UNUSED(prv)) { Py_RETURN_NONE; } -static JSOBJ Object_newPosInf(void *prv) { - UNUSED(prv); +static JSOBJ Object_newPosInf(void *Py_UNUSED(prv)) { return PyFloat_FromDouble(Py_HUGE_VAL); } -static JSOBJ Object_newNegInf(void *prv) { - UNUSED(prv); +static JSOBJ Object_newNegInf(void *Py_UNUSED(prv)) { return PyFloat_FromDouble(-Py_HUGE_VAL); } -static JSOBJ Object_newObject(void *prv, void *decoder) { - UNUSED(prv); - UNUSED(decoder); +static JSOBJ Object_newObject(void *Py_UNUSED(prv), void *Py_UNUSED(decoder)) { return PyDict_New(); } -static JSOBJ Object_endObject(void *prv, JSOBJ obj) { - UNUSED(prv); - return obj; -} +static JSOBJ Object_endObject(void *Py_UNUSED(prv), JSOBJ obj) { return obj; } -static JSOBJ Object_newArray(void *prv, void *decoder) { - UNUSED(prv); - UNUSED(decoder); +static JSOBJ Object_newArray(void *Py_UNUSED(prv), void *Py_UNUSED(decoder)) { return PyList_New(0); } -static JSOBJ Object_endArray(void *prv, JSOBJ obj) { - UNUSED(prv); - return obj; -} +static JSOBJ Object_endArray(void *Py_UNUSED(prv), JSOBJ obj) { return obj; } -static JSOBJ Object_newInteger(void *prv, JSINT32 value) { - UNUSED(prv); +static JSOBJ Object_newInteger(void *Py_UNUSED(prv), JSINT32 value) { return PyLong_FromLong(value); } -static JSOBJ Object_newLong(void *prv, JSINT64 value) { - UNUSED(prv); +static JSOBJ Object_newLong(void *Py_UNUSED(prv), JSINT64 value) { return PyLong_FromLongLong(value); } -static JSOBJ Object_newUnsignedLong(void *prv, JSUINT64 value) { - UNUSED(prv); +static JSOBJ Object_newUnsignedLong(void *Py_UNUSED(prv), JSUINT64 value) { return PyLong_FromUnsignedLongLong(value); } -static JSOBJ Object_newDouble(void *prv, double value) { - UNUSED(prv); +static JSOBJ Object_newDouble(void *Py_UNUSED(prv), double value) { return PyFloat_FromDouble(value); } -static void Object_releaseObject(void *prv, JSOBJ obj, void *_decoder) { - UNUSED(prv); - UNUSED(_decoder); +static void Object_releaseObject(void *Py_UNUSED(prv), JSOBJ obj, + void *Py_UNUSED(decoder)) { Py_XDECREF(((PyObject *)obj)); } -PyObject *JSONToObj(PyObject *self, PyObject *args, PyObject *kwargs) { - UNUSED(self); +PyObject *JSONToObj(PyObject *Py_UNUSED(self), PyObject *args, + PyObject *kwargs) { JSONObjectDecoder dec = {.newString = Object_newString, .objectAddKey = Object_objectAddKey, .arrayAddItem = Object_arrayAddItem,