Mercurial > cpython-lru_cache-weakref
annotate Modules/arraymodule.c @ 27104:2443c557cbc3 legacy-trunk
Patch #661760: Cygwin auto-import module patch
The attached patch enables shared extension
modules to build cleanly under Cygwin without
moving the static initialization of certain function
pointers (i.e., ones exported from the Python
DLL core) to a module initialization function.
Additionally, this patch fixes the modules that
have been changed in the past to accommodate
Cygwin.
| author | Jason Tishler <jason@tishler.net> |
|---|---|
| date | Mon, 06 Jan 2003 12:41:26 +0000 |
| parents | 23280a64288e |
| children | 047b6e16ab2e |
| 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 /* Array object implementation */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 /* 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
|
4 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
|
5 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
6 #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
|
7 |
| 1797 | 8 #ifdef STDC_HEADERS |
| 9 #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
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 #endif /* !STDC_HEADERS */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 struct arrayobject; /* Forward */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
18 /* All possible arraydescr values are defined in the vector "descriptors" |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
19 * below. That's defined later because the appropriate get and set |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
20 * functions aren't visible yet. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
21 */ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 struct arraydescr { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 int typecode; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 int itemsize; |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13268
diff
changeset
|
25 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
|
26 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
|
27 }; |
|
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 typedef struct arrayobject { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
30 PyObject_HEAD |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
31 int ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 char *ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 struct arraydescr *ob_descr; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 } arrayobject; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23929
diff
changeset
|
36 static PyTypeObject Arraytype; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
38 #define array_Check(op) PyObject_TypeCheck(op, &Arraytype) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
39 #define array_CheckExact(op) ((op)->ob_type == &Arraytype) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
41 /**************************************************************************** |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
42 Get and Set functions for each type. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
43 A Get function takes an arrayobject* and an integer index, returning the |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
44 array value at that index wrapped in an appropriate PyObject*. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
45 A Set function takes an arrayobject, integer index, and PyObject*; sets |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
46 the array value at that index to the raw C data extracted from the PyObject*, |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
47 and returns 0 if successful, else nonzero on failure (PyObject* not of an |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
48 appropriate type or value). |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
49 Note that the basic Get and Set functions do NOT check that the index is |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
50 in bounds; that's the responsibility of the caller. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
51 ****************************************************************************/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
53 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
|
54 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
|
55 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
56 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
|
57 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 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
|
60 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
|
61 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 char x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
63 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
|
64 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 if (i >= 0) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
66 ((char *)ap->ob_item)[i] = x; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 return 0; |
|
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 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
70 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
|
71 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
|
72 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 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
|
74 if (x >= 128) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 x -= 256; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
76 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
|
77 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 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
|
80 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
|
81 { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
82 short x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
83 /* 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
|
84 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
|
85 the overflow checking */ |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
86 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
|
87 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
|
88 else if (x < -128) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
89 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
90 "signed char is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
91 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
92 } |
|
13263
84879ab71b9f
In b_setitem(), instead of the platform dependent CHAR_MIN and
Guido van Rossum <guido@python.org>
parents:
13256
diff
changeset
|
93 else if (x > 127) { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
94 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
95 "signed char is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
96 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
97 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
99 ((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
|
100 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
103 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
|
104 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
|
105 { |
|
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
|
106 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
|
107 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
|
108 } |
|
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
|
109 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
110 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
|
111 BB_setitem(arrayobject *ap, int i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
112 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
113 unsigned char x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
114 /* '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
|
115 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
|
116 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
117 if (i >= 0) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
118 ((char *)ap->ob_item)[i] = x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
119 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
120 } |
|
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
|
121 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
122 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
123 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
124 u_getitem(arrayobject *ap, int i) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
125 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
126 return PyUnicode_FromUnicode(&((Py_UNICODE *) ap->ob_item)[i], 1); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
127 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
128 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
129 static int |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
130 u_setitem(arrayobject *ap, int i, PyObject *v) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
131 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
132 Py_UNICODE *p; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
133 int len; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
134 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
135 if (!PyArg_Parse(v, "u#;array item must be unicode character", &p, &len)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
136 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
137 if (len != 1) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
138 PyErr_SetString(PyExc_TypeError, "array item must be unicode character"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
139 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
140 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
141 if (i >= 0) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
142 ((Py_UNICODE *)ap->ob_item)[i] = p[0]; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
143 return 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
144 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
145 #endif |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
146 |
|
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
|
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 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
|
149 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
150 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
|
151 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
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 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
|
155 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 short x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
157 /* '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
|
158 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
|
159 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 ((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
|
162 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
165 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
|
166 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
|
167 { |
|
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
|
168 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
|
169 } |
|
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
|
170 |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
171 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
|
172 HH_setitem(arrayobject *ap, int i, PyObject *v) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
173 { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
174 int x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
175 /* 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
|
176 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
|
177 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
|
178 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
179 else if (x < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
180 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
181 "unsigned short is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
182 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
183 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
184 else if (x > USHRT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
185 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
186 "unsigned short is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
187 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
188 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
189 if (i >= 0) |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
190 ((short *)ap->ob_item)[i] = (short)x; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
191 return 0; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
192 } |
|
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
|
193 |
|
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
|
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 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
|
196 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
197 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
|
198 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
199 |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
200 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
|
201 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
|
202 { |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
203 int x; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
204 /* '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
|
205 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
|
206 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
|
207 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
|
208 ((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
|
209 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
|
210 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
211 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
212 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
|
213 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
|
214 { |
|
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
|
215 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
|
216 (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
|
217 } |
|
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
|
218 |
|
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
|
219 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
|
220 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
|
221 { |
|
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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 } |
|
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 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
229 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
230 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
|
231 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
232 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
233 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
234 "unsigned int is less than minimum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
235 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
236 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
237 x = (unsigned long)y; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
238 |
|
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
|
239 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
240 if (x > UINT_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
241 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
242 "unsigned int is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
243 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
244 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
245 |
|
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
|
246 if (i >= 0) |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
247 ((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
|
248 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
|
249 } |
|
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
|
250 |
|
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
|
251 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
|
252 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
|
253 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
254 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
|
255 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 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
|
258 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
|
259 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 long x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
261 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
|
262 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 ((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
|
265 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
268 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
|
269 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
|
270 { |
|
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
|
271 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
|
272 } |
|
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
|
273 |
|
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
|
274 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
|
275 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
|
276 { |
|
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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 } |
|
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 else { |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
284 long y; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
285 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
|
286 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
287 if (y < 0) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
288 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
289 "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
|
290 return -1; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
291 } |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
292 x = (unsigned long)y; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
293 |
|
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
|
294 } |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
295 if (x > ULONG_MAX) { |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
296 PyErr_SetString(PyExc_OverflowError, |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
297 "unsigned long is greater than maximum"); |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
298 return -1; |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
299 } |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
300 |
|
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
|
301 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
|
302 ((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
|
303 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
|
304 } |
|
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
|
305 |
|
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
|
306 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
|
307 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
|
308 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
309 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
|
310 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 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
|
313 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
|
314 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 float x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
316 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
|
317 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 ((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
|
320 return 0; |
|
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 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
323 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
|
324 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
|
325 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
326 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
|
327 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 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
|
330 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
|
331 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 double x; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
333 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
|
334 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 if (i >= 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 ((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
|
337 return 0; |
|
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 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 /* 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
|
341 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
|
342 {'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
|
343 {'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
|
344 {'B', sizeof(char), BB_getitem, BB_setitem}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
345 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
346 {'u', sizeof(Py_UNICODE), u_getitem, u_setitem}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
347 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 {'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
|
349 {'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
|
350 {'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
|
351 {'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
|
352 {'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
|
353 {'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
|
354 {'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
|
355 {'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
|
356 {'\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
|
357 }; |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
358 |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
359 /**************************************************************************** |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
360 Implementations of array object methods. |
|
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
361 ****************************************************************************/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
363 static PyObject * |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
364 newarrayobject(PyTypeObject *type, 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
|
365 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 arrayobject *op; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
367 size_t nbytes; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
368 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 if (size < 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
370 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
372 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
373 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 nbytes = size * descr->itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 /* Check for overflow */ |
|
5318
2c4b802a3b5d
Keep Microsoft VC happy.
Guido van Rossum <guido@python.org>
parents:
4875
diff
changeset
|
376 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
|
377 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
379 op = (arrayobject *) type->tp_alloc(type, 0); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 if (op == NULL) { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
381 return NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
383 op->ob_size = size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 if (size <= 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 op->ob_item = NULL; |
|
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 else { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
388 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
|
389 if (op->ob_item == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
11711
diff
changeset
|
390 PyObject_Del(op); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
391 return PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 op->ob_descr = descr; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
395 return (PyObject *) op; |
|
1235
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 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
398 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
|
399 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
|
400 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 register arrayobject *ap; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
402 assert(array_Check(op)); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 ap = (arrayobject *)op; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 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
|
405 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
|
406 return NULL; |
|
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 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
|
409 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 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
|
412 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
|
413 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 char *items; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
416 PyErr_BadInternalCall(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 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
|
420 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 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
|
422 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
|
423 (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
|
424 if (items == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
425 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
426 return -1; |
|
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 if (where < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
429 where = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 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
|
431 where = self->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 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
|
433 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
|
434 (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
|
435 self->ob_item = items; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 self->ob_size++; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 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
|
438 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 /* Methods */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 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
|
443 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
|
444 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 if (op->ob_item != NULL) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
446 PyMem_DEL(op->ob_item); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
447 op->ob_type->tp_free((PyObject *)op); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
448 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
450 static PyObject * |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
451 array_richcompare(PyObject *v, PyObject *w, int op) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 { |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
453 arrayobject *va, *wa; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
454 PyObject *vi = NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
455 PyObject *wi = NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
456 int i, k; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
457 PyObject *res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
458 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
459 if (!array_Check(v) || !array_Check(w)) { |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
460 Py_INCREF(Py_NotImplemented); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
461 return Py_NotImplemented; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
462 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
463 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
464 va = (arrayobject *)v; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
465 wa = (arrayobject *)w; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
466 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
467 if (va->ob_size != wa->ob_size && (op == Py_EQ || op == Py_NE)) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
468 /* Shortcut: if the lengths differ, the arrays differ */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
469 if (op == Py_EQ) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
470 res = Py_False; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
471 else |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
472 res = Py_True; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
473 Py_INCREF(res); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
474 return res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
475 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
476 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
477 /* Search for the first index where items are different */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
478 k = 1; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
479 for (i = 0; i < va->ob_size && i < wa->ob_size; i++) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
480 vi = getarrayitem(v, i); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
481 wi = getarrayitem(w, i); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
482 if (vi == NULL || wi == NULL) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
483 Py_XDECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
484 Py_XDECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
485 return NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
486 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
487 k = PyObject_RichCompareBool(vi, wi, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
488 if (k == 0) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
489 break; /* Keeping vi and wi alive! */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
490 Py_DECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
491 Py_DECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
492 if (k < 0) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
493 return NULL; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
494 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
495 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
496 if (k) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
497 /* No more items to compare -- compare sizes */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
498 int vs = va->ob_size; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
499 int ws = wa->ob_size; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 int cmp; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
501 switch (op) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
502 case Py_LT: cmp = vs < ws; break; |
|
16268
c2ce9b2e5bb4
Correct one-line typo, reported by yole @ SF, bug 130077.
Guido van Rossum <guido@python.org>
parents:
16232
diff
changeset
|
503 case Py_LE: cmp = vs <= ws; break; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
504 case Py_EQ: cmp = vs == ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
505 case Py_NE: cmp = vs != ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
506 case Py_GT: cmp = vs > ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
507 case Py_GE: cmp = vs >= ws; break; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
508 default: return NULL; /* cannot happen */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
509 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
510 if (cmp) |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
511 res = Py_True; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
512 else |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
513 res = Py_False; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
514 Py_INCREF(res); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
515 return res; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
516 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
517 |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
518 /* We have an item that differs. First, shortcuts for EQ/NE */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
519 if (op == Py_EQ) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
520 Py_INCREF(Py_False); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
521 res = Py_False; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
523 else if (op == Py_NE) { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
524 Py_INCREF(Py_True); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
525 res = Py_True; |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
526 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
527 else { |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
528 /* Compare the final item again using the proper operator */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
529 res = PyObject_RichCompare(vi, wi, op); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
530 } |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
531 Py_DECREF(vi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
532 Py_DECREF(wi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
533 return res; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
534 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
535 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
536 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
|
537 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
|
538 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
539 return a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
540 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
541 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
542 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
|
543 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
|
544 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
545 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
|
546 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
|
547 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
548 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
549 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
|
550 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
551 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
552 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
|
553 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
|
554 { |
|
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 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
557 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
558 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
|
559 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
560 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
561 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
562 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
563 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
564 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
|
565 ihigh = a->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
566 np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
569 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
|
570 (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
|
571 return (PyObject *)np; |
|
1235
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 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
574 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
|
575 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
|
576 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
577 int size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 arrayobject *np; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
579 if (!array_Check(bb)) { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
580 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
581 "can only append array (not \"%.200s\") to array", |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
582 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
|
583 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
584 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
585 #define b ((arrayobject *)bb) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
586 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
|
587 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
588 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
589 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
590 size = a->ob_size + b->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
591 np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
592 if (np == NULL) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
593 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
594 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 return (PyObject *)np; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
599 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
600 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
601 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
602 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
|
603 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
|
604 { |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
1797
diff
changeset
|
605 int i; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
606 int size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
607 arrayobject *np; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
608 char *p; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
609 int nbytes; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 if (n < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 n = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 size = a->ob_size * n; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
613 np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 if (np == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 p = np->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 p += nbytes; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
622 return (PyObject *) np; |
|
1235
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 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 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
|
626 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
|
627 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 char *item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 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
|
630 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
|
631 #define b ((arrayobject *)v) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 n = 0; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
634 else if (array_Check(v)) { |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 n = b->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 if (a == b) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
637 /* 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
|
638 int ret; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 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
|
640 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
|
641 Py_DECREF(v); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 return ret; |
|
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 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
|
645 PyErr_BadArgument(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
647 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
648 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
649 else { |
|
12814
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
650 PyErr_Format(PyExc_TypeError, |
|
b1b260a2de98
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
651 "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
|
652 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
|
653 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
654 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
655 if (ilow < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
656 ilow = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
657 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
|
658 ilow = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
659 if (ihigh < 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
660 ihigh = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
661 if (ihigh < ilow) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
662 ihigh = ilow; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
663 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
|
664 ihigh = a->ob_size; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
665 item = a->ob_item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
666 d = n - (ihigh-ilow); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
667 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
|
668 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
|
669 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
|
670 (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
|
671 a->ob_size += d; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
672 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
|
673 /* Can't fail */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
674 a->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
675 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
676 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
|
677 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
678 (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
|
679 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
680 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
681 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
682 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
683 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
|
684 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
|
685 (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
|
686 a->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
687 a->ob_size += d; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
688 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
689 if (n > 0) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
690 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
|
691 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
|
692 return 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
693 #undef b |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
694 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
695 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
696 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
|
697 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
|
698 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
699 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
|
700 PyErr_SetString(PyExc_IndexError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
701 "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
|
702 return -1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
703 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
704 if (v == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
705 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
|
706 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
|
707 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 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
|
710 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
|
711 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
712 assert(array_Check(a)); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
713 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
|
714 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
715 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
716 static int |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
717 array_do_extend(arrayobject *self, PyObject *bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
718 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
719 int size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
720 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
721 if (!array_Check(bb)) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
722 PyErr_Format(PyExc_TypeError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
723 "can only extend array with array (not \"%.200s\")", |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
724 bb->ob_type->tp_name); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
725 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
726 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
727 #define b ((arrayobject *)bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
728 if (self->ob_descr != b->ob_descr) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
729 PyErr_SetString(PyExc_TypeError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
730 "can only extend with array of same kind"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
731 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
732 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
733 size = self->ob_size + b->ob_size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
734 PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
735 if (self->ob_item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
736 PyObject_Del(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
737 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
738 return -1; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
739 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
740 memcpy(self->ob_item + self->ob_size*self->ob_descr->itemsize, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
741 b->ob_item, b->ob_size*b->ob_descr->itemsize); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
742 self->ob_size = size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
743 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
744 return 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
745 #undef b |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
746 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
747 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
748 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
749 array_inplace_concat(arrayobject *self, PyObject *bb) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
750 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
751 if (array_do_extend(self, bb) == -1) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
752 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
753 Py_INCREF(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
754 return (PyObject *)self; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
755 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
756 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
757 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
758 array_inplace_repeat(arrayobject *self, int n) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
759 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
760 char *items, *p; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
761 int size, i; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
762 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
763 if (self->ob_size > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
764 if (n < 0) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
765 n = 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
766 items = self->ob_item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
767 size = self->ob_size * self->ob_descr->itemsize; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
768 if (n == 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
769 PyMem_FREE(items); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
770 self->ob_item = NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
771 self->ob_size = 0; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
772 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
773 else { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
774 PyMem_Resize(items, char, n * size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
775 if (items == NULL) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
776 return PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
777 p = items; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
778 for (i = 1; i < n; i++) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
779 p += size; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
780 memcpy(p, items, size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
781 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
782 self->ob_item = items; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
783 self->ob_size *= n; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
784 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
785 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
786 Py_INCREF(self); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
787 return (PyObject *)self; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
788 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
789 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
790 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
791 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
|
792 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
|
793 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
794 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
|
795 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
796 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
797 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
798 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
799 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
800 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
801 array_count(arrayobject *self, PyObject *v) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
802 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
803 int count = 0; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
804 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
805 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
806 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
|
807 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
808 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
809 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
810 if (cmp > 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
811 count++; |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
812 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
813 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
814 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
815 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
|
816 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
817 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
818 PyDoc_STRVAR(count_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
819 "count(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
820 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
821 Return number of occurences of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
822 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
823 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
824 array_index(arrayobject *self, PyObject *v) |
|
13772
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 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
827 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
828 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
|
829 PyObject *selfi = getarrayitem((PyObject *)self, i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
830 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
831 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
832 if (cmp > 0) { |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
833 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
|
834 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
835 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
836 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
837 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
838 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
|
839 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
840 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
841 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
842 PyDoc_STRVAR(index_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
843 "index(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
844 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
845 Return index of first occurence of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
846 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
847 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
848 array_remove(arrayobject *self, PyObject *v) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
849 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
850 int i; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
851 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
852 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
|
853 PyObject *selfi = getarrayitem((PyObject *)self,i); |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
854 int cmp = PyObject_RichCompareBool(selfi, v, Py_EQ); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
855 Py_DECREF(selfi); |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
856 if (cmp > 0) { |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
857 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
|
858 (PyObject *)NULL) != 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
859 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
860 Py_INCREF(Py_None); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
861 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
862 } |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
863 else if (cmp < 0) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
864 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
865 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
866 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
|
867 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
868 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
869 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
870 PyDoc_STRVAR(remove_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
871 "remove(x)\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
872 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
873 Remove the first occurence of x in the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
874 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
875 static PyObject * |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
876 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
|
877 { |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
878 int i = -1; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
879 PyObject *v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
880 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
|
881 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
882 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
|
883 /* 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
|
884 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
|
885 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
886 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
887 if (i < 0) |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
888 i += self->ob_size; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
889 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
|
890 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
|
891 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
892 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
893 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
|
894 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
|
895 Py_DECREF(v); |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
896 return NULL; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
897 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
898 return v; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
899 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
900 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
901 PyDoc_STRVAR(pop_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
902 "pop([i])\n\ |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
903 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
904 Return the i-th element and delete it from the array. i defaults to -1."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
905 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
906 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
907 array_extend(arrayobject *self, PyObject *bb) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
908 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
909 if (array_do_extend(self, bb) == -1) |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
910 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
911 Py_INCREF(Py_None); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
912 return Py_None; |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
913 } |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
914 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
915 PyDoc_STRVAR(extend_doc, |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
916 "extend(array)\n\ |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
917 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
918 Append array items to the end of the array."); |
|
13772
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
919 |
|
eea51275acbf
added count, extend, index, pop and remove to arraymodule
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13651
diff
changeset
|
920 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
|
921 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
|
922 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
923 int i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
924 PyObject *v; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
925 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
|
926 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
927 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
|
928 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
929 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
930 PyDoc_STRVAR(insert_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
931 "insert(i,x)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
932 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
933 Insert a new item x into the array before position i."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
934 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
935 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
936 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
937 array_buffer_info(arrayobject *self, PyObject *unused) |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
938 { |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
939 PyObject* retval = NULL; |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
940 retval = PyTuple_New(2); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
941 if (!retval) |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
942 return NULL; |
|
13068
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
943 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
944 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
|
945 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
|
946 |
|
705132667f7b
Trent Mick <trentm@activestate.com>:
Fred Drake <fdrake@acm.org>
parents:
12814
diff
changeset
|
947 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
|
948 } |
|
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
949 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
950 PyDoc_STRVAR(buffer_info_doc, |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
951 "buffer_info() -> (address, length)\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
952 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
953 Return a tuple (address, length) giving the current memory address and\n\ |
|
18851
ef2031c54875
Fix buffer_info() docstring to match reality. See SF bug #444842.
Guido van Rossum <guido@python.org>
parents:
18036
diff
changeset
|
954 the length in items of the buffer used to hold array's contents\n\ |
|
ef2031c54875
Fix buffer_info() docstring to match reality. See SF bug #444842.
Guido van Rossum <guido@python.org>
parents:
18036
diff
changeset
|
955 The length should be multiplied by the itemsize attribute to calculate\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
956 the buffer length in bytes."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
957 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
958 |
|
5982
6aebd970b7a9
Added buffer_info() method that returns address and length in bytes of
Guido van Rossum <guido@python.org>
parents:
5696
diff
changeset
|
959 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
960 array_append(arrayobject *self, PyObject *v) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
961 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
962 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
|
963 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
965 PyDoc_STRVAR(append_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
966 "append(x)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
967 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
968 Append new value x to the end of the array."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
969 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
970 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
971 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
972 array_byteswap(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
973 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
974 char *p; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
975 int i; |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
976 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
977 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
|
978 case 1: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
979 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 case 2: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
981 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
|
982 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
983 p[0] = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
984 p[1] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
985 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
986 break; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
987 case 4: |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 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
|
989 char p0 = p[0]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
990 char p1 = p[1]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
991 p[0] = p[3]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
992 p[1] = p[2]; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
993 p[2] = p1; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
994 p[3] = p0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
995 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 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
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 } |
|
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1012 break; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1013 default: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1014 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
|
1015 "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
|
1016 return NULL; |
|
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 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1022 PyDoc_STRVAR(byteswap_doc, |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
1023 "byteswap()\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1024 \n\ |
|
11522
cbf58cd0bb57
Correct the docstring for byteswap(); error noted by Bernhard Reiter
Fred Drake <fdrake@acm.org>
parents:
11242
diff
changeset
|
1025 Byteswap all items of the array. If the items in the array are not 1, 2,\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1026 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
|
1027 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1028 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1029 array_reverse(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1030 { |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1031 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
|
1032 register char *p, *q; |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1033 /* little buffer to hold items while swapping */ |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1034 char tmp[256]; /* 8 is probably enough -- but why skimp */ |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1035 assert(itemsize <= sizeof(tmp)); |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1036 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 p += itemsize, q -= itemsize) { |
|
14649
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1042 /* memory areas guaranteed disjoint, so memcpy |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1043 * is safe (& memmove may be slower). |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1044 */ |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1045 memcpy(tmp, p, itemsize); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1046 memcpy(p, q, itemsize); |
|
1ec6c63347ea
arraymodule: Fix SF bug 113960.
Tim Peters <tim.peters@gmail.com>
parents:
14499
diff
changeset
|
1047 memcpy(q, tmp, itemsize); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1048 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1049 } |
|
14499
7f23ec5cd9ca
General cleanup in preparation for a bugfix: removed unused code, useless
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
1050 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1051 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1052 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1053 } |
|
1393
7d6a2d950f13
* nismodule.c: database keys and values can contain null bytes. be more
Guido van Rossum <guido@python.org>
parents:
1391
diff
changeset
|
1054 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1055 PyDoc_STRVAR(reverse_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1056 "reverse()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1057 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1058 Reverse the order of the items in the array."); |
|
9343
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_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
|
1062 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1063 PyObject *f; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1064 int n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1065 FILE *fp; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1066 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
|
1067 return NULL; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1068 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
|
1069 if (fp == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1070 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
|
1071 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1072 } |
|
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 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
|
1076 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
|
1077 int newlength; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1078 size_t newbytes; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1079 /* 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
|
1080 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
|
1081 (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
|
1082 (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
|
1083 goto nomem; |
|
d3bece46486e
Carefully check for overflow when allocating the memory for fromfile
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
1084 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
|
1085 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
|
1086 nomem: |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1087 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1088 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1089 } |
|
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 self->ob_size += n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1092 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
|
1093 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
|
1094 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
|
1095 self->ob_size -= (n - nread); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1096 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
|
1097 self->ob_item = item; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1098 PyErr_SetString(PyExc_EOFError, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1099 "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
|
1100 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1102 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1103 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1104 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1105 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1106 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1107 PyDoc_STRVAR(fromfile_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1108 "fromfile(f, n)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1109 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1110 Read n objects from the file object f and append them to the end of the\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1111 array. Also called as read."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1112 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1113 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1114 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1115 array_tofile(arrayobject *self, PyObject *f) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1116 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1117 FILE *fp; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1118 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1119 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
|
1120 if (fp == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1121 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
|
1122 return NULL; |
|
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 if (self->ob_size > 0) { |
|
13942
31b25ac1f019
Use safer comparisons (only matters when sizeof(int) != sizeof(size_t)). fread
Trent Mick <trentm@activestate.com>
parents:
13792
diff
changeset
|
1125 if (fwrite(self->ob_item, self->ob_descr->itemsize, |
|
31b25ac1f019
Use safer comparisons (only matters when sizeof(int) != sizeof(size_t)). fread
Trent Mick <trentm@activestate.com>
parents:
13792
diff
changeset
|
1126 self->ob_size, fp) != (size_t)self->ob_size) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1127 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
|
1128 clearerr(fp); |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1129 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1130 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1131 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1132 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1133 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1134 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1135 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1136 PyDoc_STRVAR(tofile_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1137 "tofile(f)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1138 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1139 Write all items (as machine values) to the file object f. Also called as\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1140 write."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1141 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1142 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1143 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1144 array_fromlist(arrayobject *self, PyObject *list) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1145 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1146 int n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1147 int itemsize = self->ob_descr->itemsize; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1148 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1149 if (!PyList_Check(list)) { |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1150 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
|
1151 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1152 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1153 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
|
1154 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1155 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
|
1156 int i; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1157 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
|
1158 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1159 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1160 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1161 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1162 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1163 self->ob_size += n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 self->ob_size -= n; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1169 PyMem_RESIZE(item, char, |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1170 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
|
1171 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1172 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1173 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1174 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1175 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1176 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1177 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1178 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1179 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1180 PyDoc_STRVAR(fromlist_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1181 "fromlist(list)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1182 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1183 Append items to array from list."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1184 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1185 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1186 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1187 array_tolist(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1188 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1189 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
|
1190 int i; |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1191 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1192 if (list == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1193 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1194 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
|
1195 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
|
1196 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1197 Py_DECREF(list); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1198 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1199 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1200 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
|
1201 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1202 return list; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1203 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1204 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1205 PyDoc_STRVAR(tolist_doc, |
|
9360
4c23ae6c6e82
ACK! There was still an unescaped newline in a docstring.
Guido van Rossum <guido@python.org>
parents:
9343
diff
changeset
|
1206 "tolist() -> list\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1207 \n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1208 Convert array to an ordinary list with the same items."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1209 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1210 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1211 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
|
1212 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
|
1213 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1214 char *str; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1215 int n; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1216 int itemsize = self->ob_descr->itemsize; |
|
13773
b6d93dba120e
replaced PyArgs_Parse by PyArgs_ParseTuple
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13772
diff
changeset
|
1217 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
|
1218 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1219 if (n % itemsize != 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1220 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
|
1221 "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
|
1222 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1223 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1224 n = n / itemsize; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1225 if (n > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1226 char *item = self->ob_item; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1227 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
|
1228 if (item == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1229 PyErr_NoMemory(); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1230 return NULL; |
|
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 self->ob_item = item; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1233 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
|
1234 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
|
1235 str, itemsize*n); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1236 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1237 Py_INCREF(Py_None); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1238 return Py_None; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1239 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1240 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1241 PyDoc_STRVAR(fromstring_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1242 "fromstring(string)\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1243 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1244 Appends items from the string, interpreting it as an array of machine\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1245 values,as if it had been read from a file using the fromfile() method)."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1246 |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1247 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1248 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1249 array_tostring(arrayobject *self, PyObject *unused) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1250 { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1251 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
|
1252 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
|
1253 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1254 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1255 PyDoc_STRVAR(tostring_doc, |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1256 "tostring() -> string\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1257 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1258 Convert the array to an array of machine values and return the string\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1259 representation."); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1260 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1261 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1262 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1263 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1264 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1265 array_fromunicode(arrayobject *self, PyObject *args) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1266 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1267 Py_UNICODE *ustr; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1268 int n; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1269 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1270 if (!PyArg_ParseTuple(args, "u#:fromunicode", &ustr, &n)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1271 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1272 if (self->ob_descr->typecode != 'u') { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1273 PyErr_SetString(PyExc_ValueError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1274 "fromunicode() may only be called on " |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1275 "type 'u' arrays"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1276 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1277 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1278 if (n > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1279 Py_UNICODE *item = (Py_UNICODE *) self->ob_item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1280 PyMem_RESIZE(item, Py_UNICODE, self->ob_size + n); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1281 if (item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1282 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1283 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1284 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1285 self->ob_item = (char *) item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1286 self->ob_size += n; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1287 memcpy(item + self->ob_size - n, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1288 ustr, n * sizeof(Py_UNICODE)); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1289 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1290 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1291 Py_INCREF(Py_None); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1292 return Py_None; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1293 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1294 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1295 PyDoc_STRVAR(fromunicode_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1296 "fromunicode(ustr)\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1297 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1298 Extends this array with data from the unicode string ustr.\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1299 The array must be a type 'u' array; otherwise a ValueError\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1300 is raised. Use array.fromstring(ustr.decode(...)) to\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1301 append Unicode data to an array of some other type."); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1302 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1303 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1304 static PyObject * |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1305 array_tounicode(arrayobject *self, PyObject *unused) |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1306 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1307 if (self->ob_descr->typecode != 'u') { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1308 PyErr_SetString(PyExc_ValueError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1309 "tounicode() may only be called on type 'u' arrays"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1310 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1311 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1312 return PyUnicode_FromUnicode((Py_UNICODE *) self->ob_item, self->ob_size); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1313 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1314 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1315 PyDoc_STRVAR(tounicode_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1316 "tounicode() -> unicode\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1317 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1318 Convert the array to a unicode string. The array must be\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1319 a type 'u' array; otherwise a ValueError is raised. Use\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1320 array.tostring().decode() to obtain a unicode string from\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1321 an array of some other type."); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1322 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1323 #endif /* Py_USING_UNICODE */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1324 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1325 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1326 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1327 array_get_typecode(arrayobject *a, void *closure) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1328 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1329 char tc = a->ob_descr->typecode; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1330 return PyString_FromStringAndSize(&tc, 1); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1331 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1332 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1333 static PyObject * |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1334 array_get_itemsize(arrayobject *a, void *closure) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1335 { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1336 return PyInt_FromLong((long)a->ob_descr->itemsize); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1337 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1338 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1339 static PyGetSetDef array_getsets [] = { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1340 {"typecode", (getter) array_get_typecode, NULL, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1341 "the typecode character used to create the array"}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1342 {"itemsize", (getter) array_get_itemsize, NULL, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1343 "the size, in bytes, of one array item"}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1344 {NULL} |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1345 }; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1346 |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1347 PyMethodDef array_methods[] = { |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1348 {"append", (PyCFunction)array_append, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1349 append_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1350 {"buffer_info", (PyCFunction)array_buffer_info, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1351 buffer_info_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1352 {"byteswap", (PyCFunction)array_byteswap, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1353 byteswap_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1354 {"count", (PyCFunction)array_count, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1355 count_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1356 {"extend", (PyCFunction)array_extend, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1357 extend_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1358 {"fromfile", (PyCFunction)array_fromfile, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1359 fromfile_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1360 {"fromlist", (PyCFunction)array_fromlist, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1361 fromlist_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1362 {"fromstring", (PyCFunction)array_fromstring, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1363 fromstring_doc}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1364 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1365 {"fromunicode", (PyCFunction)array_fromunicode, METH_VARARGS, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1366 fromunicode_doc}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1367 #endif |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1368 {"index", (PyCFunction)array_index, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1369 index_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1370 {"insert", (PyCFunction)array_insert, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1371 insert_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1372 {"pop", (PyCFunction)array_pop, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1373 pop_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1374 {"read", (PyCFunction)array_fromfile, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1375 fromfile_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1376 {"remove", (PyCFunction)array_remove, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1377 remove_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1378 {"reverse", (PyCFunction)array_reverse, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1379 reverse_doc}, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1380 /* {"sort", (PyCFunction)array_sort, METH_VARARGS, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1381 sort_doc},*/ |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1382 {"tofile", (PyCFunction)array_tofile, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1383 tofile_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1384 {"tolist", (PyCFunction)array_tolist, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1385 tolist_doc}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1386 {"tostring", (PyCFunction)array_tostring, METH_NOARGS, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1387 tostring_doc}, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1388 #ifdef Py_USING_UNICODE |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1389 {"tounicode", (PyCFunction)array_tounicode, METH_NOARGS, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1390 tounicode_doc}, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1391 #endif |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1392 {"write", (PyCFunction)array_tofile, METH_O, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1393 tofile_doc}, |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1394 {NULL, NULL} /* sentinel */ |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1395 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1396 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1397 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
|
1398 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
|
1399 { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1400 char buf[256], typecode; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1401 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
|
1402 int i, len; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1403 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1404 len = a->ob_size; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1405 typecode = a->ob_descr->typecode; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1406 if (len == 0) { |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1407 PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1408 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
|
1409 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1410 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1411 if (typecode == 'c' || typecode == 'u') { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1412 PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1413 s = PyString_FromString(buf); |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1414 #ifdef Py_USING_UNICODE |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1415 if (typecode == 'c') |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1416 #endif |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1417 v = array_tostring(a, NULL); |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1418 #ifdef Py_USING_UNICODE |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1419 else |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
24471
diff
changeset
|
1420 v = array_tounicode(a, NULL); |
|
23433
fb64f21176af
array_tounicode isn't defined in --disable-unicode builds...
Michael W. Hudson <mwh@python.net>
parents:
23365
diff
changeset
|
1421 #endif |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1422 t = PyObject_Repr(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1423 Py_XDECREF(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1424 PyString_ConcatAndDel(&s, t); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1425 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
|
1426 return s; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1427 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1428 PyOS_snprintf(buf, sizeof(buf), "array('%c', [", typecode); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1429 s = PyString_FromString(buf); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1430 comma = PyString_FromString(", "); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1431 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
|
1432 if (i > 0) |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1433 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
|
1434 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
|
1435 t = PyObject_Repr(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1436 Py_XDECREF(v); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1437 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
|
1438 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1439 Py_XDECREF(comma); |
|
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1440 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
|
1441 return s; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1442 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1443 |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1444 static PyObject* |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1445 array_subscr(arrayobject* self, PyObject* item) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1446 { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1447 if (PyInt_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1448 long i = PyInt_AS_LONG(item); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1449 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1450 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1451 return array_item(self, i); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1452 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1453 else if (PyLong_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1454 long i = PyLong_AsLong(item); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1455 if (i == -1 && PyErr_Occurred()) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1456 return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1457 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1458 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1459 return array_item(self, i); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1460 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1461 else if (PySlice_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1462 int start, stop, step, slicelength, cur, i; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1463 PyObject* result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1464 arrayobject* ar; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1465 int itemsize = self->ob_descr->itemsize; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1466 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1467 if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1468 &start, &stop, &step, &slicelength) < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1469 return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1470 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1471 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1472 if (slicelength <= 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1473 return newarrayobject(&Arraytype, 0, self->ob_descr); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1474 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1475 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1476 result = newarrayobject(&Arraytype, slicelength, self->ob_descr); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1477 if (!result) return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1478 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1479 ar = (arrayobject*)result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1480 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1481 for (cur = start, i = 0; i < slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1482 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1483 memcpy(ar->ob_item + i*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1484 self->ob_item + cur*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1485 itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1486 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1487 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1488 return result; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1489 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1490 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1491 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1492 PyErr_SetString(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1493 "list indices must be integers"); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1494 return NULL; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1495 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1496 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1497 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1498 static int |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1499 array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1500 { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1501 if (PyInt_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1502 long i = PyInt_AS_LONG(item); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1503 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1504 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1505 return array_ass_item(self, i, value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1506 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1507 else if (PyLong_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1508 long i = PyLong_AsLong(item); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1509 if (i == -1 && PyErr_Occurred()) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1510 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1511 if (i < 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1512 i += self->ob_size; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1513 return array_ass_item(self, i, value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1514 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1515 else if (PySlice_Check(item)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1516 int start, stop, step, slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1517 int itemsize = self->ob_descr->itemsize; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1518 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1519 if (PySlice_GetIndicesEx((PySliceObject*)item, self->ob_size, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1520 &start, &stop, &step, &slicelength) < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1521 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1522 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1523 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1524 /* treat A[slice(a,b)] = v _exactly_ like A[a:b] = v */ |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1525 if (step == 1 && ((PySliceObject*)item)->step == Py_None) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1526 return array_ass_slice(self, start, stop, value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1527 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1528 if (value == NULL) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1529 /* delete slice */ |
| 24424 | 1530 int cur, i, extra; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1531 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1532 if (slicelength <= 0) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1533 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1534 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1535 if (step < 0) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1536 stop = start + 1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1537 start = stop + step*(slicelength - 1) - 1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1538 step = -step; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1539 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1540 |
| 24424 | 1541 for (cur = start, i = 0; i < slicelength - 1; |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1542 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1543 memmove(self->ob_item + (cur - i)*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1544 self->ob_item + (cur + 1)*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1545 (step - 1) * itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1546 } |
| 24424 | 1547 extra = self->ob_size - (cur + 1); |
| 1548 if (extra > 0) { | |
| 1549 memmove(self->ob_item + (cur - i)*itemsize, | |
| 1550 self->ob_item + (cur + 1)*itemsize, | |
| 1551 extra*itemsize); | |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1552 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1553 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1554 self->ob_size -= slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1555 self->ob_item = PyMem_REALLOC(self->ob_item, itemsize*self->ob_size); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1556 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1557 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1558 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1559 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1560 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1561 /* assign slice */ |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1562 int cur, i; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1563 arrayobject* av; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1564 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1565 if (!array_Check(value)) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1566 PyErr_Format(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1567 "must assign array (not \"%.200s\") to slice", |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1568 value->ob_type->tp_name); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1569 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1570 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1571 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1572 av = (arrayobject*)value; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1573 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1574 if (av->ob_size != slicelength) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1575 PyErr_Format(PyExc_ValueError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1576 "attempt to assign array of size %d to extended slice of size %d", |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1577 av->ob_size, slicelength); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1578 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1579 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1580 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1581 if (!slicelength) |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1582 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1583 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1584 /* protect against a[::-1] = a */ |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1585 if (self == av) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1586 value = array_slice(av, 0, av->ob_size); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1587 av = (arrayobject*)value; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1588 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1589 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1590 Py_INCREF(value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1591 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1592 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1593 for (cur = start, i = 0; i < slicelength; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1594 cur += step, i++) { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1595 memcpy(self->ob_item + cur*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1596 av->ob_item + i*itemsize, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1597 itemsize); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1598 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1599 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1600 Py_DECREF(value); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1601 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1602 return 0; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1603 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1604 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1605 else { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1606 PyErr_SetString(PyExc_TypeError, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1607 "list indices must be integers"); |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1608 return -1; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1609 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1610 } |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1611 |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1612 static PyMappingMethods array_as_mapping = { |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1613 (inquiry)array_length, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1614 (binaryfunc)array_subscr, |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1615 (objobjargproc)array_ass_subscr |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1616 }; |
|
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1617 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1618 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
|
1619 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
|
1620 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1621 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1622 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1623 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1624 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1625 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1626 *ptr = (void *)self->ob_item; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1627 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
|
1628 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1629 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1630 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
|
1631 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
|
1632 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1633 if ( index != 0 ) { |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1634 PyErr_SetString(PyExc_SystemError, |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1635 "Accessing non-existent array segment"); |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1636 return -1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1637 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1638 *ptr = (void *)self->ob_item; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1639 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
|
1640 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1641 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1642 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
|
1643 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
|
1644 { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1645 if ( lenp ) |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1646 *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
|
1647 return 1; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1648 } |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1649 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1650 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
|
1651 (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
|
1652 (binaryfunc)array_concat, /*sq_concat*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1653 (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
|
1654 (intargfunc)array_item, /*sq_item*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1655 (intintargfunc)array_slice, /*sq_slice*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1656 (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
|
1657 (intintobjargproc)array_ass_slice, /*sq_ass_slice*/ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1658 NULL, /*sq_contains*/ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1659 (binaryfunc)array_inplace_concat, /*sq_inplace_concat*/ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1660 (intargfunc)array_inplace_repeat /*sq_inplace_repeat*/ |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1661 }; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1662 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1663 static PyBufferProcs array_as_buffer = { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1664 (getreadbufferproc)array_buffer_getreadbuf, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1665 (getwritebufferproc)array_buffer_getwritebuf, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1666 (getsegcountproc)array_buffer_getsegcount, |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1667 }; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
5318
diff
changeset
|
1668 |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1669 static PyObject * |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1670 array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1671 { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1672 char c; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1673 PyObject *initial = NULL; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1674 struct arraydescr *descr; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1675 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1676 if (kwds != NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1677 int i = PyObject_Length(kwds); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1678 if (i < 0) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1679 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1680 else if (i > 0) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1681 PyErr_SetString(PyExc_TypeError, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1682 "array.array constructor takes " |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1683 "no keyword arguments"); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1684 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1685 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1686 } |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1687 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1688 if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial)) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1689 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1690 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1691 if (!(initial == NULL || PyList_Check(initial) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1692 || PyString_Check(initial) |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1693 || (c == 'u' && PyUnicode_Check(initial)))) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1694 PyErr_SetString(PyExc_TypeError, |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1695 "array initializer must be list or string"); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1696 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1697 } |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1698 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
|
1699 if (descr->typecode == c) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1700 PyObject *a; |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1701 int len; |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1702 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
|
1703 len = 0; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1704 else |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1705 len = PyList_Size(initial); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1706 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1707 a = newarrayobject(type, len, descr); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1708 if (a == NULL) |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1709 return NULL; |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1710 |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1711 if (len > 0) { |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1712 int i; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1713 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
|
1714 PyObject *v = |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1715 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
|
1716 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
|
1717 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1718 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1719 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1720 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1721 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1722 if (initial != NULL && PyString_Check(initial)) { |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1723 PyObject *t_initial = Py_BuildValue("(O)", |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1724 initial); |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1725 PyObject *v = |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1726 array_fromstring((arrayobject *)a, |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1727 t_initial); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1728 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
|
1729 if (v == NULL) { |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1730 Py_DECREF(a); |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1731 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1732 } |
|
4628
7df5d4cf8277
Renamed Grandly (I think).
Roger E. Masse <rmasse@newcnri.cnri.reston.va.us>
parents:
4600
diff
changeset
|
1733 Py_DECREF(v); |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1734 #ifdef Py_USING_UNICODE |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1735 } else if (initial != NULL && PyUnicode_Check(initial)) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1736 int n = PyUnicode_GET_DATA_SIZE(initial); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1737 if (n > 0) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1738 arrayobject *self = (arrayobject *)a; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1739 char *item = self->ob_item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1740 item = PyMem_Realloc(item, n); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1741 if (item == NULL) { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1742 PyErr_NoMemory(); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1743 Py_DECREF(a); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1744 return NULL; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1745 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1746 self->ob_item = item; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1747 self->ob_size = n / sizeof(Py_UNICODE); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1748 memcpy(item, PyUnicode_AS_DATA(initial), n); |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1749 } |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1750 #endif |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1751 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1752 return a; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1753 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1754 } |
|
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
|
1755 PyErr_SetString(PyExc_ValueError, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1756 "bad typecode (must be c, b, B, u, 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
|
1757 return NULL; |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1758 } |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1759 |
|
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1760 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1761 PyDoc_STRVAR(module_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1762 "This module defines an object type which can efficiently represent\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1763 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
|
1764 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
|
1765 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
|
1766 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
|
1767 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
|
1768 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1769 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
|
1770 'c' character 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1771 'b' signed integer 1 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1772 'B' unsigned integer 1 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1773 'u' Unicode character 2 \n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1774 'h' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1775 'H' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1776 'i' signed integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1777 'I' unsigned integer 2 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1778 'l' signed integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1779 'L' unsigned integer 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1780 'f' floating point 4 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1781 'd' floating point 8 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1782 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1783 The constructor is:\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1784 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1785 array(typecode [, initializer]) -- create a new array\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1786 "); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1787 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1788 PyDoc_STRVAR(arraytype_doc, |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1789 "array(typecode [, initializer]) -> array\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1790 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1791 Return a new array whose items are restricted by typecode, and\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1792 initialized from the optional initializer value, which must be a list\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1793 or a string.\n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1794 \n\ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1795 Arrays represent basic values and behave very much like lists, except\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1796 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
|
1797 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1798 Methods:\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1799 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1800 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
|
1801 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
|
1802 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
|
1803 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
|
1804 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
|
1805 fromfile() -- read items from a file object\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1806 fromlist() -- append items from the list\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1807 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
|
1808 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
|
1809 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
|
1810 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
|
1811 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
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 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
|
1817 write() -- DEPRECATED, use tofile()\n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1818 \n\ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1819 Attributes:\n\ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1820 \n\ |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1821 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
|
1822 itemsize -- the length in bytes of one array item\n\ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23433
diff
changeset
|
1823 "); |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1824 |
|
24283
c0a67a1cab09
Removed more stray instances of statichere, but left _sre.c alone.
Tim Peters <tim.peters@gmail.com>
parents:
24280
diff
changeset
|
1825 static PyTypeObject Arraytype = { |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
1826 PyObject_HEAD_INIT(NULL) |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1827 0, |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
21073
diff
changeset
|
1828 "array.array", |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1829 sizeof(arrayobject), |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1830 0, |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1831 (destructor)array_dealloc, /* tp_dealloc */ |
| 22124 | 1832 0, /* tp_print */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1833 0, /* tp_getattr */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1834 0, /* tp_setattr */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1835 0, /* tp_compare */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1836 (reprfunc)array_repr, /* tp_repr */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1837 0, /* tp_as _number*/ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1838 &array_as_sequence, /* tp_as _sequence*/ |
|
23929
26ba17b758b9
Fix the bug described in
Michael W. Hudson <mwh@python.net>
parents:
23832
diff
changeset
|
1839 &array_as_mapping, /* tp_as _mapping*/ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1840 0, /* tp_hash */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1841 0, /* tp_call */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1842 0, /* tp_str */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
1843 PyObject_GenericGetAttr, /* tp_getattro */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1844 0, /* tp_setattro */ |
|
18036
a02085871c3f
Make it possible to find the use of tp_as_buffer here with a global search.
Tim Peters <tim.peters@gmail.com>
parents:
16268
diff
changeset
|
1845 &array_as_buffer, /* tp_as_buffer*/ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1846 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
|
15975
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1847 arraytype_doc, /* tp_doc */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1848 0, /* tp_traverse */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1849 0, /* tp_clear */ |
|
54205828b1e1
Same treatment as listobject.c:
Guido van Rossum <guido@python.org>
parents:
15396
diff
changeset
|
1850 array_richcompare, /* tp_richcompare */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1851 0, /* tp_weaklistoffset */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1852 0, /* tp_iter */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1853 0, /* tp_iternext */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1854 array_methods, /* tp_methods */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1855 0, /* tp_members */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1856 array_getsets, /* tp_getset */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1857 0, /* tp_base */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1858 0, /* tp_dict */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1859 0, /* tp_descr_get */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1860 0, /* tp_descr_set */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1861 0, /* tp_dictoffset */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1862 0, /* tp_init */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
1863 PyType_GenericAlloc, /* tp_alloc */ |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1864 array_new, /* tp_new */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27044
diff
changeset
|
1865 PyObject_Del, /* tp_free */ |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1866 }; |
|
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1867 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1868 /* No functions in array module. */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1869 static PyMethodDef a_methods[] = { |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1870 {NULL, NULL, 0, NULL} /* Sentinel */ |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1871 }; |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1872 |
|
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1873 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24424
diff
changeset
|
1874 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13590
diff
changeset
|
1875 initarray(void) |
|
1235
87ed00a62d31
Added new module "array" (for now optional) defining array objects.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1876 { |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1877 PyObject *m; |
|
11711
6546ea06e157
Patch from Paul Sokolovsky <Paul.Sokolovsky@technologist.com>:
Fred Drake <fdrake@acm.org>
parents:
11673
diff
changeset
|
1878 |
|
22098
966725095854
Patch 520694: arraymodule.c improvements:
Martin v. Löwis <martin@v.loewis.de>
parents:
21313
diff
changeset
|
1879 Arraytype.ob_type = &PyType_Type; |
|
9343
4f78504a5f81
Doc strings by Chris Petrilli.
Guido van Rossum <guido@python.org>
parents:
5982
diff
changeset
|
1880 m = Py_InitModule3("array", a_methods, module_doc); |
|
22722
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1881 |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1882 Py_INCREF((PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1883 PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1884 Py_INCREF((PyObject *)&Arraytype); |
|
ba68dda15df0
Use the PyModule_*() API instead of manipulating the module dictionary
Fred Drake <fdrake@acm.org>
parents:
22124
diff
changeset
|
1885 PyModule_AddObject(m, "array", (PyObject *)&Arraytype); |
|
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
|
1886 /* 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
|
1887 } |
