From 6128097d78d6d668545015d3546f7d77ec7f626e Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 10 Jan 2013 23:04:14 -0800 Subject: [PATCH] fix compile with python 3.3.x - closes #1595 --- bindings/python/mapnik_python.cpp | 4 ++++ bindings/python/python_cairo.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/bindings/python/mapnik_python.cpp b/bindings/python/mapnik_python.cpp index 8a0e0f58d..8a2cefcf7 100644 --- a/bindings/python/mapnik_python.cpp +++ b/bindings/python/mapnik_python.cpp @@ -382,7 +382,11 @@ bool has_cairo() bool has_pycairo() { #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) +#if PY_MAJOR_VERSION >= 3 + Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import(const_cast("cairo.CAPI"), 0); +#else Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import(const_cast("cairo"), const_cast("CAPI")); +#endif if (Pycairo_CAPI == NULL){ /* Case where pycairo support has been compiled into diff --git a/bindings/python/python_cairo.cpp b/bindings/python/python_cairo.cpp index ee6c900c3..76de1065a 100644 --- a/bindings/python/python_cairo.cpp +++ b/bindings/python/python_cairo.cpp @@ -31,6 +31,7 @@ static Pycairo_CAPI_t *Pycairo_CAPI; static void *extract_surface(PyObject* op) { + if (PyObject_TypeCheck(op, const_cast(Pycairo_CAPI->Surface_Type))) { return op; @@ -55,7 +56,11 @@ static void *extract_context(PyObject* op) void register_cairo() { +#if PY_MAJOR_VERSION >= 3 + Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import(const_cast("cairo.CAPI"), 0); +#else Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import(const_cast("cairo"), const_cast("CAPI")); +#endif if (Pycairo_CAPI == NULL) return; boost::python::converter::registry::insert(&extract_surface, boost::python::type_id());