Skip to content

Commit 39551f9

Browse files
wesmChang She
authored and
Chang She
committed
BLD: MSVC fixes, passes on 64-bit
1 parent df914b2 commit 39551f9

File tree

4 files changed

+75
-62
lines changed

4 files changed

+75
-62
lines changed

pandas/src/ujson/lib/ultrajsonenc.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,13 @@ Perhaps implement recursion detection */
604604

605605
void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
606606
{
607+
const char *value;
608+
char *objName;
609+
int count;
610+
JSOBJ iterObj;
611+
size_t szlen;
607612
JSONTypeContext tc;
608613
tc.encoder = enc;
609-
size_t szlen;
610614

611615
if (enc->level > enc->recursionMax)
612616
{
@@ -664,8 +668,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
664668

665669
case JT_ARRAY:
666670
{
667-
int count = 0;
668-
JSOBJ iterObj;
671+
count = 0;
669672
enc->iterBegin(obj, &tc);
670673

671674
Buffer_AppendCharUnchecked (enc, '[');
@@ -694,10 +697,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
694697

695698
case JT_OBJECT:
696699
{
697-
int count = 0;
698-
JSOBJ iterObj;
699-
char *objName;
700-
700+
count = 0;
701701
enc->iterBegin(obj, &tc);
702702

703703
Buffer_AppendCharUnchecked (enc, '{');
@@ -779,7 +779,7 @@ void encode(JSOBJ obj, JSONObjectEncoder *enc, const char *name, size_t cbName)
779779

780780
case JT_UTF8:
781781
{
782-
const char *value = enc->getStringValue(obj, &tc, &szlen);
782+
value = enc->getStringValue(obj, &tc, &szlen);
783783
Buffer_Reserve(enc, ((szlen / 4) + 1) * 12);
784784
Buffer_AppendCharUnchecked (enc, '\"');
785785

pandas/src/ujson/python/JSONtoObj.c

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
typedef struct __PyObjectDecoder
99
{
1010
JSONObjectDecoder dec;
11-
11+
1212
void* npyarr; // Numpy context buffer
1313
npy_intp curdim; // Current array dimension
1414

@@ -81,9 +81,9 @@ void Npy_releaseContext(NpyArrContext* npyarr)
8181

8282
JSOBJ Object_npyNewArray(void* _decoder)
8383
{
84-
PRINTMARK();
85-
PyObjectDecoder* decoder = (PyObjectDecoder*) _decoder;
8684
NpyArrContext* npyarr;
85+
PyObjectDecoder* decoder = (PyObjectDecoder*) _decoder;
86+
PRINTMARK();
8787
if (decoder->curdim <= 0)
8888
{
8989
// start of array - initialise the context buffer
@@ -123,17 +123,19 @@ JSOBJ Object_npyNewArray(void* _decoder)
123123

124124
JSOBJ Object_npyEndArray(JSOBJ obj)
125125
{
126-
PRINTMARK();
126+
PyObject *ret;
127+
char* new_data;
127128
NpyArrContext* npyarr = (NpyArrContext*) obj;
129+
int emptyType = NPY_DEFAULT_TYPE;
130+
npy_intp i;
131+
PRINTMARK();
128132
if (!npyarr)
129133
{
130134
return NULL;
131135
}
132136

133-
PyObject* ret = npyarr->ret;
134-
int emptyType = NPY_DEFAULT_TYPE;
135-
npy_intp i = npyarr->i;
136-
char* new_data;
137+
ret = npyarr->ret;
138+
i = npyarr->i;
137139

138140
npyarr->dec->curdim--;
139141

@@ -195,17 +197,18 @@ JSOBJ Object_npyEndArray(JSOBJ obj)
195197

196198
int Object_npyArrayAddItem(JSOBJ obj, JSOBJ value)
197199
{
198-
PRINTMARK();
200+
PyObject* type;
201+
PyArray_Descr* dtype;
202+
npy_intp i;
203+
char *new_data, *item;
199204
NpyArrContext* npyarr = (NpyArrContext*) obj;
205+
PRINTMARK();
200206
if (!npyarr)
201207
{
202208
return 0;
203209
}
204210

205-
PyObject* type;
206-
PyArray_Descr* dtype;
207-
npy_intp i = npyarr->i;
208-
char *new_data, *item;
211+
i = npyarr->i;
209212

210213
npyarr->shape.ptr[npyarr->dec->curdim-1]++;
211214

@@ -308,25 +311,26 @@ int Object_npyArrayAddItem(JSOBJ obj, JSOBJ value)
308311

309312
JSOBJ Object_npyNewArrayList(void* _decoder)
310313
{
311-
PRINTMARK();
312314
PyObjectDecoder* decoder = (PyObjectDecoder*) _decoder;
315+
PRINTMARK();
313316
PyErr_SetString(PyExc_ValueError, "nesting not supported for object or variable length dtypes");
314317
Npy_releaseContext(decoder->npyarr);
315318
return NULL;
316319
}
317320

318321
JSOBJ Object_npyEndArrayList(JSOBJ obj)
319322
{
320-
PRINTMARK();
323+
PyObject *list, *ret;
321324
NpyArrContext* npyarr = (NpyArrContext*) obj;
325+
PRINTMARK();
322326
if (!npyarr)
323327
{
324328
return NULL;
325329
}
326330

327331
// convert decoded list to numpy array
328-
PyObject* list = (PyObject *) npyarr->ret;
329-
PyObject* ret = PyArray_FROM_O(list);
332+
list = (PyObject *) npyarr->ret;
333+
ret = PyArray_FROM_O(list);
330334

331335
((JSONObjectDecoder*)npyarr->dec)->newArray = Object_npyNewArray;
332336
((JSONObjectDecoder*)npyarr->dec)->arrayAddItem = Object_npyArrayAddItem;
@@ -337,8 +341,8 @@ JSOBJ Object_npyEndArrayList(JSOBJ obj)
337341

338342
int Object_npyArrayListAddItem(JSOBJ obj, JSOBJ value)
339343
{
340-
PRINTMARK();
341344
NpyArrContext* npyarr = (NpyArrContext*) obj;
345+
PRINTMARK();
342346
if (!npyarr)
343347
{
344348
return 0;
@@ -351,8 +355,8 @@ int Object_npyArrayListAddItem(JSOBJ obj, JSOBJ value)
351355

352356
JSOBJ Object_npyNewObject(void* _decoder)
353357
{
354-
PRINTMARK();
355358
PyObjectDecoder* decoder = (PyObjectDecoder*) _decoder;
359+
PRINTMARK();
356360
if (decoder->curdim > 1)
357361
{
358362
PyErr_SetString(PyExc_ValueError, "labels only supported up to 2 dimensions");
@@ -364,16 +368,18 @@ JSOBJ Object_npyNewObject(void* _decoder)
364368

365369
JSOBJ Object_npyEndObject(JSOBJ obj)
366370
{
367-
PRINTMARK();
371+
PyObject *list;
372+
npy_intp labelidx;
368373
NpyArrContext* npyarr = (NpyArrContext*) obj;
374+
PRINTMARK();
369375
if (!npyarr)
370376
{
371377
return NULL;
372378
}
373379

374-
npy_intp labelidx = npyarr->dec->curdim-1;
380+
labelidx = npyarr->dec->curdim-1;
375381

376-
PyObject* list = npyarr->labels[labelidx];
382+
list = npyarr->labels[labelidx];
377383
if (list)
378384
{
379385
npyarr->labels[labelidx] = PyArray_FROM_O(list);
@@ -385,16 +391,18 @@ JSOBJ Object_npyEndObject(JSOBJ obj)
385391

386392
int Object_npyObjectAddKey(JSOBJ obj, JSOBJ name, JSOBJ value)
387393
{
388-
PRINTMARK();
389-
// add key to label array, value to values array
394+
PyObject *label;
395+
npy_intp labelidx;
396+
// add key to label array, value to values array
390397
NpyArrContext* npyarr = (NpyArrContext*) obj;
398+
PRINTMARK();
391399
if (!npyarr)
392400
{
393401
return 0;
394402
}
395403

396-
PyObject* label = (PyObject*) name;
397-
npy_intp labelidx = npyarr->dec->curdim-1;
404+
label = (PyObject*) name;
405+
labelidx = npyarr->dec->curdim-1;
398406

399407
if (!npyarr->labels[labelidx])
400408
{
@@ -498,17 +506,16 @@ static void Object_releaseObject(JSOBJ obj, void* _decoder)
498506

499507
PyObject* JSONToObj(PyObject* self, PyObject *args, PyObject *kwargs)
500508
{
501-
PRINTMARK();
502-
static char *kwlist[] = { "obj", "numpy", "labelled", "dtype", NULL};
503-
504509
PyObject *ret;
505510
PyObject *sarg;
511+
JSONObjectDecoder *decoder;
512+
PyObjectDecoder pyDecoder;
506513
PyArray_Descr *dtype = NULL;
514+
static char *kwlist[] = { "obj", "numpy", "labelled", "dtype", NULL};
507515
int numpy = 0, labelled = 0, decref = 0;
508-
509-
PyObjectDecoder pyDecoder =
510-
{
511-
{
516+
// PRINTMARK();
517+
518+
JSONObjectDecoder dec = {
512519
Object_newString,
513520
Object_objectAddKey,
514521
Object_arrayAddItem,
@@ -526,13 +533,12 @@ PyObject* JSONToObj(PyObject* self, PyObject *args, PyObject *kwargs)
526533
PyObject_Malloc,
527534
PyObject_Free,
528535
PyObject_Realloc,
529-
}
530536
};
531-
537+
pyDecoder.dec = dec;
532538
pyDecoder.curdim = 0;
533539
pyDecoder.npyarr = NULL;
534540

535-
JSONObjectDecoder* decoder = (JSONObjectDecoder*) &pyDecoder;
541+
decoder = (JSONObjectDecoder*) &pyDecoder;
536542

537543
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iiO&", kwlist, &sarg, &numpy, &labelled, PyArray_DescrConverter, &dtype))
538544
{

pandas/src/ujson/python/objToJSON.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#define EPOCH_ORD 719163
1010

11+
#define NPY_JSON_BUFSIZE 32768
12+
1113
static PyObject* cls_dataframe;
1214
static PyObject* cls_series;
1315
static PyObject* cls_index;
@@ -400,9 +402,9 @@ JSOBJ NpyArr_iterGetValue(JSOBJ obj, JSONTypeContext *tc)
400402
char *NpyArr_iterGetName(JSOBJ obj, JSONTypeContext *tc, size_t *outLen)
401403
{
402404
NpyArrContext* npyarr;
405+
npy_intp idx;
403406
PRINTMARK();
404407
npyarr = GET_TC(tc)->npyarr;
405-
npy_intp idx;
406408
if (GET_TC(tc)->iterNext == NpyArr_iterNextItem)
407409
{
408410
idx = npyarr->index[npyarr->stridedim] - 1;
@@ -903,16 +905,16 @@ void NpyArr_freeLabels(char** labels, npy_intp len)
903905
char** NpyArr_encodeLabels(PyArrayObject* labels, JSONObjectEncoder* enc, npy_intp num)
904906
{
905907
// NOTE this function steals a reference to labels.
906-
PRINTMARK();
907908
PyArray_Descr *dtype = NULL;
908909
PyArrayObject* labelsTmp = NULL;
909910
PyObject* item = NULL;
910911
npy_intp i, stride, len;
911-
npy_intp bufsize = 32768;
912+
// npy_intp bufsize = 32768;
912913
char** ret;
913914
char *dataptr, *cLabel, *origend, *origst, *origoffset;
914-
char labelBuffer[bufsize];
915+
char labelBuffer[NPY_JSON_BUFSIZE];
915916
PyArray_GetItemFunc* getitem;
917+
PRINTMARK();
916918

917919
if (PyArray_SIZE(labels) < num)
918920
{
@@ -959,7 +961,7 @@ char** NpyArr_encodeLabels(PyArrayObject* labels, JSONObjectEncoder* enc, npy_in
959961
break;
960962
}
961963

962-
cLabel = JSON_EncodeObject(item, enc, labelBuffer, bufsize);
964+
cLabel = JSON_EncodeObject(item, enc, labelBuffer, NPY_JSON_BUFSIZE);
963965
Py_DECREF(item);
964966

965967
if (PyErr_Occurred() || enc->errorMsg)
@@ -1001,18 +1003,21 @@ char** NpyArr_encodeLabels(PyArrayObject* labels, JSONObjectEncoder* enc, npy_in
10011003

10021004
void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc)
10031005
{
1006+
PyObject *obj, *exc, *toDictFunc;
1007+
TypeContext *pc;
1008+
PyObjectEncoder *enc;
1009+
int i;
1010+
double val;
10041011
PRINTMARK();
10051012
if (!_obj) {
10061013
tc->type = JT_INVALID;
10071014
return;
10081015
}
10091016

1010-
PyObject* obj = (PyObject*) _obj;
1011-
TypeContext *pc = (TypeContext *) tc->prv;
1012-
PyObjectEncoder* enc = (PyObjectEncoder*) tc->encoder;
1013-
PyObject *toDictFunc;
1017+
obj = (PyObject*) _obj;
1018+
pc = (TypeContext *) tc->prv;
1019+
enc = (PyObjectEncoder*) tc->encoder;
10141020

1015-
int i;
10161021
for (i = 0; i < 32; i++)
10171022
{
10181023
tc->prv[i] = 0;
@@ -1043,8 +1048,6 @@ void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc)
10431048
else
10441049
if (PyLong_Check(obj))
10451050
{
1046-
PyObject *exc;
1047-
10481051
PRINTMARK();
10491052
pc->PyTypeToJSON = PyLongToINT64;
10501053
tc->type = JT_LONG;
@@ -1064,12 +1067,10 @@ void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc)
10641067
else
10651068
if (PyArray_IsScalar(obj, Integer))
10661069
{
1067-
PyObject *exc;
1068-
10691070
PRINTMARK();
10701071
pc->PyTypeToJSON = PyLongToINT64;
10711072
tc->type = JT_LONG;
1072-
PyArray_CastScalarToCtype(obj, &(GET_TC(tc)->longValue), PyArray_DescrFromType(NPY_LONG));
1073+
PyArray_CastScalarToCtype(obj, &(GET_TC(tc)->longValue), PyArray_DescrFromType(NPY_INT64));
10731074

10741075
exc = PyErr_Occurred();
10751076

@@ -1100,7 +1101,7 @@ void Object_beginTypeContext (JSOBJ _obj, JSONTypeContext *tc)
11001101
if (PyFloat_Check(obj))
11011102
{
11021103
PRINTMARK();
1103-
double val = PyFloat_AS_DOUBLE (obj);
1104+
val = PyFloat_AS_DOUBLE (obj);
11041105
if (npy_isnan(val) || npy_isinf(val))
11051106
{
11061107
tc->type = JT_NULL;

setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
msg = "pandas requires NumPy >= 1.6 due to datetime64 dependency"
7575
sys.exit(msg)
7676

77-
from numpy.distutils.misc_util import get_pkg_info
77+
from numpy.distutils.misc_util import get_pkg_info, get_info
7878

7979
from distutils.extension import Extension
8080
from distutils.command.build import build
@@ -386,6 +386,8 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
386386
sources=[srcpath('sparse', suffix=suffix)],
387387
include_dirs=[np.get_include()])
388388

389+
npymath_info = get_info('npymath')
390+
389391
ujson_ext = Extension('pandas._ujson',
390392
sources=['pandas/src/ujson/python/ujson.c',
391393
'pandas/src/ujson/python/objToJSON.c',
@@ -395,7 +397,11 @@ def srcpath(name=None, suffix='.pyx', subdir='src'):
395397
include_dirs=['pandas/src/ujson/python',
396398
'pandas/src/ujson/lib',
397399
np.get_include()],
398-
extra_link_args=[get_pkg_info('npymath').libs()])
400+
libraries=['npymath'],
401+
library_dirs=npymath_info['library_dirs'],
402+
#extra_link_args=[get_info('npymath').libs()]
403+
#extra_info=get_info('npymath')
404+
)
399405

400406
sandbox_ext = Extension('pandas._sandbox',
401407
sources=[srcpath('sandbox', suffix=suffix),

0 commit comments

Comments
 (0)