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

Skip to content

Commit e877f8b

Browse files
committed
SF patch #474590 -- RISC OS support
1 parent 622cc03 commit e877f8b

12 files changed

Lines changed: 140 additions & 72 deletions

File tree

RISCOS/Modules/config.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ PERFORMANCE OF THIS SOFTWARE.
4141

4242
/* -- ADDMODULE MARKER 1 -- */
4343

44-
extern void PyMarshal_Init();
45-
extern void initimp();
46-
extern void initriscos();
47-
extern void initswi();
44+
extern void PyMarshal_Init(void);
45+
extern void initimp(void);
46+
extern void initgc(void);
47+
extern void initriscos(void);
48+
extern void initswi(void);
4849

4950
struct _inittab _PyImport_Inittab[] = {
5051

@@ -62,6 +63,12 @@ struct _inittab _PyImport_Inittab[] = {
6263
{"__main__", NULL},
6364
{"__builtin__", NULL},
6465
{"sys", NULL},
66+
{"exceptions", NULL},
67+
68+
#ifdef WITH_CYCLE_GC
69+
/* This lives in gcmodule.c */
70+
{"gc", initgc},
71+
#endif
6572

6673
/* Sentinel */
6774
{0, 0}

RISCOS/Modules/drawfmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* drawf DrawFile functions */
22

3-
#include "h.os"
4-
#include "h.osfile"
5-
#include "h.drawfile"
3+
#include "oslib/os.h"
4+
#include "oslib/osfile.h"
5+
#include "oslib/drawfile.h"
66
#include "Python.h"
77

88
#include <limits.h>

RISCOS/Modules/getpath_riscos.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static char *prefix,*exec_prefix,*progpath,*module_search_path=0;
55

66
static void
77
calculate_path()
8-
{ char *pypath=Py_GETENV("Python$Path");
8+
{ char *pypath=getenv("Python$Path");
99
if(pypath)
1010
{ module_search_path=malloc(strlen(pypath)+1);
1111
if (module_search_path) sprintf(module_search_path,"%s",pypath);
@@ -16,9 +16,9 @@ calculate_path()
1616
}
1717
}
1818
if(!module_search_path) module_search_path = "<Python$Dir>.Lib";
19-
prefix="";
19+
prefix="<Python$Dir>";
2020
exec_prefix=prefix;
21-
progpath="<Python$Dir>";
21+
progpath=Py_GetProgramName();
2222
}
2323

2424
/* External interface */

RISCOS/Modules/riscosmodule.c

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
/* RISCOS module implementation */
22

3-
#include "h.osfscontrol"
4-
#include "h.osgbpb"
5-
#include "h.os"
6-
#include "h.osfile"
3+
#include "oslib/osfscontrol.h"
4+
#include "oslib/osgbpb.h"
5+
#include "oslib/os.h"
6+
#include "oslib/osfile.h"
7+
#include "unixstuff.h"
78

89
#include "Python.h"
910

1011
#include <errno.h>
1112

1213
static os_error *e;
1314

14-
static PyObject *RiscosError; /* Exception riscos.error */
15+
/*static PyObject *RiscosError;*/ /* Exception riscos.error */
16+
17+
static PyObject *riscos_error(char *s)
18+
{
19+
PyErr_SetString(PyExc_OSError, s);
20+
return NULL;
21+
}
1522

1623
static PyObject *riscos_oserror(void)
17-
{ PyErr_SetString(RiscosError,e->errmess);
18-
return 0;
24+
{
25+
return riscos_error(e->errmess);
1926
}
2027

21-
static PyObject *riscos_error(char *s) { PyErr_SetString(RiscosError,s);return 0;}
2228

2329
/* RISCOS file commands */
2430

2531
static PyObject *riscos_remove(PyObject *self,PyObject *args)
2632
{ char *path1;
2733
if (!PyArg_Parse(args, "s", &path1)) return NULL;
28-
if (remove(path1)) return PyErr_SetFromErrno(RiscosError);
34+
if (remove(path1)) return PyErr_SetFromErrno(PyExc_OSError);
2935
Py_INCREF(Py_None);
3036
return Py_None;
3137
}
3238

3339
static PyObject *riscos_rename(PyObject *self,PyObject *args)
3440
{ char *path1, *path2;
3541
if (!PyArg_Parse(args, "(ss)", &path1, &path2)) return NULL;
36-
if (rename(path1,path2)) return PyErr_SetFromErrno(RiscosError);;
42+
if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError);
3743
Py_INCREF(Py_None);
3844
return Py_None;
3945
}
@@ -211,12 +217,56 @@ static PyObject *riscos_chmod(PyObject *self,PyObject *args)
211217
return Py_None;
212218
}
213219

220+
214221
static PyObject *riscos_utime(PyObject *self,PyObject *args)
215-
{ char *path;
216-
int x,y;
217-
if (!PyArg_Parse(args, "(s(ii))", &path,&x,&y)) return NULL;
218-
e=xosfile_stamp(path);
219-
if(e) return riscos_oserror();
222+
{
223+
char *path;
224+
long atime, mtime;
225+
PyObject* arg;
226+
227+
if (!PyArg_ParseTuple(args, "sO:utime", &path, &arg))
228+
return NULL;
229+
230+
if (arg == Py_None) {
231+
/* optional time values not given */
232+
Py_BEGIN_ALLOW_THREADS
233+
e=xosfile_stamp(path);
234+
Py_END_ALLOW_THREADS
235+
if(e) return riscos_oserror();
236+
}
237+
else if (!PyArg_Parse(arg, "(ll)", &atime, &mtime)) {
238+
PyErr_SetString(PyExc_TypeError,
239+
"utime() arg 2 must be a tuple (atime, mtime)");
240+
return NULL;
241+
}
242+
else {
243+
/* catalogue info*/
244+
fileswitch_object_type obj_type;
245+
bits load_addr, exec_addr;
246+
int size;
247+
fileswitch_attr attr;
248+
249+
/* read old catalogue info */
250+
Py_BEGIN_ALLOW_THREADS
251+
e=xosfile_read_no_path(path, &obj_type, &load_addr, &exec_addr, &size, &attr);
252+
Py_END_ALLOW_THREADS
253+
if(e) return riscos_oserror();
254+
255+
/* check if load and exec address really contain filetype and date */
256+
if ( (load_addr & 0xFFF00000U) != 0xFFF00000U)
257+
return riscos_error("can't set date for object with load and exec addresses");
258+
259+
/* convert argument mtime to RISC OS load and exec address */
260+
if(acorntime(&exec_addr, &load_addr, (time_t) mtime))
261+
return riscos_oserror();
262+
263+
/* write new load and exec address */
264+
Py_BEGIN_ALLOW_THREADS
265+
e = xosfile_write(path, load_addr, exec_addr, attr);
266+
Py_END_ALLOW_THREADS
267+
if(e) return riscos_oserror();
268+
}
269+
220270
Py_INCREF(Py_None);
221271
return Py_None;
222272
}
@@ -328,9 +378,7 @@ initriscos()
328378
d = PyModule_GetDict(m);
329379

330380
/* Initialize riscos.error exception */
331-
RiscosError = PyString_FromString("riscos.error");
332-
if (RiscosError == NULL || PyDict_SetItemString(d, "error", RiscosError) != 0)
333-
Py_FatalError("can't define riscos.error");
381+
PyDict_SetItemString(d, "error", PyExc_OSError);
334382

335383
PyStructSequence_InitType(&StatResultType, &stat_result_desc);
336384
PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType);

RISCOS/Modules/swimodule.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
* Added "errnum" attribute to swi.error, so one can now check to see what the error number was
1414
*/
1515

16-
#include "h.os"
17-
#include "h.kernel"
16+
#include "oslib/os.h"
17+
#include <kernel.h>
1818
#include "Python.h"
1919

20-
#include <errno.h>
2120

2221
#define PyBlock_Check(op) ((op)->ob_type == &PyBlockType)
2322

RISCOS/Python/dynload_riscos.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
5252
{
5353
int err;
5454
char errstr[256];
55+
void (*init_function)(void);
5556

56-
err = dlk_load(pathname);
57+
err = dlk_load_no_init(pathname, &init_function);
5758
if (err)
5859
{
5960
sprintf(errstr, "dlk failure %d", err);
6061
PyErr_SetString(PyExc_ImportError, errstr);
6162
}
62-
return dynload_init_dummy;
63+
return init_function;
6364
}

RISCOS/Python/getmtime_riscos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22

33
#define __swi
4-
#include "osfile.h"
4+
#include "oslib/osfile.h"
55

66
long PyOS_GetLastModificationTime(char *path, FILE *fp)
77
{

RISCOS/README

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ Compiling:
1717
3. Create missing directories with 'amu cdirs'.
1818
4. Build with 'amu'.
1919

20-
I've only tested Acorn C/C++ 5.06 and amu.
20+
I've only tested Acorn/Norcroft C/C++ 5.30 and amu.
2121

22+
Python now uses the 32 bit libraries from Pace as well as the 32 bit
23+
version of OSLib.
2224

2325
You will also need some additional libraries:
2426

25-
DLK
26-
ftp://ftp.infc.ulst.ac.uk/pub/users/chris/
27+
DLK (patched version)
28+
http://www.schwertberger.de
2729
OSLib
2830
http://www.mk-net.demon.co.uk/oslib
2931

3032
zlib (optional)
3133
ftp://ftp.freesoftware.com/pub/infozip/zlib/
32-
sockets (optional)
33-
http://www.mirror.ac.uk/sites/ftp.acorn.co.uk/pub/riscos/releases/networking/tcpip/sockets.arc
3434
expat (optional)
3535
http://sourceforge.net/projects/expat/
3636
(makefile and config.h available from http://www.schwertberger.de/riscos_expat.zip

RISCOS/sleep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "osmodule.h"
1+
#include "oslib/osmodule.h"
22
#include <stdio.h>
33
#include "kernel.h"
44
#include <limits.h>
55
#include <errno.h>
6-
#include "taskwindow.h"
6+
#include "oslib/taskwindow.h"
77
#include "Python.h"
88

99

RISCOS/support/!Boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ IconSprites <Obey$Dir>.!Sprites
99
set Alias$@RunType_ae5 TaskWindow |"python %%*0|" -name |"Python|" -quit
1010
| -display
1111
set File$Type_ae5 Python
12-
set Alias$Python Run <Python$Dir>.python21 %*0
12+
set Alias$Python Run <Python$Dir>.python22 %*0

0 commit comments

Comments
 (0)