Skip to content

Commit 13012ca

Browse files
committed
Revert "removed GNU extension from JSON"
This reverts commit cd6b630.
1 parent cd6b630 commit 13012ca

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

pandas/_libs/src/ujson/lib/ultrajsondec.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer,
11541154
/*
11551155
FIXME: Base the size of escBuffer of that of cbBuffer so that the unicode
11561156
escaping doesn't run into the wall each time */
1157+
char *locale;
11571158
struct DecoderState ds;
11581159
wchar_t escBuffer[(JSON_MAX_STACK_BUFFER_SIZE / sizeof(wchar_t))];
11591160
JSOBJ ret;
@@ -1172,7 +1173,19 @@ JSOBJ JSON_DecodeObject(JSONObjectDecoder *dec, const char *buffer,
11721173

11731174
ds.dec = dec;
11741175

1175-
ret = decode_any(&ds);
1176+
locale = setlocale(LC_NUMERIC, NULL);
1177+
if (strcmp(locale, "C")) {
1178+
locale = strdup(locale);
1179+
if (!locale) {
1180+
return SetError(&ds, -1, "Could not reserve memory block");
1181+
}
1182+
setlocale(LC_NUMERIC, "C");
1183+
ret = decode_any(&ds);
1184+
setlocale(LC_NUMERIC, locale);
1185+
free(locale);
1186+
} else {
1187+
ret = decode_any(&ds);
1188+
}
11761189

11771190
if (ds.escHeap) {
11781191
dec->free(ds.escStart);

pandas/_libs/src/ujson/lib/ultrajsonenc.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name,
11421142

11431143
char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *_buffer,
11441144
size_t _cbBuffer) {
1145+
char *locale;
11451146
enc->malloc = enc->malloc ? enc->malloc : malloc;
11461147
enc->free = enc->free ? enc->free : free;
11471148
enc->realloc = enc->realloc ? enc->realloc : realloc;
@@ -1174,7 +1175,20 @@ char *JSON_EncodeObject(JSOBJ obj, JSONObjectEncoder *enc, char *_buffer,
11741175
enc->end = enc->start + _cbBuffer;
11751176
enc->offset = enc->start;
11761177

1177-
encode(obj, enc, NULL, 0);
1178+
locale = setlocale(LC_NUMERIC, NULL);
1179+
if (strcmp(locale, "C")) {
1180+
locale = strdup(locale);
1181+
if (!locale) {
1182+
SetError(NULL, enc, "Could not reserve memory block");
1183+
return NULL;
1184+
}
1185+
setlocale(LC_NUMERIC, "C");
1186+
encode(obj, enc, NULL, 0);
1187+
setlocale(LC_NUMERIC, locale);
1188+
free(locale);
1189+
} else {
1190+
encode(obj, enc, NULL, 0);
1191+
}
11781192

11791193
Buffer_Reserve(enc, 1);
11801194
if (enc->errorMsg) {

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
649649
"pandas/_libs/src/datetime",
650650
numpy.get_include(),
651651
],
652-
extra_compile_args=(extra_compile_args),
652+
extra_compile_args=(["-D_GNU_SOURCE"] + extra_compile_args),
653653
extra_link_args=extra_link_args,
654654
define_macros=macros,
655655
)

0 commit comments

Comments
 (0)