diff --git a/src/object/function.cpp b/src/object/function.cpp index 9328e014..5c59cc77 100644 --- a/src/object/function.cpp +++ b/src/object/function.cpp @@ -433,23 +433,23 @@ void function::add_to_namespace( if (attribute.ptr()->ob_type == &function_type) { function* new_func = downcast(attribute.ptr()); - PyObject* dict = 0; + handle<> dict; #if PY_VERSION_HEX < 0x03000000 // Old-style class gone in Python 3 if (PyClass_Check(ns)) - dict = ((PyClassObject*)ns)->cl_dict; + dict = handle<>(borrowed(((PyClassObject*)ns)->cl_dict)); else #endif if (PyType_Check(ns)) - dict = ((PyTypeObject*)ns)->tp_dict; + dict = handle<>(borrowed(((PyTypeObject*)ns)->tp_dict)); else - dict = PyObject_GetAttrString(ns, const_cast("__dict__")); + dict = handle<>(PyObject_GetAttrString(ns, const_cast("__dict__"))); if (dict == 0) throw_error_already_set(); - handle<> existing(allow_null(::PyObject_GetItem(dict, name.ptr()))); + handle<> existing(allow_null(::PyObject_GetItem(dict.get(), name.ptr()))); if (existing) {