Skip to content
Merged
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ project(
meson_version: '>=1.2.1',
default_options: [
'buildtype=release',
'c_std=c11'
'c_std=c11',
'warning_level=2',
]
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/include/pandas/datetime/pd_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions pandas/_libs/include/pandas/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why this is needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused parameters trigger a warning, and there is no cross platform way to silence them. Gcc/clang have an unused attribute. I'm not aware of something for MSVC

Python offers a Py_UNUSED macro for this purpose too. Let me see if we can switch over to that so it's one less thing we manage


#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
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/src/datetime/pd_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/src/parser/pd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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();
Expand Down
33 changes: 21 additions & 12 deletions pandas/_libs/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1764,6 +1772,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;
Expand Down Expand Up @@ -1975,7 +1984,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;

Expand All @@ -1987,7 +1996,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;

Expand Down
Loading