Mercurial > cpython-lru_cache-weakref
annotate Python/modsupport.c @ 321:2a84b16f91b0 legacy-trunk
Support for long integers
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 27 Jul 1991 21:39:31 +0000 |
| parents | c8a979029df4 |
| children | 16b18f586fec |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
| 2 Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The | |
| 3 Netherlands. | |
| 4 | |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Module support implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 #include "modsupport.h" |
| 29 #include "import.h" | |
| 30 | |
| 31 | |
| 32 object * | |
| 33 initmodule(name, methods) | |
| 34 char *name; | |
| 35 struct methodlist *methods; | |
| 36 { | |
| 37 object *m, *d, *v; | |
| 38 struct methodlist *ml; | |
| 86 | 39 char namebuf[256]; |
| 40 if ((m = add_module(name)) == NULL) { | |
| 6 | 41 fprintf(stderr, "initializing module: %s\n", name); |
| 42 fatal("can't create a module"); | |
| 43 } | |
| 44 d = getmoduledict(m); | |
| 45 for (ml = methods; ml->ml_name != NULL; ml++) { | |
| 86 | 46 sprintf(namebuf, "%s.%s", name, ml->ml_name); |
| 47 v = newmethodobject(strdup(namebuf), ml->ml_meth, | |
| 48 (object *)NULL); | |
| 49 /* XXX The strdup'ed memory is never freed */ | |
| 6 | 50 if (v == NULL || dictinsert(d, ml->ml_name, v) != 0) { |
| 51 fprintf(stderr, "initializing module: %s\n", name); | |
| 52 fatal("can't initialize module"); | |
| 53 } | |
| 54 DECREF(v); | |
| 55 } | |
| 86 | 56 return m; |
| 6 | 57 } |
| 58 | |
| 59 | |
| 60 /* Argument list handling tools. | |
| 61 All return 1 for success, or call err_set*() and return 0 for failure */ | |
| 62 | |
| 63 int | |
| 64 getnoarg(v) | |
| 65 object *v; | |
| 66 { | |
| 67 if (v != NULL) { | |
| 68 return err_badarg(); | |
| 69 } | |
| 70 return 1; | |
| 71 } | |
| 72 | |
| 73 int | |
| 74 getintarg(v, a) | |
| 75 object *v; | |
| 76 int *a; | |
| 77 { | |
| 78 if (v == NULL || !is_intobject(v)) { | |
| 79 return err_badarg(); | |
| 80 } | |
| 81 *a = getintvalue(v); | |
| 82 return 1; | |
| 83 } | |
| 84 | |
| 85 int | |
| 86 getintintarg(v, a, b) | |
| 87 object *v; | |
| 88 int *a; | |
| 89 int *b; | |
| 90 { | |
| 91 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 92 return err_badarg(); | |
| 93 } | |
| 94 return getintarg(gettupleitem(v, 0), a) && | |
| 95 getintarg(gettupleitem(v, 1), b); | |
| 96 } | |
| 97 | |
| 98 int | |
|
306
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
99 getintintintarg(v, a, b, c) |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
100 object *v; |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
101 int *a; |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
102 int *b; |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
103 int *c; |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
104 { |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
105 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
106 return err_badarg(); |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
107 } |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
108 return getintarg(gettupleitem(v, 0), a) && |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
109 getintarg(gettupleitem(v, 1), b) && |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
110 getintarg(gettupleitem(v, 2), c); |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
111 } |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
112 |
|
c8a979029df4
Added getintintintarg() (3 int args)
Guido van Rossum <guido@python.org>
parents:
169
diff
changeset
|
113 int |
| 6 | 114 getlongarg(v, a) |
| 115 object *v; | |
| 116 long *a; | |
| 117 { | |
| 118 if (v == NULL || !is_intobject(v)) { | |
| 119 return err_badarg(); | |
| 120 } | |
| 121 *a = getintvalue(v); | |
| 122 return 1; | |
| 123 } | |
| 124 | |
| 125 int | |
| 126 getlonglongargs(v, a, b) | |
| 127 object *v; | |
| 128 long *a, *b; | |
| 129 { | |
| 130 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 131 return err_badarg(); | |
| 132 } | |
| 133 return getlongarg(gettupleitem(v, 0), a) && | |
| 134 getlongarg(gettupleitem(v, 1), b); | |
| 135 } | |
| 136 | |
| 137 int | |
| 138 getlonglongobjectargs(v, a, b, c) | |
| 139 object *v; | |
| 140 long *a, *b; | |
| 141 object **c; | |
| 142 { | |
| 143 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { | |
| 144 return err_badarg(); | |
| 145 } | |
| 146 if (getlongarg(gettupleitem(v, 0), a) && | |
| 147 getlongarg(gettupleitem(v, 1), b)) { | |
| 148 *c = gettupleitem(v, 2); | |
| 149 return 1; | |
| 150 } | |
| 151 else { | |
| 152 return err_badarg(); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 int | |
| 157 getstrarg(v, a) | |
| 158 object *v; | |
| 159 object **a; | |
| 160 { | |
| 161 if (v == NULL || !is_stringobject(v)) { | |
| 162 return err_badarg(); | |
| 163 } | |
| 164 *a = v; | |
| 165 return 1; | |
| 166 } | |
| 167 | |
| 168 int | |
| 169 getstrstrarg(v, a, b) | |
| 170 object *v; | |
| 171 object **a; | |
| 172 object **b; | |
| 173 { | |
| 174 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 175 return err_badarg(); | |
| 176 } | |
| 177 return getstrarg(gettupleitem(v, 0), a) && | |
| 178 getstrarg(gettupleitem(v, 1), b); | |
| 179 } | |
| 180 | |
| 181 int | |
| 182 getstrstrintarg(v, a, b, c) | |
| 183 object *v; | |
| 184 object **a; | |
| 185 object **b; | |
| 186 int *c; | |
| 187 { | |
| 188 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { | |
| 189 return err_badarg(); | |
| 190 } | |
| 191 return getstrarg(gettupleitem(v, 0), a) && | |
| 192 getstrarg(gettupleitem(v, 1), b) && | |
| 193 getintarg(gettupleitem(v, 2), c); | |
| 194 } | |
| 195 | |
| 196 int | |
| 197 getstrintarg(v, a, b) | |
| 198 object *v; | |
| 199 object **a; | |
| 200 int *b; | |
| 201 { | |
| 202 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 203 return err_badarg(); | |
| 204 } | |
| 205 return getstrarg(gettupleitem(v, 0), a) && | |
| 206 getintarg(gettupleitem(v, 1), b); | |
| 207 } | |
| 208 | |
| 209 int | |
| 210 getintstrarg(v, a, b) | |
| 211 object *v; | |
| 212 int *a; | |
| 213 object **b; | |
| 214 { | |
| 215 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 216 return err_badarg(); | |
| 217 } | |
| 218 return getintarg(gettupleitem(v, 0), a) && | |
| 219 getstrarg(gettupleitem(v, 1), b); | |
| 220 } | |
| 221 | |
| 222 int | |
| 223 getpointarg(v, a) | |
| 224 object *v; | |
| 225 int *a; /* [2] */ | |
| 226 { | |
| 227 return getintintarg(v, a, a+1); | |
| 228 } | |
| 229 | |
| 230 int | |
| 231 get3pointarg(v, a) | |
| 232 object *v; | |
| 233 int *a; /* [6] */ | |
| 234 { | |
| 235 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { | |
| 236 return err_badarg(); | |
| 237 } | |
| 238 return getpointarg(gettupleitem(v, 0), a) && | |
| 239 getpointarg(gettupleitem(v, 1), a+2) && | |
| 240 getpointarg(gettupleitem(v, 2), a+4); | |
| 241 } | |
| 242 | |
| 243 int | |
| 244 getrectarg(v, a) | |
| 245 object *v; | |
| 246 int *a; /* [2+2] */ | |
| 247 { | |
| 248 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 249 return err_badarg(); | |
| 250 } | |
| 251 return getpointarg(gettupleitem(v, 0), a) && | |
| 252 getpointarg(gettupleitem(v, 1), a+2); | |
| 253 } | |
| 254 | |
| 255 int | |
| 256 getrectintarg(v, a) | |
| 257 object *v; | |
| 258 int *a; /* [4+1] */ | |
| 259 { | |
| 260 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 261 return err_badarg(); | |
| 262 } | |
| 263 return getrectarg(gettupleitem(v, 0), a) && | |
| 264 getintarg(gettupleitem(v, 1), a+4); | |
| 265 } | |
| 266 | |
| 267 int | |
| 268 getpointintarg(v, a) | |
| 269 object *v; | |
| 270 int *a; /* [2+1] */ | |
| 271 { | |
| 272 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 273 return err_badarg(); | |
| 274 } | |
| 275 return getpointarg(gettupleitem(v, 0), a) && | |
| 276 getintarg(gettupleitem(v, 1), a+2); | |
| 277 } | |
| 278 | |
| 279 int | |
| 280 getpointstrarg(v, a, b) | |
| 281 object *v; | |
| 282 int *a; /* [2] */ | |
| 283 object **b; | |
| 284 { | |
| 285 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 286 return err_badarg(); | |
| 287 } | |
| 288 return getpointarg(gettupleitem(v, 0), a) && | |
| 289 getstrarg(gettupleitem(v, 1), b); | |
| 290 } | |
| 291 | |
| 292 int | |
| 293 getstrintintarg(v, a, b, c) | |
| 294 object *v; | |
| 295 object *a; | |
| 296 int *b, *c; | |
| 297 { | |
| 298 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 3) { | |
| 299 return err_badarg(); | |
| 300 } | |
| 301 return getstrarg(gettupleitem(v, 0), a) && | |
| 302 getintarg(gettupleitem(v, 1), b) && | |
| 303 getintarg(gettupleitem(v, 2), c); | |
| 304 } | |
| 305 | |
| 306 int | |
| 307 getrectpointarg(v, a) | |
| 308 object *v; | |
| 309 int *a; /* [4+2] */ | |
| 310 { | |
| 311 if (v == NULL || !is_tupleobject(v) || gettuplesize(v) != 2) { | |
| 312 return err_badarg(); | |
| 313 } | |
| 314 return getrectarg(gettupleitem(v, 0), a) && | |
| 315 getpointarg(gettupleitem(v, 1), a+4); | |
| 316 } | |
| 317 | |
| 318 int | |
| 319 getlongtuplearg(args, a, n) | |
| 320 object *args; | |
| 321 long *a; /* [n] */ | |
| 322 int n; | |
| 323 { | |
| 324 int i; | |
| 325 if (!is_tupleobject(args) || gettuplesize(args) != n) { | |
| 326 return err_badarg(); | |
| 327 } | |
| 328 for (i = 0; i < n; i++) { | |
| 329 object *v = gettupleitem(args, i); | |
| 330 if (!is_intobject(v)) { | |
| 331 return err_badarg(); | |
| 332 } | |
| 333 a[i] = getintvalue(v); | |
| 334 } | |
| 335 return 1; | |
| 336 } | |
| 337 | |
| 338 int | |
| 339 getshorttuplearg(args, a, n) | |
| 340 object *args; | |
| 341 short *a; /* [n] */ | |
| 342 int n; | |
| 343 { | |
| 344 int i; | |
| 345 if (!is_tupleobject(args) || gettuplesize(args) != n) { | |
| 346 return err_badarg(); | |
| 347 } | |
| 348 for (i = 0; i < n; i++) { | |
| 349 object *v = gettupleitem(args, i); | |
| 350 if (!is_intobject(v)) { | |
| 351 return err_badarg(); | |
| 352 } | |
| 353 a[i] = getintvalue(v); | |
| 354 } | |
| 355 return 1; | |
| 356 } | |
| 357 | |
| 358 int | |
| 359 getlonglistarg(args, a, n) | |
| 360 object *args; | |
| 361 long *a; /* [n] */ | |
| 362 int n; | |
| 363 { | |
| 364 int i; | |
| 365 if (!is_listobject(args) || getlistsize(args) != n) { | |
| 366 return err_badarg(); | |
| 367 } | |
| 368 for (i = 0; i < n; i++) { | |
| 369 object *v = getlistitem(args, i); | |
| 370 if (!is_intobject(v)) { | |
| 371 return err_badarg(); | |
| 372 } | |
| 373 a[i] = getintvalue(v); | |
| 374 } | |
| 375 return 1; | |
| 376 } | |
| 377 | |
| 378 int | |
| 379 getshortlistarg(args, a, n) | |
| 380 object *args; | |
| 381 short *a; /* [n] */ | |
| 382 int n; | |
| 383 { | |
| 384 int i; | |
| 385 if (!is_listobject(args) || getlistsize(args) != n) { | |
| 386 return err_badarg(); | |
| 387 } | |
| 388 for (i = 0; i < n; i++) { | |
| 389 object *v = getlistitem(args, i); | |
| 390 if (!is_intobject(v)) { | |
| 391 return err_badarg(); | |
| 392 } | |
| 393 a[i] = getintvalue(v); | |
| 394 } | |
| 395 return 1; | |
| 396 } | |
|
169
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
397 |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
398 int |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
399 getdoublearg(args, px) |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
400 register object *args; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
401 double *px; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
402 { |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
403 if (args == NULL) |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
404 return err_badarg(); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
405 if (is_floatobject(args)) { |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
406 *px = getfloatvalue(args); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
407 return 1; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
408 } |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
409 if (is_intobject(args)) { |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
410 *px = getintvalue(args); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
411 return 1; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
412 } |
|
321
2a84b16f91b0
Support for long integers
Guido van Rossum <guido@python.org>
parents:
306
diff
changeset
|
413 if (is_longobject(args)) { |
|
2a84b16f91b0
Support for long integers
Guido van Rossum <guido@python.org>
parents:
306
diff
changeset
|
414 *px = dgetlongvalue(args); |
|
2a84b16f91b0
Support for long integers
Guido van Rossum <guido@python.org>
parents:
306
diff
changeset
|
415 return 1; |
|
2a84b16f91b0
Support for long integers
Guido van Rossum <guido@python.org>
parents:
306
diff
changeset
|
416 } |
|
169
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
417 return err_badarg(); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
418 } |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
419 |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
420 int |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
421 get2doublearg(args, px, py) |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
422 register object *args; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
423 double *px, *py; |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
424 { |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
425 if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
426 return err_badarg(); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
427 return getdoublearg(gettupleitem(args, 0), px) && |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
428 getdoublearg(gettupleitem(args, 1), py); |
|
1ed7f6f65983
Moved get*doublearg() routines here from mathmodule.c
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
429 } |
