changed windows test symbols; removed debug printf from sockets

This commit is contained in:
Guido van Rossum 1996-06-26 18:22:49 +00:00
parent 8026febbd6
commit 8d665e6b51
2 changed files with 26 additions and 26 deletions

View file

@ -27,7 +27,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* This file is also used for Windows NT and MS-Win. In that case the module /* This file is also used for Windows NT and MS-Win. In that case the module
actually calls itself 'nt', not 'posix', and a few functions are actually calls itself 'nt', not 'posix', and a few functions are
either unimplemented or implemented differently. The source either unimplemented or implemented differently. The source
assumes that for Windows NT, the macro 'NT' is defined independent assumes that for Windows NT, the macro 'MS_WIN32' is defined independent
of the compiler used. Different compilers define their own feature of the compiler used. Different compilers define their own feature
test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */ test macro, e.g. '__BORLANDC__' or '_MSC_VER'. */
@ -78,13 +78,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define HAVE_WAIT 1 #define HAVE_WAIT 1
#else #else
#ifdef _MSC_VER /* Microsoft compiler */ #ifdef _MSC_VER /* Microsoft compiler */
#ifdef NT #define HAVE_GETCWD 1
#ifdef MS_WIN32
#define HAVE_EXECV 1 #define HAVE_EXECV 1
#define HAVE_PIPE 1 #define HAVE_PIPE 1
#define HAVE_POPEN 1 #define HAVE_POPEN 1
#define HAVE_SYSTEM 1 #define HAVE_SYSTEM 1
#else /* 16-bit Windows */ #else /* 16-bit Windows */
#endif /* NT */ #endif /* !MS_WIN32 */
#else /* all other compilers */ #else /* all other compilers */
/* Unix functions that the configure script doesn't check for */ /* Unix functions that the configure script doesn't check for */
#define HAVE_EXECV 1 #define HAVE_EXECV 1
@ -125,7 +126,7 @@ extern int pclose();
extern int lstat(); extern int lstat();
extern int symlink(); extern int symlink();
#else /* !HAVE_UNISTD_H */ #else /* !HAVE_UNISTD_H */
#if defined(__WATCOMC__) #if defined(__WATCOMC__) || defined(_MSC_VER)
extern int mkdir PROTO((const char *)); extern int mkdir PROTO((const char *));
#else #else
extern int mkdir PROTO((const char *, mode_t)); extern int mkdir PROTO((const char *, mode_t));
@ -203,13 +204,13 @@ extern int lstat PROTO((const char *, struct stat *));
#include <io.h> #include <io.h>
#include <process.h> #include <process.h>
#include <windows.h> #include <windows.h>
#ifdef NT #ifdef MS_WIN32
#define popen _popen #define popen _popen
#define pclose _pclose #define pclose _pclose
#else /* 16-bit Windows */ #else /* 16-bit Windows */
#include <dos.h> #include <dos.h>
#include <ctype.h> #include <ctype.h>
#endif /* NT */ #endif /* MS_WIN32 */
#endif /* _MSC_VER */ #endif /* _MSC_VER */
#ifdef OS2 #ifdef OS2
@ -428,7 +429,7 @@ posix_listdir(self, args)
object *self; object *self;
object *args; object *args;
{ {
#if defined(NT) && !defined(HAVE_OPENDIR) #if defined(MS_WIN32) && !defined(HAVE_OPENDIR)
char *name; char *name;
int len; int len;
@ -484,7 +485,7 @@ posix_listdir(self, args)
return d; return d;
#else /* !NT */ #else /* !MS_WIN32 */
#ifdef _MSC_VER /* 16-bit Windows */ #ifdef _MSC_VER /* 16-bit Windows */
#ifndef MAX_PATH #ifndef MAX_PATH
@ -588,7 +589,7 @@ posix_listdir(self, args)
return d; return d;
#endif /* !_MSC_VER */ #endif /* !_MSC_VER */
#endif /* !NT */ #endif /* !MS_WIN32 */
} }
static object * static object *
@ -602,7 +603,7 @@ posix_mkdir(self, args)
if (!newgetargs(args, "s|i", &path, &mode)) if (!newgetargs(args, "s|i", &path, &mode))
return NULL; return NULL;
BGN_SAVE BGN_SAVE
#if defined(__WATCOMC__) #if defined(__WATCOMC__) || defined(_MSC_VER)
res = mkdir(path); res = mkdir(path);
#else #else
res = mkdir(path, mode); res = mkdir(path, mode);
@ -1219,7 +1220,7 @@ posix_times(self, args)
(double)c / HZ); (double)c / HZ);
} }
#endif /* HAVE_TIMES */ #endif /* HAVE_TIMES */
#if defined(NT) && !defined(HAVE_TIMES) #if defined(MS_WIN32) && !defined(HAVE_TIMES)
#define HAVE_TIMES /* so the method table will pick it up */ #define HAVE_TIMES /* so the method table will pick it up */
static object * static object *
posix_times(self, args) posix_times(self, args)
@ -1239,7 +1240,7 @@ posix_times(self, args)
(double)0, (double)0,
(double)0); (double)0);
} }
#endif /* NT */ #endif /* MS_WIN32 */
#ifdef HAVE_SETSID #ifdef HAVE_SETSID
static object * static object *
@ -1502,7 +1503,7 @@ posix_pipe(self, args)
object *self; object *self;
object *args; object *args;
{ {
#if !defined(NT) #if !defined(MS_WIN32)
int fds[2]; int fds[2];
int res; int res;
if (!getargs(args, "")) if (!getargs(args, ""))
@ -1513,7 +1514,7 @@ posix_pipe(self, args)
if (res != 0) if (res != 0)
return posix_error(); return posix_error();
return mkvalue("(ii)", fds[0], fds[1]); return mkvalue("(ii)", fds[0], fds[1]);
#else /* NT */ #else /* MS_WIN32 */
HANDLE read, write; HANDLE read, write;
BOOL ok; BOOL ok;
if (!getargs(args, "")) if (!getargs(args, ""))
@ -1524,7 +1525,7 @@ posix_pipe(self, args)
if (!ok) if (!ok)
return posix_error(); return posix_error();
return mkvalue("(ii)", read, write); return mkvalue("(ii)", read, write);
#endif /* NT */ #endif /* MS_WIN32 */
} }
#endif /* HAVE_PIPE */ #endif /* HAVE_PIPE */
@ -1716,7 +1717,7 @@ initnt()
if (PosixError == NULL || dictinsert(d, "error", PosixError) != 0) if (PosixError == NULL || dictinsert(d, "error", PosixError) != 0)
fatal("can't define nt.error"); fatal("can't define nt.error");
} }
#else /* !_MSC_VER */ #else /* not a PC port */
void void
initposix() initposix()
{ {

View file

@ -112,7 +112,7 @@ Socket methods:
it must be compiled by the C++ compiler, as it takes the address of it must be compiled by the C++ compiler, as it takes the address of
a static data item exported from the main Python DLL. a static data item exported from the main Python DLL.
*/ */
#ifdef NT #ifdef MS_WINDOWS
/* seem to be a few differences in the API */ /* seem to be a few differences in the API */
#define close closesocket #define close 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... */
@ -169,7 +169,7 @@ static PyObject *PySocket_Error;
static PyObject * static PyObject *
PySocket_Err() PySocket_Err()
{ {
#ifdef NT #ifdef MS_WINDOWS
if (WSAGetLastError()) { if (WSAGetLastError()) {
PyObject *v; PyObject *v;
v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error"); v = Py_BuildValue("(is)", WSAGetLastError(), "winsock error");
@ -757,7 +757,7 @@ BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args)
if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize)) if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize))
return NULL; return NULL;
#ifdef NT #ifdef MS_WIN32
if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) || if ( ((fd = _open_osfhandle( s->sock_fd, _O_BINARY )) < 0) ||
((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) { ((fd = dup(fd)) < 0) || ((fp = fdopen(fd, mode)) == NULL)) {
#else #else
@ -817,7 +817,7 @@ BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags, n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
#ifndef NT #ifndef MS_WINDOWS
(ANY *)addrbuf, &addrlen); (ANY *)addrbuf, &addrlen);
#else #else
(struct sockaddr *)addrbuf, &addrlen); (struct sockaddr *)addrbuf, &addrlen);
@ -1250,7 +1250,7 @@ BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value)
} }
#ifdef NT #ifdef MS_WINDOWS
/* Additional initialization and cleanup for NT/Windows */ /* Additional initialization and cleanup for NT/Windows */
@ -1258,7 +1258,6 @@ static void
NTcleanup() NTcleanup()
{ {
WSACleanup(); WSACleanup();
fprintf(stderr, "WSACleanup called\n");
} }
static int static int
@ -1289,7 +1288,7 @@ NTinit()
return 0; return 0;
} }
#endif /* NT */ #endif /* MS_WINDOWS */
/* Initialize this module. /* Initialize this module.
@ -1297,7 +1296,7 @@ NTinit()
via a table in config.c, if config.c is compiled with USE_SOCKET via a table in config.c, if config.c is compiled with USE_SOCKET
defined. defined.
For NT (which actually means any Windows variant (?)), this module For MS_WINDOWS (which means any Windows variant), this module
is actually called "_socket", and there's a wrapper "socket.py" is actually called "_socket", and there's a wrapper "socket.py"
which implements some missing functionality (such as makefile(), which implements some missing functionality (such as makefile(),
dup() and fromfd()). The import of "_socket" may fail with an dup() and fromfd()). The import of "_socket" may fail with an
@ -1306,14 +1305,14 @@ NTinit()
scheduled to be made at exit time. */ scheduled to be made at exit time. */
void void
#ifdef NT #ifdef MS_WINDOWS
init_socket() init_socket()
#else #else
initsocket() initsocket()
#endif #endif
{ {
PyObject *m, *d; PyObject *m, *d;
#ifdef NT #ifdef MS_WINDOWS
if (!NTinit()) if (!NTinit())
return; return;
m = Py_InitModule("_socket", PySocket_methods); m = Py_InitModule("_socket", PySocket_methods);