From 81cf5333c3318e45b40318435e9159582f7f8261 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 30 Nov 2000 04:51:05 +0000 Subject: [PATCH] Added module() function to get the module being built Added initializing() function to distinguish whether a module is initializing Changed logic so that multiple non-overlapping module_builders() may be constructed. This fixes a bug when BPL is built as a shared lib. [SVN r8361] --- include/boost/python/module_builder.hpp | 21 ++++++++++++++++++--- src/module_builder.cpp | 12 +++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/boost/python/module_builder.hpp b/include/boost/python/module_builder.hpp index 57507e59..6a8a9b4b 100644 --- a/include/boost/python/module_builder.hpp +++ b/include/boost/python/module_builder.hpp @@ -18,11 +18,10 @@ namespace boost { namespace python { class module_builder { - typedef PyObject * (*raw_function_ptr)(boost::python::tuple const &, boost::python::dictionary const &); - public: // Create a module. REQUIRES: only one module_builder is created per module. module_builder(const char* name); + ~module_builder(); // Add elements to the module void add(detail::function* x, const char* name); @@ -41,13 +40,29 @@ class module_builder add(detail::new_wrapped_function(fn), name); } - static string name(); + // Return true iff a module is currently being built. + static bool initializing(); + // Return the name of the module currently being built. + // REQUIRES: initializing() == true + static string name(); + + // Return a pointer to the Python module object being built + PyObject* module() const; + private: PyObject* m_module; static PyMethodDef initial_methods[1]; }; +// +// inline implementations +// +inline PyObject* module_builder::module() const +{ + return m_module; +} + }} // namespace boost::python #endif diff --git a/src/module_builder.cpp b/src/module_builder.cpp index ea00b71c..57eec75f 100644 --- a/src/module_builder.cpp +++ b/src/module_builder.cpp @@ -14,10 +14,15 @@ namespace { ref name_holder; } +bool module_builder::initializing() +{ + return name_holder.get() != 0; +} + string module_builder::name() { // If this fails, you haven't created a module_builder object - assert(name_holder.get() != 0); + assert(initializing()); return string(name_holder); } @@ -29,6 +34,11 @@ module_builder::module_builder(const char* name) name_holder = ref(PyObject_GetAttrString(m_module, const_cast("__name__"))); } +module_builder::~module_builder() +{ + name_holder.reset(); +} + void module_builder::add(detail::function* x, const char* name) {