2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 06:42:27 +00:00

fixup for __module__ attribute setting

[SVN r14082]
This commit is contained in:
Dave Abrahams
2002-06-04 20:26:18 +00:00
parent 6741698f71
commit 2e3ae9decb
2 changed files with 13 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ class BOOST_PYTHON_DECL module_base
inline ref object() const;
protected:
void generic_add_class(ref class_obj);
void add_class(ref const& class_obj);
private:
ref m_module;

View File

@@ -45,15 +45,20 @@ void module_base::add_type(ref x)
add((PyTypeObject*)x.release());
}
void module_base::generic_add_class(ref class_obj)
void module_base::add_class(ref const& 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();
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 } };