Skip to content

Commit 1ab4d03

Browse files
authored
Compiled pandas with -Wextra (#56327)
* Compiled pandas with -Wextra * np_datetime_strings.c fallthrough * test fixes * win compat * win compat again? * size_t arg fixup * casts * size_t fixes * more size_t fix * json fixes * builtin Py_UNUSED
1 parent 726e8e8 commit 1ab4d03

File tree

13 files changed

+189
-139
lines changed

13 files changed

+189
-139
lines changed

meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ project(
77
meson_version: '>=1.2.1',
88
default_options: [
99
'buildtype=release',
10-
'c_std=c11'
10+
'c_std=c11',
11+
'warning_level=2',
1112
]
1213
)
1314

pandas/_libs/include/pandas/datetime/pd_datetime.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct {
5050
NPY_DATETIMEUNIT *, int *, int *, const char *,
5151
int, FormatRequirement);
5252
int (*get_datetime_iso_8601_strlen)(int, NPY_DATETIMEUNIT);
53-
int (*make_iso_8601_datetime)(npy_datetimestruct *, char *, int, int,
53+
int (*make_iso_8601_datetime)(npy_datetimestruct *, char *, size_t, int,
5454
NPY_DATETIMEUNIT);
5555
int (*make_iso_8601_timedelta)(pandas_timedeltastruct *, char *, size_t *);
5656
} PandasDateTime_CAPI;

pandas/_libs/include/pandas/portable.h

+12
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,15 @@ The full license is in the LICENSE file, distributed with this software.
2323
#define isspace_ascii(c) (((c) == ' ') || (((unsigned)(c) - '\t') < 5))
2424
#define toupper_ascii(c) ((((unsigned)(c) - 'a') < 26) ? ((c) & 0x5f) : (c))
2525
#define tolower_ascii(c) ((((unsigned)(c) - 'A') < 26) ? ((c) | 0x20) : (c))
26+
27+
#if defined(_WIN32)
28+
#define PD_FALLTHROUGH \
29+
do { \
30+
} while (0) /* fallthrough */
31+
#elif __has_attribute(__fallthrough__)
32+
#define PD_FALLTHROUGH __attribute__((__fallthrough__))
33+
#else
34+
#define PD_FALLTHROUGH \
35+
do { \
36+
} while (0) /* fallthrough */
37+
#endif

pandas/_libs/include/pandas/vendored/numpy/datetime/np_datetime_strings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int get_datetime_iso_8601_strlen(int local, NPY_DATETIMEUNIT base);
8585
* Returns 0 on success, -1 on failure (for example if the output
8686
* string was too short).
8787
*/
88-
int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, int outlen,
88+
int make_iso_8601_datetime(npy_datetimestruct *dts, char *outstr, size_t outlen,
8989
int utc, NPY_DATETIMEUNIT base);
9090

9191
/*

pandas/_libs/src/datetime/pd_datetime.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2121

2222
#include "datetime.h"
2323
#include "pandas/datetime/pd_datetime.h"
24+
#include "pandas/portable.h"
2425

2526
static void pandas_datetime_destructor(PyObject *op) {
2627
void *ptr = PyCapsule_GetPointer(op, PandasDateTime_CAPSULE_NAME);
@@ -188,7 +189,7 @@ static npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) {
188189
return npy_dt;
189190
}
190191

191-
static int pandas_datetime_exec(PyObject *module) {
192+
static int pandas_datetime_exec(PyObject *Py_UNUSED(module)) {
192193
PyDateTime_IMPORT;
193194
PandasDateTime_CAPI *capi = PyMem_Malloc(sizeof(PandasDateTime_CAPI));
194195
if (capi == NULL) {

pandas/_libs/src/parser/pd_parser.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void pandas_parser_destructor(PyObject *op) {
100100
PyMem_Free(ptr);
101101
}
102102

103-
static int pandas_parser_exec(PyObject *module) {
103+
static int pandas_parser_exec(PyObject *Py_UNUSED(module)) {
104104
PandasParser_CAPI *capi = PyMem_Malloc(sizeof(PandasParser_CAPI));
105105
if (capi == NULL) {
106106
PyErr_NoMemory();

pandas/_libs/src/parser/tokenizer.c

+22-14
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ static int tokenize_bytes(parser_t *self, size_t line_limit,
795795
break;
796796
} else if (!isblank(c)) {
797797
self->state = START_FIELD;
798-
// fall through to subsequent state
798+
PD_FALLTHROUGH; // fall through to subsequent state
799799
} else {
800800
// if whitespace char, keep slurping
801801
break;
@@ -849,12 +849,12 @@ static int tokenize_bytes(parser_t *self, size_t line_limit,
849849
self->state = WHITESPACE_LINE;
850850
break;
851851
}
852-
// fall through
853852
}
854853

855854
// normal character - fall through
856855
// to handle as START_FIELD
857856
self->state = START_FIELD;
857+
PD_FALLTHROUGH;
858858
}
859859
case START_FIELD:
860860
// expecting field
@@ -1130,10 +1130,10 @@ int parser_consume_rows(parser_t *self, size_t nrows) {
11301130

11311131
/* if word_deletions == 0 (i.e. this case) then char_count must
11321132
* be 0 too, as no data needs to be skipped */
1133-
const int64_t char_count = word_deletions >= 1
1134-
? (self->word_starts[word_deletions - 1] +
1135-
strlen(self->words[word_deletions - 1]) + 1)
1136-
: 0;
1133+
const uint64_t char_count =
1134+
word_deletions >= 1 ? (self->word_starts[word_deletions - 1] +
1135+
strlen(self->words[word_deletions - 1]) + 1)
1136+
: 0;
11371137

11381138
TRACE(("parser_consume_rows: Deleting %d words, %d chars\n", word_deletions,
11391139
char_count));
@@ -1415,9 +1415,11 @@ double xstrtod(const char *str, char **endptr, char decimal, char sci,
14151415
int negative = 0;
14161416
switch (*p) {
14171417
case '-':
1418-
negative = 1; // Fall through to increment position.
1418+
negative = 1;
1419+
PD_FALLTHROUGH; // Fall through to increment position.
14191420
case '+':
14201421
p++;
1422+
break;
14211423
}
14221424

14231425
int exponent = 0;
@@ -1485,9 +1487,11 @@ double xstrtod(const char *str, char **endptr, char decimal, char sci,
14851487
negative = 0;
14861488
switch (*++p) {
14871489
case '-':
1488-
negative = 1; // Fall through to increment pos.
1490+
negative = 1;
1491+
PD_FALLTHROUGH; // Fall through to increment position.
14891492
case '+':
14901493
p++;
1494+
break;
14911495
}
14921496

14931497
// Process string of digits.
@@ -1595,9 +1599,11 @@ double precise_xstrtod(const char *str, char **endptr, char decimal, char sci,
15951599
int negative = 0;
15961600
switch (*p) {
15971601
case '-':
1598-
negative = 1; // Fall through to increment position.
1602+
negative = 1;
1603+
PD_FALLTHROUGH; // Fall through to increment position.
15991604
case '+':
16001605
p++;
1606+
break;
16011607
}
16021608

16031609
double number = 0.;
@@ -1656,9 +1662,11 @@ double precise_xstrtod(const char *str, char **endptr, char decimal, char sci,
16561662
negative = 0;
16571663
switch (*++p) {
16581664
case '-':
1659-
negative = 1; // Fall through to increment pos.
1665+
negative = 1;
1666+
PD_FALLTHROUGH; // Fall through to increment position.
16601667
case '+':
16611668
p++;
1669+
break;
16621670
}
16631671

16641672
// Process string of digits.
@@ -1762,8 +1770,8 @@ static char *_str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
17621770
return s_copy;
17631771
}
17641772

1765-
double round_trip(const char *p, char **q, char decimal, char sci, char tsep,
1766-
int skip_trailing, int *error, int *maybe_int) {
1773+
double round_trip(const char *p, char **q, char decimal, char Py_UNUSED(sci),
1774+
char tsep, int skip_trailing, int *error, int *maybe_int) {
17671775
// 'normalize' representation to C-locale; replace decimal with '.' and
17681776
// remove thousands separator.
17691777
char *endptr;
@@ -1975,7 +1983,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
19751983
break;
19761984
}
19771985
if ((number < pre_max) ||
1978-
((number == pre_max) && (d - '0' <= dig_pre_max))) {
1986+
((number == pre_max) && ((uint64_t)(d - '0') <= dig_pre_max))) {
19791987
number = number * 10 + (d - '0');
19801988
d = *++p;
19811989

@@ -1987,7 +1995,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
19871995
} else {
19881996
while (isdigit_ascii(d)) {
19891997
if ((number < pre_max) ||
1990-
((number == pre_max) && (d - '0' <= dig_pre_max))) {
1998+
((number == pre_max) && ((uint64_t)(d - '0') <= dig_pre_max))) {
19911999
number = number * 10 + (d - '0');
19922000
d = *++p;
19932001

0 commit comments

Comments
 (0)