diff options
author | Fred Drake <fdrake@acm.org> | 2002-04-01 14:53:37 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2002-04-01 14:53:37 (GMT) |
commit | 4baedc1d9be6e5308d73439db54b58e51fb30dfc (patch) | |
tree | fb69c6411b2d7be1d2c09e0717329789ec8953ca /Modules/syslogmodule.c | |
parent | 9bb7432114c97ad99c0813c1fef1ef4f1cda3361 (diff) | |
download | cpython-4baedc1d9be6e5308d73439db54b58e51fb30dfc.zip cpython-4baedc1d9be6e5308d73439db54b58e51fb30dfc.tar.gz cpython-4baedc1d9be6e5308d73439db54b58e51fb30dfc.tar.bz2 |
Use the PyModule_Add*() APIs instead of manipulating the module dict
directly.
Diffstat (limited to 'Modules/syslogmodule.c')
-rw-r--r-- | Modules/syslogmodule.c | 77 |
1 files changed, 32 insertions, 45 deletions
diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index eda5490..2d886e1 100644 --- a/Modules/syslogmodule.c +++ b/Modules/syslogmodule.c @@ -153,67 +153,54 @@ static PyMethodDef syslog_methods[] = { {NULL, NULL, 0} }; -/* helper function for initialization function */ - -static void -ins(PyObject *d, char *s, long x) -{ - PyObject *v = PyInt_FromLong(x); - if (v) { - PyDict_SetItemString(d, s, v); - Py_DECREF(v); - } -} - /* Initialization function for the module */ DL_EXPORT(void) initsyslog(void) { - PyObject *m, *d; + PyObject *m; /* Create the module and add the functions */ m = Py_InitModule("syslog", syslog_methods); /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); /* Priorities */ - ins(d, "LOG_EMERG", LOG_EMERG); - ins(d, "LOG_ALERT", LOG_ALERT); - ins(d, "LOG_CRIT", LOG_CRIT); - ins(d, "LOG_ERR", LOG_ERR); - ins(d, "LOG_WARNING", LOG_WARNING); - ins(d, "LOG_NOTICE", LOG_NOTICE); - ins(d, "LOG_INFO", LOG_INFO); - ins(d, "LOG_DEBUG", LOG_DEBUG); + PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG); + PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT); + PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT); + PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR); + PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING); + PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE); + PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO); + PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG); /* openlog() option flags */ - ins(d, "LOG_PID", LOG_PID); - ins(d, "LOG_CONS", LOG_CONS); - ins(d, "LOG_NDELAY", LOG_NDELAY); + PyModule_AddIntConstant(m, "LOG_PID", LOG_PID); + PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS); + PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY); #ifdef LOG_NOWAIT - ins(d, "LOG_NOWAIT", LOG_NOWAIT); + PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT); #endif #ifdef LOG_PERROR - ins(d, "LOG_PERROR", LOG_PERROR); + PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR); #endif /* Facilities */ - ins(d, "LOG_KERN", LOG_KERN); - ins(d, "LOG_USER", LOG_USER); - ins(d, "LOG_MAIL", LOG_MAIL); - ins(d, "LOG_DAEMON", LOG_DAEMON); - ins(d, "LOG_AUTH", LOG_AUTH); - ins(d, "LOG_LPR", LOG_LPR); - ins(d, "LOG_LOCAL0", LOG_LOCAL0); - ins(d, "LOG_LOCAL1", LOG_LOCAL1); - ins(d, "LOG_LOCAL2", LOG_LOCAL2); - ins(d, "LOG_LOCAL3", LOG_LOCAL3); - ins(d, "LOG_LOCAL4", LOG_LOCAL4); - ins(d, "LOG_LOCAL5", LOG_LOCAL5); - ins(d, "LOG_LOCAL6", LOG_LOCAL6); - ins(d, "LOG_LOCAL7", LOG_LOCAL7); + PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN); + PyModule_AddIntConstant(m, "LOG_USER", LOG_USER); + PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL); + PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON); + PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH); + PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR); + PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0); + PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1); + PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2); + PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3); + PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4); + PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5); + PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6); + PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7); #ifndef LOG_SYSLOG #define LOG_SYSLOG LOG_DAEMON @@ -228,8 +215,8 @@ initsyslog(void) #define LOG_CRON LOG_DAEMON #endif - ins(d, "LOG_SYSLOG", LOG_SYSLOG); - ins(d, "LOG_CRON", LOG_CRON); - ins(d, "LOG_UUCP", LOG_UUCP); - ins(d, "LOG_NEWS", LOG_NEWS); + PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG); + PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON); + PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP); + PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS); } |