annotate RISCOS/Modules/swimodule.c @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 52294af4b663
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* swi
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 RISC OS swi functions
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 1.00 Chris Stretch
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 1.01 12 May 1999 Laurence Tratt
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 * Changed swi.error to be a class based exception rather than string based
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 * Added swi.ArgError which is generated for errors when the user passes invalid arguments to
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 functions etc
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 * Added "errnum" attribute to swi.error, so one can now check to see what the error number was
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
14
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
15 1.02 03 March 2002 Dietmar Schwertberger
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
16 * Added string, integer, integers, tuple and tuples
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
20652
2d3cee9f1633 SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 16941
diff changeset
19 #include "oslib/os.h"
2d3cee9f1633 SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 16941
diff changeset
20 #include <kernel.h>
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 #include "Python.h"
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 #define PyBlock_Check(op) ((op)->ob_type == &PyBlockType)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 static PyObject *SwiError; /* Exception swi.error */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 static PyObject *ArgError; /* Exception swi.ArgError */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 static os_error *e;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 static PyObject *swi_oserror(void)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 { PyErr_SetString(SwiError,e->errmess);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 PyObject_SetAttrString(PyErr_Occurred(), "errnum", PyInt_FromLong(e->errnum));
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 return 0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 static PyObject *swi_error(char *s)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 { PyErr_SetString(ArgError,s);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 return 0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 typedef struct
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 { PyObject_HEAD
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 void *block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 int length; /*length in bytes*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 int heap;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 } PyBlockObject;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 static PyTypeObject PyBlockType;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 /* block commands */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 static PyObject *PyBlock_New(PyObject *self,PyObject *args)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 { int size;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 PyBlockObject *b;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 PyObject *init=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if(!PyArg_ParseTuple(args,"i|O",&size,&init)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if(size<1) size=1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 b=PyObject_NEW(PyBlockObject,&PyBlockType);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 if(!b) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 b->block=malloc(4*size);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 if(!b->block)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 { Py_DECREF(b);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 return PyErr_NoMemory();
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 b->length=4*size;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 b->heap=1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if(init)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
69 { if(PyString_Check(init))
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
70 { int n=PyString_Size(init);
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if (n>4*size) n=4*size;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
72 memcpy(b->block,PyString_AsString(init),n);
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 memset((char*)b->block+n,0,4*size-n);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 else
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 { int n,k;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 long *p=(long*)b->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 if(!PyList_Check(init)) goto fail;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 n=PyList_Size(init);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 if (n>size) n=size;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 for(k=0;k<n;k++)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 { PyObject *q=PyList_GetItem(init,k);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 if(!PyInt_Check(q)) goto fail;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 p[k]=PyInt_AsLong(q);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 for(;k<size;k++) p[k]=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 return (PyObject *)b;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 fail:PyErr_SetString(PyExc_TypeError,
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 "block initialiser must be string or list of integers");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 Py_DECREF(b);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 static PyObject *PyRegister(PyObject *self,PyObject *args)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 { int size,ptr;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 PyBlockObject *b;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 if(!PyArg_ParseTuple(args,"ii",&size,&ptr)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 if(size<1) size=1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 b=PyObject_NEW(PyBlockObject,&PyBlockType);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 if(!b) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 b->block=(void*)ptr;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 b->length=4*size;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 b->heap=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 return (PyObject *)b;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
108
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 static PyObject *PyBlock_ToString(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 { int s=0,e=self->length;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if(!PyArg_ParseTuple(arg,"|ii",&s,&e)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 if(s<0||e>self->length||s>e)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
116 return PyString_FromStringAndSize((char*)self->block+s,e-s);
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 static PyObject *PyBlock_NullString(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 { int s=0,e=self->length,i;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 char *p=(char*)self->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if(!PyArg_ParseTuple(arg,"|ii",&s,&e)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 if(s<0||e>self->length||s>e)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 for(i=s;i<e;i++) if(p[i]==0) break;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
128 return PyString_FromStringAndSize((char*)self->block+s,i-s);
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 static PyObject *PyBlock_CtrlString(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 { int s=0,e=self->length,i;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 char *p=(char*)self->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if(!PyArg_ParseTuple(arg,"|ii",&s,&e)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 if(s<0||e>self->length||s>e)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 for(i=s;i<e;i++) if(p[i]<32) break;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
140 return PyString_FromStringAndSize((char*)self->block+s,i-s);
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 static PyObject *PyBlock_PadString(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 { int s=0,e=self->length,n,m;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 char *str;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 char c;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 char *p=(char*)self->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 if(!PyArg_ParseTuple(arg,"s#c|ii",&str,&n,&c,&s,&e)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 if(s<0||e>self->length||s>e)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 m=e-s;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 if(n>m) n=m;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 memcpy(p+s,str,n);memset(p+s+n,c,m-n);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 Py_INCREF(Py_None);return Py_None;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
158
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 static PyObject *PyBlock_BitSet(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 { int i,x,y;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 int *p=(int*)self->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 if(!PyArg_ParseTuple(arg,"iii",&i,&x,&y)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 if(i<0||i>=self->length/4)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 p[i]=(p[i]&y)^x;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 Py_INCREF(Py_None);return Py_None;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 static PyObject *PyBlock_Resize(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 { int n;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 if(!PyArg_ParseTuple(arg,"i",&n)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 if(n<1) n=1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 if(self->heap)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 { void *v=realloc(self->block,4*n);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 if (!v) return PyErr_NoMemory();
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 self->block=v;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 self->length=4*n;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 Py_INCREF(Py_None);return Py_None;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 static PyObject *PyBlock_ToFile(PyBlockObject *self,PyObject *arg)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 { int s=0,e=self->length/4;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 PyObject *f;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 FILE *fp;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 if(!PyArg_ParseTuple(arg,"O|ii",&f,&s,&e)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 fp=PyFile_AsFile(f);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 if (!fp)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 { PyErr_SetString(PyExc_TypeError, "arg must be open file");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 fwrite((int*)(self->block)+s,4,e-s,fp);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 Py_INCREF(Py_None);return Py_None;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 static struct PyMethodDef PyBlock_Methods[]=
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 { { "tostring",(PyCFunction)PyBlock_ToString,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 { "padstring",(PyCFunction)PyBlock_PadString,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 { "nullstring",(PyCFunction)PyBlock_NullString,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 { "ctrlstring",(PyCFunction)PyBlock_CtrlString,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 { "bitset",(PyCFunction)PyBlock_BitSet,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 { "resize",(PyCFunction)PyBlock_Resize,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 { "tofile",(PyCFunction)PyBlock_ToFile,1},
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 { NULL,NULL} /* sentinel */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 };
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 static int block_len(PyBlockObject *b)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 { return b->length/4;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
212
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 static PyObject *block_concat(PyBlockObject *b,PyBlockObject *c)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 { PyErr_SetString(PyExc_IndexError,"block concatenation not implemented");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
217
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
218 static PyObject *block_repeat(PyBlockObject *b,Py_ssize_t i)
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 { PyErr_SetString(PyExc_IndexError,"block repetition not implemented");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
220 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
223 static PyObject *block_item(PyBlockObject *b,Py_ssize_t i)
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 { if(i<0||4*i>=b->length)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 return PyInt_FromLong(((long*)(b->block))[i]);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
230
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
231 static PyObject *block_slice(PyBlockObject *b,Py_ssize_t i,Py_ssize_t j)
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
232 { Py_ssize_t n,k;
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 long *p=b->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 PyObject *result;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 if(j>b->length/4) j=b->length/4;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 if(i<0||i>j)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 n=j-i;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 result=PyList_New(n);
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
242 for(k=0;k<n;k++) PyList_SetItem(result,k,PyInt_FromSsize_t(p[i+k]));
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 return result;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
245
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
246 static int block_ass_item(PyBlockObject *b,Py_ssize_t i,PyObject *v)
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 { if(i<0||i>=b->length/4)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 return -1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 if(!PyInt_Check(v))
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 { PyErr_SetString(PyExc_TypeError,"block item must be integer");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 return -1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 ((long*)(b->block))[i]=PyInt_AsLong(v);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 return 0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
258
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
259 static int block_ass_slice(PyBlockObject *b,Py_ssize_t i,Py_ssize_t j,PyObject *v)
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
260 { Py_ssize_t n,k;
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 long *p=b->block;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 if(j>b->length/4) j=b->length/4;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 if(i<0||i>j)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 { PyErr_SetString(PyExc_IndexError,"block index out of range");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 return -1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 if(!PyList_Check(v)) goto fail;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 n=PyList_Size(v);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 if(n>j-i) n=j-i;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 for(k=0;k<n;k++)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 { PyObject *q=PyList_GetItem(v,k);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 if(!PyInt_Check(q)) goto fail;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 p[i+k]=PyInt_AsLong(q);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 for(;k<j-i;k++) p[i+k]=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 return 0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 fail:PyErr_SetString(PyExc_TypeError,"block slice must be integer list");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 return -1;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
279 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
280
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 static PySequenceMethods block_as_sequence=
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 { (inquiry)block_len, /*sq_length*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 (binaryfunc)block_concat, /*sq_concat*/
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
284 (ssizeargfunc)block_repeat, /*sq_repeat*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
285 (ssizeargfunc)block_item, /*sq_item*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
286 (ssizessizeargfunc)block_slice, /*sq_slice*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
287 (ssizeobjargproc)block_ass_item, /*sq_ass_item*/
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 29066
diff changeset
288 (ssizessizeobjargproc)block_ass_slice, /*sq_ass_slice*/
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 };
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
290
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 static PyObject *PyBlock_GetAttr(PyBlockObject *s,char *name)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 {
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 if (!strcmp(name, "length")) return PyInt_FromLong((long)s->length);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 if (!strcmp(name, "start")) return PyInt_FromLong((long)s->block);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 if (!strcmp(name,"end")) return PyInt_FromLong(((long)(s->block)+s->length));
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 if (!strcmp(name, "__members__"))
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 { PyObject *list = PyList_New(3);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 if (list)
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
299 { PyList_SetItem(list, 0, PyString_FromString("length"));
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
300 PyList_SetItem(list, 1, PyString_FromString("start"));
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
301 PyList_SetItem(list, 2, PyString_FromString("end"));
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 if (PyErr_Occurred()) { Py_DECREF(list);list = NULL;}
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 return list;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 return Py_FindMethod(PyBlock_Methods, (PyObject*) s,name);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
308
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 static void PyBlock_Dealloc(PyBlockObject *b)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 {
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 if(b->heap) {
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 if (b->heap)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 ;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 else
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 PyMem_DEL(b->block);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 PyMem_DEL(b);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
318 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
319
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 static PyTypeObject PyBlockType=
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 { PyObject_HEAD_INIT(&PyType_Type)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 0, /*ob_size*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 "block", /*tp_name*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 sizeof(PyBlockObject), /*tp_size*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 0, /*tp_itemsize*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 /* methods */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 (destructor)PyBlock_Dealloc, /*tp_dealloc*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 0, /*tp_print*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 (getattrfunc)PyBlock_GetAttr, /*tp_getattr*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 0, /*tp_setattr*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 0, /*tp_compare*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 0, /*tp_repr*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 0, /*tp_as_number*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 &block_as_sequence, /*tp_as_sequence*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 0, /*tp_as_mapping*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 0, /*tp_hash*/
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 };
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
338
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 /* swi commands */
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 static PyObject *swi_swi(PyObject *self,PyObject *args)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 { PyObject *name,*format,*result,*v;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 int swino,carry,rno=0,j,n;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 char *swiname,*fmt,*outfmt;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 _kernel_swi_regs r;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 PyBlockObject *ao;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 if(args==NULL||!PyTuple_Check(args)||(n=PyTuple_Size(args))<2)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 { PyErr_BadArgument(); return NULL;}
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 name=PyTuple_GetItem(args,0);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 if(!PyArg_Parse(name,"i",&swino))
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 { PyErr_Clear();
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 if(!PyArg_Parse(name,"s",&swiname)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 e=xos_swi_number_from_string(swiname,&swino);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 if(e) return swi_oserror();
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 format=PyTuple_GetItem(args,1);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 if(!PyArg_Parse(format,"s",&fmt)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 j=2;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 for(;;fmt++)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 { switch(*fmt)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 { case '.': rno++;continue;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 case ';':case 0: goto swicall;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 case '0':case '1':case '2':case '3':case '4':
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 case '5':case '6':case '7':case '8':case '9':
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 r.r[rno++]=*fmt-'0';continue;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 case '-':r.r[rno++]=-1;continue;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 if(j>=n) return swi_error("Too few arguments");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 v=PyTuple_GetItem(args,j++);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 switch(*fmt)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 { case 'i':if(!PyArg_Parse(v,"i",&r.r[rno])) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 case 's':if(!PyArg_Parse(v,"s",(char**)(&r.r[rno]))) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 case 'b':if(!PyArg_Parse(v,"O",(PyObject**)&ao)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 if(!PyBlock_Check(v)) return swi_error("Not a block");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 r.r[rno]=(int)(ao->block);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 case 'e':if(!PyArg_Parse(v,"O",(PyObject**)&ao)) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 if(!PyBlock_Check(v)) return swi_error("Not a block");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 r.r[rno]=(int)(ao->block)+ao->length;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 default:return swi_error("Odd format character");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 rno++;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 swicall:e=(os_error*)_kernel_swi_c(swino,&r,&r,&carry);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 if(e) return swi_oserror();
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 if(*fmt==0) { Py_INCREF(Py_None);return Py_None;}
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 n=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 for(outfmt=++fmt;*outfmt;outfmt++) switch(*outfmt)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 { case 'i':case 's':case '*':n++;break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 case '.':break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 default:return swi_error("Odd format character");
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 if(n==0) { Py_INCREF(Py_None);return Py_None;}
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 if(n!=1)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 { result=PyTuple_New(n);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 if(!result) return NULL;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 rno=0;j=0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 for(;*fmt;fmt++)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 { switch(*fmt)
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 { case 'i':v=PyInt_FromLong((long)r.r[rno++]); break;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
405 case 's':v=PyString_FromString((char*)(r.r[rno++])); break;
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 case '.':rno++; continue;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 case '*':v=PyInt_FromLong((long)carry); break;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 if(!v) goto fail;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 if(n==1) return v;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 PyTuple_SetItem(result,j,v);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
412 j++;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 return result;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 fail:Py_DECREF(result);return 0;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 }
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
417
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
418 static PyObject *swi_string(PyObject *self, PyObject *arg)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
419 { char *s;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
420 int l=-1;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
421 if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&s, &l)) return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
422 if (l==-1)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
423 l = strlen(s);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
424 return PyString_FromStringAndSize((char*)s, l);
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
425 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
426
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
427 static char swi_string__doc__[] =
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
428 "string(address[, length]) -> string\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
429 Read a null terminated string from the given address.";
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
430
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
431
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
432 static PyObject *swi_integer(PyObject *self, PyObject *arg)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
433 { int *i;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
434
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
435 if(!PyArg_ParseTuple(arg,"i",(unsigned int *)&i))
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
436 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
437 return PyInt_FromLong(*i);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
438 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
439
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
440 static char swi_integer__doc__[] =
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
441 "integer(address) -> string\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
442 Read an integer from the given address.";
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
443
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
444
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
445 static PyObject *swi_integers(PyObject *self, PyObject *arg)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
446 { int *i;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
447 int c=-1;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
448 PyObject *result, *result1;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
449
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
450 if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&i, &c)) return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
451 result=PyList_New(0);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
452 if (result) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
453 while ( c>0 || (c==-1 && *i) ) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
454 result1 = PyInt_FromLong((long)*i);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
455 if (!result1) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
456 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
457 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
458 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
459 if (PyList_Append(result, result1)!=0) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
460 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
461 Py_DECREF(result1);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
462 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
463 };
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
464 i++;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
465 if (c!=-1)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
466 c--;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
467 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
468 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
469 return result;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
470 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
471
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
472 static char swi_integers__doc__[] =
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
473 "integers(address[, count]) -> string\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
474 Either read a null terminated list of integers or\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
475 a list of given length from the given address.";
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
476
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
477
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
478 static PyObject *swi_tuples(PyObject *self, PyObject *arg)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
479 {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
480 unsigned char *i; /* points to current */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
481 int c=-1, l=4, j, zero; /* count, length, index */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
482 PyObject *result, *result1, *result11;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
483
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
484 if(!PyArg_ParseTuple(arg,"i|ii",(unsigned int *)&i, &l, &c)) return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
485 result=PyList_New(0);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
486 if (result) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
487 while (c) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
488 result1 = PyTuple_New(l);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
489 if (!result1) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
490 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
491 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
492 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
493 zero = (c==-1); /* check for zeros? */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
494 for(j=0;j<l;j++) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
495 if (zero && *i)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
496 zero = 0; /* non-zero found */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
497 result11 = PyInt_FromLong((long)(*i));
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
498 if (!result11) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
499 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
500 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
501 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
502 PyTuple_SetItem(result1, j, result11);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
503 i++;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
504 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
505 if (c==-1 && zero) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
506 Py_DECREF(result1);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
507 c = 0;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
508 break;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
509 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
510 if (PyList_Append(result, result1)!=0) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
511 Py_DECREF(result1);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
512 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
513 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
514 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
515 if (c!=-1)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
516 c--;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
517 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
518 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
519 return result;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
520 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
521
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
522 static char swi_tuples__doc__[] =
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
523 "tuples(address[, length=4[, count]]) -> string\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
524 Either read a null terminated list of byte tuples or\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
525 a list of given length from the given address.";
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
526
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
527
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
528 static PyObject *swi_tuple(PyObject *self, PyObject *arg)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
529 {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
530 unsigned char *i; /* points to current */
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
531 int c=1, j;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
532 PyObject *result, *result1;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
533
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
534 if(!PyArg_ParseTuple(arg,"i|i",(unsigned int *)&i, &c)) return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
535 result = PyTuple_New(c);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
536 if (!result)
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
537 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
538 for(j=0;j<c;j++) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
539 result1 = PyInt_FromLong((long)(i[j]));
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
540 if (!result1) {
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
541 Py_DECREF(result);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
542 return NULL;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
543 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
544 PyTuple_SetItem(result, j, result1);
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
545 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
546 return result;
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
547 }
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
548
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
549 static char swi_tuple__doc__[] =
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
550 "tuple(address[, count=1]]) -> tuple\n\
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
551 Read count bytes from given address.";
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
552
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
553
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 static PyMethodDef SwiMethods[]=
38490
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
555 { { "swi", swi_swi, METH_VARARGS},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
556 { "block", PyBlock_New, METH_VARARGS},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
557 { "register", PyRegister, METH_VARARGS},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
558 { "string", swi_string, METH_VARARGS, swi_string__doc__},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
559 { "integer", swi_integer, METH_VARARGS, swi_integer__doc__},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
560 { "integers", swi_integers, METH_VARARGS, swi_integers__doc__},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
561 { "tuples", swi_tuples, METH_VARARGS, swi_tuples__doc__},
a5298f371be7 Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents: 36501
diff changeset
562 { "tuple", swi_tuple, METH_VARARGS, swi_tuple__doc__},
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
563 { NULL,NULL,0,NULL} /* Sentinel */
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
564 };
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
565
29066
90342f395721 Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents: 20652
diff changeset
566
16941
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
567 void initswi()
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
568 { PyObject *m, *d;
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
569 m = Py_InitModule("swi", SwiMethods);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
570 d = PyModule_GetDict(m);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
571 SwiError=PyErr_NewException("swi.error", NULL, NULL);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 PyDict_SetItemString(d,"error",SwiError);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
573 ArgError=PyErr_NewException("swi.ArgError", NULL, NULL);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
574 PyDict_SetItemString(d,"ArgError",ArgError);
a015aed3a1ac RISCOS files by dschwertberger
Guido van Rossum <guido@python.org>
parents:
diff changeset
575 }