From 0922aca87379d9872d38eb60fc2106b71b3ea7df Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Mon, 4 Aug 2003 03:24:41 +0000 Subject: [PATCH] Better usage of handle<>. [SVN r19420] --- .../indexing/detail/indexing_suite_detail.hpp | 26 +++++++++---------- .../boost/python/indexing/indexing_suite.hpp | 11 +++----- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/include/boost/python/indexing/detail/indexing_suite_detail.hpp b/include/boost/python/indexing/detail/indexing_suite_detail.hpp index 9ba9eecd..1f7b8235 100644 --- a/include/boost/python/indexing/detail/indexing_suite_detail.hpp +++ b/include/boost/python/indexing/detail/indexing_suite_detail.hpp @@ -16,9 +16,9 @@ namespace boost { namespace python { namespace detail { #if defined(NDEBUG) -#define CHECK_INVARIANT +#define BOOST_PYTHON_INDEXING_CHECK_INVARIANT #else -#define CHECK_INVARIANT check_invariant() +#define BOOST_PYTHON_INDEXING_CHECK_INVARIANT check_invariant() #endif template @@ -76,26 +76,26 @@ namespace boost { namespace python { namespace detail { break; } } - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } void add(PyObject* prox) { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Add a proxy proxies.insert( first_proxy(extract(prox)().get_index()), prox); - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } void erase(index_type from, index_type to) { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Erase all proxies with indexes from..to replace(from, to, 0); - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } void @@ -104,7 +104,7 @@ namespace boost { namespace python { namespace detail { index_type to, typename std::vector::size_type len) { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Erase all proxies with indexes from..to. // Adjust the displaced indexes such that the // final effect is that we have inserted *len* @@ -139,13 +139,13 @@ namespace boost { namespace python { namespace detail { extract(*right)().get_index(), from, to, len)); ++right; } - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; } PyObject* find(index_type i) { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // Find the proxy with *exact* index i. // Return 0 (null) if no proxy with the // given index is found. @@ -153,17 +153,17 @@ namespace boost { namespace python { namespace detail { if (iter != proxies.end() && extract(*iter)().get_index() == i) { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; return *iter; } - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; return 0; } typename std::vector::size_type size() const { - CHECK_INVARIANT; + BOOST_PYTHON_INDEXING_CHECK_INVARIANT; // How many proxies are there so far? return proxies.size(); } diff --git a/include/boost/python/indexing/indexing_suite.hpp b/include/boost/python/indexing/indexing_suite.hpp index 013b83dd..a49ab684 100644 --- a/include/boost/python/indexing/indexing_suite.hpp +++ b/include/boost/python/indexing/indexing_suite.hpp @@ -147,12 +147,8 @@ namespace boost { namespace python { if (PyObject* shared = container_element_t::get_links().find(container.get(), idx)) { -// return extract(shared)(); - - handle<> h(shared); - object result(h); - h.release(); - return result; + handle<> h(borrowed(shared)); + return object(h); } else { @@ -314,7 +310,7 @@ namespace boost { namespace python { else { // Otherwise, it must be a list or some container - handle<> l_(v); + handle<> l_(borrowed(v)); object l(l_); std::vector temp; @@ -348,7 +344,6 @@ namespace boost { namespace python { temp.end()-temp.begin(), no_proxy()); DerivedPolicies::set_slice(container, from, to, temp.begin(), temp.end()); - l_.release(); } } }