RISCOS changes by dschwertberger.

This commit is contained in:
Guido van Rossum 2001-03-02 06:34:14 +00:00
parent 1ca8bb374e
commit 48a680c097
5 changed files with 255 additions and 105 deletions

View File

@ -123,6 +123,21 @@ Socket methods:
#include <os2.h> #include <os2.h>
#endif #endif
#ifdef RISCOS
#define NO_DUP
#undef off_t
#undef uid_t
#undef gid_t
#undef errno
#include <signal.h>
#include "socklib.h"
#include "inetlib.h"
#include "netdb.h"
#include "unixlib.h"
#include "netinet/in.h"
#include "sys/ioctl.h"
#else /*RISCOS*/
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
@ -148,6 +163,9 @@ Socket methods:
#include <winsock.h> #include <winsock.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#endif /*RISCOS*/
#ifdef HAVE_SYS_UN_H #ifdef HAVE_SYS_UN_H
#include <sys/un.h> #include <sys/un.h>
#else #else
@ -218,6 +236,12 @@ static PyObject *SSLErrorObject;
#endif /* USE_SSL */ #endif /* USE_SSL */
#ifdef RISCOS
/* Global variable which is !=0 if Python is running in a RISC OS taskwindow */
static int taskwindow;
#endif
/* Convenience function to raise an error according to errno /* Convenience function to raise an error according to errno
and return a NULL pointer from a function. */ and return a NULL pointer from a function. */
@ -234,7 +258,7 @@ PySocket_Err(void)
{ WSAEFAULT, "Bad address" }, { WSAEFAULT, "Bad address" },
{ WSAEINVAL, "Invalid argument" }, { WSAEINVAL, "Invalid argument" },
{ WSAEMFILE, "Too many open files" }, { WSAEMFILE, "Too many open files" },
{ WSAEWOULDBLOCK, { WSAEWOULDBLOCK,
"The socket operation could not complete " "The socket operation could not complete "
"without blocking" }, "without blocking" },
{ WSAEINPROGRESS, "Operation now in progress" }, { WSAEINPROGRESS, "Operation now in progress" },
@ -254,9 +278,9 @@ PySocket_Err(void)
"Can't assign requested address" }, "Can't assign requested address" },
{ WSAENETDOWN, "Network is down" }, { WSAENETDOWN, "Network is down" },
{ WSAENETUNREACH, "Network is unreachable" }, { WSAENETUNREACH, "Network is unreachable" },
{ WSAENETRESET, { WSAENETRESET,
"Network dropped connection on reset" }, "Network dropped connection on reset" },
{ WSAECONNABORTED, { WSAECONNABORTED,
"Software caused connection abort" }, "Software caused connection abort" },
{ WSAECONNRESET, "Connection reset by peer" }, { WSAECONNRESET, "Connection reset by peer" },
{ WSAENOBUFS, "No buffer space available" }, { WSAENOBUFS, "No buffer space available" },
@ -281,7 +305,7 @@ PySocket_Err(void)
"Network subsystem is unvailable" }, "Network subsystem is unvailable" },
{ WSAVERNOTSUPPORTED, { WSAVERNOTSUPPORTED,
"WinSock version is not supported" }, "WinSock version is not supported" },
{ WSANOTINITIALISED, { WSANOTINITIALISED,
"Successful WSAStartup() not yet performed" }, "Successful WSAStartup() not yet performed" },
{ WSAEDISCON, "Graceful shutdown in progress" }, { WSAEDISCON, "Graceful shutdown in progress" },
/* Resolver errors */ /* Resolver errors */
@ -295,7 +319,7 @@ PySocket_Err(void)
}; };
PyObject *v; PyObject *v;
const char *msg = "winsock error"; const char *msg = "winsock error";
for (msgp = msgs; msgp->msg; msgp++) { for (msgp = msgs; msgp->msg; msgp++) {
if (err_no == msgp->no) { if (err_no == msgp->no) {
msg = msgp->msg; msg = msgp->msg;
@ -363,7 +387,7 @@ typedef struct {
#endif #endif
#if defined(linux) && defined(AF_PACKET) #if defined(linux) && defined(AF_PACKET)
struct sockaddr_ll ll; struct sockaddr_ll ll;
#endif #endif
} sock_addr; } sock_addr;
} PySocketSockObject; } PySocketSockObject;
@ -389,7 +413,7 @@ staticforward PyObject *SSL_SSLread(SSLObject *self, PyObject *args);
#define SSLObject_Check(v) ((v)->ob_type == &SSL_Type) #define SSLObject_Check(v) ((v)->ob_type == &SSL_Type)
#endif /* USE_SSL */ #endif /* USE_SSL */
/* A forward reference to the Socktype type object. /* A forward reference to the Socktype type object.
The Socktype variable contains pointers to various functions, The Socktype variable contains pointers to various functions,
some of which call newsockobject(), which uses Socktype, so some of which call newsockobject(), which uses Socktype, so
@ -406,6 +430,9 @@ staticforward PyTypeObject PySocketSock_Type;
static PySocketSockObject * static PySocketSockObject *
PySocketSock_New(SOCKET_T fd, int family, int type, int proto) PySocketSock_New(SOCKET_T fd, int family, int type, int proto)
{ {
#ifdef RISCOS
int block = 1;
#endif
PySocketSockObject *s; PySocketSockObject *s;
PySocketSock_Type.ob_type = &PyType_Type; PySocketSock_Type.ob_type = &PyType_Type;
s = PyObject_New(PySocketSockObject, &PySocketSock_Type); s = PyObject_New(PySocketSockObject, &PySocketSock_Type);
@ -414,12 +441,17 @@ PySocketSock_New(SOCKET_T fd, int family, int type, int proto)
s->sock_family = family; s->sock_family = family;
s->sock_type = type; s->sock_type = type;
s->sock_proto = proto; s->sock_proto = proto;
#ifdef RISCOS
if(taskwindow) {
socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
}
#endif
} }
return s; return s;
} }
/* Lock to allow python interpreter to continue, but only allow one /* Lock to allow python interpreter to continue, but only allow one
thread to be in gethostbyname */ thread to be in gethostbyname */
#ifdef USE_GETHOSTBYNAME_LOCK #ifdef USE_GETHOSTBYNAME_LOCK
PyThread_type_lock gethostbyname_lock; PyThread_type_lock gethostbyname_lock;
@ -491,8 +523,8 @@ setipaddr(char* name, struct sockaddr_in * addr_ret)
if (hp == NULL) { if (hp == NULL) {
#ifdef HAVE_HSTRERROR #ifdef HAVE_HSTRERROR
/* Let's get real error message to return */ /* Let's get real error message to return */
extern int h_errno; extern int h_errno;
PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
#else #else
PyErr_SetString(PySocket_Error, "host not found"); PyErr_SetString(PySocket_Error, "host not found");
@ -582,11 +614,11 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
ifname = ifr.ifr_name; ifname = ifr.ifr_name;
} }
return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol), return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol),
a->sll_pkttype, a->sll_hatype, a->sll_pkttype, a->sll_hatype,
a->sll_addr, a->sll_halen); a->sll_addr, a->sll_halen);
} }
#endif #endif
/* More cases here... */ /* More cases here... */
default: default:
@ -607,7 +639,7 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
through len_ret. */ through len_ret. */
static int static int
getsockaddrarg(PySocketSockObject *s, PyObject *args, getsockaddrarg(PySocketSockObject *s, PyObject *args,
struct sockaddr **addr_ret, int *len_ret) struct sockaddr **addr_ret, int *len_ret)
{ {
switch (s->sock_family) { switch (s->sock_family) {
@ -668,7 +700,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
int hatype = 0; int hatype = 0;
int pkttype = 0; int pkttype = 0;
char *haddr; char *haddr;
if (!PyArg_ParseTuple(args, "si|iis", &interfaceName, if (!PyArg_ParseTuple(args, "si|iis", &interfaceName,
&protoNumber, &pkttype, &hatype, &haddr)) &protoNumber, &pkttype, &hatype, &haddr))
return 0; return 0;
@ -688,9 +720,9 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
*len_ret = sizeof *addr; *len_ret = sizeof *addr;
return 1; return 1;
} }
#endif #endif
/* More cases here... */ /* More cases here... */
default: default:
@ -701,7 +733,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
} }
/* Get the address length according to the socket object's address family. /* Get the address length according to the socket object's address family.
Return 1 if the family is known, 0 otherwise. The length is returned Return 1 if the family is known, 0 otherwise. The length is returned
through len_ret. */ through len_ret. */
@ -731,7 +763,7 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
return 1; return 1;
} }
#endif #endif
/* More cases here... */ /* More cases here... */
default: default:
@ -778,7 +810,7 @@ PySocketSock_accept(PySocketSockObject *s, PyObject *args)
SOCKETCLOSE(newfd); SOCKETCLOSE(newfd);
goto finally; goto finally;
} }
addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf,
addrlen); addrlen);
if (addr == NULL) if (addr == NULL)
goto finally; goto finally;
@ -805,8 +837,10 @@ static PyObject *
PySocketSock_setblocking(PySocketSockObject *s, PyObject *args) PySocketSock_setblocking(PySocketSockObject *s, PyObject *args)
{ {
int block; int block;
#ifndef RISCOS
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
int delay_flag; int delay_flag;
#endif
#endif #endif
if (!PyArg_ParseTuple(args, "i:setblocking", &block)) if (!PyArg_ParseTuple(args, "i:setblocking", &block))
return NULL; return NULL;
@ -816,6 +850,7 @@ PySocketSock_setblocking(PySocketSockObject *s, PyObject *args)
setsockopt( s->sock_fd, SOL_SOCKET, SO_NONBLOCK, setsockopt( s->sock_fd, SOL_SOCKET, SO_NONBLOCK,
(void *)(&block), sizeof( int ) ); (void *)(&block), sizeof( int ) );
#else #else
#ifndef RISCOS
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
#ifdef PYOS_OS2 #ifdef PYOS_OS2
block = !block; block = !block;
@ -833,6 +868,7 @@ PySocketSock_setblocking(PySocketSockObject *s, PyObject *args)
ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block); ioctlsocket(s->sock_fd, FIONBIO, (u_long*)&block);
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
#endif /* __BEOS__ */ #endif /* __BEOS__ */
#endif /* RISCOS */
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_INCREF(Py_None); Py_INCREF(Py_None);
@ -846,6 +882,30 @@ Set the socket to blocking (flag is true) or non-blocking (false).\n\
This uses the FIONBIO ioctl with the O_NDELAY flag."; This uses the FIONBIO ioctl with the O_NDELAY flag.";
#ifdef RISCOS
/* s.sleeptaskw(1 | 0) method */
static PyObject *
PySocketSock_sleeptaskw(PySocketSockObject *s,PyObject *args)
{
int block;
int delay_flag;
if (!PyArg_GetInt(args, &block))
return NULL;
Py_BEGIN_ALLOW_THREADS
socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
Py_END_ALLOW_THREADS
Py_INCREF(Py_None);
return Py_None;
}
static char sleeptaskw_doc[] =
"sleeptaskw(flag)\n\
\n\
Allow sleeps in taskwindows.";
#endif
/* s.setsockopt() method. /* s.setsockopt() method.
With an integer third argument, sets an integer option. With an integer third argument, sets an integer option.
With a string third argument, sets an option from a buffer; With a string third argument, sets an option from a buffer;
@ -909,7 +969,7 @@ PySocketSock_getsockopt(PySocketSockObject *s, PyObject *args)
if (!PyArg_ParseTuple(args, "ii|i:getsockopt", if (!PyArg_ParseTuple(args, "ii|i:getsockopt",
&level, &optname, &buflen)) &level, &optname, &buflen))
return NULL; return NULL;
if (buflen == 0) { if (buflen == 0) {
int flag = 0; int flag = 0;
socklen_t flagsize = sizeof flag; socklen_t flagsize = sizeof flag;
@ -1215,7 +1275,7 @@ PySocketSock_makefile(PySocketSockObject *s, PyObject *args)
intptr_t fd; intptr_t fd;
#else #else
int fd; int fd;
#endif #endif
FILE *fp; FILE *fp;
PyObject *f; PyObject *f;
@ -1246,7 +1306,7 @@ The mode and buffersize arguments are as for the built-in open() function.";
#endif /* NO_DUP */ #endif /* NO_DUP */
/* s.recv(nbytes [,flags]) method */ /* s.recv(nbytes [,flags]) method */
static PyObject * static PyObject *
@ -1318,7 +1378,7 @@ PySocketSock_recvfrom(PySocketSockObject *s, PyObject *args)
} }
if (n != len && _PyString_Resize(&buf, n) < 0) if (n != len && _PyString_Resize(&buf, n) < 0)
return NULL; return NULL;
if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addrlen))) if (!(addr = makesockaddr(s->sock_fd, (struct sockaddr *)addrbuf, addrlen)))
goto finally; goto finally;
@ -1420,50 +1480,54 @@ of the socket (flag == 1), or both ends (flag == 2).";
/* List of methods for socket objects */ /* List of methods for socket objects */
static PyMethodDef PySocketSock_methods[] = { static PyMethodDef PySocketSock_methods[] = {
{"accept", (PyCFunction)PySocketSock_accept, METH_VARARGS, {"accept", (PyCFunction)PySocketSock_accept, METH_VARARGS,
accept_doc}, accept_doc},
{"bind", (PyCFunction)PySocketSock_bind, METH_VARARGS, {"bind", (PyCFunction)PySocketSock_bind, METH_VARARGS,
bind_doc}, bind_doc},
{"close", (PyCFunction)PySocketSock_close, METH_VARARGS, {"close", (PyCFunction)PySocketSock_close, METH_VARARGS,
close_doc}, close_doc},
{"connect", (PyCFunction)PySocketSock_connect, METH_VARARGS, {"connect", (PyCFunction)PySocketSock_connect, METH_VARARGS,
connect_doc}, connect_doc},
{"connect_ex", (PyCFunction)PySocketSock_connect_ex, METH_VARARGS, {"connect_ex", (PyCFunction)PySocketSock_connect_ex, METH_VARARGS,
connect_ex_doc}, connect_ex_doc},
#ifndef NO_DUP #ifndef NO_DUP
{"dup", (PyCFunction)PySocketSock_dup, METH_VARARGS, {"dup", (PyCFunction)PySocketSock_dup, METH_VARARGS,
dup_doc}, dup_doc},
#endif #endif
{"fileno", (PyCFunction)PySocketSock_fileno, METH_VARARGS, {"fileno", (PyCFunction)PySocketSock_fileno, METH_VARARGS,
fileno_doc}, fileno_doc},
#ifdef HAVE_GETPEERNAME #ifdef HAVE_GETPEERNAME
{"getpeername", (PyCFunction)PySocketSock_getpeername, METH_VARARGS, {"getpeername", (PyCFunction)PySocketSock_getpeername, METH_VARARGS,
getpeername_doc}, getpeername_doc},
#endif #endif
{"getsockname", (PyCFunction)PySocketSock_getsockname, METH_VARARGS, {"getsockname", (PyCFunction)PySocketSock_getsockname, METH_VARARGS,
getsockname_doc}, getsockname_doc},
{"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS, {"getsockopt", (PyCFunction)PySocketSock_getsockopt, METH_VARARGS,
getsockopt_doc}, getsockopt_doc},
{"listen", (PyCFunction)PySocketSock_listen, METH_VARARGS, {"listen", (PyCFunction)PySocketSock_listen, METH_VARARGS,
listen_doc}, listen_doc},
#ifndef NO_DUP #ifndef NO_DUP
{"makefile", (PyCFunction)PySocketSock_makefile, METH_VARARGS, {"makefile", (PyCFunction)PySocketSock_makefile, METH_VARARGS,
makefile_doc}, makefile_doc},
#endif
{"recv", (PyCFunction)PySocketSock_recv, METH_VARARGS,
recv_doc},
{"recvfrom", (PyCFunction)PySocketSock_recvfrom, METH_VARARGS,
recvfrom_doc},
{"send", (PyCFunction)PySocketSock_send, METH_VARARGS,
send_doc},
{"sendto", (PyCFunction)PySocketSock_sendto, METH_VARARGS,
sendto_doc},
{"setblocking", (PyCFunction)PySocketSock_setblocking, METH_VARARGS,
setblocking_doc},
{"setsockopt", (PyCFunction)PySocketSock_setsockopt, METH_VARARGS,
setsockopt_doc},
{"shutdown", (PyCFunction)PySocketSock_shutdown, METH_VARARGS,
shutdown_doc},
#ifdef RISCOS
{"sleeptaskw", (PyCFunction)PySocketSock_sleeptaskw, METH_VARARGS,
sleeptaskw_doc},
#endif #endif
{"recv", (PyCFunction)PySocketSock_recv, METH_VARARGS,
recv_doc},
{"recvfrom", (PyCFunction)PySocketSock_recvfrom, METH_VARARGS,
recvfrom_doc},
{"send", (PyCFunction)PySocketSock_send, METH_VARARGS,
send_doc},
{"sendto", (PyCFunction)PySocketSock_sendto, METH_VARARGS,
sendto_doc},
{"setblocking", (PyCFunction)PySocketSock_setblocking, METH_VARARGS,
setblocking_doc},
{"setsockopt", (PyCFunction)PySocketSock_setsockopt, METH_VARARGS,
setsockopt_doc},
{"shutdown", (PyCFunction)PySocketSock_shutdown, METH_VARARGS,
shutdown_doc},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
@ -1503,8 +1567,8 @@ PySocketSock_repr(PySocketSockObject *s)
return NULL; return NULL;
} }
#endif #endif
sprintf(buf, sprintf(buf,
"<socket object, fd=%ld, family=%d, type=%d, protocol=%d>", "<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
(long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto); (long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto);
return PyString_FromString(buf); return PyString_FromString(buf);
} }
@ -1588,8 +1652,8 @@ gethost_common(struct hostent *h, struct sockaddr_in *addr)
PyObject *tmp; PyObject *tmp;
if (h == NULL) { if (h == NULL) {
#ifdef HAVE_HSTRERROR #ifdef HAVE_HSTRERROR
/* Let's get real error message to return */ /* Let's get real error message to return */
extern int h_errno; extern int h_errno;
PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno)); PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
#else #else
PyErr_SetString(PySocket_Error, "host not found"); PyErr_SetString(PySocket_Error, "host not found");
@ -1694,7 +1758,7 @@ for a host. The host argument is a string giving a host name or IP number.";
static PyObject * static PyObject *
PySocket_gethostbyaddr(PyObject *self, PyObject *args) PySocket_gethostbyaddr(PyObject *self, PyObject *args)
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
char *ip_num; char *ip_num;
struct hostent *h; struct hostent *h;
PyObject *ret; PyObject *ret;
@ -1726,7 +1790,7 @@ PySocket_gethostbyaddr(PyObject *self, PyObject *args)
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG) #elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyaddr_r((char *)&addr.sin_addr, h = gethostbyaddr_r((char *)&addr.sin_addr,
sizeof(addr.sin_addr), sizeof(addr.sin_addr),
AF_INET, AF_INET,
&hp_allocated, buf, buf_len, &errnop); &hp_allocated, buf, buf_len, &errnop);
#else /* HAVE_GETHOSTBYNAME_R_3_ARG */ #else /* HAVE_GETHOSTBYNAME_R_3_ARG */
memset((void *) &data, '\0', sizeof(data)); memset((void *) &data, '\0', sizeof(data));
@ -1850,9 +1914,9 @@ PySocket_socket(PyObject *self, PyObject *args)
(void) SOCKETCLOSE(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
(void) signal(SIGPIPE, SIG_IGN); (void) signal(SIGPIPE, SIG_IGN);
#endif #endif
return (PyObject *) s; return (PyObject *) s;
} }
@ -1888,9 +1952,9 @@ PySocket_fromfd(PyObject *self, PyObject *args)
s = PySocketSock_New(fd, family, type, proto); s = PySocketSock_New(fd, family, type, proto);
/* 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
(void) signal(SIGPIPE, SIG_IGN); (void) signal(SIGPIPE, SIG_IGN);
#endif #endif
return (PyObject *) s; return (PyObject *) s;
} }
@ -1981,7 +2045,7 @@ Convert a 32-bit integer from host to network byte order.";
* *
*/ */
static char inet_aton_doc[] = static char inet_aton_doc[] =
"inet_aton(string) -> packed 32-bit IP representation\n\ "inet_aton(string) -> packed 32-bit IP representation\n\
\n\ \n\
Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\ Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\
@ -2017,7 +2081,7 @@ PySocket_inet_aton(PyObject *self, PyObject *args)
sizeof(packed_addr)); sizeof(packed_addr));
} }
static char inet_ntoa_doc[] = static char inet_ntoa_doc[] =
"inet_ntoa(packed_ip) -> ip_address_string\n\ "inet_ntoa(packed_ip) -> ip_address_string\n\
\n\ \n\
Convert an IP address from 32-bit packed binary format to string format"; Convert an IP address from 32-bit packed binary format to string format";
@ -2032,7 +2096,7 @@ PySocket_inet_ntoa(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) { if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) {
return NULL; return NULL;
} }
if (addr_len != sizeof(packed_addr)) { if (addr_len != sizeof(packed_addr)) {
PyErr_SetString(PySocket_Error, PyErr_SetString(PySocket_Error,
"packed IP wrong length for inet_ntoa"); "packed IP wrong length for inet_ntoa");
@ -2060,8 +2124,8 @@ newSSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
return NULL; return NULL;
} }
memset(self->server, '\0', sizeof(char) * 256); memset(self->server, '\0', sizeof(char) * 256);
memset(self->issuer, '\0', 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 */
if (self->ctx == NULL) { if (self->ctx == NULL) {
@ -2138,12 +2202,12 @@ PySocket_ssl(PyObject *self, PyObject *args)
PySocketSockObject *Sock; PySocketSockObject *Sock;
char *key_file; char *key_file;
char *cert_file; char *cert_file;
if (!PyArg_ParseTuple(args, "O!zz:ssl", if (!PyArg_ParseTuple(args, "O!zz:ssl",
&PySocketSock_Type, (PyObject*)&Sock, &PySocketSock_Type, (PyObject*)&Sock,
&key_file, &cert_file) ) &key_file, &cert_file) )
return NULL; return NULL;
rv = newSSLObject(Sock, key_file, cert_file); rv = newSSLObject(Sock, key_file, cert_file);
if ( rv == NULL ) if ( rv == NULL )
return NULL; return NULL;
@ -2217,10 +2281,10 @@ static PyObject *SSL_SSLwrite(SSLObject *self, PyObject *args)
{ {
char *data; char *data;
size_t len; size_t len;
if (!PyArg_ParseTuple(args, "s#:write", &data, &len)) if (!PyArg_ParseTuple(args, "s#:write", &data, &len))
return NULL; return NULL;
len = SSL_write(self->ssl, data, len); len = SSL_write(self->ssl, data, len);
return PyInt_FromLong((long)len); return PyInt_FromLong((long)len);
} }
@ -2231,12 +2295,12 @@ static PyObject *SSL_SSLread(SSLObject *self, PyObject *args)
int count = 0; int count = 0;
int len = 1024; int len = 1024;
int res; int res;
PyArg_ParseTuple(args, "|i:read", &len); PyArg_ParseTuple(args, "|i:read", &len);
if (!(buf = PyString_FromStringAndSize((char *) 0, len))) if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
return NULL; /* Error object should already be set */ return NULL; /* Error object should already be set */
count = SSL_read(self->ssl, PyString_AsString(buf), len); count = SSL_read(self->ssl, PyString_AsString(buf), len);
res = SSL_get_error(self->ssl, count); res = SSL_get_error(self->ssl, count);
@ -2250,14 +2314,14 @@ static PyObject *SSL_SSLread(SSLObject *self, PyObject *args)
default: default:
return PyErr_SetFromErrno(SSLErrorObject); return PyErr_SetFromErrno(SSLErrorObject);
} }
fflush(stderr); fflush(stderr);
if (count < 0) { if (count < 0) {
Py_DECREF(buf); Py_DECREF(buf);
return PyErr_SetFromErrno(SSLErrorObject); return PyErr_SetFromErrno(SSLErrorObject);
} }
if (count != len && _PyString_Resize(&buf, count) < 0) if (count != len && _PyString_Resize(&buf, count) < 0)
return NULL; return NULL;
return buf; return buf;
@ -2269,38 +2333,38 @@ static PyObject *SSL_SSLread(SSLObject *self, PyObject *args)
/* List of functions exported by this module. */ /* List of functions exported by this module. */
static PyMethodDef PySocket_methods[] = { static PyMethodDef PySocket_methods[] = {
{"gethostbyname", PySocket_gethostbyname, {"gethostbyname", PySocket_gethostbyname,
METH_VARARGS, gethostbyname_doc}, METH_VARARGS, gethostbyname_doc},
{"gethostbyname_ex", PySocket_gethostbyname_ex, {"gethostbyname_ex", PySocket_gethostbyname_ex,
METH_VARARGS, ghbn_ex_doc}, METH_VARARGS, ghbn_ex_doc},
{"gethostbyaddr", PySocket_gethostbyaddr, {"gethostbyaddr", PySocket_gethostbyaddr,
METH_VARARGS, gethostbyaddr_doc}, METH_VARARGS, gethostbyaddr_doc},
{"gethostname", PySocket_gethostname, {"gethostname", PySocket_gethostname,
METH_VARARGS, gethostname_doc}, METH_VARARGS, gethostname_doc},
{"getservbyname", PySocket_getservbyname, {"getservbyname", PySocket_getservbyname,
METH_VARARGS, getservbyname_doc}, METH_VARARGS, getservbyname_doc},
{"getprotobyname", PySocket_getprotobyname, {"getprotobyname", PySocket_getprotobyname,
METH_VARARGS,getprotobyname_doc}, METH_VARARGS,getprotobyname_doc},
{"socket", PySocket_socket, {"socket", PySocket_socket,
METH_VARARGS, socket_doc}, METH_VARARGS, socket_doc},
#ifndef NO_DUP #ifndef NO_DUP
{"fromfd", PySocket_fromfd, {"fromfd", PySocket_fromfd,
METH_VARARGS, fromfd_doc}, METH_VARARGS, fromfd_doc},
#endif #endif
{"ntohs", PySocket_ntohs, {"ntohs", PySocket_ntohs,
METH_VARARGS, ntohs_doc}, METH_VARARGS, ntohs_doc},
{"ntohl", PySocket_ntohl, {"ntohl", PySocket_ntohl,
METH_VARARGS, ntohl_doc}, METH_VARARGS, ntohl_doc},
{"htons", PySocket_htons, {"htons", PySocket_htons,
METH_VARARGS, htons_doc}, METH_VARARGS, htons_doc},
{"htonl", PySocket_htonl, {"htonl", PySocket_htonl,
METH_VARARGS, htonl_doc}, METH_VARARGS, htonl_doc},
{"inet_aton", PySocket_inet_aton, {"inet_aton", PySocket_inet_aton,
METH_VARARGS, inet_aton_doc}, METH_VARARGS, inet_aton_doc},
{"inet_ntoa", PySocket_inet_ntoa, {"inet_ntoa", PySocket_inet_ntoa,
METH_VARARGS, inet_ntoa_doc}, METH_VARARGS, inet_ntoa_doc},
#ifdef USE_SSL #ifdef USE_SSL
{"ssl", PySocket_ssl, {"ssl", PySocket_ssl,
METH_VARARGS, ssl_doc}, METH_VARARGS, ssl_doc},
#endif /* USE_SSL */ #endif /* USE_SSL */
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
@ -2445,6 +2509,12 @@ DL_EXPORT(void)
init_socket(void) init_socket(void)
{ {
PyObject *m, *d; PyObject *m, *d;
#ifdef RISCOS
_kernel_swi_regs r;
r.r[0]=0;
_kernel_swi(0x43380, &r, &r);
taskwindow = r.r[0];
#else
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
if (!NTinit()) if (!NTinit())
return; return;
@ -2454,6 +2524,7 @@ init_socket(void)
return; return;
#endif /* __TOS_OS2__ */ #endif /* __TOS_OS2__ */
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
#endif /* RISCOS */
#ifdef USE_SSL #ifdef USE_SSL
SSL_Type.ob_type = &PyType_Type; SSL_Type.ob_type = &PyType_Type;
#endif #endif
@ -2527,7 +2598,7 @@ init_socket(void)
insint(d, "PACKET_OUTGOING", PACKET_OUTGOING); insint(d, "PACKET_OUTGOING", PACKET_OUTGOING);
insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK); insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK);
insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE); insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE);
#endif #endif
/* Socket types */ /* Socket types */
insint(d, "SOCK_STREAM", SOCK_STREAM); insint(d, "SOCK_STREAM", SOCK_STREAM);

View File

@ -16,7 +16,9 @@
#define GUSI_TO_MSL_EPOCH (4*365*24*60*60) #define GUSI_TO_MSL_EPOCH (4*365*24*60*60)
#endif /* USE_GUSI2 */ #endif /* USE_GUSI2 */
#else #else
#ifndef RISCOS
#include <sys/types.h> #include <sys/types.h>
#endif /* RISCOS */
#endif #endif
#ifdef QUICKWIN #ifdef QUICKWIN
@ -38,7 +40,7 @@ extern int ftime(struct timeb *);
#include <i86.h> #include <i86.h>
#else #else
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
#include <windows.h> include <windows.h>
#ifdef MS_WIN16 #ifdef MS_WIN16
/* These overrides not needed for Win32 */ /* These overrides not needed for Win32 */
#define timezone _timezone #define timezone _timezone
@ -747,7 +749,9 @@ floatsleep(double secs)
#if defined(__WATCOMC__) && !defined(__QNX__) #if defined(__WATCOMC__) && !defined(__QNX__)
/* XXX Can't interrupt this sleep */ /* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
#ifndef RISCOS
delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */ delay((int)(secs * 1000 + 0.5)); /* delay() uses milliseconds */
#endif
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
#else /* !__WATCOMC__ || __QNX__ */ #else /* !__WATCOMC__ || __QNX__ */
#ifdef MSDOS #ifdef MSDOS

View File

@ -137,7 +137,11 @@ intcatcher(int sig)
case 0: case 0:
break; break;
case 1: case 1:
#ifdef RISCOS
fprintf(stderr, message);
#else
write(2, message, strlen(message)); write(2, message, strlen(message));
#endif
break; break;
case 2: case 2:
interrupted = 0; interrupted = 0;

View File

@ -13,6 +13,10 @@
int (*PyOS_InputHook)(void) = NULL; int (*PyOS_InputHook)(void) = NULL;
#ifdef RISCOS
int Py_RISCOSWimpFlag;
#endif
/* This function restarts a fgets() after an EINTR error occurred /* This function restarts a fgets() after an EINTR error occurred
except if PyOS_InterruptOccurred() returns true. */ except if PyOS_InterruptOccurred() returns true. */
@ -58,8 +62,17 @@ PyOS_StdioReadline(char *prompt)
if ((p = PyMem_MALLOC(n)) == NULL) if ((p = PyMem_MALLOC(n)) == NULL)
return NULL; return NULL;
fflush(stdout); fflush(stdout);
#ifndef RISCOS
if (prompt) if (prompt)
fprintf(stderr, "%s", prompt); fprintf(stderr, "%s", prompt);
#else
if (prompt) {
if(Py_RISCOSWimpFlag)
fprintf(stderr, "\x0cr%s\x0c", prompt);
else
fprintf(stderr, "%s", prompt);
}
#endif
fflush(stderr); fflush(stderr);
switch (my_fgets(p, (int)n, stdin)) { switch (my_fgets(p, (int)n, stdin)) {
case 0: /* Normal case */ case 0: /* Normal case */

View File

@ -60,11 +60,20 @@ struct _inittab *PyImport_Inittab = _PyImport_Inittab;
/* these tables define the module suffixes that Python recognizes */ /* these tables define the module suffixes that Python recognizes */
struct filedescr * _PyImport_Filetab = NULL; struct filedescr * _PyImport_Filetab = NULL;
#ifdef RISCOS
static const struct filedescr _PyImport_StandardFiletab[] = {
{"/py", "r", PY_SOURCE},
{"/pyc", "rb", PY_COMPILED},
{0, 0}
};
#else
static const struct filedescr _PyImport_StandardFiletab[] = { static const struct filedescr _PyImport_StandardFiletab[] = {
{".py", "r", PY_SOURCE}, {".py", "r", PY_SOURCE},
{".pyc", "rb", PY_COMPILED}, {".pyc", "rb", PY_COMPILED},
{0, 0} {0, 0}
}; };
#endif
/* Initialize things */ /* Initialize things */
@ -95,8 +104,13 @@ _PyImport_Init(void)
if (Py_OptimizeFlag) { if (Py_OptimizeFlag) {
/* Replace ".pyc" with ".pyo" in _PyImport_Filetab */ /* Replace ".pyc" with ".pyo" in _PyImport_Filetab */
for (; filetab->suffix != NULL; filetab++) { for (; filetab->suffix != NULL; filetab++) {
#ifndef RISCOS
if (strcmp(filetab->suffix, ".pyc") == 0) if (strcmp(filetab->suffix, ".pyc") == 0)
filetab->suffix = ".pyo"; filetab->suffix = ".pyo";
#else
if (strcmp(filetab->suffix, "/pyc") == 0)
filetab->suffix = "/pyo";
#endif
} }
} }
@ -842,7 +856,9 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
struct _frozen *f; struct _frozen *f;
struct filedescr *fdp = NULL; struct filedescr *fdp = NULL;
FILE *fp = NULL; FILE *fp = NULL;
#ifndef RISCOS
struct stat statbuf; struct stat statbuf;
#endif
static struct filedescr fd_frozen = {"", "", PY_FROZEN}; static struct filedescr fd_frozen = {"", "", PY_FROZEN};
static struct filedescr fd_builtin = {"", "", C_BUILTIN}; static struct filedescr fd_builtin = {"", "", C_BUILTIN};
static struct filedescr fd_package = {"", "", PKG_DIRECTORY}; static struct filedescr fd_package = {"", "", PKG_DIRECTORY};
@ -951,6 +967,15 @@ find_module(char *realname, PyObject *path, char *buf, size_t buflen,
} }
#else #else
/* XXX How are you going to test for directories? */ /* XXX How are you going to test for directories? */
#ifdef RISCOS
{
static struct filedescr fd = {"", "", PKG_DIRECTORY};
if (isdir(buf)) {
if (find_init_module(buf))
return &fd;
}
}
#endif
#endif #endif
#ifdef macintosh #ifdef macintosh
fdp = PyMac_FindModuleExtension(buf, &len, name); fdp = PyMac_FindModuleExtension(buf, &len, name);
@ -1196,6 +1221,39 @@ find_init_module(char *buf)
buf[save_len] = '\0'; buf[save_len] = '\0';
return 0; return 0;
} }
#else
#ifdef RISCOS
static int
find_init_module(buf)
char *buf;
{
int save_len = strlen(buf);
int i = save_len;
if (save_len + 13 >= MAXPATHLEN)
return 0;
buf[i++] = SEP;
strcpy(buf+i, "__init__/py");
if (isfile(buf)) {
buf[save_len] = '\0';
return 1;
}
if (Py_OptimizeFlag)
strcpy(buf+i, "o");
else
strcpy(buf+i, "c");
if (isfile(buf)) {
buf[save_len] = '\0';
return 1;
}
buf[save_len] = '\0';
return 0;
}
#endif /*RISCOS*/
#endif /* HAVE_STAT */ #endif /* HAVE_STAT */