Mercurial > cpython-lru_cache-weakref
annotate Modules/cgensupport.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | db40dba3f79a |
| children | 916fb024ce94 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2062
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
d0d0a69b5ca3
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 6 | 32 /* Functions used by cgen output */ |
| 33 | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
34 #include "Python.h" |
| 6 | 35 #include "cgensupport.h" |
| 36 | |
| 37 | |
| 38 /* Functions to extract arguments. | |
| 39 These needs to know the total number of arguments supplied, | |
| 40 since the argument list is a tuple only of there is more than | |
| 41 one argument. */ | |
| 42 | |
| 43 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
44 PyArg_GetObject(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
45 register PyObject *args; |
| 6 | 46 int nargs, i; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
47 PyObject **p_arg; |
| 6 | 48 { |
| 49 if (nargs != 1) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
50 if (args == NULL || !PyTuple_Check(args) || |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
51 nargs != PyTuple_Size(args) || |
| 6 | 52 i < 0 || i >= nargs) { |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
53 return PyErr_BadArgument(); |
| 6 | 54 } |
| 55 else { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
56 args = PyTuple_GetItem(args, i); |
| 6 | 57 } |
| 58 } | |
| 59 if (args == NULL) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
60 return PyErr_BadArgument(); |
| 6 | 61 } |
| 62 *p_arg = args; | |
| 63 return 1; | |
| 64 } | |
| 65 | |
| 66 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
67 PyArg_GetLong(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
68 register PyObject *args; |
| 6 | 69 int nargs, i; |
| 70 long *p_arg; | |
| 71 { | |
| 72 if (nargs != 1) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
73 if (args == NULL || !PyTuple_Check(args) || |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
74 nargs != PyTuple_Size(args) || |
| 6 | 75 i < 0 || i >= nargs) { |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
76 return PyErr_BadArgument(); |
| 6 | 77 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
78 args = PyTuple_GetItem(args, i); |
| 6 | 79 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
80 if (args == NULL || !PyInt_Check(args)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
81 return PyErr_BadArgument(); |
| 6 | 82 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
83 *p_arg = PyInt_AsLong(args); |
| 6 | 84 return 1; |
| 85 } | |
| 86 | |
| 87 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
88 PyArg_GetShort(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
89 register PyObject *args; |
| 6 | 90 int nargs, i; |
| 91 short *p_arg; | |
| 92 { | |
| 93 long x; | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
94 if (!PyArg_GetLong(args, nargs, i, &x)) |
| 6 | 95 return 0; |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
96 *p_arg = (short) x; |
| 6 | 97 return 1; |
| 98 } | |
| 99 | |
| 100 static int | |
| 101 extractdouble(v, p_arg) | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
102 register PyObject *v; |
| 6 | 103 double *p_arg; |
| 104 { | |
| 105 if (v == NULL) { | |
| 106 /* Fall through to error return at end of function */ | |
| 107 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
108 else if (PyFloat_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
109 *p_arg = PyFloat_AS_DOUBLE((PyFloatObject *)v); |
| 6 | 110 return 1; |
| 111 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
112 else if (PyInt_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
113 *p_arg = PyInt_AS_LONG((PyIntObject *)v); |
| 6 | 114 return 1; |
| 115 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
116 else if (PyLong_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
117 *p_arg = PyLong_AsDouble(v); |
|
316
a9d467e84631
Support for long integers
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
118 return 1; |
|
a9d467e84631
Support for long integers
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
119 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
120 return PyErr_BadArgument(); |
| 6 | 121 } |
| 122 | |
| 123 static int | |
| 124 extractfloat(v, p_arg) | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
125 register PyObject *v; |
| 6 | 126 float *p_arg; |
| 127 { | |
| 128 if (v == NULL) { | |
| 129 /* Fall through to error return at end of function */ | |
| 130 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
131 else if (PyFloat_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
132 *p_arg = (float) PyFloat_AS_DOUBLE((PyFloatObject *)v); |
| 6 | 133 return 1; |
| 134 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
135 else if (PyInt_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
136 *p_arg = (float) PyInt_AS_LONG((PyIntObject *)v); |
| 6 | 137 return 1; |
| 138 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
139 else if (PyLong_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
140 *p_arg = (float) PyLong_AsDouble(v); |
|
316
a9d467e84631
Support for long integers
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
141 return 1; |
|
a9d467e84631
Support for long integers
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
142 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
143 return PyErr_BadArgument(); |
| 6 | 144 } |
| 145 | |
| 146 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
147 PyArg_GetFloat(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
148 register PyObject *args; |
| 6 | 149 int nargs, i; |
| 150 float *p_arg; | |
| 151 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
152 PyObject *v; |
| 6 | 153 float x; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
154 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 155 return 0; |
| 156 if (!extractfloat(v, &x)) | |
| 157 return 0; | |
| 158 *p_arg = x; | |
| 159 return 1; | |
| 160 } | |
| 161 | |
| 162 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
163 PyArg_GetString(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
164 PyObject *args; |
| 6 | 165 int nargs, i; |
| 166 string *p_arg; | |
| 167 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
168 PyObject *v; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
169 if (!PyArg_GetObject(args, nargs, i, &v)) |
|
799
784c51cb1b79
Don't use NULL as 0 int!
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
170 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
171 if (!PyString_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
172 return PyErr_BadArgument(); |
| 6 | 173 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
174 *p_arg = PyString_AsString(v); |
| 6 | 175 return 1; |
| 176 } | |
| 177 | |
| 178 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
179 PyArg_GetChar(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
180 PyObject *args; |
| 6 | 181 int nargs, i; |
| 182 char *p_arg; | |
| 183 { | |
| 184 string x; | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
185 if (!PyArg_GetString(args, nargs, i, &x)) |
| 6 | 186 return 0; |
| 187 if (x[0] == '\0' || x[1] != '\0') { | |
| 188 /* Not exactly one char */ | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
189 return PyErr_BadArgument(); |
| 6 | 190 } |
| 191 *p_arg = x[0]; | |
| 192 return 1; | |
| 193 } | |
| 194 | |
| 195 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
196 PyArg_GetLongArraySize(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
197 PyObject *args; |
| 6 | 198 int nargs, i; |
| 199 long *p_arg; | |
| 200 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
201 PyObject *v; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
202 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 203 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
204 if (PyTuple_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
205 *p_arg = PyTuple_Size(v); |
| 6 | 206 return 1; |
| 207 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
208 if (PyList_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
209 *p_arg = PyList_Size(v); |
| 6 | 210 return 1; |
| 211 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
212 return PyErr_BadArgument(); |
| 6 | 213 } |
| 214 | |
| 215 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
216 PyArg_GetShortArraySize(args, nargs, i, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
217 PyObject *args; |
| 6 | 218 int nargs, i; |
| 219 short *p_arg; | |
| 220 { | |
| 221 long x; | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
222 if (!PyArg_GetLongArraySize(args, nargs, i, &x)) |
| 6 | 223 return 0; |
|
5317
c72c7e1930b3
Keep gcc -Wall and Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
224 *p_arg = (short) x; |
| 6 | 225 return 1; |
| 226 } | |
| 227 | |
| 228 /* XXX The following four are too similar. Should share more code. */ | |
| 229 | |
| 230 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
231 PyArg_GetLongArray(args, nargs, i, n, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
232 PyObject *args; |
| 6 | 233 int nargs, i; |
| 234 int n; | |
| 235 long *p_arg; /* [n] */ | |
| 236 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
237 PyObject *v, *w; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
238 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 239 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
240 if (PyTuple_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
241 if (PyTuple_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
242 return PyErr_BadArgument(); |
| 6 | 243 } |
| 244 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
245 w = PyTuple_GetItem(v, i); |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
246 if (!PyInt_Check(w)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
247 return PyErr_BadArgument(); |
| 6 | 248 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
249 p_arg[i] = PyInt_AsLong(w); |
| 6 | 250 } |
| 251 return 1; | |
| 252 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
253 else if (PyList_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
254 if (PyList_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
255 return PyErr_BadArgument(); |
| 6 | 256 } |
| 257 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
258 w = PyList_GetItem(v, i); |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
259 if (!PyInt_Check(w)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
260 return PyErr_BadArgument(); |
| 6 | 261 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
262 p_arg[i] = PyInt_AsLong(w); |
| 6 | 263 } |
| 264 return 1; | |
| 265 } | |
| 266 else { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
267 return PyErr_BadArgument(); |
| 6 | 268 } |
| 269 } | |
| 270 | |
| 271 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
272 PyArg_GetShortArray(args, nargs, i, n, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
273 PyObject *args; |
| 6 | 274 int nargs, i; |
| 275 int n; | |
| 276 short *p_arg; /* [n] */ | |
| 277 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
278 PyObject *v, *w; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
279 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 280 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
281 if (PyTuple_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
282 if (PyTuple_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
283 return PyErr_BadArgument(); |
| 6 | 284 } |
| 285 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
286 w = PyTuple_GetItem(v, i); |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
287 if (!PyInt_Check(w)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
288 return PyErr_BadArgument(); |
| 6 | 289 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
290 p_arg[i] = (short) PyInt_AsLong(w); |
| 6 | 291 } |
| 292 return 1; | |
| 293 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
294 else if (PyList_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
295 if (PyList_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
296 return PyErr_BadArgument(); |
| 6 | 297 } |
| 298 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
299 w = PyList_GetItem(v, i); |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
300 if (!PyInt_Check(w)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
301 return PyErr_BadArgument(); |
| 6 | 302 } |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
303 p_arg[i] = (short) PyInt_AsLong(w); |
| 6 | 304 } |
| 305 return 1; | |
| 306 } | |
| 307 else { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
308 return PyErr_BadArgument(); |
| 6 | 309 } |
| 310 } | |
| 311 | |
| 312 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
313 PyArg_GetDoubleArray(args, nargs, i, n, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
314 PyObject *args; |
| 6 | 315 int nargs, i; |
| 316 int n; | |
| 317 double *p_arg; /* [n] */ | |
| 318 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
319 PyObject *v, *w; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
320 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 321 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
322 if (PyTuple_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
323 if (PyTuple_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
324 return PyErr_BadArgument(); |
| 6 | 325 } |
| 326 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
327 w = PyTuple_GetItem(v, i); |
| 6 | 328 if (!extractdouble(w, &p_arg[i])) |
| 329 return 0; | |
| 330 } | |
| 331 return 1; | |
| 332 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
333 else if (PyList_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
334 if (PyList_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
335 return PyErr_BadArgument(); |
| 6 | 336 } |
| 337 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
338 w = PyList_GetItem(v, i); |
| 6 | 339 if (!extractdouble(w, &p_arg[i])) |
| 340 return 0; | |
| 341 } | |
| 342 return 1; | |
| 343 } | |
| 344 else { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
345 return PyErr_BadArgument(); |
| 6 | 346 } |
| 347 } | |
| 348 | |
| 349 int | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
350 PyArg_GetFloatArray(args, nargs, i, n, p_arg) |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
351 PyObject *args; |
| 6 | 352 int nargs, i; |
| 353 int n; | |
| 354 float *p_arg; /* [n] */ | |
| 355 { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
356 PyObject *v, *w; |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
357 if (!PyArg_GetObject(args, nargs, i, &v)) |
| 6 | 358 return 0; |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
359 if (PyTuple_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
360 if (PyTuple_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
361 return PyErr_BadArgument(); |
| 6 | 362 } |
| 363 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
364 w = PyTuple_GetItem(v, i); |
| 6 | 365 if (!extractfloat(w, &p_arg[i])) |
| 366 return 0; | |
| 367 } | |
| 368 return 1; | |
| 369 } | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
370 else if (PyList_Check(v)) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
371 if (PyList_Size(v) != n) { |
|
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
372 return PyErr_BadArgument(); |
| 6 | 373 } |
| 374 for (i = 0; i < n; i++) { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
375 w = PyList_GetItem(v, i); |
| 6 | 376 if (!extractfloat(w, &p_arg[i])) |
| 377 return 0; | |
| 378 } | |
| 379 return 1; | |
| 380 } | |
| 381 else { | |
|
5358
db40dba3f79a
Moved here from ../Python and quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5317
diff
changeset
|
382 return PyErr_BadArgument(); |
| 6 | 383 } |
| 384 } |
