From 60ed8e57c121ef9b923a351a97301cd40d11a2e3 Mon Sep 17 00:00:00 2001 From: Haoyu Bai Date: Thu, 2 Apr 2009 15:27:53 +0000 Subject: [PATCH] More BPL .cpps compiled. A part of Python 3 module initilization support done. [SVN r52131] --- include/boost/python/module_init.hpp | 5 ++++- src/module.cpp | 19 +++++++++++++++++-- src/object/life_support.cpp | 7 +++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/boost/python/module_init.hpp b/include/boost/python/module_init.hpp index aaf2a0f9..0d53b5e1 100644 --- a/include/boost/python/module_init.hpp +++ b/include/boost/python/module_init.hpp @@ -11,10 +11,13 @@ namespace boost { namespace python { namespace detail { -BOOST_PYTHON_DECL void init_module(char const* name, void(*)()); +BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*)()); }}} +// TODO(bhy) Take care of this later. +// But any reseaon we don't use BOOST_PYTHON_DECL here? + # if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(BOOST_PYTHON_STATIC_MODULE) # define BOOST_PYTHON_MODULE_INIT(name) \ diff --git a/src/module.cpp b/src/module.cpp index 864651ca..5bfbfd1f 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -24,11 +24,25 @@ namespace PyMethodDef initial_methods[] = { { 0, 0, 0, 0 } }; } -BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)()) +BOOST_PYTHON_DECL PyObject* init_module(char const* name, void(*init_function)()) { - +#if PY_VERSION_HEX >= 0x03000000 + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + name, + 0, /* m_doc */ + -1, /* m_size */ + initial_methods, + 0, /* m_reload */ + 0, /* m_traverse */ + 0, /* m_clear */ + 0, /* m_free */ + }; + PyObject* m = PyModule_Create(&moduledef); +#else PyObject* m = Py_InitModule(const_cast(name), initial_methods); +#endif if (m != 0) { @@ -38,6 +52,7 @@ BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)()) handle_exception(init_function); } + return m; } }}} // namespace boost::python::detail diff --git a/src/object/life_support.cpp b/src/object/life_support.cpp index 013253b5..b7e9aa86 100644 --- a/src/object/life_support.cpp +++ b/src/object/life_support.cpp @@ -36,8 +36,7 @@ extern "C" } PyTypeObject life_support_type = { - PyObject_HEAD_INIT(0)//(&PyType_Type) - 0, + PyVarObject_HEAD_INIT(NULL, 0)//(&PyType_Type) const_cast("Boost.Python.life_support"), sizeof(life_support), 0, @@ -92,9 +91,9 @@ PyObject* make_nurse_and_patient(PyObject* nurse, PyObject* patient) if (nurse == Py_None || nurse == patient) return nurse; - if (life_support_type.ob_type == 0) + if (Py_TYPE(&life_support_type) == 0) { - life_support_type.ob_type = &PyType_Type; + Py_TYPE(&life_support_type) = &PyType_Type; PyType_Ready(&life_support_type); }