@@ -80,9 +80,13 @@ ImmutableDict_subscript(ImmutableDict *self, PyObject *key)
80
80
PyObject * err_bytes ;
81
81
#endif
82
82
83
- value = PyDict_GetItem (( PyObject * ) self -> dict , key );
83
+ value = PyDict_GetItemWithError ( self -> dict , key );
84
84
85
85
if (value == NULL ) {
86
+ if (PyErr_Occurred () != NULL ) {
87
+ // there was an error while hashing the key
88
+ return NULL ;
89
+ }
86
90
#if PY_MAJOR_VERSION >= 3
87
91
err_bytes = PyUnicode_AsUTF8String (key );
88
92
if (err_bytes == NULL )
@@ -280,20 +284,34 @@ static PyObject *
280
284
ImmutableDict_get (ImmutableDict * self , PyObject * args )
281
285
{
282
286
PyObject * key ;
287
+ PyObject * value ;
283
288
PyObject * default_value = Py_None ;
284
289
285
290
if (!PyArg_UnpackTuple (args , "key" , 1 , 2 , & key , & default_value )) {
286
291
return NULL ;
287
292
}
288
293
294
+ value = PyDict_GetItemWithError (self -> dict , key );
289
295
290
- return PyObject_CallMethod (self -> dict , "get" , "OO" , key , default_value );
296
+ if (value == NULL ) {
297
+ if (PyErr_Occurred () != NULL ) {
298
+ // there was an error while hashing the key
299
+ return NULL ;
300
+ } else {
301
+ // return default
302
+ Py_INCREF (default_value );
303
+ return default_value ;
304
+ }
305
+ } else {
306
+ Py_INCREF (value );
307
+ return value ;
308
+ }
291
309
}
292
310
293
311
static PyObject *
294
312
ImmutableDict_keys (ImmutableDict * self )
295
313
{
296
- return PyObject_CallMethod (self -> dict , "keys" , "" );
314
+ return PyDict_Keys (self -> dict );
297
315
}
298
316
299
317
static int
@@ -312,20 +330,19 @@ ImmutableDict_richcompare(ImmutableDict *self, PyObject *other, int op)
312
330
static PyObject *
313
331
ImmutableDict_iter (ImmutableDict * self )
314
332
{
315
- return PyObject_CallMethod (self -> dict , "__iter__" , "" );
333
+ return PyObject_GetIter (self -> dict );
316
334
}
317
335
318
336
static PyObject *
319
337
ImmutableDict_items (ImmutableDict * self )
320
338
{
321
- return PyObject_CallMethod (self -> dict , "items" , "" );
339
+ return PyDict_Items (self -> dict );
322
340
}
323
341
324
342
static PyObject *
325
343
ImmutableDict_values (ImmutableDict * self )
326
344
{
327
- return PyObject_CallMethod (self -> dict , "values" , "" );
328
-
345
+ return PyDict_Values (self -> dict );
329
346
}
330
347
331
348
static PyObject *
0 commit comments