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/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/portable.h b/pandas/_libs/include/pandas/portable.h index be9080172fe42..1d0509d9e9724 100644 --- a/pandas/_libs/include/pandas/portable.h +++ b/pandas/_libs/include/pandas/portable.h @@ -23,3 +23,15 @@ 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)) + +#if defined(_WIN32) +#define PD_FALLTHROUGH \ + do { \ + } while (0) /* fallthrough */ +#elif __has_attribute(__fallthrough__) +#define PD_FALLTHROUGH __attribute__((__fallthrough__)) +#else +#define PD_FALLTHROUGH \ + do { \ + } while (0) /* fallthrough */ +#endif 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/datetime/pd_datetime.c b/pandas/_libs/src/datetime/pd_datetime.c index 606edf1184aad..19de51be6e1b2 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); @@ -188,7 +189,7 @@ static npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) { return npy_dt; } -static int pandas_datetime_exec(PyObject *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 2e16f5b756dd0..48f3cd14cbc30 100644 --- a/pandas/_libs/src/parser/pd_parser.c +++ b/pandas/_libs/src/parser/pd_parser.c @@ -100,7 +100,7 @@ static void pandas_parser_destructor(PyObject *op) { PyMem_Free(ptr); } -static int pandas_parser_exec(PyObject *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 74a3a51c61e15..0e4188bea4dc7 100644 --- a/pandas/_libs/src/parser/tokenizer.c +++ b/pandas/_libs/src/parser/tokenizer.c @@ -795,7 +795,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; @@ -849,12 +849,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 @@ -1130,10 +1130,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)); @@ -1415,9 +1415,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; @@ -1485,9 +1487,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. @@ -1595,9 +1599,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.; @@ -1656,9 +1662,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. @@ -1762,8 +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) { +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; @@ -1975,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; @@ -1987,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; 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; 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 73bce9ab27a8b..a46f5bc467c5d 100644 --- a/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c +++ b/pandas/_libs/src/vendored/numpy/datetime/np_datetime_strings.c @@ -35,6 +35,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" @@ -767,27 +768,38 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base) { /* return 4;*/ case NPY_FR_as: len += 3; /* "###" */ + PD_FALLTHROUGH; case NPY_FR_fs: len += 3; /* "###" */ + PD_FALLTHROUGH; case NPY_FR_ps: len += 3; /* "###" */ + PD_FALLTHROUGH; case NPY_FR_ns: len += 3; /* "###" */ + PD_FALLTHROUGH; case NPY_FR_us: len += 3; /* "###" */ + PD_FALLTHROUGH; case NPY_FR_ms: len += 4; /* ".###" */ + PD_FALLTHROUGH; case NPY_FR_s: len += 3; /* ":##" */ + PD_FALLTHROUGH; case NPY_FR_m: len += 3; /* ":##" */ + PD_FALLTHROUGH; case NPY_FR_h: len += 3; /* "T##" */ + PD_FALLTHROUGH; case NPY_FR_D: case NPY_FR_W: len += 3; /* "-##" */ + PD_FALLTHROUGH; case NPY_FR_M: len += 3; /* "-##" */ + PD_FALLTHROUGH; case NPY_FR_Y: len += 21; /* 64-bit year */ break; @@ -823,10 +835,10 @@ 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; + size_t sublen = outlen; int tmplen; /* @@ -851,7 +863,7 @@ int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int 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; diff --git a/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c b/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c index 876d9f276f5d2..c8d8b5ab6bd6e 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 @@ -461,6 +462,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); @@ -645,6 +647,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 b7ee58c63a275..7cc20a52f1849 100644 --- a/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c +++ b/pandas/_libs/src/vendored/ujson/python/JSONtoObj.c @@ -42,66 +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) { +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) { +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) { +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) { Py_RETURN_TRUE; } +static JSOBJ Object_newTrue(void *Py_UNUSED(prv)) { Py_RETURN_TRUE; } -static JSOBJ Object_newFalse(void *prv) { Py_RETURN_FALSE; } +static JSOBJ Object_newFalse(void *Py_UNUSED(prv)) { Py_RETURN_FALSE; } -static JSOBJ Object_newNull(void *prv) { Py_RETURN_NONE; } +static JSOBJ Object_newNull(void *Py_UNUSED(prv)) { Py_RETURN_NONE; } -static JSOBJ Object_newPosInf(void *prv) { +static JSOBJ Object_newPosInf(void *Py_UNUSED(prv)) { return PyFloat_FromDouble(Py_HUGE_VAL); } -static JSOBJ Object_newNegInf(void *prv) { +static JSOBJ Object_newNegInf(void *Py_UNUSED(prv)) { return PyFloat_FromDouble(-Py_HUGE_VAL); } -static JSOBJ Object_newObject(void *prv, void *decoder) { return PyDict_New(); } +static JSOBJ Object_newObject(void *Py_UNUSED(prv), void *Py_UNUSED(decoder)) { + return PyDict_New(); +} -static JSOBJ Object_endObject(void *prv, JSOBJ obj) { return obj; } +static JSOBJ Object_endObject(void *Py_UNUSED(prv), JSOBJ obj) { return obj; } -static JSOBJ Object_newArray(void *prv, void *decoder) { return PyList_New(0); } +static JSOBJ Object_newArray(void *Py_UNUSED(prv), void *Py_UNUSED(decoder)) { + return PyList_New(0); +} -static JSOBJ Object_endArray(void *prv, JSOBJ obj) { return obj; } +static JSOBJ Object_endArray(void *Py_UNUSED(prv), JSOBJ obj) { return obj; } -static JSOBJ Object_newInteger(void *prv, JSINT32 value) { - return PyLong_FromLong((long)value); +static JSOBJ Object_newInteger(void *Py_UNUSED(prv), JSINT32 value) { + return PyLong_FromLong(value); } -static JSOBJ Object_newLong(void *prv, JSINT64 value) { +static JSOBJ Object_newLong(void *Py_UNUSED(prv), JSINT64 value) { return PyLong_FromLongLong(value); } -static JSOBJ Object_newUnsignedLong(void *prv, JSUINT64 value) { +static JSOBJ Object_newUnsignedLong(void *Py_UNUSED(prv), JSUINT64 value) { return PyLong_FromUnsignedLongLong(value); } -static JSOBJ Object_newDouble(void *prv, double value) { +static JSOBJ Object_newDouble(void *Py_UNUSED(prv), double value) { return PyFloat_FromDouble(value); } -static void Object_releaseObject(void *prv, JSOBJ obj, void *_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) { +PyObject *JSONToObj(PyObject *Py_UNUSED(self), PyObject *args, + PyObject *kwargs) { JSONObjectDecoder dec = {.newString = Object_newString, .objectAddKey = Object_objectAddKey, .arrayAddItem = Object_arrayAddItem, diff --git a/pandas/_libs/src/vendored/ujson/python/objToJSON.c b/pandas/_libs/src/vendored/ujson/python/objToJSON.c index ef88b97918d76..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 @@ -1934,40 +1934,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 351f5226b57c9..075411a23b075 100644 --- a/pandas/_libs/src/vendored/ujson/python/ujson.c +++ b/pandas/_libs/src/vendored/ujson/python/ujson.c @@ -56,9 +56,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 */