File tree Expand file tree Collapse file tree 1 file changed +26
-18
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +26
-18
lines changed
Original file line number Diff line number Diff line change @@ -238,20 +238,29 @@ PyDict_SetItemProxy(PyObject *dict, PyObject *key, PyObject *item)
238
238
return result ;
239
239
}
240
240
241
- PyObject *
242
- PyDict_GetItemProxy (PyObject * dict , PyObject * key )
241
+ static int
242
+ _PyDict_GetItemProxy (PyObject * dict , PyObject * key , PyObject * * presult )
243
243
{
244
- PyObject * result ;
245
244
PyObject * item = PyDict_GetItemWithError (dict , key );
245
+ if (item == NULL ) {
246
+ if (PyErr_Occurred ()) {
247
+ return -1 ;
248
+ }
249
+ * presult = NULL ;
250
+ return 0 ;
251
+ }
246
252
247
- if (item == NULL )
248
- return NULL ;
249
- if (!PyWeakref_CheckProxy (item ))
250
- return item ;
251
- result = PyWeakref_GET_OBJECT (item );
252
- if (result == Py_None )
253
- return NULL ;
254
- return result ;
253
+ if (!PyWeakref_CheckProxy (item )) {
254
+ * presult = Py_NewRef (item );
255
+ return 0 ;
256
+ }
257
+ PyObject * ref ;
258
+ if (PyWeakref_GetRef (item , & ref ) < 0 ) {
259
+ return -1 ;
260
+ }
261
+ // ref is NULL if the referenced object was destroyed
262
+ * presult = ref ;
263
+ return 0 ;
255
264
}
256
265
257
266
/******************************************************************/
@@ -4832,7 +4841,6 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
4832
4841
{
4833
4842
static PyObject * cache ;
4834
4843
PyObject * key ;
4835
- PyObject * result ;
4836
4844
char name [256 ];
4837
4845
PyObject * len ;
4838
4846
@@ -4848,15 +4856,15 @@ PyCArrayType_from_ctype(PyObject *itemtype, Py_ssize_t length)
4848
4856
Py_DECREF (len );
4849
4857
if (!key )
4850
4858
return NULL ;
4851
- result = PyDict_GetItemProxy ( cache , key );
4852
- if ( result ) {
4853
- Py_INCREF ( result );
4859
+
4860
+ PyObject * result ;
4861
+ if ( _PyDict_GetItemProxy ( cache , key , & result ) < 0 ) {
4854
4862
Py_DECREF (key );
4855
- return result ;
4863
+ return NULL ;
4856
4864
}
4857
- else if (PyErr_Occurred () ) {
4865
+ if (result ) {
4858
4866
Py_DECREF (key );
4859
- return NULL ;
4867
+ return result ;
4860
4868
}
4861
4869
4862
4870
if (!PyType_Check (itemtype )) {
You can’t perform that action at this time.
0 commit comments