Kaydet (Commit) 2dd8ddde authored tarafından Guido van Rossum's avatar Guido van Rossum

Use an explicit macro SOCKETCLOSE which expands to closesocket (on

Windows), soclose (on OS2), or to close (everywhere else).

Hopefully this fixes a new compilation error that I suddenly get on
Windows because the macro definition for close -> closesocket
apparently was done before including io.h, which contains a prototype
for close.  (No idea why this wasn't an error before.)
üst ace88aeb
...@@ -214,17 +214,21 @@ int shutdown( int, int ); ...@@ -214,17 +214,21 @@ int shutdown( int, int );
#if defined(MS_WINDOWS) || defined(__BEOS__) #if defined(MS_WINDOWS) || defined(__BEOS__)
/* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */ /* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */
/* seem to be a few differences in the API */ /* seem to be a few differences in the API */
#define close closesocket #define SOCKETCLOSE closesocket
#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */ #define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
#define FORCE_ANSI_FUNC_DEFS #define FORCE_ANSI_FUNC_DEFS
#endif #endif
#if defined(PYOS_OS2) #if defined(PYOS_OS2)
#define close soclose #define SOCKETCLOSE soclose
#define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */ #define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */
#define FORCE_ANSI_FUNC_DEFS #define FORCE_ANSI_FUNC_DEFS
#endif #endif
#ifndef SOCKETCLOSE
#define SOCKETCLOSE close
#endif
#ifdef FORCE_ANSI_FUNC_DEFS #ifdef FORCE_ANSI_FUNC_DEFS
#define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \ #define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \
fnname( arg1type arg1name ) fnname( arg1type arg1name )
...@@ -682,7 +686,7 @@ BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args) ...@@ -682,7 +686,7 @@ BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args)
s->sock_type, s->sock_type,
s->sock_proto); s->sock_proto);
if (sock == NULL) { if (sock == NULL) {
close(newfd); SOCKETCLOSE(newfd);
goto finally; goto finally;
} }
if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen))) if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen)))
...@@ -889,7 +893,7 @@ BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args) ...@@ -889,7 +893,7 @@ BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
return NULL; return NULL;
if (s->sock_fd != -1) { if (s->sock_fd != -1) {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
(void) close(s->sock_fd); (void) SOCKETCLOSE(s->sock_fd);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
s->sock_fd = -1; s->sock_fd = -1;
...@@ -988,7 +992,7 @@ BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args) ...@@ -988,7 +992,7 @@ BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args)
s->sock_type, s->sock_type,
s->sock_proto); s->sock_proto);
if (sock == NULL) if (sock == NULL)
close(newfd); SOCKETCLOSE(newfd);
return sock; return sock;
} }
...@@ -1112,7 +1116,7 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args) ...@@ -1112,7 +1116,7 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
#endif #endif
{ {
if (fd >= 0) if (fd >= 0)
close(fd); SOCKETCLOSE(fd);
return PySocket_Err(); return PySocket_Err();
} }
f = PyFile_FromFile(fp, "<socket>", mode, fclose); f = PyFile_FromFile(fp, "<socket>", mode, fclose);
...@@ -1357,7 +1361,7 @@ static void ...@@ -1357,7 +1361,7 @@ static void
BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s) BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
{ {
if (s->sock_fd != -1) if (s->sock_fd != -1)
(void) close(s->sock_fd); (void) SOCKETCLOSE(s->sock_fd);
PyMem_DEL(s); PyMem_DEL(s);
} }
...@@ -1725,7 +1729,7 @@ BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args) ...@@ -1725,7 +1729,7 @@ BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
/* If the object can't be created, don't forget to close the /* If the object can't be created, don't forget to close the
file descriptor again! */ file descriptor again! */
if (s == NULL) if (s == NULL)
(void) close(fd); (void) SOCKETCLOSE(fd);
/* From now on, ignore SIGPIPE and let the error checking /* From now on, ignore SIGPIPE and let the error checking
do the work. */ do the work. */
#ifdef SIGPIPE #ifdef SIGPIPE
...@@ -1944,8 +1948,8 @@ BUILD_FUNC_DEF_3(newSSLObject, ...@@ -1944,8 +1948,8 @@ BUILD_FUNC_DEF_3(newSSLObject,
PyString_FromString("newSSLObject error")); PyString_FromString("newSSLObject error"));
return NULL; return NULL;
} }
memset(self->server, NULL, sizeof(char) * 256); memset(self->server, '\0', sizeof(char) * 256);
memset(self->issuer, NULL, sizeof(char) * 256); memset(self->issuer, '\0', sizeof(char) * 256);
self->x_attr = PyDict_New(); self->x_attr = PyDict_New();
self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */ self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment