summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Doc/c-api/module.rst10
-rw-r--r--Include/moduleobject.h3
-rw-r--r--Objects/moduleobject.c23
3 files changed, 28 insertions, 8 deletions
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index a31046ce27..b914068a1f 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -29,7 +29,7 @@ There are only a few functions special to module objects.
:c:data:`PyModule_Type`.
-.. c:function:: PyObject* PyModule_New(const char *name)
+.. c:function:: PyObject* PyModule_NewObject(PyObject *name)
.. index::
single: __name__ (module attribute)
@@ -40,6 +40,14 @@ There are only a few functions special to module objects.
Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in;
the caller is responsible for providing a :attr:`__file__` attribute.
+ .. versionadded:: 3.3
+
+
+.. c:function:: PyObject* PyModule_New(const char *name)
+
+ Similar to :c:func:`PyImport_NewObject`, but the name is an UTF-8 encoded
+ string instead of a Unicode object.
+
.. c:function:: PyObject* PyModule_GetDict(PyObject *module)
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index 79ca7ec74a..8013dd9b48 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -12,6 +12,9 @@ PyAPI_DATA(PyTypeObject) PyModule_Type;
#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type)
+PyAPI_FUNC(PyObject *) PyModule_NewObject(
+ PyObject *name
+ );
PyAPI_FUNC(PyObject *) PyModule_New(
const char *name /* UTF-8 encoded string */
);
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 103ac83142..06f58d80d7 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -27,36 +27,45 @@ static PyTypeObject moduledef_type = {
PyObject *
-PyModule_New(const char *name)
+PyModule_NewObject(PyObject *name)
{
PyModuleObject *m;
- PyObject *nameobj;
m = PyObject_GC_New(PyModuleObject, &PyModule_Type);
if (m == NULL)
return NULL;
m->md_def = NULL;
m->md_state = NULL;
- nameobj = PyUnicode_FromString(name);
m->md_dict = PyDict_New();
- if (m->md_dict == NULL || nameobj == NULL)
+ if (m->md_dict == NULL)
goto fail;
- if (PyDict_SetItemString(m->md_dict, "__name__", nameobj) != 0)
+ if (PyDict_SetItemString(m->md_dict, "__name__", name) != 0)
goto fail;
if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0)
goto fail;
if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0)
goto fail;
- Py_DECREF(nameobj);
PyObject_GC_Track(m);
return (PyObject *)m;
fail:
- Py_XDECREF(nameobj);
Py_DECREF(m);
return NULL;
}
PyObject *
+PyModule_New(const char *name)
+{
+ PyObject *nameobj, *module;
+ nameobj = PyUnicode_FromString(name);
+ if (nameobj == NULL)
+ return NULL;
+ module = PyModule_NewObject(nameobj);
+ Py_DECREF(nameobj);
+ return module;
+}
+
+
+PyObject *
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
{
PyObject *d, *v, *n;