Mercurial > cpython-lru_cache-weakref
annotate Modules/arraymodule.c @ 13792:136d3d72666a legacy-trunk
Removed decl of unreferenced vrbl.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Tue, 01 Aug 2000 21:00:58 +0000 |
| parents | b6d93dba120e |
| children | 31b25ac1f019 |
| rev | line source |
|---|---|
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
5 All rights reserved. |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
13081
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 ******************************************************************/ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 /* Array object implementation */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 /* An array is a uniform list -- all items have the same type. |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 The item type is restricted to simple C types like int or float */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
16 #include "Python.h" |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
17 |
| 1797 | 18 #ifdef STDC_HEADERS |
| 19 #include <stddef.h> | |
|
11242
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
20 #else /* !STDC_HEADERS */ |
|
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
21 #ifndef DONT_HAVE_SYS_TYPES_H |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
22 #include <sys/types.h> /* For size_t */ |
|
11242
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
23 #endif /* DONT_HAVE_SYS_TYPES_H */ |
|
0061ca4865d7
Tiny patch by Mark Hammond to avoid sys/types.h if we don't have it
Guido van Rossum <guido@python.org>
parents:
10434
diff
changeset
|
24 #endif /* !STDC_HEADERS */ |
|
13268
83377fc298d8
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13263
diff
changeset
|
25 #ifdef HAVE_LIMITS_H |
|
83377fc298d8
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13263
diff
changeset
|
26 #include <limits.h> |
|
83377fc298d8
Jack Jansen, Mac patch:
Guido van Rossum <guido@python.org>
parents:
13263
diff
changeset
|
27 #endif /* HAVE_LIMITS_H */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 struct arrayobject; /* Forward */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 struct arraydescr { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 int typecode; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 int itemsize; |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
34 PyObject * (*getitem)(struct arrayobject *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
35 int (*setitem)(struct arrayobject *, int, PyObject *); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 typedef struct arrayobject { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
39 PyObject_VAR_HEAD |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 char *ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 struct arraydescr *ob_descr; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 } arrayobject; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
44 staticforward PyTypeObject Arraytype; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 #define is_arrayobject(op) ((op)->ob_type == &Arraytype) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
1391
7c3245c18677
* ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
48 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
49 static PyObject *newarrayobject(int, struct arraydescr *); |
| 4600 | 50 #if 0 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
51 static int getarraysize(PyObject *); |
| 4600 | 52 #endif |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
53 static PyObject *getarrayitem(PyObject *, int); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
54 static int setarrayitem(PyObject *, int, PyObject *); |
| 4600 | 55 #if 0 |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
56 static int insarrayitem(PyObject *, int, PyObject *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
57 static int addarrayitem(PyObject *, PyObject *); |
| 4600 | 58 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
60 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
61 c_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
63 return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
67 c_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 char x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
70 if (!PyArg_Parse(v, "c;array item must be char", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 ((char *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
77 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
78 b_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 long x = ((char *)ap->ob_item)[i]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 if (x >= 128) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 x -= 256; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
83 return PyInt_FromLong(x); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
87 b_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
89 short x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
90 /* PyArg_Parse's 'b' formatter is for an unsigned char, therefore |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
91 must use the next size up that is signed ('h') and manually do |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
92 the overflow checking */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
93 if (!PyArg_Parse(v, "h;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 return -1; |
|
13263
84879ab71b9f
In b_setitem(), instead of the platform dependent CHAR_MIN and
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
95 else if (x < -128) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
96 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
97 "signed char is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
98 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
99 } |
|
13263
84879ab71b9f
In b_setitem(), instead of the platform dependent CHAR_MIN and
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
100 else if (x > 127) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
101 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
102 "signed char is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
103 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
104 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
106 ((char *)ap->ob_item)[i] = (char)x; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
110 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
111 BB_getitem(arrayobject *ap, int i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
112 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
113 long x = ((unsigned char *)ap->ob_item)[i]; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
114 return PyInt_FromLong(x); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
115 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
116 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
117 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
118 BB_setitem(arrayobject *ap, int i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
119 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
120 unsigned char x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
121 /* 'B' == unsigned char, maps to PyArg_Parse's 'b' formatter */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
122 if (!PyArg_Parse(v, "b;array item must be integer", &x)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
123 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
124 if (i >= 0) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
125 ((char *)ap->ob_item)[i] = x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
126 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
127 } |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
128 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
129 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
130 h_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
132 return PyInt_FromLong((long) ((short *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
136 h_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 short x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
139 /* 'h' == signed short, maps to PyArg_Parse's 'h' formatter */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
140 if (!PyArg_Parse(v, "h;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 ((short *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
147 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
148 HH_getitem(arrayobject *ap, int i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
149 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
150 return PyInt_FromLong((long) ((unsigned short *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
151 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
152 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
153 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
154 HH_setitem(arrayobject *ap, int i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
155 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
156 int x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
157 /* PyArg_Parse's 'h' formatter is for a signed short, therefore |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
158 must use the next size up and manually do the overflow checking */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
159 if (!PyArg_Parse(v, "i;array item must be integer", &x)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
160 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
161 else if (x < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
162 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
163 "unsigned short is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
164 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
165 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
166 else if (x > USHRT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
167 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
168 "unsigned short is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
169 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
170 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
171 if (i >= 0) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
172 ((short *)ap->ob_item)[i] = (short)x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
173 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
174 } |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
175 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
176 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
177 i_getitem(arrayobject *ap, int i) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
178 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
179 return PyInt_FromLong((long) ((int *)ap->ob_item)[i]); |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
180 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
181 |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
182 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
183 i_setitem(arrayobject *ap, int i, PyObject *v) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
184 { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
185 int x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
186 /* 'i' == signed int, maps to PyArg_Parse's 'i' formatter */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
187 if (!PyArg_Parse(v, "i;array item must be integer", &x)) |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
188 return -1; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
189 if (i >= 0) |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
190 ((int *)ap->ob_item)[i] = x; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
191 return 0; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
192 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
193 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
194 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
195 II_getitem(arrayobject *ap, int i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
196 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
197 return PyLong_FromUnsignedLong( |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
198 (unsigned long) ((unsigned int *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
199 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
200 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
201 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
202 II_setitem(arrayobject *ap, int i, PyObject *v) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
203 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
204 unsigned long x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
205 if (PyLong_Check(v)) { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
206 x = PyLong_AsUnsignedLong(v); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
207 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
208 return -1; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
209 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
210 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
211 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
212 if (!PyArg_Parse(v, "l;array item must be integer", &y)) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
213 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
214 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
215 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
216 "unsigned int is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
217 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
218 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
219 x = (unsigned long)y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
220 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
221 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
222 if (x > UINT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
223 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
224 "unsigned int is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
225 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
226 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
227 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
228 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
229 ((unsigned int *)ap->ob_item)[i] = (unsigned int)x; |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
230 return 0; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
231 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
232 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
233 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
234 l_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
236 return PyInt_FromLong(((long *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
240 l_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 long x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
243 if (!PyArg_Parse(v, "l;array item must be integer", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 ((long *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
250 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
251 LL_getitem(arrayobject *ap, int i) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
252 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
253 return PyLong_FromUnsignedLong(((unsigned long *)ap->ob_item)[i]); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
254 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
255 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
256 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
257 LL_setitem(arrayobject *ap, int i, PyObject *v) |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
258 { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
259 unsigned long x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
260 if (PyLong_Check(v)) { |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
261 x = PyLong_AsUnsignedLong(v); |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
262 if (x == (unsigned long) -1 && PyErr_Occurred()) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
263 return -1; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
264 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
265 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
266 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
267 if (!PyArg_Parse(v, "l;array item must be integer", &y)) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
268 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
269 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
270 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
271 "unsigned long is less than minimum"); |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
272 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
273 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
274 x = (unsigned long)y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
275 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
276 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
277 if (x > ULONG_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
278 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
279 "unsigned long is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
280 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
281 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
282 |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
283 if (i >= 0) |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
284 ((unsigned long *)ap->ob_item)[i] = x; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
285 return 0; |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
286 } |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
287 |
|
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
288 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
289 f_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
291 return PyFloat_FromDouble((double) ((float *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
295 f_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 float x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
298 if (!PyArg_Parse(v, "f;array item must be float", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 ((float *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
305 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
306 d_getitem(arrayobject *ap, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
308 return PyFloat_FromDouble(((double *)ap->ob_item)[i]); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
312 d_setitem(arrayobject *ap, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 double x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
315 if (!PyArg_Parse(v, "d;array item must be float", &x)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 ((double *)ap->ob_item)[i] = x; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 /* Description of types */ |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1271
diff
changeset
|
323 static struct arraydescr descriptors[] = { |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 {'c', sizeof(char), c_getitem, c_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 {'b', sizeof(char), b_getitem, b_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
326 {'B', sizeof(char), BB_getitem, BB_setitem}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 {'h', sizeof(short), h_getitem, h_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
328 {'H', sizeof(short), HH_getitem, HH_setitem}, |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
329 {'i', sizeof(int), i_getitem, i_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
330 {'I', sizeof(int), II_getitem, II_setitem}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 {'l', sizeof(long), l_getitem, l_setitem}, |
|
5542
cfc13f3f3876
Address the following problem on DOS and Win 3.1, reported by Jim
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
332 {'L', sizeof(long), LL_getitem, LL_setitem}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 {'f', sizeof(float), f_getitem, f_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 {'d', sizeof(double), d_getitem, d_setitem}, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 {'\0', 0, 0, 0} /* Sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 }; |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
337 /* If we ever allow items larger than double, we must change reverse()! */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
340 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
341 newarrayobject(int size, struct arraydescr *descr) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 arrayobject *op; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
344 size_t nbytes; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 if (size < 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
346 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 nbytes = size * descr->itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 /* Check for overflow */ |
|
5318
2c4b802a3b5d
Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4875
diff
changeset
|
351 if (nbytes / descr->itemsize != (size_t)size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
352 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
354 op = PyObject_NewVar(arrayobject, &Arraytype, size); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 if (op == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
356 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 if (size <= 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 op->ob_item = NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 else { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
362 op->ob_item = PyMem_NEW(char, nbytes); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 if (op->ob_item == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
364 PyObject_Del(op); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
365 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 op->ob_descr = descr; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
369 return (PyObject *) op; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 |
| 4600 | 372 #if 0 |
| 2214 | 373 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
374 getarraysize(PyObject *op) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 if (!is_arrayobject(op)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
377 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 return ((arrayobject *)op) -> ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 } |
| 4600 | 382 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
384 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
385 getarrayitem(PyObject *op, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 register arrayobject *ap; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 if (!is_arrayobject(op)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
389 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 ap = (arrayobject *)op; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 if (i < 0 || i >= ap->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
394 PyErr_SetString(PyExc_IndexError, "array index out of range"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 return (*ap->ob_descr->getitem)(ap, i); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
401 ins1(arrayobject *self, int where, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 char *items; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
405 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 if ((*self->ob_descr->setitem)(self, -1, v) < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 items = self->ob_item; |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
411 PyMem_RESIZE(items, char, |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
412 (self->ob_size+1) * self->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 if (items == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
414 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 if (where < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 where = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 if (where > self->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 where = self->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 memmove(items + (where+1)*self->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
422 items + where*self->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 (self->ob_size-where)*self->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 self->ob_item = items; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
425 self->ob_size++; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 return (*self->ob_descr->setitem)(self, where, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
427 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
428 |
| 4600 | 429 #if 0 |
| 2214 | 430 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
431 insarrayitem(PyObject *op, int where, PyObject *newitem) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
433 if (!is_arrayobject(op)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
434 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 return ins1((arrayobject *)op, where, newitem); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 |
| 2214 | 440 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
441 addarrayitem(PyObject *op, PyObject *newitem) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
443 if (!is_arrayobject(op)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
444 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
447 return ins1((arrayobject *)op, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 (int) ((arrayobject *)op)->ob_size, newitem); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 } |
| 4600 | 450 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 /* Methods */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 static void |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
455 array_dealloc(arrayobject *op) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 if (op->ob_item != NULL) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
458 PyMem_DEL(op->ob_item); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
459 PyObject_Del(op); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
462 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
463 array_compare(arrayobject *v, arrayobject *w) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 int len = (v->ob_size < w->ob_size) ? v->ob_size : w->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 int i; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 for (i = 0; i < len; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
468 PyObject *ai, *bi; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 int cmp; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
470 ai = getarrayitem((PyObject *)v, i); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
471 bi = getarrayitem((PyObject *)w, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 if (ai && bi) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
473 cmp = PyObject_Compare(ai, bi); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
474 else |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
475 cmp = -1; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
476 Py_XDECREF(ai); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
477 Py_XDECREF(bi); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5583
diff
changeset
|
478 if (cmp != 0) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 return cmp; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
481 return v->ob_size - w->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
482 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
483 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
485 array_length(arrayobject *a) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
486 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
487 return a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
488 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
489 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
490 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
491 array_item(arrayobject *a, int i) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
492 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
493 if (i < 0 || i >= a->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
494 PyErr_SetString(PyExc_IndexError, "array index out of range"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
495 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
497 return getarrayitem((PyObject *)a, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
500 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
501 array_slice(arrayobject *a, int ilow, int ihigh) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
503 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
504 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 else if (ilow > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
507 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
508 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
509 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
510 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
511 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 else if (ihigh > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
513 ihigh = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
514 np = (arrayobject *) newarrayobject(ihigh - ilow, a->ob_descr); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
515 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
516 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
518 (ihigh-ilow) * a->ob_descr->itemsize); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
519 return (PyObject *)np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
522 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
523 array_concat(arrayobject *a, PyObject *bb) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 int size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
527 if (!is_arrayobject(bb)) { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
528 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
529 "can only append array (not \"%.200s\") to array", |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
530 bb->ob_type->tp_name); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
531 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
532 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
533 #define b ((arrayobject *)bb) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 if (a->ob_descr != b->ob_descr) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
535 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
537 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
538 size = a->ob_size + b->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 np = (arrayobject *) newarrayobject(size, a->ob_descr); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 if (np == NULL) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
542 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
543 memcpy(np->ob_item, a->ob_item, a->ob_size*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
544 memcpy(np->ob_item + a->ob_size*a->ob_descr->itemsize, |
|
1397
1ce2c0f565ef
Fix stupib bug in concatenation
Guido van Rossum <guido@python.org>
parents:
1393
diff
changeset
|
545 b->ob_item, b->ob_size*b->ob_descr->itemsize); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
546 return (PyObject *)np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
547 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
549 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
550 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
551 array_repeat(arrayobject *a, int n) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
552 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1797
diff
changeset
|
553 int i; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
554 int size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
555 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
556 char *p; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 int nbytes; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
558 if (n < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
559 n = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
560 size = a->ob_size * n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
561 np = (arrayobject *) newarrayobject(size, a->ob_descr); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
562 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
563 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 p = np->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
565 nbytes = a->ob_size * a->ob_descr->itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
566 for (i = 0; i < n; i++) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 memcpy(p, a->ob_item, nbytes); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 p += nbytes; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
569 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
570 return (PyObject *) np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
574 array_ass_slice(arrayobject *a, int ilow, int ihigh, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
575 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
576 char *item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
577 int n; /* Size of replacement array */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 int d; /* Change in size */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
579 #define b ((arrayobject *)v) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
580 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
581 n = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
582 else if (is_arrayobject(v)) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
583 n = b->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 if (a == b) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 /* Special case "a[i:j] = a" -- copy b first */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 int ret; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
587 v = array_slice(b, 0, n); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 ret = array_ass_slice(a, ilow, ihigh, v); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
589 Py_DECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 return ret; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
591 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 if (b->ob_descr != a->ob_descr) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
593 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
596 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
597 else { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
598 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
599 "can only assign array (not \"%.200s\") to array slice", |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
600 v->ob_type->tp_name); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
602 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
603 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
604 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
605 else if (ilow > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
609 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 else if (ihigh > a->ob_size) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 ihigh = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 item = a->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 d = n - (ihigh-ilow); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 if (d < 0) { /* Delete -d items */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 memmove(item + (ihigh+d)*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 item + ihigh*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 (a->ob_size-ihigh)*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 a->ob_size += d; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
620 PyMem_RESIZE(item, char, a->ob_size*a->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 /* Can't fail */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 a->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 else if (d > 0) { /* Insert d items */ |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
625 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
626 (a->ob_size + d)*a->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
627 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
628 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
631 memmove(item + (ihigh+d)*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 item + ihigh*a->ob_descr->itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 (a->ob_size-ihigh)*a->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 a->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 a->ob_size += d; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 if (n > 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 memcpy(item + ilow*a->ob_descr->itemsize, b->ob_item, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 n*b->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
645 array_ass_item(arrayobject *a, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 if (i < 0 || i >= a->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
648 PyErr_SetString(PyExc_IndexError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
649 "array assignment index out of range"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
650 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
651 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
652 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
653 return array_ass_slice(a, i, i+1, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 return (*a->ob_descr->setitem)(a, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
658 setarrayitem(PyObject *a, int i, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 if (!is_arrayobject(a)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
661 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
664 return array_ass_item((arrayobject *)a, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
667 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
668 ins(arrayobject *self, int where, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
669 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
670 if (ins1(self, where, v) != 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
671 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
672 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
673 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
676 static PyObject * |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
677 array_count(arrayobject *self, PyObject *args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
678 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
679 int count = 0; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
680 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
681 PyObject *v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
682 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
683 if (!PyArg_ParseTuple(args, "O:count", &v)) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
684 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
685 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
686 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
687 if (PyObject_Compare(selfi, v) == 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
688 count++; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
689 Py_DECREF(selfi); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
690 if (PyErr_Occurred()) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
691 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
692 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
693 return PyInt_FromLong((long)count); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
694 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
695 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
696 static char count_doc [] = |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
697 "count (x)\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
698 \n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
699 Return number of occurences of x in the array."; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
700 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
701 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
702 array_index(arrayobject *self, PyObject *args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
703 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
704 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
705 PyObject *v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
706 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
707 if (!PyArg_ParseTuple(args, "O:index", &v)) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
708 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
709 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
710 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
711 if (PyObject_Compare(selfi, v) == 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
712 Py_DECREF(selfi); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
713 return PyInt_FromLong((long)i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
714 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
715 Py_DECREF(selfi); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
716 if (PyErr_Occurred()) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
717 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
718 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
719 PyErr_SetString(PyExc_ValueError, "array.index(x): x not in list"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
720 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
721 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
722 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
723 static char index_doc [] = |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
724 "index (x)\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
725 \n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
726 Return index of first occurence of x in the array."; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
727 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
728 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
729 array_remove(arrayobject *self, PyObject *args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
730 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
731 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
732 PyObject *v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
733 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
734 if (!PyArg_ParseTuple(args, "O:remove", &v)) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
735 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
736 for (i = 0; i < self->ob_size; i++) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
737 PyObject *selfi = getarrayitem((PyObject *)self,i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
738 if (PyObject_Compare(selfi, v) == 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
739 Py_DECREF(selfi); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
740 if (array_ass_slice(self, i, i+1, |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
741 (PyObject *)NULL) != 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
742 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
743 Py_INCREF(Py_None); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
744 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
745 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
746 Py_DECREF(selfi); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
747 if (PyErr_Occurred()) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
748 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
749 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
750 PyErr_SetString(PyExc_ValueError, "array.remove(x): x not in list"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
751 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
752 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
753 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
754 static char remove_doc [] = |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
755 "remove (x)\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
756 \n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
757 Remove the first occurence of x in the array."; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
758 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
759 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
760 array_pop(arrayobject *self, PyObject *args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
761 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
762 int i = -1; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
763 PyObject *v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
764 if (!PyArg_ParseTuple(args, "|i:pop", &i)) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
765 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
766 if (self->ob_size == 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
767 /* Special-case most common failure cause */ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
768 PyErr_SetString(PyExc_IndexError, "pop from empty array"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
769 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
770 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
771 if (i < 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
772 i += self->ob_size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
773 if (i < 0 || i >= self->ob_size) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
774 PyErr_SetString(PyExc_IndexError, "pop index out of range"); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
775 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
776 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
777 v = getarrayitem((PyObject *)self,i); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
778 if (array_ass_slice(self, i, i+1, (PyObject *)NULL) != 0) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
779 Py_DECREF(v); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
780 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
781 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
782 return v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
783 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
784 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
785 static char pop_doc [] = |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
786 "pop ([i])\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
787 \n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
788 Return the i-th element and delete it from the array. i defaults to -1."; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
789 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
790 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
791 array_extend(self, args) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
792 arrayobject *self; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
793 PyObject *args; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
794 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
795 int size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
796 PyObject *bb; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
797 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
798 if (!PyArg_ParseTuple(args, "O:extend", &bb)) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
799 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
800 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
801 if (!is_arrayobject(bb)) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
802 PyErr_Format(PyExc_TypeError, |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
803 "can only extend array with array (not \"%.200s\")", |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
804 bb->ob_type->tp_name); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
805 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
806 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
807 #define b ((arrayobject *)bb) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
808 if (self->ob_descr != b->ob_descr) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
809 PyErr_SetString(PyExc_TypeError, |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
810 "can only extend with array of same kind"); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
811 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
812 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
813 size = self->ob_size + b->ob_size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
814 PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
815 if (self->ob_item == NULL) { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
816 PyObject_Del(self); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
817 return PyErr_NoMemory(); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
818 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
819 memcpy(self->ob_item + self->ob_size*self->ob_descr->itemsize, |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
820 b->ob_item, b->ob_size*b->ob_descr->itemsize); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
821 self->ob_size = size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
822 Py_INCREF(Py_None); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
823 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
824 #undef b |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
825 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
826 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
827 static char extend_doc [] = |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
828 "extend(array)\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
829 \n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
830 Append array items to the end of the array."; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
831 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
832 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
833 array_insert(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
834 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
835 int i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
836 PyObject *v; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
837 if (!PyArg_ParseTuple(args, "iO:insert", &i, &v)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
838 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
839 return ins(self, i, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
840 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
841 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
842 static char insert_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
843 "insert (i,x)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
844 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
845 Insert a new item x into the array before position i."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
846 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
847 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
848 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
849 array_buffer_info(arrayobject *self, PyObject *args) |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
850 { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
851 PyObject* retval = PyTuple_New(2); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
852 if (!retval) return NULL; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
853 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
854 PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item)); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
855 PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(self->ob_size))); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
856 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
857 return retval; |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
858 } |
|
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
859 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
860 static char buffer_info_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
861 "buffer_info -> (address, length)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
862 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
863 Return a tuple (address, length) giving the current memory address and\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
864 the length in bytes of the buffer used to hold array's contents."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
865 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
866 |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
867 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
868 array_append(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
869 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
870 PyObject *v; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
871 if (!PyArg_ParseTuple(args, "O:append", &v)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
872 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
873 return ins(self, (int) self->ob_size, v); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
874 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
875 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
876 static char append_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
877 "append(x)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
878 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
879 Append new value x to the end of the array."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
880 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
881 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
882 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
883 array_byteswap(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
884 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
885 char *p; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
886 int i; |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
887 |
|
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
888 if (!PyArg_ParseTuple(args, ":byteswap")) |
|
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
889 return NULL; |
|
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
890 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
891 switch (self->ob_descr->itemsize) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
892 case 1: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
893 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
894 case 2: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
895 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 2) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
896 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
897 p[0] = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
898 p[1] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
899 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
900 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
901 case 4: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
902 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 4) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
903 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
904 char p1 = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
905 p[0] = p[3]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
906 p[1] = p[2]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
907 p[2] = p1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
908 p[3] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
909 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
910 break; |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
911 case 8: |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
912 for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 8) { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
913 char p0 = p[0]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
914 char p1 = p[1]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
915 char p2 = p[2]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
916 char p3 = p[3]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
917 p[0] = p[7]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
918 p[1] = p[6]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
919 p[2] = p[5]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
920 p[3] = p[4]; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
921 p[4] = p3; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
922 p[5] = p2; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
923 p[6] = p1; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
924 p[7] = p0; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
925 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
926 break; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 default: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
928 PyErr_SetString(PyExc_RuntimeError, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
929 "don't know how to byteswap this array type"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
930 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
931 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
932 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
933 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
934 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
935 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
936 static char byteswap_doc [] = |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
937 "byteswap()\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
938 \n\ |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
939 Byteswap all items of the array. If the items in the array are not 1, 2,\n\ |
|
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
940 4, or 8 bytes in size, RuntimeError is raised."; |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
941 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
942 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
943 array_reverse(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
944 { |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
945 register int itemsize = self->ob_descr->itemsize; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
946 register char *p, *q; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
947 char tmp[sizeof(double)]; /* Assume that's the max item size */ |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
948 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
949 if (args != NULL) { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
950 PyErr_SetString(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
951 "<array>.reverse requires exactly 0 arguments"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
952 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
953 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
955 if (self->ob_size > 1) { |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
956 for (p = self->ob_item, |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
957 q = self->ob_item + (self->ob_size - 1)*itemsize; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
958 p < q; |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
959 p += itemsize, q -= itemsize) { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
960 memmove(tmp, p, itemsize); |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
961 memmove(p, q, itemsize); |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
962 memmove(q, tmp, itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
963 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
966 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
967 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
968 } |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
969 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
970 static char reverse_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
971 "reverse()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
972 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
973 Reverse the order of the items in the array."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
974 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
975 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
976 array_fromfile(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
978 PyObject *f; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 int n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 FILE *fp; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
981 if (!PyArg_ParseTuple(args, "Oi:fromfile", &f, &n)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
982 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
983 fp = PyFile_AsFile(f); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
984 if (fp == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
985 PyErr_SetString(PyExc_TypeError, "arg1 must be open file"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
986 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
987 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
989 char *item = self->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
990 int itemsize = self->ob_descr->itemsize; |
|
13081
0acec211a209
Trent Mick: use size_t instead of int where appropriate (in
Guido van Rossum <guido@python.org>
parents:
13068
diff
changeset
|
991 size_t nread; |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
992 int newlength; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
993 size_t newbytes; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
994 /* Be careful here about overflow */ |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
995 if ((newlength = self->ob_size + n) <= 0 || |
|
10434
a4768315948d
Use an unsigned cast to avoid a warning in VC++.
Guido van Rossum <guido@python.org>
parents:
10283
diff
changeset
|
996 (newbytes = newlength * itemsize) / itemsize != |
|
a4768315948d
Use an unsigned cast to avoid a warning in VC++.
Guido van Rossum <guido@python.org>
parents:
10283
diff
changeset
|
997 (size_t)newlength) |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
998 goto nomem; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
999 PyMem_RESIZE(item, char, newbytes); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1000 if (item == NULL) { |
|
10283
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1001 nomem: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1002 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1003 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1004 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1005 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1006 self->ob_size += n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1007 nread = fread(item + (self->ob_size - n) * itemsize, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1008 itemsize, n, fp); |
|
13081
0acec211a209
Trent Mick: use size_t instead of int where appropriate (in
Guido van Rossum <guido@python.org>
parents:
13068
diff
changeset
|
1009 if (nread < (size_t)n) { |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1010 self->ob_size -= (n - nread); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1011 PyMem_RESIZE(item, char, self->ob_size*itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1012 self->ob_item = item; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1013 PyErr_SetString(PyExc_EOFError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1014 "not enough items in file"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1015 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1016 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1017 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1018 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1019 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1020 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1021 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1022 static char fromfile_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1023 "fromfile(f, n)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1024 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1025 Read n objects from the file object f and append them to the end of the\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1026 array. Also called as read."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1027 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1028 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1029 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1030 array_tofile(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1031 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1032 PyObject *f; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1033 FILE *fp; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1034 if (!PyArg_ParseTuple(args, "O:tofile", &f)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1035 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1036 fp = PyFile_AsFile(f); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1037 if (fp == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1038 PyErr_SetString(PyExc_TypeError, "arg must be open file"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1039 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1040 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1041 if (self->ob_size > 0) { |
|
5318
2c4b802a3b5d
Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4875
diff
changeset
|
1042 if ((int)fwrite(self->ob_item, self->ob_descr->itemsize, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1043 self->ob_size, fp) != self->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1044 PyErr_SetFromErrno(PyExc_IOError); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1045 clearerr(fp); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1046 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1047 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1048 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1049 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1050 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1051 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1052 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1053 static char tofile_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1054 "tofile(f)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1055 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1056 Write all items (as machine values) to the file object f. Also called as\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1057 write."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1058 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1059 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1060 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1061 array_fromlist(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1062 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1063 int n; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1064 PyObject *list; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1065 int itemsize = self->ob_descr->itemsize; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1066 if (!PyArg_ParseTuple(args, "O:fromlist", &list)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1067 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1068 if (!PyList_Check(list)) { |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1069 PyErr_SetString(PyExc_TypeError, "arg must be list"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1070 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1071 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1072 n = PyList_Size(list); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1073 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1074 char *item = self->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1075 int i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1076 PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1077 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1078 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1079 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1080 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1081 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1082 self->ob_size += n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1083 for (i = 0; i < n; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1084 PyObject *v = PyList_GetItem(list, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1085 if ((*self->ob_descr->setitem)(self, |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1086 self->ob_size - n + i, v) != 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1087 self->ob_size -= n; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1088 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1089 self->ob_size * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1090 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1091 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1092 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1094 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1095 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1096 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1097 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1098 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1099 static char fromlist_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1100 "fromlist(list)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1101 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1102 Append items to array from list."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1103 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1104 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1105 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1106 array_tolist(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1107 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1108 PyObject *list = PyList_New(self->ob_size); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1109 int i; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1110 if (!PyArg_ParseTuple(args, ":tolist")) |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1111 return NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1112 if (list == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1113 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1114 for (i = 0; i < self->ob_size; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1115 PyObject *v = getarrayitem((PyObject *)self, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1116 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1117 Py_DECREF(list); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1118 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1119 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1120 PyList_SetItem(list, i, v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1121 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1122 return list; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1123 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1124 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1125 static char tolist_doc [] = |
|
9360
4c23ae6c6e82
ACK! There was still an unescaped newline in a docstring.
Guido van Rossum <guido@python.org>
parents:
9343
diff
changeset
|
1126 "tolist() -> list\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1127 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1128 Convert array to an ordinary list with the same items."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1129 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1130 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1131 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1132 array_fromstring(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1133 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1134 char *str; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1135 int n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1136 int itemsize = self->ob_descr->itemsize; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1137 if (!PyArg_ParseTuple(args, "s#:fromstring", &str, &n)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1138 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1139 if (n % itemsize != 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1140 PyErr_SetString(PyExc_ValueError, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1141 "string length not a multiple of item size"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1142 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1143 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1144 n = n / itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1145 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1146 char *item = self->ob_item; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1147 PyMem_RESIZE(item, char, (self->ob_size + n) * itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1148 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1149 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1150 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1151 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1152 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1153 self->ob_size += n; |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1154 memcpy(item + (self->ob_size - n) * itemsize, |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1155 str, itemsize*n); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1156 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1157 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1158 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1159 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1160 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1161 static char fromstring_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1162 "fromstring(string)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1163 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1164 Appends items from the string, interpreting it as an array of machine\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1165 values,as if it had been read from a file using the fromfile() method)."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1166 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1167 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1168 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1169 array_tostring(arrayobject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1170 { |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1171 if (!PyArg_ParseTuple(args, ":tostring")) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1172 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1173 return PyString_FromStringAndSize(self->ob_item, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1174 self->ob_size * self->ob_descr->itemsize); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1175 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1176 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1177 static char tostring_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1178 "tostring() -> string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1179 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1180 Convert the array to an array of machine values and return the string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1181 representation."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1182 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1183 PyMethodDef array_methods[] = { |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1184 {"append", (PyCFunction)array_append, METH_VARARGS, append_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1185 {"buffer_info", (PyCFunction)array_buffer_info, METH_VARARGS, buffer_info_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1186 {"byteswap", (PyCFunction)array_byteswap, METH_VARARGS, byteswap_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1187 {"count", (PyCFunction)array_count, METH_VARARGS, count_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1188 {"extend", (PyCFunction)array_extend, METH_VARARGS, extend_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1189 {"fromfile", (PyCFunction)array_fromfile, METH_VARARGS, fromfile_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1190 {"fromlist", (PyCFunction)array_fromlist, METH_VARARGS, fromlist_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1191 {"fromstring", (PyCFunction)array_fromstring, METH_VARARGS, fromstring_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1192 {"index", (PyCFunction)array_index, METH_VARARGS, index_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1193 {"insert", (PyCFunction)array_insert, METH_VARARGS, insert_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1194 {"pop", (PyCFunction)array_pop, METH_VARARGS, pop_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1195 {"read", (PyCFunction)array_fromfile, METH_VARARGS, fromfile_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1196 {"remove", (PyCFunction)array_remove, METH_VARARGS, remove_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1197 {"reverse", (PyCFunction)array_reverse, METH_VARARGS, reverse_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1198 /* {"sort", (PyCFunction)array_sort, METH_VARARGS, sort_doc},*/ |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1199 {"tofile", (PyCFunction)array_tofile, METH_VARARGS, tofile_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1200 {"tolist", (PyCFunction)array_tolist, METH_VARARGS, tolist_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1201 {"tostring", (PyCFunction)array_tostring, METH_VARARGS, tostring_doc}, |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1202 {"write", (PyCFunction)array_tofile, METH_VARARGS, tofile_doc}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1203 {NULL, NULL} /* sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1204 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1205 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1206 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1207 array_getattr(arrayobject *a, char *name) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1208 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1209 if (strcmp(name, "typecode") == 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1210 char tc = a->ob_descr->typecode; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1211 return PyString_FromStringAndSize(&tc, 1); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1212 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1213 if (strcmp(name, "itemsize") == 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1214 return PyInt_FromLong((long)a->ob_descr->itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1215 } |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1216 if (strcmp(name, "__members__") == 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1217 PyObject *list = PyList_New(2); |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1218 if (list) { |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1219 PyList_SetItem(list, 0, |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1220 PyString_FromString("typecode")); |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1221 PyList_SetItem(list, 1, |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1222 PyString_FromString("itemsize")); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1223 if (PyErr_Occurred()) { |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1224 Py_DECREF(list); |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1225 list = NULL; |
|
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1226 } |
|
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1227 } |
|
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1228 return list; |
|
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1397
diff
changeset
|
1229 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1230 return Py_FindMethod(array_methods, (PyObject *)a, name); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1231 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1232 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1233 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1234 array_print(arrayobject *a, FILE *fp, int flags) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1235 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1236 int ok = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1237 int i, len; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1238 PyObject *t_empty = PyTuple_New(0); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1239 PyObject *v; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1240 len = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1241 if (len == 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1242 fprintf(fp, "array('%c')", a->ob_descr->typecode); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1243 return ok; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1244 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1245 if (a->ob_descr->typecode == 'c') { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1246 fprintf(fp, "array('c', "); |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1247 v = array_tostring(a, t_empty); |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1248 Py_DECREF(t_empty);; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1249 ok = PyObject_Print(v, fp, 0); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1250 Py_XDECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1251 fprintf(fp, ")"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1252 return ok; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1253 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1254 fprintf(fp, "array('%c', [", a->ob_descr->typecode); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1255 for (i = 0; i < len && ok == 0; i++) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1256 if (i > 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1257 fprintf(fp, ", "); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1258 v = (a->ob_descr->getitem)(a, i); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1259 ok = PyObject_Print(v, fp, 0); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1260 Py_XDECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1261 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1262 fprintf(fp, "])"); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1263 return ok; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1264 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1265 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1266 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1267 array_repr(arrayobject *a) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1268 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1269 char buf[256]; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1270 PyObject *s, *t, *comma, *v; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1271 int i, len; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1272 len = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1273 if (len == 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1274 sprintf(buf, "array('%c')", a->ob_descr->typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1275 return PyString_FromString(buf); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1276 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1277 if (a->ob_descr->typecode == 'c') { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1278 sprintf(buf, "array('c', "); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1279 s = PyString_FromString(buf); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1280 v = array_tostring(a, (PyObject *)NULL); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1281 t = PyObject_Repr(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1282 Py_XDECREF(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1283 PyString_ConcatAndDel(&s, t); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1284 PyString_ConcatAndDel(&s, PyString_FromString(")")); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1285 return s; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1286 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1287 sprintf(buf, "array('%c', [", a->ob_descr->typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1288 s = PyString_FromString(buf); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1289 comma = PyString_FromString(", "); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1290 for (i = 0; i < len && !PyErr_Occurred(); i++) { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1291 if (i > 0) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1292 PyString_Concat(&s, comma); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1293 v = (a->ob_descr->getitem)(a, i); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1294 t = PyObject_Repr(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1295 Py_XDECREF(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1296 PyString_ConcatAndDel(&s, t); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1297 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1298 Py_XDECREF(comma); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1299 PyString_ConcatAndDel(&s, PyString_FromString("])")); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1300 return s; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1301 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1302 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1303 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1304 array_buffer_getreadbuf(arrayobject *self, int index, const void **ptr) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1305 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1306 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1307 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1308 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1309 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1310 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1311 *ptr = (void *)self->ob_item; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1312 return self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1313 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1314 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1315 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1316 array_buffer_getwritebuf(arrayobject *self, int index, const void **ptr) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1317 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1318 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1319 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1320 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1321 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1322 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1323 *ptr = (void *)self->ob_item; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1324 return self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1325 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1326 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1327 static int |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1328 array_buffer_getsegcount(arrayobject *self, int *lenp) |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1329 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1330 if ( lenp ) |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1331 *lenp = self->ob_size*self->ob_descr->itemsize; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1332 return 1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1333 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1334 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1335 static PySequenceMethods array_as_sequence = { |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1336 (inquiry)array_length, /*sq_length*/ |
|
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1337 (binaryfunc)array_concat, /*sq_concat*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1338 (intargfunc)array_repeat, /*sq_repeat*/ |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1339 (intargfunc)array_item, /*sq_item*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1340 (intintargfunc)array_slice, /*sq_slice*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1341 (intobjargproc)array_ass_item, /*sq_ass_item*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1342 (intintobjargproc)array_ass_slice, /*sq_ass_slice*/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1343 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1344 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1345 static PyBufferProcs array_as_buffer = { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1346 (getreadbufferproc)array_buffer_getreadbuf, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1347 (getwritebufferproc)array_buffer_getwritebuf, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1348 (getsegcountproc)array_buffer_getsegcount, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1349 }; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1350 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1351 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1352 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1353 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1354 static PyObject * |
|
13590
c503d8e474b3
ANSI-fication (got lost in the deep seas of source forge <wink>)
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13447
diff
changeset
|
1355 a_array(PyObject *self, PyObject *args) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1356 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1357 char c; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1358 PyObject *initial = NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1359 struct arraydescr *descr; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1360 if (!PyArg_ParseTuple(args, "c:array", &c)) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1361 PyErr_Clear(); |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1362 if (!PyArg_ParseTuple(args, "cO:array", &c, &initial)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1363 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1364 if (!PyList_Check(initial) && !PyString_Check(initial)) { |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1365 PyErr_SetString(PyExc_TypeError, |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1366 "array initializer must be list or string"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1367 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1368 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1369 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1370 for (descr = descriptors; descr->typecode != '\0'; descr++) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1371 if (descr->typecode == c) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1372 PyObject *a; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1373 int len; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1374 if (initial == NULL || !PyList_Check(initial)) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1375 len = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1376 else |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1377 len = PyList_Size(initial); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1378 a = newarrayobject(len, descr); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1379 if (a == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1380 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1381 if (len > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1382 int i; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1383 for (i = 0; i < len; i++) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1384 PyObject *v = |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1385 PyList_GetItem(initial, i); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1386 if (setarrayitem(a, i, v) != 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1387 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1388 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1389 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1390 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1391 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1392 if (initial != NULL && PyString_Check(initial)) { |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1393 PyObject *t_initial = Py_BuildValue("(O)", initial); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1394 PyObject *v = |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1395 array_fromstring((arrayobject *)a, t_initial); |
|
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1396 Py_DECREF(t_initial); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1397 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1398 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1399 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1400 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1401 Py_DECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1402 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1403 return a; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1404 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1405 } |
|
4634
9facbab152cd
Removed some unneeded header files and reedited with a fixed-width font
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4628
diff
changeset
|
1406 PyErr_SetString(PyExc_ValueError, |
|
4875
911040e1bb11
Add new formats B, H, I, L for unsigned data types (analogous to the
Guido van Rossum <guido@python.org>
parents:
4634
diff
changeset
|
1407 "bad typecode (must be c, b, B, h, H, i, I, l, L, f or d)"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1408 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1409 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1410 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1411 static char a_array_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1412 "array(typecode [, initializer]) -> array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1413 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1414 Return a new array whose items are restricted by typecode, and\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1415 initialized from the optional initializer value, which must be a list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1416 or a string."; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1417 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1418 static PyMethodDef a_methods[] = { |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1419 {"array", a_array, METH_VARARGS, a_array_doc}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1420 {NULL, NULL} /* sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1421 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1422 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1423 static char module_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1424 "This module defines a new object type which can efficiently represent\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1425 an array of basic values: characters, integers, floating point\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1426 numbers. Arrays are sequence types and behave very much like lists,\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1427 except that the type of objects stored in them is constrained. The\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1428 type is specified at object creation time by using a type code, which\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1429 is a single character. The following type codes are defined:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1430 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1431 Type code C Type Minimum size in bytes \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1432 'c' character 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1433 'b' signed integer 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1434 'B' unsigned integer 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1435 'h' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1436 'H' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1437 'i' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1438 'I' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1439 'l' signed integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1440 'L' unsigned integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1441 'f' floating point 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1442 'd' floating point 8 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1443 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1444 Functions:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1445 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1446 array(typecode [, initializer]) -- create a new array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1447 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1448 Special Objects:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1449 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1450 ArrayType -- type object for array objects\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1451 "; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1452 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1453 static char arraytype_doc [] = |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1454 "An array represents basic values and behave very much like lists, except\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1455 the type of objects stored in them is constrained.\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1456 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1457 Methods:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1458 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1459 append() -- append a new item to the end of the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1460 buffer_info() -- return information giving the current memory info\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1461 byteswap() -- byteswap all the items of the array\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1462 count() -- return number of occurences of an object\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1463 extend() -- extend array by appending array elements\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1464 fromfile() -- read items from a file object\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1465 fromlist() -- append items from the list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1466 fromstring() -- append items from the string\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1467 index() -- return index of first occurence of an object\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1468 insert() -- insert a new item into the array at a provided position\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1469 pop() -- remove and return item (default last)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1470 read() -- DEPRECATED, use fromfile()\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
1471 remove() -- remove first occurence of an object\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1472 reverse() -- reverse the order of the items in the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1473 tofile() -- write all items to a file object\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1474 tolist() -- return the array converted to an ordinary list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1475 tostring() -- return the array converted to a string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1476 write() -- DEPRECATED, use tofile()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1477 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1478 Variables:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1479 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1480 typecode -- the typecode character used to create the array\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1481 itemsize -- the length in bytes of one array item\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1482 "; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1483 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1484 statichere PyTypeObject Arraytype = { |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
1485 PyObject_HEAD_INIT(NULL) |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1486 0, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1487 "array", |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1488 sizeof(arrayobject), |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1489 0, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1490 (destructor)array_dealloc, /*tp_dealloc*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1491 (printfunc)array_print, /*tp_print*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1492 (getattrfunc)array_getattr, /*tp_getattr*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1493 0, /*tp_setattr*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1494 (cmpfunc)array_compare, /*tp_compare*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1495 (reprfunc)array_repr, /*tp_repr*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1496 0, /*tp_as_number*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1497 &array_as_sequence, /*tp_as_sequence*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1498 0, /*tp_as_mapping*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1499 0, /*tp_hash*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1500 0, /*tp_call*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1501 0, /*tp_str*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1502 0, /*tp_getattro*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1503 0, /*tp_setattro*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1504 &array_as_buffer, /*tp_as_buffer*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1505 0, /*tp_xxx4*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1506 arraytype_doc, /*tp_doc*/ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1507 }; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1508 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9362
diff
changeset
|
1509 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13590
diff
changeset
|
1510 initarray(void) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1511 { |
|
5583
edbcfed7fc7b
Defined array.array_type, the type object.
Guido van Rossum <guido@python.org>
parents:
5542
diff
changeset
|
1512 PyObject *m, *d; |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
1513 |
|
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
1514 Arraytype.ob_type = &PyType_Type; |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1515 m = Py_InitModule3("array", a_methods, module_doc); |
|
5583
edbcfed7fc7b
Defined array.array_type, the type object.
Guido van Rossum <guido@python.org>
parents:
5542
diff
changeset
|
1516 d = PyModule_GetDict(m); |
|
9362
50e0631cf117
No need to issue a fatal error if the PyDict_SetItemString fails; the
Guido van Rossum <guido@python.org>
parents:
9360
diff
changeset
|
1517 PyDict_SetItemString(d, "ArrayType", (PyObject *)&Arraytype); |
|
50e0631cf117
No need to issue a fatal error if the PyDict_SetItemString fails; the
Guido van Rossum <guido@python.org>
parents:
9360
diff
changeset
|
1518 /* No need to check the error here, the caller will do that */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1519 } |
