mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Use PyModule_AddObject() instead of accessing the module dict directly.
This commit is contained in:
parent
cca657b8fe
commit
78f6c867ae
2 changed files with 14 additions and 10 deletions
|
|
@ -1502,16 +1502,18 @@ static PyMethodDef struct_methods[] = {
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
initstruct(void)
|
initstruct(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d;
|
PyObject *m;
|
||||||
|
|
||||||
/* Create the module and add the functions */
|
/* Create the module and add the functions */
|
||||||
m = Py_InitModule4("struct", struct_methods, struct__doc__,
|
m = Py_InitModule4("struct", struct_methods, struct__doc__,
|
||||||
(PyObject*)NULL, PYTHON_API_VERSION);
|
(PyObject*)NULL, PYTHON_API_VERSION);
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = PyModule_GetDict(m);
|
if (StructError == NULL) {
|
||||||
StructError = PyErr_NewException("struct.error", NULL, NULL);
|
StructError = PyErr_NewException("struct.error", NULL, NULL);
|
||||||
if (StructError == NULL)
|
if (StructError == NULL)
|
||||||
return;
|
return;
|
||||||
PyDict_SetItemString(d, "error", StructError);
|
}
|
||||||
|
Py_INCREF(StructError);
|
||||||
|
PyModule_AddObject(d, "error", StructError);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -891,15 +891,17 @@ static struct constant {
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
PyInit_termios(void)
|
PyInit_termios(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d;
|
PyObject *m;
|
||||||
struct constant *constant = termios_constants;
|
struct constant *constant = termios_constants;
|
||||||
|
|
||||||
m = Py_InitModule4("termios", termios_methods, termios__doc__,
|
m = Py_InitModule4("termios", termios_methods, termios__doc__,
|
||||||
(PyObject *)NULL, PYTHON_API_VERSION);
|
(PyObject *)NULL, PYTHON_API_VERSION);
|
||||||
|
|
||||||
d = PyModule_GetDict(m);
|
if (TermiosError == NULL) {
|
||||||
TermiosError = PyErr_NewException("termios.error", NULL, NULL);
|
TermiosError = PyErr_NewException("termios.error", NULL, NULL);
|
||||||
PyDict_SetItemString(d, "error", TermiosError);
|
}
|
||||||
|
Py_INCREF(TermiosError);
|
||||||
|
PyModule_AddObject(m, "error", TermiosError);
|
||||||
|
|
||||||
while (constant->name != NULL) {
|
while (constant->name != NULL) {
|
||||||
PyModule_AddIntConstant(m, constant->name, constant->value);
|
PyModule_AddIntConstant(m, constant->name, constant->value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue