Skip to content

Removed GNU strdup extension from JSON #49780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 23, 2022
6 changes: 0 additions & 6 deletions pandas/_libs/src/headers/portable.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
#ifndef _PANDAS_PORTABLE_H_
#define _PANDAS_PORTABLE_H_

// To get `strdup` from strings.h
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif

#include <string.h>

#if defined(_MSC_VER)
#define strcasecmp( s1, s2 ) _stricmp( s1, s2 )
#define strdup _strdup
#endif

// GH-23516 - works around locale perf issues
Expand Down
9 changes: 4 additions & 5 deletions pandas/_libs/src/ujson/lib/ultrajsondec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,15 +1174,14 @@ JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer,
ds.dec = dec;

locale = setlocale(LC_NUMERIC, NULL);
if (!locale) {
return SetError(&ds, -1, "setlocale call failed");
}

if (strcmp(locale, "C")) {
locale = strdup(locale);
if (!locale) {
return SetError(&ds, -1, "Could not reserve memory block");
}
setlocale(LC_NUMERIC, "C");
ret = decode_any(&ds);
setlocale(LC_NUMERIC, locale);
free(locale);
} else {
ret = decode_any(&ds);
}
Expand Down
11 changes: 5 additions & 6 deletions pandas/_libs/src/ujson/lib/ultrajsonenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,16 +1176,15 @@ char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *_buffer,
enc->offset = enc->start;

locale = setlocale(LC_NUMERIC, NULL);
if (!locale) {
SetError(NULL, enc, "setlocale call failed");
return NULL;
}

if (strcmp(locale, "C")) {
locale = strdup(locale);
if (!locale) {
SetError(NULL, enc, "Could not reserve memory block");
return NULL;
}
setlocale(LC_NUMERIC, "C");
encode(obj, enc, NULL, 0);
setlocale(LC_NUMERIC, locale);
free(locale);
} else {
encode(obj, enc, NULL, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
"pandas/_libs/src/datetime",
numpy.get_include(),
],
extra_compile_args=(["-D_GNU_SOURCE"] + extra_compile_args),
extra_compile_args=(extra_compile_args),
extra_link_args=extra_link_args,
define_macros=macros,
)
Expand Down