Index: libs/python/src/object/function.cpp =================================================================== --- libs/python/src/object/function.cpp (revision 66262) +++ libs/python/src/object/function.cpp (working copy) @@ -433,23 +433,23 @@ 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) {