From 77e4c496573dd9f6d64d08da8aa88c0f76bcdc88 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Thu, 18 Oct 2018 14:42:04 -0400 Subject: [PATCH 1/2] Fix for Python 3 versus Python 2 where the PyVarObject is different. --- include/boost/parameter/python.hpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/include/boost/parameter/python.hpp b/include/boost/parameter/python.hpp index a52fc6e..cf05a91 100755 --- a/include/boost/parameter/python.hpp +++ b/include/boost/parameter/python.hpp @@ -41,8 +41,7 @@ namespace boost { namespace parameter { namespace python { namespace aux inline PyObject* unspecified_type() { static PyTypeObject unspecified = { - PyObject_HEAD_INIT(NULL) - 0, /* ob_size */ + PyVarObject_HEAD_INIT(NULL,0) "Boost.Parameter.Unspecified", /* tp_name */ PyType_Type.tp_basicsize, /* tp_basicsize */ 0, /* tp_itemsize */ @@ -64,12 +63,24 @@ namespace boost { namespace parameter { namespace python { namespace aux Py_TPFLAGS_DEFAULT, /* tp_flags */ 0, /* tp_doc */ }; + +#if PY_MAJOR_VERSION <= 2 if (unspecified.ob_type == 0) { unspecified.ob_type = &PyType_Type; PyType_Ready(&unspecified); } + +#else + + if (unspecified.ob_base.ob_base.ob_type == 0) + { + unspecified.ob_base.ob_base.ob_type = &PyType_Type; + PyType_Ready(&unspecified); + } + +#endif return (PyObject*)&unspecified; } From d76576a6a4be79ed5882fa30fc8dd6c7c0289c4f Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Fri, 19 Oct 2018 15:59:46 -0400 Subject: [PATCH 2/2] Changed to use Py_TYPE instead of separate code depending on Python version. --- include/boost/parameter/python.hpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/include/boost/parameter/python.hpp b/include/boost/parameter/python.hpp index cf05a91..0cab762 100755 --- a/include/boost/parameter/python.hpp +++ b/include/boost/parameter/python.hpp @@ -64,24 +64,12 @@ namespace boost { namespace parameter { namespace python { namespace aux 0, /* tp_doc */ }; -#if PY_MAJOR_VERSION <= 2 - - if (unspecified.ob_type == 0) + if (Py_TYPE(&unspecified) == 0) { - unspecified.ob_type = &PyType_Type; + Py_TYPE(&unspecified) = &PyType_Type; PyType_Ready(&unspecified); } -#else - - if (unspecified.ob_base.ob_base.ob_type == 0) - { - unspecified.ob_base.ob_base.ob_type = &PyType_Type; - PyType_Ready(&unspecified); - } - -#endif - return (PyObject*)&unspecified; }