From 2353deced405ca2e30f2313be659c11c3b389bee Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 11 Dec 2012 18:13:33 -0800 Subject: [PATCH] enable conversion from Py_None to mapnik::value_null - refs #1642,#794 --- bindings/python/mapnik_feature.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bindings/python/mapnik_feature.cpp b/bindings/python/mapnik_feature.cpp index c4d7f75b6..841b8be65 100644 --- a/bindings/python/mapnik_feature.cpp +++ b/bindings/python/mapnik_feature.cpp @@ -156,18 +156,53 @@ struct UnicodeString_from_python_str } }; + +struct value_null_from_python +{ + value_null_from_python() + { + boost::python::converter::registry::push_back( + &convertible, + &construct, + boost::python::type_id()); + } + + static void* convertible(PyObject* obj_ptr) + { + if (obj_ptr == Py_None) return obj_ptr; + return 0; + } + + static void construct( + PyObject* obj_ptr, + boost::python::converter::rvalue_from_python_stage1_data* data) + { + if (obj_ptr != Py_None) boost::python::throw_error_already_set(); + void* storage = ( + (boost::python::converter::rvalue_from_python_storage*) + data)->storage.bytes; + new (storage) mapnik::value_null(); + data->convertible = storage; + } +}; + void export_feature() { using namespace boost::python; using mapnik::Feature; // Python to mapnik::value converters + // NOTE: order matters here. For example value_null must be listed before + // bool otherwise Py_None will be interpreted as bool (false) implicitly_convertible(); implicitly_convertible(); implicitly_convertible(); + implicitly_convertible(); implicitly_convertible(); + // http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ UnicodeString_from_python_str(); + value_null_from_python(); class_ ("Context",init<>("Default ctor."))