@@ -77,21 +77,21 @@ void function::add_overload(function* overload)
7777}
7878
7979void function::add_to_namespace (
80- PyObject* name_space, char const * name_, PyObject* attribute_ )
80+ ref const & name_space, char const * name_, ref const & attribute )
8181{
82- ref attribute (attribute_, ref::increment_count );
83- string name (name_ );
82+ string const name (name_ );
83+ PyObject* const ns = name_space. get ( );
8484
85- if (attribute_ ->ob_type == &function_type)
85+ if (attribute ->ob_type == &function_type)
8686 {
8787 PyObject* dict = 0 ;
8888
89- if (PyClass_Check (name_space ))
90- dict = ((PyClassObject*)name_space )->cl_dict ;
91- else if (PyType_Check (name_space ))
92- dict = ((PyTypeObject*)name_space )->tp_dict ;
89+ if (PyClass_Check (ns ))
90+ dict = ((PyClassObject*)ns )->cl_dict ;
91+ else if (PyType_Check (ns ))
92+ dict = ((PyTypeObject*)ns )->tp_dict ;
9393 else
94- dict = PyObject_GetAttrString (name_space , " __dict__" );
94+ dict = PyObject_GetAttrString (ns , " __dict__" );
9595
9696 if (dict == 0 )
9797 throw error_already_set ();
@@ -101,14 +101,14 @@ void function::add_to_namespace(
101101 if (existing.get () && existing->ob_type == &function_type)
102102 {
103103 static_cast <function*>(existing.get ())->add_overload (
104- static_cast <function*>(attribute_ ));
104+ static_cast <function*>(attribute. get () ));
105105 return ;
106106 }
107107 }
108108
109109 // The PyObject_GetAttrString() call above left an active error
110110 PyErr_Clear ();
111- if (PyObject_SetAttr (name_space , name.get (), attribute_ ) < 0 )
111+ if (PyObject_SetAttr (ns , name.get (), attribute. get () ) < 0 )
112112 throw error_already_set ();
113113}
114114
0 commit comments