diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-04 12:57:07 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-04 12:57:07 (GMT) |
commit | 0639b56672112e69a1d55c0105dae9198f757ec2 (patch) | |
tree | e98517568ca1ddb7932018f6f0c88a732ff1d2a7 /Objects/moduleobject.c | |
parent | 3a9559b844153c4fe8584d129d88fa8f0a396944 (diff) | |
download | cpython-0639b56672112e69a1d55c0105dae9198f757ec2.zip cpython-0639b56672112e69a1d55c0105dae9198f757ec2.tar.gz cpython-0639b56672112e69a1d55c0105dae9198f757ec2.tar.bz2 |
Issue #3080: Add PyModule_NewObject() function
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r-- | Objects/moduleobject.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 103ac83..06f58d8 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; |