Use the PyModule_Add*() APIs instead of manipulating the module dict

directly.
This commit is contained in:
Fred Drake 2002-04-01 14:53:37 +00:00
parent 9bb7432114
commit 4baedc1d9b
5 changed files with 280 additions and 283 deletions

View File

@ -657,34 +657,35 @@ insint(PyObject *d, char *name, int value)
DL_EXPORT(void) DL_EXPORT(void)
initselect(void) initselect(void)
{ {
PyObject *m, *d; PyObject *m;
m = Py_InitModule3("select", select_methods, module_doc); m = Py_InitModule3("select", select_methods, module_doc);
d = PyModule_GetDict(m);
SelectError = PyErr_NewException("select.error", NULL, NULL); SelectError = PyErr_NewException("select.error", NULL, NULL);
PyDict_SetItemString(d, "error", SelectError); Py_INCREF(SelectError);
PyModule_AddObject(m, "error", SelectError);
#ifdef HAVE_POLL #ifdef HAVE_POLL
poll_Type.ob_type = &PyType_Type; poll_Type.ob_type = &PyType_Type;
insint(d, "POLLIN", POLLIN); PyModule_AddIntConstant(m, "POLLIN", POLLIN);
insint(d, "POLLPRI", POLLPRI); PyModule_AddIntConstant(m, "POLLPRI", POLLPRI);
insint(d, "POLLOUT", POLLOUT); PyModule_AddIntConstant(m, "POLLOUT", POLLOUT);
insint(d, "POLLERR", POLLERR); PyModule_AddIntConstant(m, "POLLERR", POLLERR);
insint(d, "POLLHUP", POLLHUP); PyModule_AddIntConstant(m, "POLLHUP", POLLHUP);
insint(d, "POLLNVAL", POLLNVAL); PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL);
#ifdef POLLRDNORM #ifdef POLLRDNORM
insint(d, "POLLRDNORM", POLLRDNORM); PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM);
#endif #endif
#ifdef POLLRDBAND #ifdef POLLRDBAND
insint(d, "POLLRDBAND", POLLRDBAND); PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND);
#endif #endif
#ifdef POLLWRNORM #ifdef POLLWRNORM
insint(d, "POLLWRNORM", POLLWRNORM); PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM);
#endif #endif
#ifdef POLLWRBAND #ifdef POLLWRBAND
insint(d, "POLLWRBAND", POLLWRBAND); PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND);
#endif #endif
#ifdef POLLMSG #ifdef POLLMSG
insint(d, "POLLMSG", POLLMSG); PyModule_AddIntConstant(m, "POLLMSG", POLLMSG);
#endif #endif
#endif /* HAVE_POLL */ #endif /* HAVE_POLL */
} }

View File

@ -2694,7 +2694,7 @@ for documentation.";
DL_EXPORT(void) DL_EXPORT(void)
init_socket(void) init_socket(void)
{ {
PyObject *m, *d; PyObject *m;
#ifdef RISCOS #ifdef RISCOS
_kernel_swi_regs r; _kernel_swi_regs r;
r.r[0]=0; r.r[0]=0;
@ -2718,588 +2718,604 @@ init_socket(void)
m = Py_InitModule3(PySocket_MODULE_NAME, m = Py_InitModule3(PySocket_MODULE_NAME,
PySocket_methods, PySocket_methods,
module_doc); module_doc);
d = PyModule_GetDict(m);
PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); PySocket_Error = PyErr_NewException("socket.error", NULL, NULL);
if (PySocket_Error == NULL) if (PySocket_Error == NULL)
return; 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); PyH_Error = PyErr_NewException("socket.herror", PySocket_Error, NULL);
if (PyH_Error == NULL) if (PyH_Error == NULL)
return; 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, PyGAI_Error = PyErr_NewException("socket.gaierror", PySocket_Error,
NULL); NULL);
if (PyGAI_Error == NULL) if (PyGAI_Error == NULL)
return; return;
PyDict_SetItemString(d, "gaierror", PyGAI_Error); Py_INCREF(PyGAI_Error);
if (PyDict_SetItemString(d, "SocketType", PyModule_AddObject(m, "gaierror", PyGAI_Error);
(PyObject *)&PySocketSock_Type) != 0) Py_INCREF((PyObject *)&PySocketSock_Type);
if (PyModule_AddObject(m, "SocketType",
(PyObject *)&PySocketSock_Type) != 0)
return; return;
if (PyDict_SetItemString(d, "socket", Py_INCREF((PyObject *)&PySocketSock_Type);
(PyObject *)&PySocketSock_Type) != 0) if (PyModule_AddObject(m, "socket",
(PyObject *)&PySocketSock_Type) != 0)
return; return;
/* Export C API */ /* Export C API */
if (PyDict_SetItemString(d, PySocket_CAPI_NAME, if (PyModule_AddObject(m, PySocket_CAPI_NAME,
PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL) PyCObject_FromVoidPtr((void *)&PySocketModuleAPI, NULL)
) != 0) ) != 0)
return; return;
/* Address families (we only support AF_INET and AF_UNIX) */ /* Address families (we only support AF_INET and AF_UNIX) */
#ifdef AF_UNSPEC #ifdef AF_UNSPEC
insint(d, "AF_UNSPEC", AF_UNSPEC); PyModule_AddIntConstant(m, "AF_UNSPEC", AF_UNSPEC);
#endif #endif
insint(d, "AF_INET", AF_INET); PyModule_AddIntConstant(m, "AF_INET", AF_INET);
#ifdef AF_INET6 #ifdef AF_INET6
insint(d, "AF_INET6", AF_INET6); PyModule_AddIntConstant(m, "AF_INET6", AF_INET6);
#endif /* AF_INET6 */ #endif /* AF_INET6 */
#ifdef AF_UNIX #ifdef AF_UNIX
insint(d, "AF_UNIX", AF_UNIX); PyModule_AddIntConstant(m, "AF_UNIX", AF_UNIX);
#endif /* AF_UNIX */ #endif /* AF_UNIX */
#ifdef AF_AX25 #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 #endif
#ifdef AF_IPX #ifdef AF_IPX
insint(d, "AF_IPX", AF_IPX); /* Novell IPX */ PyModule_AddIntConstant(m, "AF_IPX", AF_IPX); /* Novell IPX */
#endif #endif
#ifdef AF_APPLETALK #ifdef AF_APPLETALK
insint(d, "AF_APPLETALK", AF_APPLETALK); /* Appletalk DDP */ /* Appletalk DDP */
PyModule_AddIntConstant(m, "AF_APPLETALK", AF_APPLETALK);
#endif #endif
#ifdef AF_NETROM #ifdef AF_NETROM
insint(d, "AF_NETROM", AF_NETROM); /* Amateur radio NetROM */ /* Amateur radio NetROM */
PyModule_AddIntConstant(m, "AF_NETROM", AF_NETROM);
#endif #endif
#ifdef AF_BRIDGE #ifdef AF_BRIDGE
insint(d, "AF_BRIDGE", AF_BRIDGE); /* Multiprotocol bridge */ /* Multiprotocol bridge */
PyModule_AddIntConstant(m, "AF_BRIDGE", AF_BRIDGE);
#endif #endif
#ifdef AF_AAL5 #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 #endif
#ifdef AF_X25 #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 #endif
#ifdef AF_INET6 #ifdef AF_INET6
insint(d, "AF_INET6", AF_INET6); /* IP version 6 */ PyModule_AddIntConstant(m, "AF_INET6", AF_INET6); /* IP version 6 */
#endif #endif
#ifdef AF_ROSE #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 #endif
#ifdef HAVE_NETPACKET_PACKET_H #ifdef HAVE_NETPACKET_PACKET_H
insint(d, "AF_PACKET", AF_PACKET); PyModule_AddIntConstant(m, "AF_PACKET", AF_PACKET);
insint(d, "PF_PACKET", PF_PACKET); PyModule_AddIntConstant(m, "PF_PACKET", PF_PACKET);
insint(d, "PACKET_HOST", PACKET_HOST); PyModule_AddIntConstant(m, "PACKET_HOST", PACKET_HOST);
insint(d, "PACKET_BROADCAST", PACKET_BROADCAST); PyModule_AddIntConstant(m, "PACKET_BROADCAST", PACKET_BROADCAST);
insint(d, "PACKET_MULTICAST", PACKET_MULTICAST); PyModule_AddIntConstant(m, "PACKET_MULTICAST", PACKET_MULTICAST);
insint(d, "PACKET_OTHERHOST", PACKET_OTHERHOST); PyModule_AddIntConstant(m, "PACKET_OTHERHOST", PACKET_OTHERHOST);
insint(d, "PACKET_OUTGOING", PACKET_OUTGOING); PyModule_AddIntConstant(m, "PACKET_OUTGOING", PACKET_OUTGOING);
insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK); PyModule_AddIntConstant(m, "PACKET_LOOPBACK", PACKET_LOOPBACK);
insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE); PyModule_AddIntConstant(m, "PACKET_FASTROUTE", PACKET_FASTROUTE);
#endif #endif
/* Socket types */ /* Socket types */
insint(d, "SOCK_STREAM", SOCK_STREAM); PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM);
insint(d, "SOCK_DGRAM", SOCK_DGRAM); PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM);
#ifndef __BEOS__ #ifndef __BEOS__
/* We have incomplete socket support. */ /* We have incomplete socket support. */
insint(d, "SOCK_RAW", SOCK_RAW); PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW);
insint(d, "SOCK_SEQPACKET", SOCK_SEQPACKET); PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET);
insint(d, "SOCK_RDM", SOCK_RDM); PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM);
#endif #endif
#ifdef SO_DEBUG #ifdef SO_DEBUG
insint(d, "SO_DEBUG", SO_DEBUG); PyModule_AddIntConstant(m, "SO_DEBUG", SO_DEBUG);
#endif #endif
#ifdef SO_ACCEPTCONN #ifdef SO_ACCEPTCONN
insint(d, "SO_ACCEPTCONN", SO_ACCEPTCONN); PyModule_AddIntConstant(m, "SO_ACCEPTCONN", SO_ACCEPTCONN);
#endif #endif
#ifdef SO_REUSEADDR #ifdef SO_REUSEADDR
insint(d, "SO_REUSEADDR", SO_REUSEADDR); PyModule_AddIntConstant(m, "SO_REUSEADDR", SO_REUSEADDR);
#endif #endif
#ifdef SO_KEEPALIVE #ifdef SO_KEEPALIVE
insint(d, "SO_KEEPALIVE", SO_KEEPALIVE); PyModule_AddIntConstant(m, "SO_KEEPALIVE", SO_KEEPALIVE);
#endif #endif
#ifdef SO_DONTROUTE #ifdef SO_DONTROUTE
insint(d, "SO_DONTROUTE", SO_DONTROUTE); PyModule_AddIntConstant(m, "SO_DONTROUTE", SO_DONTROUTE);
#endif #endif
#ifdef SO_BROADCAST #ifdef SO_BROADCAST
insint(d, "SO_BROADCAST", SO_BROADCAST); PyModule_AddIntConstant(m, "SO_BROADCAST", SO_BROADCAST);
#endif #endif
#ifdef SO_USELOOPBACK #ifdef SO_USELOOPBACK
insint(d, "SO_USELOOPBACK", SO_USELOOPBACK); PyModule_AddIntConstant(m, "SO_USELOOPBACK", SO_USELOOPBACK);
#endif #endif
#ifdef SO_LINGER #ifdef SO_LINGER
insint(d, "SO_LINGER", SO_LINGER); PyModule_AddIntConstant(m, "SO_LINGER", SO_LINGER);
#endif #endif
#ifdef SO_OOBINLINE #ifdef SO_OOBINLINE
insint(d, "SO_OOBINLINE", SO_OOBINLINE); PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE);
#endif #endif
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
insint(d, "SO_REUSEPORT", SO_REUSEPORT); PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT);
#endif #endif
#ifdef SO_SNDBUF #ifdef SO_SNDBUF
insint(d, "SO_SNDBUF", SO_SNDBUF); PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF);
#endif #endif
#ifdef SO_RCVBUF #ifdef SO_RCVBUF
insint(d, "SO_RCVBUF", SO_RCVBUF); PyModule_AddIntConstant(m, "SO_RCVBUF", SO_RCVBUF);
#endif #endif
#ifdef SO_SNDLOWAT #ifdef SO_SNDLOWAT
insint(d, "SO_SNDLOWAT", SO_SNDLOWAT); PyModule_AddIntConstant(m, "SO_SNDLOWAT", SO_SNDLOWAT);
#endif #endif
#ifdef SO_RCVLOWAT #ifdef SO_RCVLOWAT
insint(d, "SO_RCVLOWAT", SO_RCVLOWAT); PyModule_AddIntConstant(m, "SO_RCVLOWAT", SO_RCVLOWAT);
#endif #endif
#ifdef SO_SNDTIMEO #ifdef SO_SNDTIMEO
insint(d, "SO_SNDTIMEO", SO_SNDTIMEO); PyModule_AddIntConstant(m, "SO_SNDTIMEO", SO_SNDTIMEO);
#endif #endif
#ifdef SO_RCVTIMEO #ifdef SO_RCVTIMEO
insint(d, "SO_RCVTIMEO", SO_RCVTIMEO); PyModule_AddIntConstant(m, "SO_RCVTIMEO", SO_RCVTIMEO);
#endif #endif
#ifdef SO_ERROR #ifdef SO_ERROR
insint(d, "SO_ERROR", SO_ERROR); PyModule_AddIntConstant(m, "SO_ERROR", SO_ERROR);
#endif #endif
#ifdef SO_TYPE #ifdef SO_TYPE
insint(d, "SO_TYPE", SO_TYPE); PyModule_AddIntConstant(m, "SO_TYPE", SO_TYPE);
#endif #endif
/* Maximum number of connections for "listen" */ /* Maximum number of connections for "listen" */
#ifdef SOMAXCONN #ifdef SOMAXCONN
insint(d, "SOMAXCONN", SOMAXCONN); PyModule_AddIntConstant(m, "SOMAXCONN", SOMAXCONN);
#else #else
insint(d, "SOMAXCONN", 5); /* Common value */ PyModule_AddIntConstant(m, "SOMAXCONN", 5); /* Common value */
#endif #endif
/* Flags for send, recv */ /* Flags for send, recv */
#ifdef MSG_OOB #ifdef MSG_OOB
insint(d, "MSG_OOB", MSG_OOB); PyModule_AddIntConstant(m, "MSG_OOB", MSG_OOB);
#endif #endif
#ifdef MSG_PEEK #ifdef MSG_PEEK
insint(d, "MSG_PEEK", MSG_PEEK); PyModule_AddIntConstant(m, "MSG_PEEK", MSG_PEEK);
#endif #endif
#ifdef MSG_DONTROUTE #ifdef MSG_DONTROUTE
insint(d, "MSG_DONTROUTE", MSG_DONTROUTE); PyModule_AddIntConstant(m, "MSG_DONTROUTE", MSG_DONTROUTE);
#endif #endif
#ifdef MSG_DONTWAIT #ifdef MSG_DONTWAIT
insint(d, "MSG_DONTWAIT", MSG_DONTWAIT); PyModule_AddIntConstant(m, "MSG_DONTWAIT", MSG_DONTWAIT);
#endif #endif
#ifdef MSG_EOR #ifdef MSG_EOR
insint(d, "MSG_EOR", MSG_EOR); PyModule_AddIntConstant(m, "MSG_EOR", MSG_EOR);
#endif #endif
#ifdef MSG_TRUNC #ifdef MSG_TRUNC
insint(d, "MSG_TRUNC", MSG_TRUNC); PyModule_AddIntConstant(m, "MSG_TRUNC", MSG_TRUNC);
#endif #endif
#ifdef MSG_CTRUNC #ifdef MSG_CTRUNC
insint(d, "MSG_CTRUNC", MSG_CTRUNC); PyModule_AddIntConstant(m, "MSG_CTRUNC", MSG_CTRUNC);
#endif #endif
#ifdef MSG_WAITALL #ifdef MSG_WAITALL
insint(d, "MSG_WAITALL", MSG_WAITALL); PyModule_AddIntConstant(m, "MSG_WAITALL", MSG_WAITALL);
#endif #endif
#ifdef MSG_BTAG #ifdef MSG_BTAG
insint(d, "MSG_BTAG", MSG_BTAG); PyModule_AddIntConstant(m, "MSG_BTAG", MSG_BTAG);
#endif #endif
#ifdef MSG_ETAG #ifdef MSG_ETAG
insint(d, "MSG_ETAG", MSG_ETAG); PyModule_AddIntConstant(m, "MSG_ETAG", MSG_ETAG);
#endif #endif
/* Protocol level and numbers, usable for [gs]etsockopt */ /* Protocol level and numbers, usable for [gs]etsockopt */
#ifdef SOL_SOCKET #ifdef SOL_SOCKET
insint(d, "SOL_SOCKET", SOL_SOCKET); PyModule_AddIntConstant(m, "SOL_SOCKET", SOL_SOCKET);
#endif #endif
#ifdef SOL_IP #ifdef SOL_IP
insint(d, "SOL_IP", SOL_IP); PyModule_AddIntConstant(m, "SOL_IP", SOL_IP);
#else #else
insint(d, "SOL_IP", 0); PyModule_AddIntConstant(m, "SOL_IP", 0);
#endif #endif
#ifdef SOL_IPX #ifdef SOL_IPX
insint(d, "SOL_IPX", SOL_IPX); PyModule_AddIntConstant(m, "SOL_IPX", SOL_IPX);
#endif #endif
#ifdef SOL_AX25 #ifdef SOL_AX25
insint(d, "SOL_AX25", SOL_AX25); PyModule_AddIntConstant(m, "SOL_AX25", SOL_AX25);
#endif #endif
#ifdef SOL_ATALK #ifdef SOL_ATALK
insint(d, "SOL_ATALK", SOL_ATALK); PyModule_AddIntConstant(m, "SOL_ATALK", SOL_ATALK);
#endif #endif
#ifdef SOL_NETROM #ifdef SOL_NETROM
insint(d, "SOL_NETROM", SOL_NETROM); PyModule_AddIntConstant(m, "SOL_NETROM", SOL_NETROM);
#endif #endif
#ifdef SOL_ROSE #ifdef SOL_ROSE
insint(d, "SOL_ROSE", SOL_ROSE); PyModule_AddIntConstant(m, "SOL_ROSE", SOL_ROSE);
#endif #endif
#ifdef SOL_TCP #ifdef SOL_TCP
insint(d, "SOL_TCP", SOL_TCP); PyModule_AddIntConstant(m, "SOL_TCP", SOL_TCP);
#else #else
insint(d, "SOL_TCP", 6); PyModule_AddIntConstant(m, "SOL_TCP", 6);
#endif #endif
#ifdef SOL_UDP #ifdef SOL_UDP
insint(d, "SOL_UDP", SOL_UDP); PyModule_AddIntConstant(m, "SOL_UDP", SOL_UDP);
#else #else
insint(d, "SOL_UDP", 17); PyModule_AddIntConstant(m, "SOL_UDP", 17);
#endif #endif
#ifdef IPPROTO_IP #ifdef IPPROTO_IP
insint(d, "IPPROTO_IP", IPPROTO_IP); PyModule_AddIntConstant(m, "IPPROTO_IP", IPPROTO_IP);
#else #else
insint(d, "IPPROTO_IP", 0); PyModule_AddIntConstant(m, "IPPROTO_IP", 0);
#endif #endif
#ifdef IPPROTO_HOPOPTS #ifdef IPPROTO_HOPOPTS
insint(d, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS); PyModule_AddIntConstant(m, "IPPROTO_HOPOPTS", IPPROTO_HOPOPTS);
#endif #endif
#ifdef IPPROTO_ICMP #ifdef IPPROTO_ICMP
insint(d, "IPPROTO_ICMP", IPPROTO_ICMP); PyModule_AddIntConstant(m, "IPPROTO_ICMP", IPPROTO_ICMP);
#else #else
insint(d, "IPPROTO_ICMP", 1); PyModule_AddIntConstant(m, "IPPROTO_ICMP", 1);
#endif #endif
#ifdef IPPROTO_IGMP #ifdef IPPROTO_IGMP
insint(d, "IPPROTO_IGMP", IPPROTO_IGMP); PyModule_AddIntConstant(m, "IPPROTO_IGMP", IPPROTO_IGMP);
#endif #endif
#ifdef IPPROTO_GGP #ifdef IPPROTO_GGP
insint(d, "IPPROTO_GGP", IPPROTO_GGP); PyModule_AddIntConstant(m, "IPPROTO_GGP", IPPROTO_GGP);
#endif #endif
#ifdef IPPROTO_IPV4 #ifdef IPPROTO_IPV4
insint(d, "IPPROTO_IPV4", IPPROTO_IPV4); PyModule_AddIntConstant(m, "IPPROTO_IPV4", IPPROTO_IPV4);
#endif #endif
#ifdef IPPROTO_IPIP #ifdef IPPROTO_IPIP
insint(d, "IPPROTO_IPIP", IPPROTO_IPIP); PyModule_AddIntConstant(m, "IPPROTO_IPIP", IPPROTO_IPIP);
#endif #endif
#ifdef IPPROTO_TCP #ifdef IPPROTO_TCP
insint(d, "IPPROTO_TCP", IPPROTO_TCP); PyModule_AddIntConstant(m, "IPPROTO_TCP", IPPROTO_TCP);
#else #else
insint(d, "IPPROTO_TCP", 6); PyModule_AddIntConstant(m, "IPPROTO_TCP", 6);
#endif #endif
#ifdef IPPROTO_EGP #ifdef IPPROTO_EGP
insint(d, "IPPROTO_EGP", IPPROTO_EGP); PyModule_AddIntConstant(m, "IPPROTO_EGP", IPPROTO_EGP);
#endif #endif
#ifdef IPPROTO_PUP #ifdef IPPROTO_PUP
insint(d, "IPPROTO_PUP", IPPROTO_PUP); PyModule_AddIntConstant(m, "IPPROTO_PUP", IPPROTO_PUP);
#endif #endif
#ifdef IPPROTO_UDP #ifdef IPPROTO_UDP
insint(d, "IPPROTO_UDP", IPPROTO_UDP); PyModule_AddIntConstant(m, "IPPROTO_UDP", IPPROTO_UDP);
#else #else
insint(d, "IPPROTO_UDP", 17); PyModule_AddIntConstant(m, "IPPROTO_UDP", 17);
#endif #endif
#ifdef IPPROTO_IDP #ifdef IPPROTO_IDP
insint(d, "IPPROTO_IDP", IPPROTO_IDP); PyModule_AddIntConstant(m, "IPPROTO_IDP", IPPROTO_IDP);
#endif #endif
#ifdef IPPROTO_HELLO #ifdef IPPROTO_HELLO
insint(d, "IPPROTO_HELLO", IPPROTO_HELLO); PyModule_AddIntConstant(m, "IPPROTO_HELLO", IPPROTO_HELLO);
#endif #endif
#ifdef IPPROTO_ND #ifdef IPPROTO_ND
insint(d, "IPPROTO_ND", IPPROTO_ND); PyModule_AddIntConstant(m, "IPPROTO_ND", IPPROTO_ND);
#endif #endif
#ifdef IPPROTO_TP #ifdef IPPROTO_TP
insint(d, "IPPROTO_TP", IPPROTO_TP); PyModule_AddIntConstant(m, "IPPROTO_TP", IPPROTO_TP);
#endif #endif
#ifdef IPPROTO_IPV6 #ifdef IPPROTO_IPV6
insint(d, "IPPROTO_IPV6", IPPROTO_IPV6); PyModule_AddIntConstant(m, "IPPROTO_IPV6", IPPROTO_IPV6);
#endif #endif
#ifdef IPPROTO_ROUTING #ifdef IPPROTO_ROUTING
insint(d, "IPPROTO_ROUTING", IPPROTO_ROUTING); PyModule_AddIntConstant(m, "IPPROTO_ROUTING", IPPROTO_ROUTING);
#endif #endif
#ifdef IPPROTO_FRAGMENT #ifdef IPPROTO_FRAGMENT
insint(d, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT); PyModule_AddIntConstant(m, "IPPROTO_FRAGMENT", IPPROTO_FRAGMENT);
#endif #endif
#ifdef IPPROTO_RSVP #ifdef IPPROTO_RSVP
insint(d, "IPPROTO_RSVP", IPPROTO_RSVP); PyModule_AddIntConstant(m, "IPPROTO_RSVP", IPPROTO_RSVP);
#endif #endif
#ifdef IPPROTO_GRE #ifdef IPPROTO_GRE
insint(d, "IPPROTO_GRE", IPPROTO_GRE); PyModule_AddIntConstant(m, "IPPROTO_GRE", IPPROTO_GRE);
#endif #endif
#ifdef IPPROTO_ESP #ifdef IPPROTO_ESP
insint(d, "IPPROTO_ESP", IPPROTO_ESP); PyModule_AddIntConstant(m, "IPPROTO_ESP", IPPROTO_ESP);
#endif #endif
#ifdef IPPROTO_AH #ifdef IPPROTO_AH
insint(d, "IPPROTO_AH", IPPROTO_AH); PyModule_AddIntConstant(m, "IPPROTO_AH", IPPROTO_AH);
#endif #endif
#ifdef IPPROTO_MOBILE #ifdef IPPROTO_MOBILE
insint(d, "IPPROTO_MOBILE", IPPROTO_MOBILE); PyModule_AddIntConstant(m, "IPPROTO_MOBILE", IPPROTO_MOBILE);
#endif #endif
#ifdef IPPROTO_ICMPV6 #ifdef IPPROTO_ICMPV6
insint(d, "IPPROTO_ICMPV6", IPPROTO_ICMPV6); PyModule_AddIntConstant(m, "IPPROTO_ICMPV6", IPPROTO_ICMPV6);
#endif #endif
#ifdef IPPROTO_NONE #ifdef IPPROTO_NONE
insint(d, "IPPROTO_NONE", IPPROTO_NONE); PyModule_AddIntConstant(m, "IPPROTO_NONE", IPPROTO_NONE);
#endif #endif
#ifdef IPPROTO_DSTOPTS #ifdef IPPROTO_DSTOPTS
insint(d, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS); PyModule_AddIntConstant(m, "IPPROTO_DSTOPTS", IPPROTO_DSTOPTS);
#endif #endif
#ifdef IPPROTO_XTP #ifdef IPPROTO_XTP
insint(d, "IPPROTO_XTP", IPPROTO_XTP); PyModule_AddIntConstant(m, "IPPROTO_XTP", IPPROTO_XTP);
#endif #endif
#ifdef IPPROTO_EON #ifdef IPPROTO_EON
insint(d, "IPPROTO_EON", IPPROTO_EON); PyModule_AddIntConstant(m, "IPPROTO_EON", IPPROTO_EON);
#endif #endif
#ifdef IPPROTO_PIM #ifdef IPPROTO_PIM
insint(d, "IPPROTO_PIM", IPPROTO_PIM); PyModule_AddIntConstant(m, "IPPROTO_PIM", IPPROTO_PIM);
#endif #endif
#ifdef IPPROTO_IPCOMP #ifdef IPPROTO_IPCOMP
insint(d, "IPPROTO_IPCOMP", IPPROTO_IPCOMP); PyModule_AddIntConstant(m, "IPPROTO_IPCOMP", IPPROTO_IPCOMP);
#endif #endif
#ifdef IPPROTO_VRRP #ifdef IPPROTO_VRRP
insint(d, "IPPROTO_VRRP", IPPROTO_VRRP); PyModule_AddIntConstant(m, "IPPROTO_VRRP", IPPROTO_VRRP);
#endif #endif
#ifdef IPPROTO_BIP #ifdef IPPROTO_BIP
insint(d, "IPPROTO_BIP", IPPROTO_BIP); PyModule_AddIntConstant(m, "IPPROTO_BIP", IPPROTO_BIP);
#endif #endif
/**/ /**/
#ifdef IPPROTO_RAW #ifdef IPPROTO_RAW
insint(d, "IPPROTO_RAW", IPPROTO_RAW); PyModule_AddIntConstant(m, "IPPROTO_RAW", IPPROTO_RAW);
#else #else
insint(d, "IPPROTO_RAW", 255); PyModule_AddIntConstant(m, "IPPROTO_RAW", 255);
#endif #endif
#ifdef IPPROTO_MAX #ifdef IPPROTO_MAX
insint(d, "IPPROTO_MAX", IPPROTO_MAX); PyModule_AddIntConstant(m, "IPPROTO_MAX", IPPROTO_MAX);
#endif #endif
/* Some port configuration */ /* Some port configuration */
#ifdef IPPORT_RESERVED #ifdef IPPORT_RESERVED
insint(d, "IPPORT_RESERVED", IPPORT_RESERVED); PyModule_AddIntConstant(m, "IPPORT_RESERVED", IPPORT_RESERVED);
#else #else
insint(d, "IPPORT_RESERVED", 1024); PyModule_AddIntConstant(m, "IPPORT_RESERVED", 1024);
#endif #endif
#ifdef IPPORT_USERRESERVED #ifdef IPPORT_USERRESERVED
insint(d, "IPPORT_USERRESERVED", IPPORT_USERRESERVED); PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", IPPORT_USERRESERVED);
#else #else
insint(d, "IPPORT_USERRESERVED", 5000); PyModule_AddIntConstant(m, "IPPORT_USERRESERVED", 5000);
#endif #endif
/* Some reserved IP v.4 addresses */ /* Some reserved IP v.4 addresses */
#ifdef INADDR_ANY #ifdef INADDR_ANY
insint(d, "INADDR_ANY", INADDR_ANY); PyModule_AddIntConstant(m, "INADDR_ANY", INADDR_ANY);
#else #else
insint(d, "INADDR_ANY", 0x00000000); PyModule_AddIntConstant(m, "INADDR_ANY", 0x00000000);
#endif #endif
#ifdef INADDR_BROADCAST #ifdef INADDR_BROADCAST
insint(d, "INADDR_BROADCAST", INADDR_BROADCAST); PyModule_AddIntConstant(m, "INADDR_BROADCAST", INADDR_BROADCAST);
#else #else
insint(d, "INADDR_BROADCAST", 0xffffffff); PyModule_AddIntConstant(m, "INADDR_BROADCAST", 0xffffffff);
#endif #endif
#ifdef INADDR_LOOPBACK #ifdef INADDR_LOOPBACK
insint(d, "INADDR_LOOPBACK", INADDR_LOOPBACK); PyModule_AddIntConstant(m, "INADDR_LOOPBACK", INADDR_LOOPBACK);
#else #else
insint(d, "INADDR_LOOPBACK", 0x7F000001); PyModule_AddIntConstant(m, "INADDR_LOOPBACK", 0x7F000001);
#endif #endif
#ifdef INADDR_UNSPEC_GROUP #ifdef INADDR_UNSPEC_GROUP
insint(d, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP); PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", INADDR_UNSPEC_GROUP);
#else #else
insint(d, "INADDR_UNSPEC_GROUP", 0xe0000000); PyModule_AddIntConstant(m, "INADDR_UNSPEC_GROUP", 0xe0000000);
#endif #endif
#ifdef INADDR_ALLHOSTS_GROUP #ifdef INADDR_ALLHOSTS_GROUP
insint(d, "INADDR_ALLHOSTS_GROUP", INADDR_ALLHOSTS_GROUP); PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP",
INADDR_ALLHOSTS_GROUP);
#else #else
insint(d, "INADDR_ALLHOSTS_GROUP", 0xe0000001); PyModule_AddIntConstant(m, "INADDR_ALLHOSTS_GROUP", 0xe0000001);
#endif #endif
#ifdef INADDR_MAX_LOCAL_GROUP #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 #else
insint(d, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff); PyModule_AddIntConstant(m, "INADDR_MAX_LOCAL_GROUP", 0xe00000ff);
#endif #endif
#ifdef INADDR_NONE #ifdef INADDR_NONE
insint(d, "INADDR_NONE", INADDR_NONE); PyModule_AddIntConstant(m, "INADDR_NONE", INADDR_NONE);
#else #else
insint(d, "INADDR_NONE", 0xffffffff); PyModule_AddIntConstant(m, "INADDR_NONE", 0xffffffff);
#endif #endif
/* IPv4 [gs]etsockopt options */ /* IPv4 [gs]etsockopt options */
#ifdef IP_OPTIONS #ifdef IP_OPTIONS
insint(d, "IP_OPTIONS", IP_OPTIONS); PyModule_AddIntConstant(m, "IP_OPTIONS", IP_OPTIONS);
#endif #endif
#ifdef IP_HDRINCL #ifdef IP_HDRINCL
insint(d, "IP_HDRINCL", IP_HDRINCL); PyModule_AddIntConstant(m, "IP_HDRINCL", IP_HDRINCL);
#endif #endif
#ifdef IP_TOS #ifdef IP_TOS
insint(d, "IP_TOS", IP_TOS); PyModule_AddIntConstant(m, "IP_TOS", IP_TOS);
#endif #endif
#ifdef IP_TTL #ifdef IP_TTL
insint(d, "IP_TTL", IP_TTL); PyModule_AddIntConstant(m, "IP_TTL", IP_TTL);
#endif #endif
#ifdef IP_RECVOPTS #ifdef IP_RECVOPTS
insint(d, "IP_RECVOPTS", IP_RECVOPTS); PyModule_AddIntConstant(m, "IP_RECVOPTS", IP_RECVOPTS);
#endif #endif
#ifdef IP_RECVRETOPTS #ifdef IP_RECVRETOPTS
insint(d, "IP_RECVRETOPTS", IP_RECVRETOPTS); PyModule_AddIntConstant(m, "IP_RECVRETOPTS", IP_RECVRETOPTS);
#endif #endif
#ifdef IP_RECVDSTADDR #ifdef IP_RECVDSTADDR
insint(d, "IP_RECVDSTADDR", IP_RECVDSTADDR); PyModule_AddIntConstant(m, "IP_RECVDSTADDR", IP_RECVDSTADDR);
#endif #endif
#ifdef IP_RETOPTS #ifdef IP_RETOPTS
insint(d, "IP_RETOPTS", IP_RETOPTS); PyModule_AddIntConstant(m, "IP_RETOPTS", IP_RETOPTS);
#endif #endif
#ifdef IP_MULTICAST_IF #ifdef IP_MULTICAST_IF
insint(d, "IP_MULTICAST_IF", IP_MULTICAST_IF); PyModule_AddIntConstant(m, "IP_MULTICAST_IF", IP_MULTICAST_IF);
#endif #endif
#ifdef IP_MULTICAST_TTL #ifdef IP_MULTICAST_TTL
insint(d, "IP_MULTICAST_TTL", IP_MULTICAST_TTL); PyModule_AddIntConstant(m, "IP_MULTICAST_TTL", IP_MULTICAST_TTL);
#endif #endif
#ifdef IP_MULTICAST_LOOP #ifdef IP_MULTICAST_LOOP
insint(d, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP); PyModule_AddIntConstant(m, "IP_MULTICAST_LOOP", IP_MULTICAST_LOOP);
#endif #endif
#ifdef IP_ADD_MEMBERSHIP #ifdef IP_ADD_MEMBERSHIP
insint(d, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP); PyModule_AddIntConstant(m, "IP_ADD_MEMBERSHIP", IP_ADD_MEMBERSHIP);
#endif #endif
#ifdef IP_DROP_MEMBERSHIP #ifdef IP_DROP_MEMBERSHIP
insint(d, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP); PyModule_AddIntConstant(m, "IP_DROP_MEMBERSHIP", IP_DROP_MEMBERSHIP);
#endif #endif
#ifdef IP_DEFAULT_MULTICAST_TTL #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 #endif
#ifdef IP_DEFAULT_MULTICAST_LOOP #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 #endif
#ifdef IP_MAX_MEMBERSHIPS #ifdef IP_MAX_MEMBERSHIPS
insint(d, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS); PyModule_AddIntConstant(m, "IP_MAX_MEMBERSHIPS", IP_MAX_MEMBERSHIPS);
#endif #endif
/* IPv6 [gs]etsockopt options, defined in RFC2553 */ /* IPv6 [gs]etsockopt options, defined in RFC2553 */
#ifdef IPV6_JOIN_GROUP #ifdef IPV6_JOIN_GROUP
insint(d, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP); PyModule_AddIntConstant(m, "IPV6_JOIN_GROUP", IPV6_JOIN_GROUP);
#endif #endif
#ifdef IPV6_LEAVE_GROUP #ifdef IPV6_LEAVE_GROUP
insint(d, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP); PyModule_AddIntConstant(m, "IPV6_LEAVE_GROUP", IPV6_LEAVE_GROUP);
#endif #endif
#ifdef IPV6_MULTICAST_HOPS #ifdef IPV6_MULTICAST_HOPS
insint(d, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS); PyModule_AddIntConstant(m, "IPV6_MULTICAST_HOPS", IPV6_MULTICAST_HOPS);
#endif #endif
#ifdef IPV6_MULTICAST_IF #ifdef IPV6_MULTICAST_IF
insint(d, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF); PyModule_AddIntConstant(m, "IPV6_MULTICAST_IF", IPV6_MULTICAST_IF);
#endif #endif
#ifdef IPV6_MULTICAST_LOOP #ifdef IPV6_MULTICAST_LOOP
insint(d, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP); PyModule_AddIntConstant(m, "IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP);
#endif #endif
#ifdef IPV6_UNICAST_HOPS #ifdef IPV6_UNICAST_HOPS
insint(d, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS); PyModule_AddIntConstant(m, "IPV6_UNICAST_HOPS", IPV6_UNICAST_HOPS);
#endif #endif
/* TCP options */ /* TCP options */
#ifdef TCP_NODELAY #ifdef TCP_NODELAY
insint(d, "TCP_NODELAY", TCP_NODELAY); PyModule_AddIntConstant(m, "TCP_NODELAY", TCP_NODELAY);
#endif #endif
#ifdef TCP_MAXSEG #ifdef TCP_MAXSEG
insint(d, "TCP_MAXSEG", TCP_MAXSEG); PyModule_AddIntConstant(m, "TCP_MAXSEG", TCP_MAXSEG);
#endif #endif
#ifdef TCP_CORK #ifdef TCP_CORK
insint(d, "TCP_CORK", TCP_CORK); PyModule_AddIntConstant(m, "TCP_CORK", TCP_CORK);
#endif #endif
#ifdef TCP_KEEPIDLE #ifdef TCP_KEEPIDLE
insint(d, "TCP_KEEPIDLE", TCP_KEEPIDLE); PyModule_AddIntConstant(m, "TCP_KEEPIDLE", TCP_KEEPIDLE);
#endif #endif
#ifdef TCP_KEEPINTVL #ifdef TCP_KEEPINTVL
insint(d, "TCP_KEEPINTVL", TCP_KEEPINTVL); PyModule_AddIntConstant(m, "TCP_KEEPINTVL", TCP_KEEPINTVL);
#endif #endif
#ifdef TCP_KEEPCNT #ifdef TCP_KEEPCNT
insint(d, "TCP_KEEPCNT", TCP_KEEPCNT); PyModule_AddIntConstant(m, "TCP_KEEPCNT", TCP_KEEPCNT);
#endif #endif
#ifdef TCP_SYNCNT #ifdef TCP_SYNCNT
insint(d, "TCP_SYNCNT", TCP_SYNCNT); PyModule_AddIntConstant(m, "TCP_SYNCNT", TCP_SYNCNT);
#endif #endif
#ifdef TCP_LINGER2 #ifdef TCP_LINGER2
insint(d, "TCP_LINGER2", TCP_LINGER2); PyModule_AddIntConstant(m, "TCP_LINGER2", TCP_LINGER2);
#endif #endif
#ifdef TCP_DEFER_ACCEPT #ifdef TCP_DEFER_ACCEPT
insint(d, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT); PyModule_AddIntConstant(m, "TCP_DEFER_ACCEPT", TCP_DEFER_ACCEPT);
#endif #endif
#ifdef TCP_WINDOW_CLAMP #ifdef TCP_WINDOW_CLAMP
insint(d, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP); PyModule_AddIntConstant(m, "TCP_WINDOW_CLAMP", TCP_WINDOW_CLAMP);
#endif #endif
#ifdef TCP_INFO #ifdef TCP_INFO
insint(d, "TCP_INFO", TCP_INFO); PyModule_AddIntConstant(m, "TCP_INFO", TCP_INFO);
#endif #endif
#ifdef TCP_QUICKACK #ifdef TCP_QUICKACK
insint(d, "TCP_QUICKACK", TCP_QUICKACK); PyModule_AddIntConstant(m, "TCP_QUICKACK", TCP_QUICKACK);
#endif #endif
/* IPX options */ /* IPX options */
#ifdef IPX_TYPE #ifdef IPX_TYPE
insint(d, "IPX_TYPE", IPX_TYPE); PyModule_AddIntConstant(m, "IPX_TYPE", IPX_TYPE);
#endif #endif
/* get{addr,name}info parameters */ /* get{addr,name}info parameters */
#ifdef EAI_ADDRFAMILY #ifdef EAI_ADDRFAMILY
insint(d, "EAI_ADDRFAMILY", EAI_ADDRFAMILY); PyModule_AddIntConstant(m, "EAI_ADDRFAMILY", EAI_ADDRFAMILY);
#endif #endif
#ifdef EAI_AGAIN #ifdef EAI_AGAIN
insint(d, "EAI_AGAIN", EAI_AGAIN); PyModule_AddIntConstant(m, "EAI_AGAIN", EAI_AGAIN);
#endif #endif
#ifdef EAI_BADFLAGS #ifdef EAI_BADFLAGS
insint(d, "EAI_BADFLAGS", EAI_BADFLAGS); PyModule_AddIntConstant(m, "EAI_BADFLAGS", EAI_BADFLAGS);
#endif #endif
#ifdef EAI_FAIL #ifdef EAI_FAIL
insint(d, "EAI_FAIL", EAI_FAIL); PyModule_AddIntConstant(m, "EAI_FAIL", EAI_FAIL);
#endif #endif
#ifdef EAI_FAMILY #ifdef EAI_FAMILY
insint(d, "EAI_FAMILY", EAI_FAMILY); PyModule_AddIntConstant(m, "EAI_FAMILY", EAI_FAMILY);
#endif #endif
#ifdef EAI_MEMORY #ifdef EAI_MEMORY
insint(d, "EAI_MEMORY", EAI_MEMORY); PyModule_AddIntConstant(m, "EAI_MEMORY", EAI_MEMORY);
#endif #endif
#ifdef EAI_NODATA #ifdef EAI_NODATA
insint(d, "EAI_NODATA", EAI_NODATA); PyModule_AddIntConstant(m, "EAI_NODATA", EAI_NODATA);
#endif #endif
#ifdef EAI_NONAME #ifdef EAI_NONAME
insint(d, "EAI_NONAME", EAI_NONAME); PyModule_AddIntConstant(m, "EAI_NONAME", EAI_NONAME);
#endif #endif
#ifdef EAI_SERVICE #ifdef EAI_SERVICE
insint(d, "EAI_SERVICE", EAI_SERVICE); PyModule_AddIntConstant(m, "EAI_SERVICE", EAI_SERVICE);
#endif #endif
#ifdef EAI_SOCKTYPE #ifdef EAI_SOCKTYPE
insint(d, "EAI_SOCKTYPE", EAI_SOCKTYPE); PyModule_AddIntConstant(m, "EAI_SOCKTYPE", EAI_SOCKTYPE);
#endif #endif
#ifdef EAI_SYSTEM #ifdef EAI_SYSTEM
insint(d, "EAI_SYSTEM", EAI_SYSTEM); PyModule_AddIntConstant(m, "EAI_SYSTEM", EAI_SYSTEM);
#endif #endif
#ifdef EAI_BADHINTS #ifdef EAI_BADHINTS
insint(d, "EAI_BADHINTS", EAI_BADHINTS); PyModule_AddIntConstant(m, "EAI_BADHINTS", EAI_BADHINTS);
#endif #endif
#ifdef EAI_PROTOCOL #ifdef EAI_PROTOCOL
insint(d, "EAI_PROTOCOL", EAI_PROTOCOL); PyModule_AddIntConstant(m, "EAI_PROTOCOL", EAI_PROTOCOL);
#endif #endif
#ifdef EAI_MAX #ifdef EAI_MAX
insint(d, "EAI_MAX", EAI_MAX); PyModule_AddIntConstant(m, "EAI_MAX", EAI_MAX);
#endif #endif
#ifdef AI_PASSIVE #ifdef AI_PASSIVE
insint(d, "AI_PASSIVE", AI_PASSIVE); PyModule_AddIntConstant(m, "AI_PASSIVE", AI_PASSIVE);
#endif #endif
#ifdef AI_CANONNAME #ifdef AI_CANONNAME
insint(d, "AI_CANONNAME", AI_CANONNAME); PyModule_AddIntConstant(m, "AI_CANONNAME", AI_CANONNAME);
#endif #endif
#ifdef AI_NUMERICHOST #ifdef AI_NUMERICHOST
insint(d, "AI_NUMERICHOST", AI_NUMERICHOST); PyModule_AddIntConstant(m, "AI_NUMERICHOST", AI_NUMERICHOST);
#endif #endif
#ifdef AI_MASK #ifdef AI_MASK
insint(d, "AI_MASK", AI_MASK); PyModule_AddIntConstant(m, "AI_MASK", AI_MASK);
#endif #endif
#ifdef AI_ALL #ifdef AI_ALL
insint(d, "AI_ALL", AI_ALL); PyModule_AddIntConstant(m, "AI_ALL", AI_ALL);
#endif #endif
#ifdef AI_V4MAPPED_CFG #ifdef AI_V4MAPPED_CFG
insint(d, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG); PyModule_AddIntConstant(m, "AI_V4MAPPED_CFG", AI_V4MAPPED_CFG);
#endif #endif
#ifdef AI_ADDRCONFIG #ifdef AI_ADDRCONFIG
insint(d, "AI_ADDRCONFIG", AI_ADDRCONFIG); PyModule_AddIntConstant(m, "AI_ADDRCONFIG", AI_ADDRCONFIG);
#endif #endif
#ifdef AI_V4MAPPED #ifdef AI_V4MAPPED
insint(d, "AI_V4MAPPED", AI_V4MAPPED); PyModule_AddIntConstant(m, "AI_V4MAPPED", AI_V4MAPPED);
#endif #endif
#ifdef AI_DEFAULT #ifdef AI_DEFAULT
insint(d, "AI_DEFAULT", AI_DEFAULT); PyModule_AddIntConstant(m, "AI_DEFAULT", AI_DEFAULT);
#endif #endif
#ifdef NI_MAXHOST #ifdef NI_MAXHOST
insint(d, "NI_MAXHOST", NI_MAXHOST); PyModule_AddIntConstant(m, "NI_MAXHOST", NI_MAXHOST);
#endif #endif
#ifdef NI_MAXSERV #ifdef NI_MAXSERV
insint(d, "NI_MAXSERV", NI_MAXSERV); PyModule_AddIntConstant(m, "NI_MAXSERV", NI_MAXSERV);
#endif #endif
#ifdef NI_NOFQDN #ifdef NI_NOFQDN
insint(d, "NI_NOFQDN", NI_NOFQDN); PyModule_AddIntConstant(m, "NI_NOFQDN", NI_NOFQDN);
#endif #endif
#ifdef NI_NUMERICHOST #ifdef NI_NUMERICHOST
insint(d, "NI_NUMERICHOST", NI_NUMERICHOST); PyModule_AddIntConstant(m, "NI_NUMERICHOST", NI_NUMERICHOST);
#endif #endif
#ifdef NI_NAMEREQD #ifdef NI_NAMEREQD
insint(d, "NI_NAMEREQD", NI_NAMEREQD); PyModule_AddIntConstant(m, "NI_NAMEREQD", NI_NAMEREQD);
#endif #endif
#ifdef NI_NUMERICSERV #ifdef NI_NUMERICSERV
insint(d, "NI_NUMERICSERV", NI_NUMERICSERV); PyModule_AddIntConstant(m, "NI_NUMERICSERV", NI_NUMERICSERV);
#endif #endif
#ifdef NI_DGRAM #ifdef NI_DGRAM
insint(d, "NI_DGRAM", NI_DGRAM); PyModule_AddIntConstant(m, "NI_DGRAM", NI_DGRAM);
#endif #endif
/* Initialize gethostbyname lock */ /* Initialize gethostbyname lock */

View File

@ -1215,12 +1215,11 @@ strop_methods[] = {
DL_EXPORT(void) DL_EXPORT(void)
initstrop(void) initstrop(void)
{ {
PyObject *m, *d, *s; PyObject *m, *s;
char buf[256]; char buf[256];
int c, n; int c, n;
m = Py_InitModule4("strop", strop_methods, strop_module__doc__, m = Py_InitModule4("strop", strop_methods, strop_module__doc__,
(PyObject*)NULL, PYTHON_API_VERSION); (PyObject*)NULL, PYTHON_API_VERSION);
d = PyModule_GetDict(m);
/* Create 'whitespace' object */ /* Create 'whitespace' object */
n = 0; n = 0;
@ -1229,10 +1228,9 @@ initstrop(void)
buf[n++] = c; buf[n++] = c;
} }
s = PyString_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) { if (s)
PyDict_SetItemString(d, "whitespace", s); PyModule_AddObject(m, "whitespace", s);
Py_DECREF(s);
}
/* Create 'lowercase' object */ /* Create 'lowercase' object */
n = 0; n = 0;
for (c = 0; c < 256; c++) { for (c = 0; c < 256; c++) {
@ -1240,10 +1238,8 @@ initstrop(void)
buf[n++] = c; buf[n++] = c;
} }
s = PyString_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) { if (s)
PyDict_SetItemString(d, "lowercase", s); PyModule_AddObject(m, "lowercase", s);
Py_DECREF(s);
}
/* Create 'uppercase' object */ /* Create 'uppercase' object */
n = 0; n = 0;
@ -1252,8 +1248,6 @@ initstrop(void)
buf[n++] = c; buf[n++] = c;
} }
s = PyString_FromStringAndSize(buf, n); s = PyString_FromStringAndSize(buf, n);
if (s) { if (s)
PyDict_SetItemString(d, "uppercase", s); PyModule_AddObject(m, "uppercase", s);
Py_DECREF(s);
}
} }

View File

@ -153,67 +153,54 @@ static PyMethodDef syslog_methods[] = {
{NULL, NULL, 0} {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 */ /* Initialization function for the module */
DL_EXPORT(void) DL_EXPORT(void)
initsyslog(void) initsyslog(void)
{ {
PyObject *m, *d; PyObject *m;
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule("syslog", syslog_methods); m = Py_InitModule("syslog", syslog_methods);
/* Add some symbolic constants to the module */ /* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
/* Priorities */ /* Priorities */
ins(d, "LOG_EMERG", LOG_EMERG); PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG);
ins(d, "LOG_ALERT", LOG_ALERT); PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT);
ins(d, "LOG_CRIT", LOG_CRIT); PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT);
ins(d, "LOG_ERR", LOG_ERR); PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR);
ins(d, "LOG_WARNING", LOG_WARNING); PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING);
ins(d, "LOG_NOTICE", LOG_NOTICE); PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE);
ins(d, "LOG_INFO", LOG_INFO); PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO);
ins(d, "LOG_DEBUG", LOG_DEBUG); PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG);
/* openlog() option flags */ /* openlog() option flags */
ins(d, "LOG_PID", LOG_PID); PyModule_AddIntConstant(m, "LOG_PID", LOG_PID);
ins(d, "LOG_CONS", LOG_CONS); PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS);
ins(d, "LOG_NDELAY", LOG_NDELAY); PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY);
#ifdef LOG_NOWAIT #ifdef LOG_NOWAIT
ins(d, "LOG_NOWAIT", LOG_NOWAIT); PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT);
#endif #endif
#ifdef LOG_PERROR #ifdef LOG_PERROR
ins(d, "LOG_PERROR", LOG_PERROR); PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR);
#endif #endif
/* Facilities */ /* Facilities */
ins(d, "LOG_KERN", LOG_KERN); PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN);
ins(d, "LOG_USER", LOG_USER); PyModule_AddIntConstant(m, "LOG_USER", LOG_USER);
ins(d, "LOG_MAIL", LOG_MAIL); PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL);
ins(d, "LOG_DAEMON", LOG_DAEMON); PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON);
ins(d, "LOG_AUTH", LOG_AUTH); PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH);
ins(d, "LOG_LPR", LOG_LPR); PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR);
ins(d, "LOG_LOCAL0", LOG_LOCAL0); PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0);
ins(d, "LOG_LOCAL1", LOG_LOCAL1); PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1);
ins(d, "LOG_LOCAL2", LOG_LOCAL2); PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2);
ins(d, "LOG_LOCAL3", LOG_LOCAL3); PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3);
ins(d, "LOG_LOCAL4", LOG_LOCAL4); PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4);
ins(d, "LOG_LOCAL5", LOG_LOCAL5); PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5);
ins(d, "LOG_LOCAL6", LOG_LOCAL6); PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6);
ins(d, "LOG_LOCAL7", LOG_LOCAL7); PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7);
#ifndef LOG_SYSLOG #ifndef LOG_SYSLOG
#define LOG_SYSLOG LOG_DAEMON #define LOG_SYSLOG LOG_DAEMON
@ -228,8 +215,8 @@ initsyslog(void)
#define LOG_CRON LOG_DAEMON #define LOG_CRON LOG_DAEMON
#endif #endif
ins(d, "LOG_SYSLOG", LOG_SYSLOG); PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG);
ins(d, "LOG_CRON", LOG_CRON); PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON);
ins(d, "LOG_UUCP", LOG_UUCP); PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP);
ins(d, "LOG_NEWS", LOG_NEWS); PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS);
} }

View File

@ -847,17 +847,18 @@ static char zlib_module_documentation[]=
DL_EXPORT(void) DL_EXPORT(void)
PyInit_zlib(void) PyInit_zlib(void)
{ {
PyObject *m, *d, *ver; PyObject *m, *ver;
Comptype.ob_type = &PyType_Type; Comptype.ob_type = &PyType_Type;
Decomptype.ob_type = &PyType_Type; Decomptype.ob_type = &PyType_Type;
m = Py_InitModule4("zlib", zlib_methods, m = Py_InitModule4("zlib", zlib_methods,
zlib_module_documentation, zlib_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION); (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, "MAX_WBITS", MAX_WBITS);
PyModule_AddIntConstant(m, "DEFLATED", DEFLATED); PyModule_AddIntConstant(m, "DEFLATED", DEFLATED);
PyModule_AddIntConstant(m, "DEF_MEM_LEVEL", DEF_MEM_LEVEL); 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); PyModule_AddIntConstant(m, "Z_FULL_FLUSH", Z_FULL_FLUSH);
ver = PyString_FromString(ZLIB_VERSION); ver = PyString_FromString(ZLIB_VERSION);
if (ver != NULL) { if (ver != NULL)
PyDict_SetItemString(d, "ZLIB_VERSION", ver); PyModule_AddObject(m, "ZLIB_VERSION", ver);
Py_DECREF(ver);
}
#ifdef WITH_THREAD #ifdef WITH_THREAD
zlib_lock = PyThread_allocate_lock(); zlib_lock = PyThread_allocate_lock();