Skip to content

Commit 2e3ae9d

Browse files
committed
fixup for __module__ attribute setting
[SVN r14082]
1 parent 6741698 commit 2e3ae9d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

include/boost/python/detail/module_base.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BOOST_PYTHON_DECL module_base
2727
inline ref object() const;
2828

2929
protected:
30-
void generic_add_class(ref class_obj);
30+
void add_class(ref const& class_obj);
3131

3232
private:
3333
ref m_module;

src/module.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,20 @@ void module_base::add_type(ref x)
4545
add((PyTypeObject*)x.release());
4646
}
4747

48-
void module_base::generic_add_class(ref class_obj)
48+
void module_base::add_class(ref const& class_obj)
4949
{
50-
Py_INCREF(class_obj.get());
5150
this->add_type(class_obj);
52-
ref module_name(PyObject_GetAttrString(m_module.get(),
53-
const_cast<char*>("__name__")));
54-
int status = PyObject_SetAttrString(class_obj.get(),
55-
const_cast<char*>("__module__"), module_name.get());
56-
if (status == -1) throw_error_already_set();
51+
52+
ref module_name(
53+
PyObject_GetAttrString(
54+
m_module.get(), const_cast<char*>("__name__"))
55+
);
56+
57+
int status = PyObject_SetAttrString(
58+
class_obj.get(), const_cast<char*>("__module__"), module_name.get());
59+
60+
if (status == -1)
61+
throw_error_already_set();
5762
}
5863

5964
PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } };

0 commit comments

Comments
 (0)