From 4baedc1d9be6e5308d73439db54b58e51fb30dfc Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 1 Apr 2002 14:53:37 +0000 Subject: [PATCH] Use the PyModule_Add*() APIs instead of manipulating the module dict directly. --- Modules/selectmodule.c | 29 +-- Modules/socketmodule.c | 418 +++++++++++++++++++++-------------------- Modules/stropmodule.c | 22 +-- Modules/syslogmodule.c | 77 ++++---- Modules/zlibmodule.c | 17 +- 5 files changed, 280 insertions(+), 283 deletions(-) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 0a29f2efd5c..03c222ad477 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -657,34 +657,35 @@ insint(PyObject *d, char *name, int value) DL_EXPORT(void) initselect(void) { - PyObject *m, *d; + PyObject *m; m = Py_InitModule3("select", select_methods, module_doc); - d = PyModule_GetDict(m); + SelectError = PyErr_NewException("select.error", NULL, NULL); - PyDict_SetItemString(d, "error", SelectError); + Py_INCREF(SelectError); + PyModule_AddObject(m, "error", SelectError); #ifdef HAVE_POLL poll_Type.ob_type = &PyType_Type; - insint(d, "POLLIN", POLLIN); - insint(d, "POLLPRI", POLLPRI); - insint(d, "POLLOUT", POLLOUT); - insint(d, "POLLERR", POLLERR); - insint(d, "POLLHUP", POLLHUP); - insint(d, "POLLNVAL", POLLNVAL); + PyModule_AddIntConstant(m, "POLLIN", POLLIN); + PyModule_AddIntConstant(m, "POLLPRI", POLLPRI); + PyModule_AddIntConstant(m, "POLLOUT", POLLOUT); + PyModule_AddIntConstant(m, "POLLERR", POLLERR); + PyModule_AddIntConstant(m, "POLLHUP", POLLHUP); + PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL); #ifdef POLLRDNORM - insint(d, "POLLRDNORM", POLLRDNORM); + PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM); #endif #ifdef POLLRDBAND - insint(d, "POLLRDBAND", POLLRDBAND); + PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND); #endif #ifdef POLLWRNORM - insint(d, "POLLWRNORM", POLLWRNORM); + PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM); #endif #ifdef POLLWRBAND - insint(d, "POLLWRBAND", POLLWRBAND); + PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND); #endif #ifdef POLLMSG - insint(d, "POLLMSG", POLLMSG); + PyModule_AddIntConstant(m, "POLLMSG", POLLMSG); #endif #endif /* HAVE_POLL */ } diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 42605ba2601..74e28f2681a 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2694,7 +2694,7 @@ for documentation."; DL_EXPORT(void) init_socket(void) { - PyObject *m, *d; + PyObject *m; #ifdef RISCOS _kernel_swi_regs r; r.r[0]=0; @@ -2718,588 +2718,604 @@ init_socket(void) m = Py_InitModule3(PySocket_MODULE_NAME, PySocket_methods, module_doc); - d = PyModule_GetDict(m); + PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); if (PySocket_Error == NULL) return; - PyDict_SetItemString(d, "error", PySocket_Error); + Py_INCREF(PySocket_Error); + PyModule_AddObject(m, "error", PySocket_Error); PyH_Error = PyErr_NewException("socket.herror", PySocket_Error, NULL); if (PyH_Error == NULL) return; - PyDict_SetItemString(d, "herror", PyH_Error); + Py_INCREF(PyH_Error); + PyModule_AddObject(m, "herror", PyH_Error); PyGAI_Error = PyErr_NewException("socket.gaierror", PySocket_Error, NULL); if (PyGAI_Error == NULL) return; - PyDict_SetItemString(d, "gaierror", PyGAI_Error); - if (PyDict_SetItemString(d, "SocketType", - (PyObject *)&PySocketSock_Type) != 0) + Py_INCREF(PyGAI_Error); + PyModule_AddObject(m, "gaierror", PyGAI_Error); + Py_INCREF((PyObject *)&PySocketSock_Type); + if (PyModule_AddObject(m, "SocketType", + (PyObject *)&PySocketSock_Type) != 0) return; - if (PyDict_SetItemString(d, "socket", - (PyObject *)&PySocketSock_Type) != 0) + Py_INCREF((PyObject *)&PySocketSock_Type); + if (PyModule_AddObject(m, "socket", + (PyObject *)&PySocketSock_Type) != 0) return; /* Export C API */ - if (PyDict_SetItemString(d, PySocket_CAPI_NAME, + if (PyModule_AddObject(m, PySocket_CAPI_NAME, PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL) ) != 0) return; /* Address families (we only support AF_INET and AF_UNIX) */ #ifdef AF_UNSPEC - insint(d, "AF_UNSPEC", AF_UNSPEC); + PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC); #endif - insint(d, "AF_INET", AF_INET); + PyModule_AddIntConstant(m, "AF_INET", AF_INET); #ifdef AF_INET6 - insint(d, "AF_INET6", AF_INET6); + PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); #endif /* AF_INET6 */ #ifdef AF_UNIX - insint(d, "AF_UNIX", AF_UNIX); + PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX); #endif /* AF_UNIX */ #ifdef AF_AX25 - insint(d, "AF_AX25", AF_AX25); /* Amateur Radio AX.25 */ + /* Amateur Radio AX.25 */ + PyModule_AddIntConstant(m, "AF_AX25", AF_AX25); #endif #ifdef AF_IPX - insint(d, "AF_IPX", AF_IPX); /* Novell IPX */ + PyModule_AddIntConstant(m, "AF_IPX", AF_IPX); /* Novell IPX */ #endif #ifdef AF_APPLETALK - insint(d, "AF_APPLETALK", AF_APPLETALK); /* Appletalk DDP */ + /* Appletalk DDP */ + PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK); #endif #ifdef AF_NETROM - insint(d, "AF_NETROM", AF_NETROM); /* Amateur radio NetROM */ + /* Amateur radio NetROM */ + PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM); #endif #ifdef AF_BRIDGE - insint(d, "AF_BRIDGE", AF_BRIDGE); /* Multiprotocol bridge */ + /* Multiprotocol bridge */ + PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE); #endif #ifdef AF_AAL5 - insint(d, "AF_AAL5", AF_AAL5); /* Reserved for Werner's ATM */ + /* Reserved for Werner's ATM */ + PyModule_AddIntConstant(m, "AF_AAL5", AF_AAL5); #endif #ifdef AF_X25 - insint(d, "AF_X25", AF_X25); /* Reserved for X.25 project */ + /* Reserved for X.25 project */ + PyModule_AddIntConstant(m, "AF_X25", AF_X25); #endif #ifdef AF_INET6 - insint(d, "AF_INET6", AF_INET6); /* IP version 6 */ + PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); /* IP version 6 */ #endif #ifdef AF_ROSE - insint(d, "AF_ROSE", AF_ROSE); /* Amateur Radio X.25 PLP */ + /* Amateur Radio X.25 PLP */ + PyModule_AddIntConstant(m, "AF_ROSE", AF_ROSE); #endif #ifdef HAVE_NETPACKET_PACKET_H - insint(d, "AF_PACKET", AF_PACKET); - insint(d, "PF_PACKET", PF_PACKET); - insint(d, "PACKET_HOST", PACKET_HOST); - insint(d, "PACKET_BROADCAST", PACKET_BROADCAST); - insint(d, "PACKET_MULTICAST", PACKET_MULTICAST); - insint(d, "PACKET_OTHERHOST", PACKET_OTHERHOST); - insint(d, "PACKET_OUTGOING", PACKET_OUTGOING); - insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK); - insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE); + PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET); + PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET); + PyModule_AddIntConstant(m, "PACKET_HOST", PACKET_HOST); + PyModule_AddIntConstant(m, "PACKET_BROADCAST", PACKET_BROADCAST); + PyModule_AddIntConstant(m, "PACKET_MULTICAST", PACKET_MULTICAST); + PyModule_AddIntConstant(m, "PACKET_OTHERHOST", PACKET_OTHERHOST); + PyModule_AddIntConstant(m, "PACKET_OUTGOING", PACKET_OUTGOING); + PyModule_AddIntConstant(m, "PACKET_LOOPBACK", PACKET_LOOPBACK); + PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE); #endif /* Socket types */ - insint(d, "SOCK_STREAM", SOCK_STREAM); - insint(d, "SOCK_DGRAM", SOCK_DGRAM); + PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); + PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM); #ifndef __BEOS__ /* We have incomplete socket support. */ - insint(d, "SOCK_RAW", SOCK_RAW); - insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET); - insint(d, "SOCK_RDM", SOCK_RDM); + PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW); + PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); + PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM); #endif #ifdef SO_DEBUG - insint(d, "SO_DEBUG", SO_DEBUG); + PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG); #endif #ifdef SO_ACCEPTCONN - insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN); + PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN); #endif #ifdef SO_REUSEADDR - insint(d, "SO_REUSEADDR", SO_REUSEADDR); + PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR); #endif #ifdef SO_KEEPALIVE - insint(d, "SO_KEEPALIVE", SO_KEEPALIVE); + PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE); #endif #ifdef SO_DONTROUTE - insint(d, "SO_DONTROUTE", SO_DONTROUTE); + PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE); #endif #ifdef SO_BROADCAST - insint(d, "SO_BROADCAST", SO_BROADCAST); + PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST); #endif #ifdef SO_USELOOPBACK - insint(d, "SO_USELOOPBACK", SO_USELOOPBACK); + PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK); #endif #ifdef SO_LINGER - insint(d, "SO_LINGER", SO_LINGER); + PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER); #endif #ifdef SO_OOBINLINE - insint(d, "SO_OOBINLINE", SO_OOBINLINE); + PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); #endif #ifdef SO_REUSEPORT - insint(d, "SO_REUSEPORT", SO_REUSEPORT); + PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); #endif #ifdef SO_SNDBUF - insint(d, "SO_SNDBUF", SO_SNDBUF); + PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); #endif #ifdef SO_RCVBUF - insint(d, "SO_RCVBUF", SO_RCVBUF); + PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF); #endif #ifdef SO_SNDLOWAT - insint(d, "SO_SNDLOWAT", SO_SNDLOWAT); + PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT); #endif #ifdef SO_RCVLOWAT - insint(d, "SO_RCVLOWAT", SO_RCVLOWAT); + PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT); #endif #ifdef SO_SNDTIMEO - insint(d, "SO_SNDTIMEO", SO_SNDTIMEO); + PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO); #endif #ifdef SO_RCVTIMEO - insint(d, "SO_RCVTIMEO", SO_RCVTIMEO); + PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO); #endif #ifdef SO_ERROR - insint(d, "SO_ERROR", SO_ERROR); + PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR); #endif #ifdef SO_TYPE - insint(d, "SO_TYPE", SO_TYPE); + PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE); #endif /* Maximum number of connections for "listen" */ #ifdef SOMAXCONN - insint(d, "SOMAXCONN", SOMAXCONN); + PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN); #else - insint(d, "SOMAXCONN", 5); /* Common value */ + PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */ #endif /* Flags for send, recv */ #ifdef MSG_OOB - insint(d, "MSG_OOB", MSG_OOB); + PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB); #endif #ifdef MSG_PEEK - insint(d, "MSG_PEEK", MSG_PEEK); + PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK); #endif #ifdef MSG_DONTROUTE - insint(d, "MSG_DONTROUTE", MSG_DONTROUTE); + PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE); #endif #ifdef MSG_DONTWAIT - insint(d, "MSG_DONTWAIT", MSG_DONTWAIT); + PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT); #endif #ifdef MSG_EOR - insint(d, "MSG_EOR", MSG_EOR); + PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR); #endif #ifdef MSG_TRUNC - insint(d, "MSG_TRUNC", MSG_TRUNC); + PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC); #endif #ifdef MSG_CTRUNC - insint(d, "MSG_CTRUNC", MSG_CTRUNC); + PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC); #endif #ifdef MSG_WAITALL - insint(d, "MSG_WAITALL", MSG_WAITALL); + PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL); #endif #ifdef MSG_BTAG - insint(d, "MSG_BTAG", MSG_BTAG); + PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG); #endif #ifdef MSG_ETAG - insint(d, "MSG_ETAG", MSG_ETAG); + PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG); #endif /* Protocol level and numbers, usable for [gs]etsockopt */ #ifdef SOL_SOCKET - insint(d, "SOL_SOCKET", SOL_SOCKET); + PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET); #endif #ifdef SOL_IP - insint(d, "SOL_IP", SOL_IP); + PyModule_AddIntConstant(m, "SOL_IP", SOL_IP); #else - insint(d, "SOL_IP", 0); + PyModule_AddIntConstant(m, "SOL_IP", 0); #endif #ifdef SOL_IPX - insint(d, "SOL_IPX", SOL_IPX); + PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX); #endif #ifdef SOL_AX25 - insint(d, "SOL_AX25", SOL_AX25); + PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25); #endif #ifdef SOL_ATALK - insint(d, "SOL_ATALK", SOL_ATALK); + PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK); #endif #ifdef SOL_NETROM - insint(d, "SOL_NETROM", SOL_NETROM); + PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM); #endif #ifdef SOL_ROSE - insint(d, "SOL_ROSE", SOL_ROSE); + PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE); #endif #ifdef SOL_TCP - insint(d, "SOL_TCP", SOL_TCP); + PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP); #else - insint(d, "SOL_TCP", 6); + PyModule_AddIntConstant(m, "SOL_TCP", 6); #endif #ifdef SOL_UDP - insint(d, "SOL_UDP", SOL_UDP); + PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP); #else - insint(d, "SOL_UDP", 17); + PyModule_AddIntConstant(m, "SOL_UDP", 17); #endif #ifdef IPPROTO_IP - insint(d, "IPPROTO_IP", IPPROTO_IP); + PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP); #else - insint(d, "IPPROTO_IP", 0); + PyModule_AddIntConstant(m, "IPPROTO_IP", 0); #endif #ifdef IPPROTO_HOPOPTS - insint(d, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); + PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); #endif #ifdef IPPROTO_ICMP - insint(d, "IPPROTO_ICMP", IPPROTO_ICMP); + PyModule_AddIntConstant(m, "IPPROTO_ICMP", IPPROTO_ICMP); #else - insint(d, "IPPROTO_ICMP", 1); + PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1); #endif #ifdef IPPROTO_IGMP - insint(d, "IPPROTO_IGMP", IPPROTO_IGMP); + PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP); #endif #ifdef IPPROTO_GGP - insint(d, "IPPROTO_GGP", IPPROTO_GGP); + PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP); #endif #ifdef IPPROTO_IPV4 - insint(d, "IPPROTO_IPV4", IPPROTO_IPV4); + PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV4); #endif #ifdef IPPROTO_IPIP - insint(d, "IPPROTO_IPIP", IPPROTO_IPIP); + PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP); #endif #ifdef IPPROTO_TCP - insint(d, "IPPROTO_TCP", IPPROTO_TCP); + PyModule_AddIntConstant(m, "IPPROTO_TCP", IPPROTO_TCP); #else - insint(d, "IPPROTO_TCP", 6); + PyModule_AddIntConstant(m, "IPPROTO_TCP", 6); #endif #ifdef IPPROTO_EGP - insint(d, "IPPROTO_EGP", IPPROTO_EGP); + PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP); #endif #ifdef IPPROTO_PUP - insint(d, "IPPROTO_PUP", IPPROTO_PUP); + PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP); #endif #ifdef IPPROTO_UDP - insint(d, "IPPROTO_UDP", IPPROTO_UDP); + PyModule_AddIntConstant(m, "IPPROTO_UDP", IPPROTO_UDP); #else - insint(d, "IPPROTO_UDP", 17); + PyModule_AddIntConstant(m, "IPPROTO_UDP", 17); #endif #ifdef IPPROTO_IDP - insint(d, "IPPROTO_IDP", IPPROTO_IDP); + PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP); #endif #ifdef IPPROTO_HELLO - insint(d, "IPPROTO_HELLO", IPPROTO_HELLO); + PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO); #endif #ifdef IPPROTO_ND - insint(d, "IPPROTO_ND", IPPROTO_ND); + PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND); #endif #ifdef IPPROTO_TP - insint(d, "IPPROTO_TP", IPPROTO_TP); + PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP); #endif #ifdef IPPROTO_IPV6 - insint(d, "IPPROTO_IPV6", IPPROTO_IPV6); + PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6); #endif #ifdef IPPROTO_ROUTING - insint(d, "IPPROTO_ROUTING", IPPROTO_ROUTING); + PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING); #endif #ifdef IPPROTO_FRAGMENT - insint(d, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); + PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); #endif #ifdef IPPROTO_RSVP - insint(d, "IPPROTO_RSVP", IPPROTO_RSVP); + PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP); #endif #ifdef IPPROTO_GRE - insint(d, "IPPROTO_GRE", IPPROTO_GRE); + PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE); #endif #ifdef IPPROTO_ESP - insint(d, "IPPROTO_ESP", IPPROTO_ESP); + PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP); #endif #ifdef IPPROTO_AH - insint(d, "IPPROTO_AH", IPPROTO_AH); + PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH); #endif #ifdef IPPROTO_MOBILE - insint(d, "IPPROTO_MOBILE", IPPROTO_MOBILE); + PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE); #endif #ifdef IPPROTO_ICMPV6 - insint(d, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); + PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); #endif #ifdef IPPROTO_NONE - insint(d, "IPPROTO_NONE", IPPROTO_NONE); + PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE); #endif #ifdef IPPROTO_DSTOPTS - insint(d, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); + PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); #endif #ifdef IPPROTO_XTP - insint(d, "IPPROTO_XTP", IPPROTO_XTP); + PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP); #endif #ifdef IPPROTO_EON - insint(d, "IPPROTO_EON", IPPROTO_EON); + PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON); #endif #ifdef IPPROTO_PIM - insint(d, "IPPROTO_PIM", IPPROTO_PIM); + PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM); #endif #ifdef IPPROTO_IPCOMP - insint(d, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); + PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); #endif #ifdef IPPROTO_VRRP - insint(d, "IPPROTO_VRRP", IPPROTO_VRRP); + PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP); #endif #ifdef IPPROTO_BIP - insint(d, "IPPROTO_BIP", IPPROTO_BIP); + PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP); #endif /**/ #ifdef IPPROTO_RAW - insint(d, "IPPROTO_RAW", IPPROTO_RAW); + PyModule_AddIntConstant(m, "IPPROTO_RAW", IPPROTO_RAW); #else - insint(d, "IPPROTO_RAW", 255); + PyModule_AddIntConstant(m, "IPPROTO_RAW", 255); #endif #ifdef IPPROTO_MAX - insint(d, "IPPROTO_MAX", IPPROTO_MAX); + PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX); #endif /* Some port configuration */ #ifdef IPPORT_RESERVED - insint(d, "IPPORT_RESERVED", IPPORT_RESERVED); + PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED); #else - insint(d, "IPPORT_RESERVED", 1024); + PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024); #endif #ifdef IPPORT_USERRESERVED - insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); + PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); #else - insint(d, "IPPORT_USERRESERVED", 5000); + PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000); #endif /* Some reserved IP v.4 addresses */ #ifdef INADDR_ANY - insint(d, "INADDR_ANY", INADDR_ANY); + PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY); #else - insint(d, "INADDR_ANY", 0x00000000); + PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000); #endif #ifdef INADDR_BROADCAST - insint(d, "INADDR_BROADCAST", INADDR_BROADCAST); + PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST); #else - insint(d, "INADDR_BROADCAST", 0xffffffff); + PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff); #endif #ifdef INADDR_LOOPBACK - insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK); + PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK); #else - insint(d, "INADDR_LOOPBACK", 0x7F000001); + PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001); #endif #ifdef INADDR_UNSPEC_GROUP - insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); + PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); #else - insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000); + PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000); #endif #ifdef INADDR_ALLHOSTS_GROUP - insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP); + PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", + INADDR_ALLHOSTS_GROUP); #else - insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001); + PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001); #endif #ifdef INADDR_MAX_LOCAL_GROUP - insint(d, "INADDR_MAX_LOCAL_GROUP", INADDR_MAX_LOCAL_GROUP); + PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", + INADDR_MAX_LOCAL_GROUP); #else - insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); + PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); #endif #ifdef INADDR_NONE - insint(d, "INADDR_NONE", INADDR_NONE); + PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE); #else - insint(d, "INADDR_NONE", 0xffffffff); + PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff); #endif /* IPv4 [gs]etsockopt options */ #ifdef IP_OPTIONS - insint(d, "IP_OPTIONS", IP_OPTIONS); + PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS); #endif #ifdef IP_HDRINCL - insint(d, "IP_HDRINCL", IP_HDRINCL); + PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL); #endif #ifdef IP_TOS - insint(d, "IP_TOS", IP_TOS); + PyModule_AddIntConstant(m, "IP_TOS", IP_TOS); #endif #ifdef IP_TTL - insint(d, "IP_TTL", IP_TTL); + PyModule_AddIntConstant(m, "IP_TTL", IP_TTL); #endif #ifdef IP_RECVOPTS - insint(d, "IP_RECVOPTS", IP_RECVOPTS); + PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS); #endif #ifdef IP_RECVRETOPTS - insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS); + PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS); #endif #ifdef IP_RECVDSTADDR - insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR); + PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR); #endif #ifdef IP_RETOPTS - insint(d, "IP_RETOPTS", IP_RETOPTS); + PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS); #endif #ifdef IP_MULTICAST_IF - insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF); + PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF); #endif #ifdef IP_MULTICAST_TTL - insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); + PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); #endif #ifdef IP_MULTICAST_LOOP - insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); #endif #ifdef IP_ADD_MEMBERSHIP - insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); + PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); #endif #ifdef IP_DROP_MEMBERSHIP - insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); + PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); #endif #ifdef IP_DEFAULT_MULTICAST_TTL - insint(d, "IP_DEFAULT_MULTICAST_TTL", IP_DEFAULT_MULTICAST_TTL); + PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_TTL", + IP_DEFAULT_MULTICAST_TTL); #endif #ifdef IP_DEFAULT_MULTICAST_LOOP - insint(d, "IP_DEFAULT_MULTICAST_LOOP", IP_DEFAULT_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IP_DEFAULT_MULTICAST_LOOP", + IP_DEFAULT_MULTICAST_LOOP); #endif #ifdef IP_MAX_MEMBERSHIPS - insint(d, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); + PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); #endif /* IPv6 [gs]etsockopt options, defined in RFC2553 */ #ifdef IPV6_JOIN_GROUP - insint(d, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); + PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); #endif #ifdef IPV6_LEAVE_GROUP - insint(d, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); + PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); #endif #ifdef IPV6_MULTICAST_HOPS - insint(d, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); #endif #ifdef IPV6_MULTICAST_IF - insint(d, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); #endif #ifdef IPV6_MULTICAST_LOOP - insint(d, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); + PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); #endif #ifdef IPV6_UNICAST_HOPS - insint(d, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); + PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); #endif /* TCP options */ #ifdef TCP_NODELAY - insint(d, "TCP_NODELAY", TCP_NODELAY); + PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY); #endif #ifdef TCP_MAXSEG - insint(d, "TCP_MAXSEG", TCP_MAXSEG); + PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG); #endif #ifdef TCP_CORK - insint(d, "TCP_CORK", TCP_CORK); + PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK); #endif #ifdef TCP_KEEPIDLE - insint(d, "TCP_KEEPIDLE", TCP_KEEPIDLE); + PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE); #endif #ifdef TCP_KEEPINTVL - insint(d, "TCP_KEEPINTVL", TCP_KEEPINTVL); + PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL); #endif #ifdef TCP_KEEPCNT - insint(d, "TCP_KEEPCNT", TCP_KEEPCNT); + PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT); #endif #ifdef TCP_SYNCNT - insint(d, "TCP_SYNCNT", TCP_SYNCNT); + PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT); #endif #ifdef TCP_LINGER2 - insint(d, "TCP_LINGER2", TCP_LINGER2); + PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2); #endif #ifdef TCP_DEFER_ACCEPT - insint(d, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); + PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); #endif #ifdef TCP_WINDOW_CLAMP - insint(d, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); + PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); #endif #ifdef TCP_INFO - insint(d, "TCP_INFO", TCP_INFO); + PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO); #endif #ifdef TCP_QUICKACK - insint(d, "TCP_QUICKACK", TCP_QUICKACK); + PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK); #endif /* IPX options */ #ifdef IPX_TYPE - insint(d, "IPX_TYPE", IPX_TYPE); + PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE); #endif /* get{addr,name}info parameters */ #ifdef EAI_ADDRFAMILY - insint(d, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); + PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); #endif #ifdef EAI_AGAIN - insint(d, "EAI_AGAIN", EAI_AGAIN); + PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN); #endif #ifdef EAI_BADFLAGS - insint(d, "EAI_BADFLAGS", EAI_BADFLAGS); + PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS); #endif #ifdef EAI_FAIL - insint(d, "EAI_FAIL", EAI_FAIL); + PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL); #endif #ifdef EAI_FAMILY - insint(d, "EAI_FAMILY", EAI_FAMILY); + PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY); #endif #ifdef EAI_MEMORY - insint(d, "EAI_MEMORY", EAI_MEMORY); + PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY); #endif #ifdef EAI_NODATA - insint(d, "EAI_NODATA", EAI_NODATA); + PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA); #endif #ifdef EAI_NONAME - insint(d, "EAI_NONAME", EAI_NONAME); + PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME); #endif #ifdef EAI_SERVICE - insint(d, "EAI_SERVICE", EAI_SERVICE); + PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE); #endif #ifdef EAI_SOCKTYPE - insint(d, "EAI_SOCKTYPE", EAI_SOCKTYPE); + PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE); #endif #ifdef EAI_SYSTEM - insint(d, "EAI_SYSTEM", EAI_SYSTEM); + PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM); #endif #ifdef EAI_BADHINTS - insint(d, "EAI_BADHINTS", EAI_BADHINTS); + PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS); #endif #ifdef EAI_PROTOCOL - insint(d, "EAI_PROTOCOL", EAI_PROTOCOL); + PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL); #endif #ifdef EAI_MAX - insint(d, "EAI_MAX", EAI_MAX); + PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX); #endif #ifdef AI_PASSIVE - insint(d, "AI_PASSIVE", AI_PASSIVE); + PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE); #endif #ifdef AI_CANONNAME - insint(d, "AI_CANONNAME", AI_CANONNAME); + PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME); #endif #ifdef AI_NUMERICHOST - insint(d, "AI_NUMERICHOST", AI_NUMERICHOST); + PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST); #endif #ifdef AI_MASK - insint(d, "AI_MASK", AI_MASK); + PyModule_AddIntConstant(m, "AI_MASK", AI_MASK); #endif #ifdef AI_ALL - insint(d, "AI_ALL", AI_ALL); + PyModule_AddIntConstant(m, "AI_ALL", AI_ALL); #endif #ifdef AI_V4MAPPED_CFG - insint(d, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); + PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); #endif #ifdef AI_ADDRCONFIG - insint(d, "AI_ADDRCONFIG", AI_ADDRCONFIG); + PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG); #endif #ifdef AI_V4MAPPED - insint(d, "AI_V4MAPPED", AI_V4MAPPED); + PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED); #endif #ifdef AI_DEFAULT - insint(d, "AI_DEFAULT", AI_DEFAULT); + PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT); #endif #ifdef NI_MAXHOST - insint(d, "NI_MAXHOST", NI_MAXHOST); + PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST); #endif #ifdef NI_MAXSERV - insint(d, "NI_MAXSERV", NI_MAXSERV); + PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV); #endif #ifdef NI_NOFQDN - insint(d, "NI_NOFQDN", NI_NOFQDN); + PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN); #endif #ifdef NI_NUMERICHOST - insint(d, "NI_NUMERICHOST", NI_NUMERICHOST); + PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST); #endif #ifdef NI_NAMEREQD - insint(d, "NI_NAMEREQD", NI_NAMEREQD); + PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD); #endif #ifdef NI_NUMERICSERV - insint(d, "NI_NUMERICSERV", NI_NUMERICSERV); + PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV); #endif #ifdef NI_DGRAM - insint(d, "NI_DGRAM", NI_DGRAM); + PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM); #endif /* Initialize gethostbyname lock */ diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 3c69fb30d78..9af93129ccc 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -1215,12 +1215,11 @@ strop_methods[] = { DL_EXPORT(void) initstrop(void) { - PyObject *m, *d, *s; + PyObject *m, *s; char buf[256]; int c, n; m = Py_InitModule4("strop", strop_methods, strop_module__doc__, (PyObject*)NULL, PYTHON_API_VERSION); - d = PyModule_GetDict(m); /* Create 'whitespace' object */ n = 0; @@ -1229,10 +1228,9 @@ initstrop(void) buf[n++] = c; } s = PyString_FromStringAndSize(buf, n); - if (s) { - PyDict_SetItemString(d, "whitespace", s); - Py_DECREF(s); - } + if (s) + PyModule_AddObject(m, "whitespace", s); + /* Create 'lowercase' object */ n = 0; for (c = 0; c < 256; c++) { @@ -1240,10 +1238,8 @@ initstrop(void) buf[n++] = c; } s = PyString_FromStringAndSize(buf, n); - if (s) { - PyDict_SetItemString(d, "lowercase", s); - Py_DECREF(s); - } + if (s) + PyModule_AddObject(m, "lowercase", s); /* Create 'uppercase' object */ n = 0; @@ -1252,8 +1248,6 @@ initstrop(void) buf[n++] = c; } s = PyString_FromStringAndSize(buf, n); - if (s) { - PyDict_SetItemString(d, "uppercase", s); - Py_DECREF(s); - } + if (s) + PyModule_AddObject(m, "uppercase", s); } diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index eda5490c16f..2d886e1e5b8 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); } diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index feb52ea9381..8fc3bc20fdd 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -847,17 +847,18 @@ static char zlib_module_documentation[]= DL_EXPORT(void) PyInit_zlib(void) { - PyObject *m, *d, *ver; + PyObject *m, *ver; Comptype.ob_type = &PyType_Type; Decomptype.ob_type = &PyType_Type; m = Py_InitModule4("zlib", zlib_methods, zlib_module_documentation, (PyObject*)NULL,PYTHON_API_VERSION); - d = PyModule_GetDict(m); - ZlibError = PyErr_NewException("zlib.error", NULL, NULL); - if (ZlibError != NULL) - PyDict_SetItemString(d, "error", ZlibError); + ZlibError = PyErr_NewException("zlib.error", NULL, NULL); + if (ZlibError != NULL) { + Py_INCREF(ZlibError); + PyModule_AddObject(m, "error", ZlibError); + } PyModule_AddIntConstant(m, "MAX_WBITS", MAX_WBITS); PyModule_AddIntConstant(m, "DEFLATED", DEFLATED); PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); @@ -874,10 +875,8 @@ PyInit_zlib(void) PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH); ver = PyString_FromString(ZLIB_VERSION); - if (ver != NULL) { - PyDict_SetItemString(d, "ZLIB_VERSION", ver); - Py_DECREF(ver); - } + if (ver != NULL) + PyModule_AddObject(m, "ZLIB_VERSION", ver); #ifdef WITH_THREAD zlib_lock = PyThread_allocate_lock();