From ae1c1b3a47e7a76d572ce13e8aa473d5c8ff9e06 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sun, 10 Mar 2002 06:25:09 +0000 Subject: [PATCH] Improved None <==> NULL correspondence [SVN r13155] --- include/boost/python/to_python_indirect.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/boost/python/to_python_indirect.hpp b/include/boost/python/to_python_indirect.hpp index fbbfc6f7..a636ff66 100644 --- a/include/boost/python/to_python_indirect.hpp +++ b/include/boost/python/to_python_indirect.hpp @@ -67,6 +67,22 @@ namespace detail return python::objects::class_object::reference; } }; + + // null_pointer_to_none -- return none() for null pointers and 0 for all other types/values + // + // Uses simulated partial ordering + template + inline PyObject* null_pointer_to_none(T&, int) + { + return 0; + } + + // overload for pointers + template + inline PyObject* null_pointer_to_none(T* x, long) + { + return x == 0 ? python::detail::none() : 0; + } } template @@ -79,6 +95,10 @@ inline bool to_python_indirect::convertible() template inline PyObject* to_python_indirect::operator()(T x) const { + PyObject* const null_result = detail::null_pointer_to_none(x, 1L); + if (null_result != 0) + return null_result; + PyObject* raw_result = type()->tp_alloc(type(), 0); if (raw_result == 0)