diff --git a/functions.cpp b/functions.cpp index 912cd087..4976a2cd 100644 --- a/functions.cpp +++ b/functions.cpp @@ -97,20 +97,17 @@ PyObject* Function::call(PyObject* args, PyObject* keywords) const return 0; } -Ptr BoundFunction::create(Ptr target, Ptr fn) +BoundFunction* BoundFunction::create(const Ptr& target, const Ptr& fn) { - BoundFunction* result = free_list; - if (result != 0) - { - free_list = result->m_free_list_link; - result->m_target = target; - result->m_unbound_function = fn; - } - else - { - result = new BoundFunction(target, fn); - } - return Ptr(result, Ptr::new_ref); + BoundFunction* const result = free_list; + if (result == 0) + return new BoundFunction(target, fn); + + free_list = result->m_free_list_link; + result->m_target = target; + result->m_unbound_function = fn; + Py_INCREF(result); + return result; } // The singleton class whose instance represents the type of BoundFunction @@ -126,7 +123,7 @@ private: // TypeObject hook override void dealloc(BoundFunction*) const; }; -BoundFunction::BoundFunction(Ptr target, Ptr fn) +BoundFunction::BoundFunction(const Ptr& target, const Ptr& fn) : PythonObject(TypeObject::singleton()), m_target(target), m_unbound_function(fn), diff --git a/functions.h b/functions.h index 1cf52407..9f8add61 100644 --- a/functions.h +++ b/functions.h @@ -201,9 +201,9 @@ namespace detail { class BoundFunction : public PythonObject { public: - static Ptr create(Ptr target, Ptr fn); + static BoundFunction* create(const Ptr& target, const Ptr& fn); - BoundFunction(Ptr target, Ptr fn); + BoundFunction(const Ptr& target, const Ptr& fn); PyObject* call(PyObject*args, PyObject* keywords) const; PyObject* getattr(const char* name) const;