BUG, COMPAT: PyList_GET_SIZE works only by chance on ndarray · pandas-dev/pandas@d161b08 (original) (raw)
`@@ -409,7 +409,7 @@ JSOBJ Object_npyEndObject(void *prv, JSOBJ obj) {
`
409
409
`}
`
410
410
``
411
411
`int Object_npyObjectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) {
`
412
``
`-
PyObject *label;
`
``
412
`+
PyObject *label, *labels;
`
413
413
`npy_intp labelidx;
`
414
414
`// add key to label array, value to values array
`
415
415
`NpyArrContext *npyarr = (NpyArrContext *)obj;
`
`@@ -424,11 +424,11 @@ int Object_npyObjectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) {
`
424
424
`if (!npyarr->labels[labelidx]) {
`
425
425
`npyarr->labels[labelidx] = PyList_New(0);
`
426
426
` }
`
427
``
-
``
427
`+
labels = npyarr->labels[labelidx];
`
428
428
`// only fill label array once, assumes all column labels are the same
`
429
429
`// for 2-dimensional arrays.
`
430
``
`-
if (PyList_GET_SIZE(npyarr->labels[labelidx]) <= npyarr->elcount) {
`
431
``
`-
PyList_Append(npyarr->labels[labelidx], label);
`
``
430
`+
if (PyList_Check(labels) && PyList_GET_SIZE(labels) <= npyarr->elcount) {
`
``
431
`+
PyList_Append(labels, label);
`
432
432
` }
`
433
433
``
434
434
`if (((JSONObjectDecoder *)npyarr->dec)->arrayAddItem(prv, obj, value)) {
`
`@@ -439,16 +439,16 @@ int Object_npyObjectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) {
`
439
439
`}
`
440
440
``
441
441
`int Object_objectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) {
`
442
``
`-
PyDict_SetItem(obj, name, value);
`
``
442
`+
int ret = PyDict_SetItem(obj, name, value);
`
443
443
`Py_DECREF((PyObject *)name);
`
444
444
`Py_DECREF((PyObject *)value);
`
445
``
`-
return 1;
`
``
445
`+
return ret==0 ? 1 : 0;
`
446
446
`}
`
447
447
``
448
448
`int Object_arrayAddItem(void *prv, JSOBJ obj, JSOBJ value) {
`
449
``
`-
PyList_Append(obj, value);
`
``
449
`+
int ret = PyList_Append(obj, value);
`
450
450
`Py_DECREF((PyObject *)value);
`
451
``
`-
return 1;
`
``
451
`+
return ret==0 ? 1 : 0;
`
452
452
`}
`
453
453
``
454
454
`JSOBJ Object_newString(void *prv, wchar_t *start, wchar_t *end) {
`