@@ -10,6 +10,7 @@ typedef struct __PyObjectDecoder
10
10
JSONObjectDecoder dec ;
11
11
12
12
void * npyarr ; // Numpy context buffer
13
+ void * npyarr_addr ; // Ref to npyarr ptr to track DECREF calls
13
14
npy_intp curdim ; // Current array dimension
14
15
15
16
PyArray_Descr * dtype ;
@@ -67,9 +68,7 @@ void Npy_releaseContext(NpyArrContext* npyarr)
67
68
}
68
69
if (npyarr -> dec )
69
70
{
70
- // Don't set to null, used to make sure we don't Py_DECREF npyarr
71
- // in releaseObject
72
- // npyarr->dec->npyarr = NULL;
71
+ npyarr -> dec -> npyarr = NULL ;
73
72
npyarr -> dec -> curdim = 0 ;
74
73
}
75
74
Py_XDECREF (npyarr -> labels [0 ]);
@@ -88,6 +87,7 @@ JSOBJ Object_npyNewArray(void* _decoder)
88
87
{
89
88
// start of array - initialise the context buffer
90
89
npyarr = decoder -> npyarr = PyObject_Malloc (sizeof (NpyArrContext ));
90
+ decoder -> npyarr_addr = npyarr ;
91
91
92
92
if (!npyarr )
93
93
{
@@ -515,7 +515,7 @@ JSOBJ Object_newDouble(double value)
515
515
static void Object_releaseObject (JSOBJ obj , void * _decoder )
516
516
{
517
517
PyObjectDecoder * decoder = (PyObjectDecoder * ) _decoder ;
518
- if (obj != decoder -> npyarr )
518
+ if (obj != decoder -> npyarr_addr )
519
519
{
520
520
Py_XDECREF ( ((PyObject * )obj ));
521
521
}
@@ -555,11 +555,13 @@ PyObject* JSONToObj(PyObject* self, PyObject *args, PyObject *kwargs)
555
555
pyDecoder .dec = dec ;
556
556
pyDecoder .curdim = 0 ;
557
557
pyDecoder .npyarr = NULL ;
558
+ pyDecoder .npyarr_addr = NULL ;
558
559
559
560
decoder = (JSONObjectDecoder * ) & pyDecoder ;
560
561
561
562
if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O|iiO&" , kwlist , & sarg , & numpy , & labelled , PyArray_DescrConverter2 , & dtype ))
562
563
{
564
+ Npy_releaseContext (pyDecoder .npyarr );
563
565
return NULL ;
564
566
}
565
567
0 commit comments