mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 05:42:30 +00:00
automatic addition of __module__ to class dict
[SVN r14072]
This commit is contained in:
@@ -26,6 +26,9 @@ class BOOST_PYTHON_DECL module_base
|
||||
// Return a reference to the Python module object being built
|
||||
inline ref object() const;
|
||||
|
||||
protected:
|
||||
void generic_add_class(ref class_obj);
|
||||
|
||||
private:
|
||||
ref m_module;
|
||||
static PyMethodDef initial_methods[1];
|
||||
|
||||
@@ -31,8 +31,7 @@ class module : public detail::module_base
|
||||
template <class T, class Bases, class HolderGenerator>
|
||||
module& add(class_<T,Bases,HolderGenerator> const& c)
|
||||
{
|
||||
Py_INCREF(c.object());
|
||||
this->add_type(c.object());
|
||||
this->generic_add_class(c.object());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,17 @@ void module_base::add_type(ref x)
|
||||
add((PyTypeObject*)x.release());
|
||||
}
|
||||
|
||||
void module_base::generic_add_class(ref class_obj)
|
||||
{
|
||||
Py_INCREF(class_obj.get());
|
||||
this->add_type(class_obj);
|
||||
ref module_name(PyObject_GetAttrString(m_module.get(),
|
||||
const_cast<char*>("__name__")));
|
||||
int status = PyObject_SetAttrString(class_obj.get(),
|
||||
const_cast<char*>("__module__"), module_name.get());
|
||||
if (status == -1) throw_error_already_set();
|
||||
}
|
||||
|
||||
PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } };
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
Reference in New Issue
Block a user