SF patch #474590 -- RISC OS support

This commit is contained in:
Guido van Rossum 2001-10-24 20:13:15 +00:00
parent 622cc03f0b
commit e877f8ba33
12 changed files with 142 additions and 74 deletions

View File

@ -41,10 +41,11 @@ PERFORMANCE OF THIS SOFTWARE.
/* -- ADDMODULE MARKER 1 -- */ /* -- ADDMODULE MARKER 1 -- */
extern void PyMarshal_Init(); extern void PyMarshal_Init(void);
extern void initimp(); extern void initimp(void);
extern void initriscos(); extern void initgc(void);
extern void initswi(); extern void initriscos(void);
extern void initswi(void);
struct _inittab _PyImport_Inittab[] = { struct _inittab _PyImport_Inittab[] = {
@ -62,6 +63,12 @@ struct _inittab _PyImport_Inittab[] = {
{"__main__", NULL}, {"__main__", NULL},
{"__builtin__", NULL}, {"__builtin__", NULL},
{"sys", NULL}, {"sys", NULL},
{"exceptions", NULL},
#ifdef WITH_CYCLE_GC
/* This lives in gcmodule.c */
{"gc", initgc},
#endif
/* Sentinel */ /* Sentinel */
{0, 0} {0, 0}

View File

@ -1,8 +1,8 @@
/* drawf DrawFile functions */ /* drawf DrawFile functions */
#include "h.os" #include "oslib/os.h"
#include "h.osfile" #include "oslib/osfile.h"
#include "h.drawfile" #include "oslib/drawfile.h"
#include "Python.h" #include "Python.h"
#include <limits.h> #include <limits.h>

View File

@ -5,7 +5,7 @@ static char *prefix,*exec_prefix,*progpath,*module_search_path=0;
static void static void
calculate_path() calculate_path()
{ char *pypath=Py_GETENV("Python$Path"); { char *pypath=getenv("Python$Path");
if(pypath) if(pypath)
{ module_search_path=malloc(strlen(pypath)+1); { module_search_path=malloc(strlen(pypath)+1);
if (module_search_path) sprintf(module_search_path,"%s",pypath); if (module_search_path) sprintf(module_search_path,"%s",pypath);
@ -16,9 +16,9 @@ calculate_path()
} }
} }
if(!module_search_path) module_search_path = "<Python$Dir>.Lib"; if(!module_search_path) module_search_path = "<Python$Dir>.Lib";
prefix=""; prefix="<Python$Dir>";
exec_prefix=prefix; exec_prefix=prefix;
progpath="<Python$Dir>"; progpath=Py_GetProgramName();
} }
/* External interface */ /* External interface */

View File

@ -1,9 +1,10 @@
/* RISCOS module implementation */ /* RISCOS module implementation */
#include "h.osfscontrol" #include "oslib/osfscontrol.h"
#include "h.osgbpb" #include "oslib/osgbpb.h"
#include "h.os" #include "oslib/os.h"
#include "h.osfile" #include "oslib/osfile.h"
#include "unixstuff.h"
#include "Python.h" #include "Python.h"
@ -11,21 +12,26 @@
static os_error *e; static os_error *e;
static PyObject *RiscosError; /* Exception riscos.error */ /*static PyObject *RiscosError;*/ /* Exception riscos.error */
static PyObject *riscos_oserror(void) static PyObject *riscos_error(char *s)
{ PyErr_SetString(RiscosError,e->errmess); {
return 0; PyErr_SetString(PyExc_OSError, s);
return NULL;
}
static PyObject *riscos_oserror(void)
{
return riscos_error(e->errmess);
} }
static PyObject *riscos_error(char *s) { PyErr_SetString(RiscosError,s);return 0;}
/* RISCOS file commands */ /* RISCOS file commands */
static PyObject *riscos_remove(PyObject *self,PyObject *args) static PyObject *riscos_remove(PyObject *self,PyObject *args)
{ char *path1; { char *path1;
if (!PyArg_Parse(args, "s", &path1)) return NULL; if (!PyArg_Parse(args, "s", &path1)) return NULL;
if (remove(path1)) return PyErr_SetFromErrno(RiscosError); if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -33,7 +39,7 @@ static PyObject *riscos_remove(PyObject *self,PyObject *args)
static PyObject *riscos_rename(PyObject *self,PyObject *args) static PyObject *riscos_rename(PyObject *self,PyObject *args)
{ char *path1, *path2; { char *path1, *path2;
if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL; if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL;
if (rename(path1,path2)) return PyErr_SetFromErrno(RiscosError);; if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -211,12 +217,56 @@ static PyObject *riscos_chmod(PyObject *self,PyObject *args)
return Py_None; return Py_None;
} }
static PyObject *riscos_utime(PyObject *self,PyObject *args) static PyObject *riscos_utime(PyObject *self,PyObject *args)
{ char *path; {
int x,y; char *path;
if (!PyArg_Parse(args, "(s(ii))", &path,&x,&y)) return NULL; long atime, mtime;
PyObject* arg;
if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
return NULL;
if (arg == Py_None) {
/* optional time values not given */
Py_BEGIN_ALLOW_THREADS
e=xosfile_stamp(path); e=xosfile_stamp(path);
Py_END_ALLOW_THREADS
if(e) return riscos_oserror(); if(e) return riscos_oserror();
}
else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) {
PyErr_SetString(PyExc_TypeError,
"utime() arg 2 must be a tuple (atime, mtime)");
return NULL;
}
else {
/* catalogue info*/
fileswitch_object_type obj_type;
bits load_addr, exec_addr;
int size;
fileswitch_attr attr;
/* read old catalogue info */
Py_BEGIN_ALLOW_THREADS
e=xosfile_read_no_path(path, &obj_type, &load_addr, &exec_addr, &size, &attr);
Py_END_ALLOW_THREADS
if(e) return riscos_oserror();
/* check if load and exec address really contain filetype and date */
if ( (load_addr & 0xFFF00000U) != 0xFFF00000U)
return riscos_error("can't set date for object with load and exec addresses");
/* convert argument mtime to RISC OS load and exec address */
if(acorntime(&exec_addr, &load_addr, (time_t) mtime))
return riscos_oserror();
/* write new load and exec address */
Py_BEGIN_ALLOW_THREADS
e = xosfile_write(path, load_addr, exec_addr, attr);
Py_END_ALLOW_THREADS
if(e) return riscos_oserror();
}
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -328,9 +378,7 @@ initriscos()
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
/* Initialize riscos.error exception */ /* Initialize riscos.error exception */
RiscosError = PyString_FromString("riscos.error"); PyDict_SetItemString(d, "error", PyExc_OSError);
if (RiscosError == NULL || PyDict_SetItemString(d, "error", RiscosError) != 0)
Py_FatalError("can't define riscos.error");
PyStructSequence_InitType(&StatResultType, &stat_result_desc); PyStructSequence_InitType(&StatResultType, &stat_result_desc);
PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType); PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType);

View File

@ -13,11 +13,10 @@
* Added "errnum" attribute to swi.error, so one can now check to see what the error number was * Added "errnum" attribute to swi.error, so one can now check to see what the error number was
*/ */
#include "h.os" #include "oslib/os.h"
#include "h.kernel" #include <kernel.h>
#include "Python.h" #include "Python.h"
#include <errno.h>
#define PyBlock_Check(op) ((op)->ob_type == &PyBlockType) #define PyBlock_Check(op) ((op)->ob_type == &PyBlockType)

View File

@ -52,12 +52,13 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
{ {
int err; int err;
char errstr[256]; char errstr[256];
void (*init_function)(void);
err = dlk_load(pathname); err = dlk_load_no_init(pathname, &init_function);
if (err) if (err)
{ {
sprintf(errstr, "dlk failure %d", err); sprintf(errstr, "dlk failure %d", err);
PyErr_SetString(PyExc_ImportError, errstr); PyErr_SetString(PyExc_ImportError, errstr);
} }
return dynload_init_dummy; return init_function;
} }

View File

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#define __swi #define __swi
#include "osfile.h" #include "oslib/osfile.h"
long PyOS_GetLastModificationTime(char *path, FILE *fp) long PyOS_GetLastModificationTime(char *path, FILE *fp)
{ {

View File

@ -17,20 +17,20 @@ Compiling:
3. Create missing directories with 'amu cdirs'. 3. Create missing directories with 'amu cdirs'.
4. Build with 'amu'. 4. Build with 'amu'.
I've only tested Acorn C/C++ 5.06 and amu. I've only tested Acorn/Norcroft C/C++ 5.30 and amu.
Python now uses the 32 bit libraries from Pace as well as the 32 bit
version of OSLib.
You will also need some additional libraries: You will also need some additional libraries:
DLK DLK (patched version)
ftp://ftp.infc.ulst.ac.uk/pub/users/chris/ http://www.schwertberger.de
OSLib OSLib
http://www.mk-net.demon.co.uk/oslib http://www.mk-net.demon.co.uk/oslib
zlib (optional) zlib (optional)
ftp://ftp.freesoftware.com/pub/infozip/zlib/ ftp://ftp.freesoftware.com/pub/infozip/zlib/
sockets (optional)
http://www.mirror.ac.uk/sites/ftp.acorn.co.uk/pub/riscos/releases/networking/tcpip/sockets.arc
expat (optional) expat (optional)
http://sourceforge.net/projects/expat/ http://sourceforge.net/projects/expat/
(makefile and config.h available from http://www.schwertberger.de/riscos_expat.zip (makefile and config.h available from http://www.schwertberger.de/riscos_expat.zip

View File

@ -1,9 +1,9 @@
#include "osmodule.h" #include "oslib/osmodule.h"
#include <stdio.h> #include <stdio.h>
#include "kernel.h" #include "kernel.h"
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include "taskwindow.h" #include "oslib/taskwindow.h"
#include "Python.h" #include "Python.h"

View File

@ -9,4 +9,4 @@ IconSprites <Obey$Dir>.!Sprites
set Alias$@RunType_ae5 TaskWindow |"python %%*0|" -name |"Python|" -quit set Alias$@RunType_ae5 TaskWindow |"python %%*0|" -name |"Python|" -quit
| -display | -display
set File$Type_ae5 Python set File$Type_ae5 Python
set Alias$Python Run <Python$Dir>.python21 %*0 set Alias$Python Run <Python$Dir>.python22 %*0

View File

@ -1,8 +1,9 @@
/* Fudge unix isatty and fileno for RISCOS */ /* Fudge unix isatty and fileno for RISCOS */
#include "h.unixstuff" #include "unixstuff.h"
#include <math.h> #include <math.h>
#include "h.osfile" #include <time.h>
#include "oslib/osfile.h"
int fileno(FILE *f) int fileno(FILE *f)
{ return (int)f; { return (int)f;
@ -15,48 +16,59 @@ int isatty(int fn)
bits unixtime(bits ld,bits ex) bits unixtime(bits ld,bits ex)
{ ld&=0xFF; { ld&=0xFF;
ld-=51; ld-=51;
if(ex<1855548004U) ld--; if(ex<1855547904U) ld--;
ex-=1855548004U; ex-=1855548004U;
return ex/100+42949672*ld+(95*ld)/100; return ex/100+42949673U*ld-ld/25;
}
int unlink(char *fname)
{ remove(fname);
return 0;
} }
/*#define RET(k) {printf(" %d\n",k);return k;}*/ /* from RISC OS infozip, preserves filetype in ld */
#define RET(k) return k int acorntime(bits *ex, bits *ld, time_t utime)
{
unsigned timlo; /* 3 lower bytes of acorn file-time plus carry byte */
unsigned timhi; /* 2 high bytes of acorn file-time */
timlo = ((unsigned)utime & 0x00ffffffU) * 100 + 0x00996a00U;
timhi = ((unsigned)utime >> 24);
timhi = timhi * 100 + 0x0000336eU + (timlo >> 24);
if (timhi & 0xffff0000U)
return 1; /* calculation overflow, do not change time */
/* insert the five time bytes into loadaddr and execaddr variables */
*ex = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24);
*ld = (*ld & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU);
return 0; /* subject to future extension to signal overflow */
}
int isdir(char *fn) int isdir(char *fn)
{ int ob; { int ob;
/* printf("isdir %s",fn);*/ if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0);
switch (ob) switch (ob)
{ case osfile_IS_DIR:RET(1); { case osfile_IS_DIR:return 1;
case osfile_IS_IMAGE:RET(1); case osfile_IS_IMAGE:return 1;
} }
RET(0); return 0;
} }
int isfile(char *fn) int isfile(char *fn)
{ int ob; /*printf("isfile %s",fn);*/ { int ob;
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0); if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
switch (ob) switch (ob)
{ case osfile_IS_FILE:RET(1); { case osfile_IS_FILE:return 1;
case osfile_IS_IMAGE:RET(1); case osfile_IS_IMAGE:return 1;
} }
RET(0); return 0;
} }
int exists(char *fn) int object_exists(char *fn)
{ int ob; /*printf("exists %s",fn);*/ { int ob;
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) RET(0); if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
switch (ob) switch (ob)
{ case osfile_IS_FILE:RET(1); { case osfile_IS_FILE:return 1;
case osfile_IS_DIR:RET(1); case osfile_IS_DIR:return 1;
case osfile_IS_IMAGE:RET(1); case osfile_IS_IMAGE:return 1;
} }
RET(0); return 0;
} }

View File

@ -1,13 +1,14 @@
/* Fudge unix isatty and fileno for RISCOS */ /* Fudge unix isatty and fileno for RISCOS */
#include <stdio.h> #include <stdio.h>
#include <time.h>
int fileno(FILE *f); int fileno(FILE *f);
int isatty(int fn); int isatty(int fn);
unsigned int unixtime(unsigned int ld,unsigned int ex); unsigned int unixtime(unsigned int ld,unsigned int ex);
/*long PyOS_GetLastModificationTime(char *name);*/ int acorntime(unsigned int *ex, unsigned int *ld, time_t ut);
int unlink(char *fname);
int isdir(char *fn); int isdir(char *fn);
int isfile(char *fn); int isfile(char *fn);
int exists(char *fn); int object_exists(char *fn);