File tree 2 files changed +17
-6
lines changed 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -270,8 +270,10 @@ extern "C" {
270
270
271
271
.. code-block:: cpp
272
272
273
+ static pybind11::module_::module_def example_module_def;
273
274
PYBIND11_PLUGIN(example) {
274
- pybind11::module_ m("example", "pybind11 example plugin");
275
+ auto m = pybind11::module_::create_extension_module(
276
+ "example", "pybind11 example plugin", &example_module_def);
275
277
/// Set up bindings here
276
278
return m.ptr();
277
279
}
Original file line number Diff line number Diff line change @@ -883,19 +883,28 @@ class cpp_function : public function {
883
883
}
884
884
};
885
885
886
- // / Wrapper for Python extension modules
886
+ // / Wrapper for Python modules
887
887
class module_ : public object {
888
888
public:
889
889
PYBIND11_OBJECT_DEFAULT (module_, object, PyModule_Check)
890
890
891
891
// / Create a new top-level Python module with the given name and docstring
892
- PYBIND11_DEPRECATED (" Use PYBIND11_MODULE or module_::create_extension_module instead" )
893
892
explicit module_ (const char *name, const char *doc = nullptr ) {
894
- #if PY_MAJOR_VERSION >= 3
895
- * this = create_extension_module (name, doc, new PyModuleDef ( ));
893
+ #if defined(PYPY_VERSION)
894
+ m_ptr = PyModule_New ( const_cast < char *>(name ));
896
895
#else
897
- * this = create_extension_module (name, doc, nullptr );
896
+ m_ptr = PyModule_New (name);
898
897
#endif
898
+ if (m_ptr == nullptr )
899
+ pybind11_fail (" Internal error in module_::module_()" );
900
+ if (doc && options::show_user_defined_docstrings ()) {
901
+ #if PY_MAJOR_VERSION >= 3 && !defined(PYPY_VERSION)
902
+ if (PyModule_SetDocString (m_ptr, doc) != 0 )
903
+ throw error_already_set ();
904
+ #else
905
+ setattr (m_ptr, " __doc__" , PYBIND11_STR_TYPE (doc));
906
+ #endif
907
+ }
899
908
}
900
909
901
910
/* * \rst
You can’t perform that action at this time.
0 commit comments