annotate Objects/structseq.c @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents d40e1e133039
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Implementation helper: a struct that looks like a tuple. See timemodule
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 and posixmodule for example uses. */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #include "Python.h"
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #include "structmember.h"
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 #include "structseq.h"
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 static char visible_length_key[] = "n_sequence_fields";
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 static char real_length_key[] = "n_fields";
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
10 static char unnamed_fields_key[] = "n_unnamed_fields";
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
12 /* Fields with this name have only a field index, not a field name.
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
13 They are only allowed for indices < n_visible_fields. */
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
14 char *PyStructSequence_UnnamedField = "unnamed field";
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
15
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42951
diff changeset
16 #define VISIBLE_SIZE(op) Py_SIZE(op)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #define VISIBLE_SIZE_TP(tp) PyInt_AsLong( \
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 PyDict_GetItemString((tp)->tp_dict, visible_length_key))
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 #define REAL_SIZE_TP(tp) PyInt_AsLong( \
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 PyDict_GetItemString((tp)->tp_dict, real_length_key))
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42951
diff changeset
22 #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op))
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
24 #define UNNAMED_FIELDS_TP(tp) PyInt_AsLong( \
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
25 PyDict_GetItemString((tp)->tp_dict, unnamed_fields_key))
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42951
diff changeset
26 #define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op))
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
27
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 PyStructSequence_New(PyTypeObject *type)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
32 PyStructSequence *obj;
44668
7e41e1c46b57 I missed the most important file
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
33
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
34 obj = PyObject_New(PyStructSequence, type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
35 if (obj == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
36 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
37 Py_SIZE(obj) = VISIBLE_SIZE_TP(type);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
39 return (PyObject*) obj;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 static void
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 structseq_dealloc(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
45 Py_ssize_t i, size;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
47 size = REAL_SIZE(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
48 for (i = 0; i < size; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
49 Py_XDECREF(obj->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
50 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
51 PyObject_Del(obj);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
54 static Py_ssize_t
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 structseq_length(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
57 return VISIBLE_SIZE(obj);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 static PyObject*
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
61 structseq_item(PyStructSequence *obj, Py_ssize_t i)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
63 if (i < 0 || i >= VISIBLE_SIZE(obj)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
64 PyErr_SetString(PyExc_IndexError, "tuple index out of range");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
65 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
66 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
67 Py_INCREF(obj->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
68 return obj->ob_item[i];
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 static PyObject*
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
72 structseq_slice(PyStructSequence *obj, Py_ssize_t low, Py_ssize_t high)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
74 PyTupleObject *np;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
75 Py_ssize_t i;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
77 if (low < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
78 low = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
79 if (high > VISIBLE_SIZE(obj))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
80 high = VISIBLE_SIZE(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
81 if (high < low)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
82 high = low;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
83 np = (PyTupleObject *)PyTuple_New(high-low);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
84 if (np == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
85 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
86 for(i = low; i < high; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
87 PyObject *v = obj->ob_item[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
88 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
89 PyTuple_SET_ITEM(np, i-low, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
90 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
91 return (PyObject *) np;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 static PyObject *
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
95 structseq_subscript(PyStructSequence *self, PyObject *item)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
96 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
97 if (PyIndex_Check(item)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
98 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
99 if (i == -1 && PyErr_Occurred())
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
100 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
101
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
102 if (i < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
103 i += VISIBLE_SIZE(self);
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
104
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
105 if (i < 0 || i >= VISIBLE_SIZE(self)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
106 PyErr_SetString(PyExc_IndexError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
107 "tuple index out of range");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
108 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
109 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
110 Py_INCREF(self->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
111 return self->ob_item[i];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
112 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
113 else if (PySlice_Check(item)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
114 Py_ssize_t start, stop, step, slicelen, cur, i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
115 PyObject *result;
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
116
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
117 if (PySlice_GetIndicesEx((PySliceObject *)item,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
118 VISIBLE_SIZE(self), &start, &stop,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
119 &step, &slicelen) < 0) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
120 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
121 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
122 if (slicelen <= 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
123 return PyTuple_New(0);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
124 result = PyTuple_New(slicelen);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
125 if (result == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
126 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
127 for (cur = start, i = 0; i < slicelen;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
128 cur += step, i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
129 PyObject *v = self->ob_item[cur];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
130 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
131 PyTuple_SET_ITEM(result, i, v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
132 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
133 return result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
134 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
135 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
136 PyErr_SetString(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
137 "structseq index must be integer");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
138 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
139 }
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
140 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
141
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
142 static PyObject *
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
145 PyObject *arg = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
146 PyObject *dict = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
147 PyObject *ob;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
148 PyStructSequence *res = NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
149 Py_ssize_t len, min_len, max_len, i, n_unnamed_fields;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
150 static char *kwlist[] = {"sequence", "dict", 0};
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
152 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:structseq",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
153 kwlist, &arg, &dict))
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
154 return NULL;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
156 arg = PySequence_Fast(arg, "constructor requires a sequence");
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
157
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
158 if (!arg) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
159 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
160 }
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
161
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
162 if (dict && !PyDict_Check(dict)) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
163 PyErr_Format(PyExc_TypeError,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
164 "%.500s() takes a dict as second arg, if any",
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
165 type->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
166 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
167 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
168 }
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
170 len = PySequence_Fast_GET_SIZE(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
171 min_len = VISIBLE_SIZE_TP(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
172 max_len = REAL_SIZE_TP(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
173 n_unnamed_fields = UNNAMED_FIELDS_TP(type);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
174
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
175 if (min_len != max_len) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
176 if (len < min_len) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
177 PyErr_Format(PyExc_TypeError,
74944
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
178 "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
179 type->tp_name, min_len, len);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
180 Py_DECREF(arg);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
181 return NULL;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
182 }
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
183
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
184 if (len > max_len) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
185 PyErr_Format(PyExc_TypeError,
74944
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
186 "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
187 type->tp_name, max_len, len);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
188 Py_DECREF(arg);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
189 return NULL;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
190 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
191 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
192 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
193 if (len != min_len) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
194 PyErr_Format(PyExc_TypeError,
74944
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
195 "%.500s() takes a %zd-sequence (%zd-sequence given)",
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
196 type->tp_name, min_len, len);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
197 Py_DECREF(arg);
d40e1e133039 Fix indentation.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74943
diff changeset
198 return NULL;
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
199 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
200 }
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
201
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
202 res = (PyStructSequence*) PyStructSequence_New(type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
203 if (res == NULL) {
74943
08a85fc85bf2 Issue #13020: Fix a reference leak when allocating a structsequence object fails.
Antoine Pitrou <solipsis@pitrou.net>
parents: 61463
diff changeset
204 Py_DECREF(arg);
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
205 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
206 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
207 for (i = 0; i < len; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
208 PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
209 Py_INCREF(v);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
210 res->ob_item[i] = v;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
211 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
212 for (; i < max_len; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
213 if (dict && (ob = PyDict_GetItemString(
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
214 dict, type->tp_members[i-n_unnamed_fields].name))) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
215 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
216 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
217 ob = Py_None;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
218 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
219 Py_INCREF(ob);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
220 res->ob_item[i] = ob;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
221 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
222
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
223 Py_DECREF(arg);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
224 return (PyObject*) res;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 make_tuple(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
230 return structseq_slice(obj, 0, VISIBLE_SIZE(obj));
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
232
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 structseq_repr(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
236 /* buffer and type size were chosen well considered. */
44671
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
237 #define REPR_BUFFER_SIZE 512
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
238 #define TYPE_MAXSIZE 100
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
239
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
240 PyObject *tup;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
241 PyTypeObject *typ = Py_TYPE(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
242 int i, removelast = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
243 Py_ssize_t len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
244 char buf[REPR_BUFFER_SIZE];
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
245 char *endofbuf, *pbuf = buf;
44668
7e41e1c46b57 I missed the most important file
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
246
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
247 /* pointer to end of writeable buffer; safes space for "...)\0" */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
248 endofbuf= &buf[REPR_BUFFER_SIZE-5];
44668
7e41e1c46b57 I missed the most important file
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
249
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
250 if ((tup = make_tuple(obj)) == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
251 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
252 }
44671
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
253
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
254 /* "typename(", limited to TYPE_MAXSIZE */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
255 len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE :
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
256 strlen(typ->tp_name);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
257 strncpy(pbuf, typ->tp_name, len);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
258 pbuf += len;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
259 *pbuf++ = '(';
44671
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
260
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
261 for (i=0; i < VISIBLE_SIZE(obj); i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
262 PyObject *val, *repr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
263 char *cname, *crepr;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
264
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
265 cname = typ->tp_members[i].name;
44671
33f6709075e8 Added more comments to the new structseq repr code and implemented several of Neal's suggestions.
Christian Heimes <christian@cheimes.de>
parents: 44668
diff changeset
266
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
267 val = PyTuple_GetItem(tup, i);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
268 if (cname == NULL || val == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
269 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
270 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
271 repr = PyObject_Repr(val);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
272 if (repr == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
273 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
274 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
275 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
276 crepr = PyString_AsString(repr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
277 if (crepr == NULL) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
278 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
279 Py_DECREF(repr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
280 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
281 }
44668
7e41e1c46b57 I missed the most important file
Christian Heimes <christian@cheimes.de>
parents: 44350
diff changeset
282
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
283 /* + 3: keep space for "=" and ", " */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
284 len = strlen(cname) + strlen(crepr) + 3;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
285 if ((pbuf+len) <= endofbuf) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
286 strcpy(pbuf, cname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
287 pbuf += strlen(cname);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
288 *pbuf++ = '=';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
289 strcpy(pbuf, crepr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
290 pbuf += strlen(crepr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
291 *pbuf++ = ',';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
292 *pbuf++ = ' ';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
293 removelast = 1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
294 Py_DECREF(repr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
295 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
296 else {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
297 strcpy(pbuf, "...");
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
298 pbuf += 3;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
299 removelast = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
300 Py_DECREF(repr);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
301 break;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
302 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
303 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
304 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
305 if (removelast) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
306 /* overwrite last ", " */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
307 pbuf-=2;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
308 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
309 *pbuf++ = ')';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
310 *pbuf = '\0';
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
311
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
312 return PyString_FromString(buf);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
314
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 structseq_concat(PyStructSequence *obj, PyObject *b)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
318 PyObject *tup, *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
319 tup = make_tuple(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
320 result = PySequence_Concat(tup, b);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
321 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
322 return result;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
326 structseq_repeat(PyStructSequence *obj, Py_ssize_t n)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
328 PyObject *tup, *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
329 tup = make_tuple(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
330 result = PySequence_Repeat(tup, n);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
331 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
332 return result;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
334
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 static int
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 structseq_contains(PyStructSequence *obj, PyObject *o)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
338 PyObject *tup;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
339 int result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
340 tup = make_tuple(obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
341 if (!tup)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
342 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
343 result = PySequence_Contains(tup, o);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
344 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
345 return result;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
347
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 static long
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 structseq_hash(PyObject *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
351 PyObject *tup;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
352 long result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
353 tup = make_tuple((PyStructSequence*) obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
354 if (!tup)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
355 return -1;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
356 result = PyObject_Hash(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
357 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
358 return result;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
360
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 structseq_richcompare(PyObject *obj, PyObject *o2, int op)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
364 PyObject *tup, *result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
365 tup = make_tuple((PyStructSequence*) obj);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
366 result = PyObject_RichCompare(tup, o2, op);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
367 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
368 return result;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
370
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
371 static PyObject *
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
372 structseq_reduce(PyStructSequence* self)
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
373 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
374 PyObject* tup;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
375 PyObject* dict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
376 PyObject* result;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
377 Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
378 int i;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
379
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
380 n_fields = REAL_SIZE(self);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
381 n_visible_fields = VISIBLE_SIZE(self);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
382 n_unnamed_fields = UNNAMED_FIELDS(self);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
383 tup = PyTuple_New(n_visible_fields);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
384 if (!tup) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
385 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
386 }
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
387
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
388 dict = PyDict_New();
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
389 if (!dict) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
390 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
391 return NULL;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
392 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
393
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
394 for (i = 0; i < n_visible_fields; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
395 Py_INCREF(self->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
396 PyTuple_SET_ITEM(tup, i, self->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
397 }
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
398
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
399 for (; i < n_fields; i++) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
400 char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
401 PyDict_SetItemString(dict, n,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
402 self->ob_item[i]);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
403 }
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
404
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
405 result = Py_BuildValue("(O(OO))", Py_TYPE(self), tup, dict);
22168
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
406
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
407 Py_DECREF(tup);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
408 Py_DECREF(dict);
22168
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
409
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
410 return result;
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
411 }
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
412
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 static PySequenceMethods structseq_as_sequence = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
414 (lenfunc)structseq_length,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
415 (binaryfunc)structseq_concat, /* sq_concat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
416 (ssizeargfunc)structseq_repeat, /* sq_repeat */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
417 (ssizeargfunc)structseq_item, /* sq_item */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
418 (ssizessizeargfunc)structseq_slice, /* sq_slice */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
419 0, /* sq_ass_item */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
420 0, /* sq_ass_slice */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
421 (objobjproc)structseq_contains, /* sq_contains */
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 };
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
423
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
424 static PyMappingMethods structseq_as_mapping = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
425 (lenfunc)structseq_length,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
426 (binaryfunc)structseq_subscript,
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
427 };
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
428
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
429 static PyMethodDef structseq_methods[] = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
430 {"__reduce__", (PyCFunction)structseq_reduce,
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
431 METH_NOARGS, NULL},
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
432 {NULL, NULL}
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
433 };
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
434
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 static PyTypeObject _struct_sequence_template = {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
436 PyVarObject_HEAD_INIT(&PyType_Type, 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
437 NULL, /* tp_name */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
438 0, /* tp_basicsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
439 0, /* tp_itemsize */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
440 (destructor)structseq_dealloc, /* tp_dealloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
441 0, /* tp_print */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
442 0, /* tp_getattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
443 0, /* tp_setattr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
444 0, /* tp_compare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
445 (reprfunc)structseq_repr, /* tp_repr */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
446 0, /* tp_as_number */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
447 &structseq_as_sequence, /* tp_as_sequence */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
448 &structseq_as_mapping, /* tp_as_mapping */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
449 structseq_hash, /* tp_hash */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
450 0, /* tp_call */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
451 0, /* tp_str */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
452 0, /* tp_getattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
453 0, /* tp_setattro */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
454 0, /* tp_as_buffer */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
455 Py_TPFLAGS_DEFAULT, /* tp_flags */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
456 NULL, /* tp_doc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
457 0, /* tp_traverse */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
458 0, /* tp_clear */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
459 structseq_richcompare, /* tp_richcompare */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
460 0, /* tp_weaklistoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
461 0, /* tp_iter */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
462 0, /* tp_iternext */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
463 structseq_methods, /* tp_methods */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
464 NULL, /* tp_members */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
465 0, /* tp_getset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
466 0, /* tp_base */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
467 0, /* tp_dict */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
468 0, /* tp_descr_get */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
469 0, /* tp_descr_set */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
470 0, /* tp_dictoffset */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
471 0, /* tp_init */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
472 0, /* tp_alloc */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
473 structseq_new, /* tp_new */
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 };
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
475
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 void
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
477 PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 {
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
479 PyObject *dict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
480 PyMemberDef* members;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
481 int n_members, n_unnamed_members, i, k;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
482
37745
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
483 #ifdef Py_TRACE_REFS
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
484 /* if the type object was chained, unchain it first
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
485 before overwriting its storage */
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
486 if (type->_ob_next) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
487 _Py_ForgetReference((PyObject*)type);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
488 }
37745
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
489 #endif
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
490
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
491 n_unnamed_members = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
492 for (i = 0; desc->fields[i].name != NULL; ++i)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
493 if (desc->fields[i].name == PyStructSequence_UnnamedField)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
494 n_unnamed_members++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
495 n_members = i;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
496
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
497 memcpy(type, &_struct_sequence_template, sizeof(PyTypeObject));
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
498 type->tp_name = desc->name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
499 type->tp_doc = desc->doc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
500 type->tp_basicsize = sizeof(PyStructSequence)+
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
501 sizeof(PyObject*)*(n_members-1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
502 type->tp_itemsize = 0;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
503
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
504 members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
505 if (members == NULL)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
506 return;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
507
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
508 for (i = k = 0; i < n_members; ++i) {
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
509 if (desc->fields[i].name == PyStructSequence_UnnamedField)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
510 continue;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
511 members[k].name = desc->fields[i].name;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
512 members[k].type = T_OBJECT;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
513 members[k].offset = offsetof(PyStructSequence, ob_item)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
514 + i * sizeof(PyObject*);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
515 members[k].flags = READONLY;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
516 members[k].doc = desc->fields[i].doc;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
517 k++;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
518 }
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
519 members[k].name = NULL;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
520
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
521 type->tp_members = members;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
522
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
523 if (PyType_Ready(type) < 0)
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
524 return;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
525 Py_INCREF(type);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
526
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
527 dict = type->tp_dict;
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
528 #define SET_DICT_FROM_INT(key, value) \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
529 do { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
530 PyObject *v = PyInt_FromLong((long) value); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
531 if (v != NULL) { \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
532 PyDict_SetItemString(dict, key, v); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
533 Py_DECREF(v); \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
534 } \
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
535 } while (0)
48847
Neal Norwitz <nnorwitz@gmail.com>
parents: 47527
diff changeset
536
61463
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
537 SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
538 SET_DICT_FROM_INT(real_length_key, n_members);
fd25030223b0 Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48847
diff changeset
539 SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
540 }