Kaydet (Commit) 8e9ebfd3 authored tarafından Guido van Rossum's avatar Guido van Rossum

os2 patch by Jeff Rush

üst c0b93191
......@@ -44,7 +44,7 @@ PERFORMANCE OF THIS SOFTWARE.
#define DELIM '\n'
#endif
#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__)
#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(__TOS_OS2__)
#define SEP '\\'
#define ALTSEP '/'
#define MAXPATHLEN 256
......
......@@ -59,6 +59,18 @@ elif 'dos' in _names:
import dospath
path = dospath
del dospath
elif 'os2' in _names:
name = 'os2'
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
defpath = '.;C:\\bin'
from os2 import *
try:
from os2 import _exit
except ImportError:
pass
import ntpath
path = ntpath
del ntpath
elif 'mac' in _names:
name = 'mac'
curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
......
......@@ -35,7 +35,7 @@ else:
def test():
import sys
if sys.platform[:3] in ('win', 'mac'):
if sys.platform[:3] in ('win', 'mac', 'os2'):
if verbose:
print "Can't test select easily on", sys.platform
return
......
......@@ -4,9 +4,8 @@ import signal
import os
import sys
if sys.platform[:3] == 'win':
raise ImportError, "Can't test signal on Windows"
if sys.platform[:3] in ('win', 'os2'):
raise ImportError, "Can't test signal on %s" % sys.platform[:3]
if verbose:
x = '-x'
......
This diff is collapsed.
......@@ -48,6 +48,11 @@ extern void bzero();
#include <sys/types.h>
#if defined(PYOS_OS2)
#include <sys/time.h>
#include <utils.h>
#endif
#ifdef MS_WINDOWS
#include <winsock.h>
#else
......
......@@ -50,6 +50,11 @@ PERFORMANCE OF THIS SOFTWARE.
#define SIG_ERR ((RETSIGTYPE (*)())-1)
#endif
#if defined(PYOS_OS2)
#define NSIG 12
#include <process.h>
#endif
#ifndef NSIG
#ifdef _SIGMAX
#define NSIG (_SIGMAX + 1) /* For QNX */
......
......@@ -91,10 +91,25 @@ Socket methods:
#include <unistd.h>
#endif
#ifndef MS_WINDOWS
#if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
extern int gethostname(); /* For Solaris, at least */
#endif
#if defined(PYCC_VACPP)
#include <types.h>
#include <io.h>
#include <sys/ioctl.h>
#include <utils.h>
#include <ctype.h>
#endif
#if defined(PYOS_OS2)
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#endif
#include <sys/types.h>
#include "mytime.h"
......@@ -136,6 +151,12 @@ extern int gethostname(); /* For Solaris, at least */
#define FORCE_ANSI_FUNC_DEFS
#endif
#if defined(PYOS_OS2)
#define close soclose
#define NO_DUP /* Sockets are Not Actual File Handles under OS/2 */
#define FORCE_ANSI_FUNC_DEFS
#endif
#ifdef FORCE_ANSI_FUNC_DEFS
#define BUILD_FUNC_DEF_1( fnname, arg1type, arg1name ) \
fnname( arg1type arg1name )
......@@ -198,6 +219,36 @@ PySocket_Err()
}
else
#endif
#if defined(PYOS_OS2)
if (sock_errno() != NO_ERROR) {
APIRET rc;
ULONG msglen;
char outbuf[100];
int myerrorcode = sock_errno();
/* Retrieve Socket-Related Error Message from MPTN.MSG File */
rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen);
if (rc == NO_ERROR) {
PyObject *v;
outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
char *lastc = &outbuf[ strlen(outbuf)-1 ];
while (lastc > outbuf && isspace(*lastc))
*lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
}
v = Py_BuildValue("(is)", myerrorcode, outbuf);
if (v != NULL) {
PyErr_SetObject(PySocket_Error, v);
Py_DECREF(v);
}
return NULL;
}
}
#endif
return PyErr_SetFromErrno(PySocket_Error);
}
......@@ -527,16 +578,21 @@ BUILD_FUNC_DEF_2(PySocketSock_setblocking,PySocketSockObject*,s,PyObject*,args)
return NULL;
Py_BEGIN_ALLOW_THREADS
#ifndef MS_WINDOWS
#ifdef PYOS_OS2
block = !block;
ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
#else /* !PYOS_OS2 */
delay_flag = fcntl (s->sock_fd, F_GETFL, 0);
if (block)
delay_flag &= (~O_NDELAY);
else
delay_flag |= O_NDELAY;
fcntl (s->sock_fd, F_SETFL, delay_flag);
#else
#endif /* !PYOS_OS2 */
#else /* MS_WINDOWS */
block = !block;
ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
#endif
#endif /* MS_WINDOWS */
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
......@@ -883,7 +939,11 @@ BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
Py_BEGIN_ALLOW_THREADS
n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
#ifndef MS_WINDOWS
#if defined(PYOS_OS2)
(struct sockaddr *)addrbuf, &addrlen
#else
(ANY *)addrbuf, &addrlen
#endif
#else
(struct sockaddr *)addrbuf, &addrlen
#endif
......@@ -1388,22 +1448,57 @@ NTinit()
#endif /* MS_WINDOWS */
#if defined(PYOS_OS2)
/* Additional initialization and cleanup for OS/2 */
static void
OS2cleanup()
{
/* No cleanup is necessary for OS/2 Sockets */
}
static int
OS2init()
{
char reason[64];
int rc = sock_init();
if (rc == 0) {
atexit(OS2cleanup);
return 1; // Indicate Success
}
sprintf(reason, "OS/2 TCP/IP Error# %d", sock_errno());
PyErr_SetString(PyExc_ImportError, reason);
return 0; // Indicate Failure
}
#endif /* PYOS_OS2 */
/* Initialize this module.
This is called when the first 'import socket' is done,
via a table in config.c, if config.c is compiled with USE_SOCKET
defined.
For MS_WINDOWS (which means any Windows variant), this module
is actually called "_socket", and there's a wrapper "socket.py"
which implements some missing functionality (such as makefile(),
dup() and fromfd()). The import of "_socket" may fail with an
ImportError exception if initialization of WINSOCK fails. When
WINSOCK is initialized succesfully, a call to WSACleanup() is
scheduled to be made at exit time. */
* This is called when the first 'import socket' is done,
* via a table in config.c, if config.c is compiled with USE_SOCKET
* defined.
*
* For MS_WINDOWS (which means any Windows variant), this module
* is actually called "_socket", and there's a wrapper "socket.py"
* which implements some missing functionality (such as makefile(),
* dup() and fromfd()). The import of "_socket" may fail with an
* ImportError exception if initialization of WINSOCK fails. When
* WINSOCK is initialized succesfully, a call to WSACleanup() is
* scheduled to be made at exit time.
*
* For OS/2, this module is also called "_socket" and uses a wrapper
* "socket.py" which implements that functionality that is missing
* when PC operating systems don't put socket descriptors in the
* operating system's filesystem layer.
*/
void
#ifdef MS_WINDOWS
#if defined(MS_WINDOWS) || defined(PYOS_OS2)
init_socket()
#else
initsocket()
......@@ -1415,7 +1510,13 @@ initsocket()
return;
m = Py_InitModule("_socket", PySocket_methods);
#else
#if defined(__TOS_OS2__)
if (!OS2init())
return;
m = Py_InitModule("_socket", PySocket_methods);
#else
m = Py_InitModule("socket", PySocket_methods);
#endif
#endif
d = PyModule_GetDict(m);
PySocket_Error = PyErr_NewException("socket.error", NULL, NULL);
......
......@@ -59,7 +59,7 @@ PERFORMANCE OF THIS SOFTWARE.
#ifdef HAVE_FTIME
#include <sys/timeb.h>
#ifndef MS_WINDOWS
#if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
extern int ftime();
#endif /* MS_WINDOWS */
#endif /* HAVE_FTIME */
......@@ -85,6 +85,18 @@ extern int ftime();
#undef HAVE_CLOCK /* We have our own version down below */
#endif /* MS_WIN32 */
#if defined(PYOS_OS2)
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_NOPMAPI
#include <os2.h>
#endif
#if defined(PYCC_VACPP)
#include <time.h>
#define timezone _timezone
#endif
/* Forward declarations */
static int floatsleep Py_PROTO((double));
static double floattime Py_PROTO(());
......@@ -588,10 +600,18 @@ floatsleep(double secs)
Sleep((int)(secs*1000));
Py_END_ALLOW_THREADS
#else /* !MS_WIN32 */
#ifdef PYOS_OS2
/* This Sleep *IS* Interruptable by Exceptions */
if (DosSleep(secs * 1000) != NO_ERROR) {
PyErr_SetFromErrno(PyExc_IOError);
return -1;
}
#else /* !PYOS_OS2 */
/* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS
sleep((int)secs);
Py_END_ALLOW_THREADS
#endif /* !PYOS_OS2 */
#endif /* !MS_WIN32 */
#endif /* !MSDOS */
#endif /* !__WATCOMC__ */
......
......@@ -47,6 +47,7 @@ PERFORMANCE OF THIS SOFTWARE.
_AIX -- AIX style dynamic linking
MS_WIN32 -- Windows NT style dynamic linking (using DLLs)
MS_WIN16 -- Windows 16-bit dynamic linking (using DLLs)
PYOS_OS2 -- IBM OS/2 dynamic linking (using DLLs)
_DL_FUNCPTR_DEFINED -- if the typedef dl_funcptr has been defined
USE_MAC_DYNAMIC_LOADING -- Mac CFM shared libraries
SHORT_EXT -- short extension for dynamic module, e.g. ".so"
......@@ -76,6 +77,17 @@ typedef void (*dl_funcptr)();
#define LONG_EXT "module.sl"
#endif
#if defined(PYOS_OS2)
#define DYNAMIC_LINK
#define INCL_DOSERRORS
#define INCL_DOSMODULEMGR
#include <os2.h>
typedef int (* APIENTRY dl_funcptr)();
#define _DL_FUNCPTR_DEFINED 1
#define SHORT_EXT ".pyd"
#define LONG_EXT ".dll"
#endif
#if defined(__NetBSD__)
#define DYNAMIC_LINK
#define USE_SHLIB
......@@ -458,6 +470,32 @@ _PyImport_LoadDynamicModule(name, pathname, fp)
p = GetProcAddress(hDLL, funcname);
}
#endif /* MS_WIN16 */
#if defined(PYOS_OS2)
{
APIRET rc;
HMODULE hDLL;
char failreason[256];
rc = DosLoadModule(failreason,
sizeof(failreason),
pathname,
&hDLL);
if (rc != NO_ERROR) {
char errBuf[256];
sprintf(errBuf,
"DLL load failed, rc = %d, problem '%s': %s", rc, failreason);
PyErr_SetString(PyExc_ImportError, errBuf);
return NULL;
}
rc = DosQueryProcAddr(hDLL, 0L, funcname, &p);
if (rc != NO_ERROR)
p = NULL; /* Signify Failure to Acquire Entrypoint */
}
#endif /* PYOS_OS2 */
#ifdef USE_DL
p = dl_loadmod(Py_GetProgramName(), pathname, funcname);
#endif /* USE_DL */
......
......@@ -149,6 +149,10 @@ void init_thread _P0()
#include "thread_nt.h"
#endif
#ifdef OS2_THREADS
#include "thread_os2.h"
#endif
/*
#ifdef FOOBAR_THREADS
#include "thread_foobar.h"
......
......@@ -56,7 +56,7 @@ int start_new_thread(void (*func)(void *), void *arg)
int aThread;
int success = 1;
aThread = _beginthread(func,4096,arg);
aThread = _beginthread(func,NULL,65536,arg);
if( aThread == -1 ) {
success = 0;
......@@ -210,7 +210,7 @@ void free_sema(type_sema aSemaphore)
}
void down_sema(type_sema aSemaphore, int waitflag)
int down_sema(type_sema aSemaphore, int waitflag)
{
return -1;
}
......
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