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
15 changes: 1 addition & 14 deletions pandas/_libs/src/ujson/lib/ultrajsondec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,6 @@ JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer,
/*
FIXME: Base the size of escBuffer of that of cbBuffer so that the unicode
escaping doesn't run into the wall each time */
char *locale;
struct DecoderState ds;
wchar_t escBuffer[(JSON_MAX_STACK_BUFFER_SIZE / sizeof(wchar_t))];
JSOBJ ret;
Expand All @@ -1173,19 +1172,7 @@ JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer,

ds.dec = dec;

locale = setlocale(LC_NUMERIC, NULL);
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);
}
ret = decode_any(&ds);

if (ds.escHeap) {
dec->free(ds.escStart);
Expand Down
16 changes: 1 addition & 15 deletions pandas/_libs/src/ujson/lib/ultrajsonenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,6 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,

char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *_buffer,
size_t _cbBuffer) {
char *locale;
enc->malloc = enc->malloc ? enc->malloc : malloc;
enc->free = enc->free ? enc->free : free;
enc->realloc = enc->realloc ? enc->realloc : realloc;
Expand Down Expand Up @@ -1175,20 +1174,7 @@ char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *_buffer,
enc->end = enc->start + _cbBuffer;
enc->offset = enc->start;

locale = setlocale(LC_NUMERIC, 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);
}
encode(obj, enc, NULL, 0);

Buffer_Reserve(enc, 1);
if (enc->errorMsg) {
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