Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dd8ddd

Browse files
committed
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.)
1 parent ace88ae commit 2dd8ddd

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Modules/socketmodule.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,21 @@ int shutdown( int, int );
214214
#if defined(MS_WINDOWS) || defined(__BEOS__)
215215
/* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */
216216
/* seem to be a few differences in the API */
217-
#define close closesocket
217+
#define SOCKETCLOSE closesocket
218218
#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
219219
#define FORCE_ANSI_FUNC_DEFS
220220
#endif
221221

222222
#if defined(PYOS_OS2)
223-
#define close soclose
223+
#define SOCKETCLOSE soclose
224224
#define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */
225225
#define FORCE_ANSI_FUNC_DEFS
226226
#endif
227227

228+
#ifndef SOCKETCLOSE
229+
#define SOCKETCLOSE close
230+
#endif
231+
228232
#ifdef FORCE_ANSI_FUNC_DEFS
229233
#define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \
230234
fnname( arg1type arg1name )
@@ -682,7 +686,7 @@ BUILD_FUNC_DEF_2(PySocketSock_accept,PySocketSockObject *,s, PyObject *,args)
682686
s->sock_type,
683687
s->sock_proto);
684688
if (sock == NULL) {
685-
close(newfd);
689+
SOCKETCLOSE(newfd);
686690
goto finally;
687691
}
688692
if (!(addr = makesockaddr((struct sockaddr *) addrbuf, addrlen)))
@@ -889,7 +893,7 @@ BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
889893
return NULL;
890894
if (s->sock_fd != -1) {
891895
Py_BEGIN_ALLOW_THREADS
892-
(void) close(s->sock_fd);
896+
(void) SOCKETCLOSE(s->sock_fd);
893897
Py_END_ALLOW_THREADS
894898
}
895899
s->sock_fd = -1;
@@ -988,7 +992,7 @@ BUILD_FUNC_DEF_2(PySocketSock_dup,PySocketSockObject *,s, PyObject *,args)
988992
s->sock_type,
989993
s->sock_proto);
990994
if (sock == NULL)
991-
close(newfd);
995+
SOCKETCLOSE(newfd);
992996
return sock;
993997
}
994998

@@ -1112,7 +1116,7 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
11121116
#endif
11131117
{
11141118
if (fd >= 0)
1115-
close(fd);
1119+
SOCKETCLOSE(fd);
11161120
return PySocket_Err();
11171121
}
11181122
f = PyFile_FromFile(fp, "<socket>", mode, fclose);
@@ -1357,7 +1361,7 @@ static void
13571361
BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
13581362
{
13591363
if (s->sock_fd != -1)
1360-
(void) close(s->sock_fd);
1364+
(void) SOCKETCLOSE(s->sock_fd);
13611365
PyMem_DEL(s);
13621366
}
13631367

@@ -1725,7 +1729,7 @@ BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
17251729
/* If the object can't be created, don't forget to close the
17261730
file descriptor again! */
17271731
if (s == NULL)
1728-
(void) close(fd);
1732+
(void) SOCKETCLOSE(fd);
17291733
/* From now on, ignore SIGPIPE and let the error checking
17301734
do the work. */
17311735
#ifdef SIGPIPE
@@ -1944,8 +1948,8 @@ BUILD_FUNC_DEF_3(newSSLObject,
19441948
PyString_FromString("newSSLObject error"));
19451949
return NULL;
19461950
}
1947-
memset(self->server, NULL, sizeof(char) * 256);
1948-
memset(self->issuer, NULL, sizeof(char) * 256);
1951+
memset(self->server, '\0', sizeof(char) * 256);
1952+
memset(self->issuer, '\0', sizeof(char) * 256);
19491953

19501954
self->x_attr = PyDict_New();
19511955
self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */

0 commit comments

Comments
 (0)