Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Functions used by cgen output */ |
| 3 | |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 4 | #include "Python.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 5 | #include "cgensupport.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 6 | |
| 7 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 8 | /* Functions to extract arguments. |
| 9 | These needs to know the total number of arguments supplied, |
| 10 | since the argument list is a tuple only of there is more than |
| 11 | one argument. */ |
| 12 | |
| 13 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 14 | PyArg_GetObject(register PyObject *args, int nargs, int i, PyObject **p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 15 | { |
| 16 | if (nargs != 1) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 17 | if (args == NULL || !PyTuple_Check(args) || |
| 18 | nargs != PyTuple_Size(args) || |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 19 | i < 0 || i >= nargs) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 20 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 21 | } |
| 22 | else { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 23 | args = PyTuple_GetItem(args, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | if (args == NULL) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 27 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | } |
| 29 | *p_arg = args; |
| 30 | return 1; |
| 31 | } |
| 32 | |
| 33 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 34 | PyArg_GetLong(register PyObject *args, int nargs, int i, long *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 35 | { |
| 36 | if (nargs != 1) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 37 | if (args == NULL || !PyTuple_Check(args) || |
| 38 | nargs != PyTuple_Size(args) || |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 39 | i < 0 || i >= nargs) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 40 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 42 | args = PyTuple_GetItem(args, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 43 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 44 | if (args == NULL || !PyInt_Check(args)) { |
| 45 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 46 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 47 | *p_arg = PyInt_AsLong(args); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 48 | return 1; |
| 49 | } |
| 50 | |
| 51 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 52 | PyArg_GetShort(register PyObject *args, int nargs, int i, short *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 53 | { |
| 54 | long x; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 55 | if (!PyArg_GetLong(args, nargs, i, &x)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 56 | return 0; |
Guido van Rossum | 6bf62da | 1997-04-11 20:37:35 +0000 | [diff] [blame] | 57 | *p_arg = (short) x; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | static int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 62 | extractdouble(register PyObject *v, double *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 63 | { |
| 64 | if (v == NULL) { |
| 65 | /* Fall through to error return at end of function */ |
| 66 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 67 | else if (PyFloat_Check(v)) { |
| 68 | *p_arg = PyFloat_AS_DOUBLE((PyFloatObject *)v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 69 | return 1; |
| 70 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 71 | else if (PyInt_Check(v)) { |
| 72 | *p_arg = PyInt_AS_LONG((PyIntObject *)v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 73 | return 1; |
| 74 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 75 | else if (PyLong_Check(v)) { |
| 76 | *p_arg = PyLong_AsDouble(v); |
Guido van Rossum | 76a00af | 1991-07-27 21:34:00 +0000 | [diff] [blame] | 77 | return 1; |
| 78 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 79 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 83 | extractfloat(register PyObject *v, float *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 84 | { |
| 85 | if (v == NULL) { |
| 86 | /* Fall through to error return at end of function */ |
| 87 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 88 | else if (PyFloat_Check(v)) { |
| 89 | *p_arg = (float) PyFloat_AS_DOUBLE((PyFloatObject *)v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 90 | return 1; |
| 91 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 92 | else if (PyInt_Check(v)) { |
| 93 | *p_arg = (float) PyInt_AS_LONG((PyIntObject *)v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 94 | return 1; |
| 95 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 96 | else if (PyLong_Check(v)) { |
| 97 | *p_arg = (float) PyLong_AsDouble(v); |
Guido van Rossum | 76a00af | 1991-07-27 21:34:00 +0000 | [diff] [blame] | 98 | return 1; |
| 99 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 100 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 104 | PyArg_GetFloat(register PyObject *args, int nargs, int i, float *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 105 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 106 | PyObject *v; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 107 | float x; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 108 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 109 | return 0; |
| 110 | if (!extractfloat(v, &x)) |
| 111 | return 0; |
| 112 | *p_arg = x; |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 117 | PyArg_GetString(PyObject *args, int nargs, int i, string *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 118 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 119 | PyObject *v; |
| 120 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 7cdf5eb | 1992-04-06 12:34:45 +0000 | [diff] [blame] | 121 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 122 | if (!PyString_Check(v)) { |
| 123 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 124 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 125 | *p_arg = PyString_AsString(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 126 | return 1; |
| 127 | } |
| 128 | |
| 129 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 130 | PyArg_GetChar(PyObject *args, int nargs, int i, char *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 131 | { |
| 132 | string x; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 133 | if (!PyArg_GetString(args, nargs, i, &x)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | if (x[0] == '\0' || x[1] != '\0') { |
| 136 | /* Not exactly one char */ |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 137 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 138 | } |
| 139 | *p_arg = x[0]; |
| 140 | return 1; |
| 141 | } |
| 142 | |
| 143 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 144 | PyArg_GetLongArraySize(PyObject *args, int nargs, int i, long *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 145 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 146 | PyObject *v; |
| 147 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 148 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 149 | if (PyTuple_Check(v)) { |
| 150 | *p_arg = PyTuple_Size(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 151 | return 1; |
| 152 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 153 | if (PyList_Check(v)) { |
| 154 | *p_arg = PyList_Size(v); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 155 | return 1; |
| 156 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 157 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 161 | PyArg_GetShortArraySize(PyObject *args, int nargs, int i, short *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 162 | { |
| 163 | long x; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 164 | if (!PyArg_GetLongArraySize(args, nargs, i, &x)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 165 | return 0; |
Guido van Rossum | 6bf62da | 1997-04-11 20:37:35 +0000 | [diff] [blame] | 166 | *p_arg = (short) x; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | /* XXX The following four are too similar. Should share more code. */ |
| 171 | |
| 172 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 173 | PyArg_GetLongArray(PyObject *args, int nargs, int i, int n, long *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 174 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 175 | PyObject *v, *w; |
| 176 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 177 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 178 | if (PyTuple_Check(v)) { |
| 179 | if (PyTuple_Size(v) != n) { |
| 180 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 181 | } |
| 182 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 183 | w = PyTuple_GetItem(v, i); |
| 184 | if (!PyInt_Check(w)) { |
| 185 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 186 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 187 | p_arg[i] = PyInt_AsLong(w); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 188 | } |
| 189 | return 1; |
| 190 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 191 | else if (PyList_Check(v)) { |
| 192 | if (PyList_Size(v) != n) { |
| 193 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 194 | } |
| 195 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 196 | w = PyList_GetItem(v, i); |
| 197 | if (!PyInt_Check(w)) { |
| 198 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 199 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 200 | p_arg[i] = PyInt_AsLong(w); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 201 | } |
| 202 | return 1; |
| 203 | } |
| 204 | else { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 205 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 210 | PyArg_GetShortArray(PyObject *args, int nargs, int i, int n, short *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 211 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 212 | PyObject *v, *w; |
| 213 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 214 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 215 | if (PyTuple_Check(v)) { |
| 216 | if (PyTuple_Size(v) != n) { |
| 217 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 218 | } |
| 219 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 220 | w = PyTuple_GetItem(v, i); |
| 221 | if (!PyInt_Check(w)) { |
| 222 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 223 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 224 | p_arg[i] = (short) PyInt_AsLong(w); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 225 | } |
| 226 | return 1; |
| 227 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 228 | else if (PyList_Check(v)) { |
| 229 | if (PyList_Size(v) != n) { |
| 230 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 231 | } |
| 232 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 233 | w = PyList_GetItem(v, i); |
| 234 | if (!PyInt_Check(w)) { |
| 235 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 236 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 237 | p_arg[i] = (short) PyInt_AsLong(w); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 238 | } |
| 239 | return 1; |
| 240 | } |
| 241 | else { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 242 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 247 | PyArg_GetDoubleArray(PyObject *args, int nargs, int i, int n, double *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 248 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 249 | PyObject *v, *w; |
| 250 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 251 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 252 | if (PyTuple_Check(v)) { |
| 253 | if (PyTuple_Size(v) != n) { |
| 254 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 255 | } |
| 256 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 257 | w = PyTuple_GetItem(v, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 258 | if (!extractdouble(w, &p_arg[i])) |
| 259 | return 0; |
| 260 | } |
| 261 | return 1; |
| 262 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 263 | else if (PyList_Check(v)) { |
| 264 | if (PyList_Size(v) != n) { |
| 265 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 266 | } |
| 267 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 268 | w = PyList_GetItem(v, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 269 | if (!extractdouble(w, &p_arg[i])) |
| 270 | return 0; |
| 271 | } |
| 272 | return 1; |
| 273 | } |
| 274 | else { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 275 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | int |
Peter Schneider-Kamp | 6a85027 | 2000-07-10 17:04:33 +0000 | [diff] [blame] | 280 | PyArg_GetFloatArray(PyObject *args, int nargs, int i, int n, float *p_arg) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 281 | { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 282 | PyObject *v, *w; |
| 283 | if (!PyArg_GetObject(args, nargs, i, &v)) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 284 | return 0; |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 285 | if (PyTuple_Check(v)) { |
| 286 | if (PyTuple_Size(v) != n) { |
| 287 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 288 | } |
| 289 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 290 | w = PyTuple_GetItem(v, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 291 | if (!extractfloat(w, &p_arg[i])) |
| 292 | return 0; |
| 293 | } |
| 294 | return 1; |
| 295 | } |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 296 | else if (PyList_Check(v)) { |
| 297 | if (PyList_Size(v) != n) { |
| 298 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 299 | } |
| 300 | for (i = 0; i < n; i++) { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 301 | w = PyList_GetItem(v, i); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 302 | if (!extractfloat(w, &p_arg[i])) |
| 303 | return 0; |
| 304 | } |
| 305 | return 1; |
| 306 | } |
| 307 | else { |
Guido van Rossum | 3837de0 | 1997-04-29 15:43:55 +0000 | [diff] [blame] | 308 | return PyErr_BadArgument(); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 309 | } |
| 310 | } |