GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — automatic addition of __module__ to class dict · mborgerding/python@7a832f1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • include/boost/python
    • detail
      • module_base.hpp
    • module.hpp
  • src
    • module.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎include/boost/python/detail/module_base.hpp‎

Copy file name to clipboardExpand all lines: include/boost/python/detail/module_base.hpp
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class BOOST_PYTHON_DECL module_base
2626
// Return a reference to the Python module object being built
2727
inline ref object() const;
2828

29+
protected:
30+
void generic_add_class(ref class_obj);
31+
2932
private:
3033
ref m_module;
3134
static PyMethodDef initial_methods[1];
Collapse file

‎include/boost/python/module.hpp‎

Copy file name to clipboardExpand all lines: include/boost/python/module.hpp
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class module : public detail::module_base
3131
template <class T, class Bases, class HolderGenerator>
3232
module& add(class_<T,Bases,HolderGenerator> const& c)
3333
{
34-
Py_INCREF(c.object());
35-
this->add_type(c.object());
34+
this->generic_add_class(c.object());
3635
return *this;
3736
}
3837

Collapse file

‎src/module.cpp‎

Copy file name to clipboardExpand all lines: src/module.cpp
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ void module_base::add_type(ref x)
4545
add((PyTypeObject*)x.release());
4646
}
4747

48+
void module_base::generic_add_class(ref class_obj)
49+
{
50+
Py_INCREF(class_obj.get());
51+
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();
57+
}
58+
4859
PyMethodDef module_base::initial_methods[] = { { 0, 0, 0, 0 } };
4960

5061
}}} // namespace boost::python::detail

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.