annotate Objects/structseq.c @ 43405:c19ec9515a33 legacy-trunk

Annotated the correction to urllib.py, issue #1177
author Facundo Batista <facundobatista@gmail.com>
date Wed, 19 Sep 2007 14:02:03 +0000
parents 9620134010a5
children 26384b8180c7
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
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
12 /* Fields with this name have only a field index, not a field name.
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
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
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))
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
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))
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
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 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 PyStructSequence *obj;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
22978
363c7fc174ac Remove PyMalloc_New and PyMalloc_Del.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22446
diff changeset
34 obj = PyObject_New(PyStructSequence, type);
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
35 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
36
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 return (PyObject*) obj;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 static void
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 structseq_dealloc(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
43 Py_ssize_t i, size;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 size = REAL_SIZE(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 for (i = 0; i < size; ++i) {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 Py_XDECREF(obj->ob_item[i]);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 }
22978
363c7fc174ac Remove PyMalloc_New and PyMalloc_Del.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22446
diff changeset
49 PyObject_Del(obj);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
52 static Py_ssize_t
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 structseq_length(PyStructSequence *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 return VISIBLE_SIZE(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 static PyObject*
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
59 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
60 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 if (i < 0 || i >= VISIBLE_SIZE(obj)) {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 PyErr_SetString(PyExc_IndexError, "tuple index out of range");
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 return NULL;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 Py_INCREF(obj->ob_item[i]);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 return obj->ob_item[i];
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 static PyObject*
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
70 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
71 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 PyTupleObject *np;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
73 Py_ssize_t i;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 if (low < 0)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 low = 0;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 if (high > VISIBLE_SIZE(obj))
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 high = VISIBLE_SIZE(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 if (high < low)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 high = low;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 np = (PyTupleObject *)PyTuple_New(high-low);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 if (np == NULL)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 return NULL;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 for(i = low; i < high; ++i) {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 PyObject *v = obj->ob_item[i];
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 Py_INCREF(v);
20780
ab2e315849a7 Fix bad bug in structseq slicing (NULL pointers in result). Reported by
Tim Peters <tim.peters@gmail.com>
parents: 20540
diff changeset
87 PyTuple_SET_ITEM(np, i-low, v);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 return (PyObject *) np;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 static PyObject *
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
93 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
94 {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
95 if (PyIndex_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
96 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
97 if (i == -1 && PyErr_Occurred())
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
98 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
99
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
100 if (i < 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
101 i += VISIBLE_SIZE(self);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
102
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
103 if (i < 0 || i >= VISIBLE_SIZE(self)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
104 PyErr_SetString(PyExc_IndexError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
105 "tuple index out of range");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
106 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
107 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
108 Py_INCREF(self->ob_item[i]);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
109 return self->ob_item[i];
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
110 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
111 else if (PySlice_Check(item)) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
112 Py_ssize_t start, stop, step, slicelen, cur, i;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
113 PyObject *result;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
114
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
115 if (PySlice_GetIndicesEx((PySliceObject *)item,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
116 VISIBLE_SIZE(self), &start, &stop,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
117 &step, &slicelen) < 0) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
118 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
119 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
120 if (slicelen <= 0)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
121 return PyTuple_New(0);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
122 result = PyTuple_New(slicelen);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
123 if (result == NULL)
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
124 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
125 for (cur = start, i = 0; i < slicelen;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
126 cur += step, i++) {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
127 PyObject *v = self->ob_item[cur];
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
128 Py_INCREF(v);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
129 PyTuple_SET_ITEM(result, i, v);
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
130 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
131 return result;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
132 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
133 else {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
134 PyErr_SetString(PyExc_TypeError,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
135 "structseq index must be integer");
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
136 return NULL;
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
137 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
138 }
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
139
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
140 static PyObject *
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 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
142 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 PyObject *arg = NULL;
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
144 PyObject *dict = NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
145 PyObject *ob;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 PyStructSequence *res = NULL;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
147 Py_ssize_t len, min_len, max_len, i, n_unnamed_fields;
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36519
diff changeset
148 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
149
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
150 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:structseq",
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
151 kwlist, &arg, &dict))
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 return NULL;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
154 arg = PySequence_Fast(arg, "constructor requires a sequence");
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
155
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
156 if (!arg) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
157 return NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
158 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
159
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
160 if (dict && !PyDict_Check(dict)) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
161 PyErr_Format(PyExc_TypeError,
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
162 "%.500s() takes a dict as second arg, if any",
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
163 type->tp_name);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
164 Py_DECREF(arg);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 return NULL;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
168 len = PySequence_Fast_GET_SIZE(arg);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
169 min_len = VISIBLE_SIZE_TP(type);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
170 max_len = REAL_SIZE_TP(type);
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
171 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
172
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
173 if (min_len != max_len) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
174 if (len < min_len) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
175 PyErr_Format(PyExc_TypeError,
36510
0f3894bb2ada Support %zd in PyErr_Format and PyString_FromFormat.
Martin v. Löwis <martin@v.loewis.de>
parents: 36509
diff changeset
176 "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
36511
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
177 type->tp_name, min_len, len);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
178 Py_DECREF(arg);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
179 return NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
180 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
181
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
182 if (len > max_len) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
183 PyErr_Format(PyExc_TypeError,
36510
0f3894bb2ada Support %zd in PyErr_Format and PyString_FromFormat.
Martin v. Löwis <martin@v.loewis.de>
parents: 36509
diff changeset
184 "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
36511
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
185 type->tp_name, max_len, len);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
186 Py_DECREF(arg);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
187 return NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
188 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
189 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
190 else {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
191 if (len != min_len) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
192 PyErr_Format(PyExc_TypeError,
36510
0f3894bb2ada Support %zd in PyErr_Format and PyString_FromFormat.
Martin v. Löwis <martin@v.loewis.de>
parents: 36509
diff changeset
193 "%.500s() takes a %zd-sequence (%zd-sequence given)",
36511
1596ff5c79b5 Revert 42400.
Martin v. Löwis <martin@v.loewis.de>
parents: 36510
diff changeset
194 type->tp_name, min_len, len);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
195 Py_DECREF(arg);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
196 return NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
197 }
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 res = (PyStructSequence*) PyStructSequence_New(type);
26708
3593f2b91d7d SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents: 25808
diff changeset
201 if (res == NULL) {
3593f2b91d7d SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents: 25808
diff changeset
202 return NULL;
3593f2b91d7d SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents: 25808
diff changeset
203 }
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 for (i = 0; i < len; ++i) {
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
205 PyObject *v = PySequence_Fast_GET_ITEM(arg, i);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
206 Py_INCREF(v);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
207 res->ob_item[i] = v;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
208 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
209 for (; i < max_len; ++i) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
210 if (dict && (ob = PyDict_GetItemString(
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
211 dict, type->tp_members[i-n_unnamed_fields].name))) {
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
212 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
213 else {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
214 ob = Py_None;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
215 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
216 Py_INCREF(ob);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
217 res->ob_item[i] = ob;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
220 Py_DECREF(arg);
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 return (PyObject*) res;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
222 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 make_tuple(PyStructSequence *obj)
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 return structseq_slice(obj, 0, VISIBLE_SIZE(obj));
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
228 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 structseq_repr(PyStructSequence *obj)
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 PyObject *tup, *str;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 tup = make_tuple(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 str = PyObject_Repr(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 return str;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
239
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 structseq_concat(PyStructSequence *obj, PyObject *b)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 PyObject *tup, *result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 tup = make_tuple(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 result = PySequence_Concat(tup, b);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 return result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 static PyObject *
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
251 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
252 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 PyObject *tup, *result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 tup = make_tuple(obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 result = PySequence_Repeat(tup, n);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 return result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
259
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 static int
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 structseq_contains(PyStructSequence *obj, PyObject *o)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 PyObject *tup;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 int result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 tup = make_tuple(obj);
39445
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 37745
diff changeset
266 if (!tup)
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 37745
diff changeset
267 return -1;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 result = PySequence_Contains(tup, o);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 return result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
271 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
272
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 static long
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 structseq_hash(PyObject *obj)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
276 PyObject *tup;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 long result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 tup = make_tuple((PyStructSequence*) obj);
39445
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 37745
diff changeset
279 if (!tup)
e11caad7e029 Klocwork made another run and found a bunch more problems.
Neal Norwitz <nnorwitz@gmail.com>
parents: 37745
diff changeset
280 return -1;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 result = PyObject_Hash(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 return result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
285
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 static PyObject *
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 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
288 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 PyObject *tup, *result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 tup = make_tuple((PyStructSequence*) obj);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 result = PyObject_RichCompare(tup, o2, op);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 Py_DECREF(tup);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 return result;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 }
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
295
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
296 static PyObject *
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
297 structseq_reduce(PyStructSequence* self)
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
298 {
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
299 PyObject* tup;
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
300 PyObject* dict;
22168
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
301 PyObject* result;
36519
d6d415df0df0 Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36511
diff changeset
302 Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields;
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
303 int i;
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
304
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
305 n_fields = REAL_SIZE(self);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
306 n_visible_fields = VISIBLE_SIZE(self);
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
307 n_unnamed_fields = UNNAMED_FIELDS(self);
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
308 tup = PyTuple_New(n_visible_fields);
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
309 if (!tup) {
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
310 return NULL;
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
311 }
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
312
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
313 dict = PyDict_New();
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
314 if (!dict) {
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
315 Py_DECREF(tup);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
316 return NULL;
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
317 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
318
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
319 for (i = 0; i < n_visible_fields; i++) {
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
320 Py_INCREF(self->ob_item[i]);
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
321 PyTuple_SET_ITEM(tup, i, self->ob_item[i]);
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
322 }
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
323
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
324 for (; i < n_fields; i++) {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
325 char *n = Py_Type(self)->tp_members[i-n_unnamed_fields].name;
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
326 PyDict_SetItemString(dict, n,
22166
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
327 self->ob_item[i]);
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
328 }
837951ecdce9 After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents: 22137
diff changeset
329
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
330 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
331
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
332 Py_DECREF(tup);
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
333 Py_DECREF(dict);
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
334
68831ac5495b backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22166
diff changeset
335 return result;
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
336 }
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
337
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 static PySequenceMethods structseq_as_sequence = {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
339 (lenfunc)structseq_length,
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 (binaryfunc)structseq_concat, /* sq_concat */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
341 (ssizeargfunc)structseq_repeat, /* sq_repeat */
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
342 (ssizeargfunc)structseq_item, /* sq_item */
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 35999
diff changeset
343 (ssizessizeargfunc)structseq_slice, /* sq_slice */
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 0, /* sq_ass_item */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 0, /* sq_ass_slice */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 (objobjproc)structseq_contains, /* sq_contains */
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
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
349 static PyMappingMethods structseq_as_mapping = {
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
350 (lenfunc)structseq_length,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
351 (binaryfunc)structseq_subscript,
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
352 };
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
353
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
354 static PyMethodDef structseq_methods[] = {
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
355 {"__reduce__", (PyCFunction)structseq_reduce,
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
356 METH_NOARGS, NULL},
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
357 {NULL, NULL}
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
358 };
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
359
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 static PyTypeObject _struct_sequence_template = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 39445
diff changeset
361 PyVarObject_HEAD_INIT(&PyType_Type, 0)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 NULL, /* tp_name */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 0, /* tp_basicsize */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 0, /* tp_itemsize */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 (destructor)structseq_dealloc, /* tp_dealloc */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 0, /* tp_print */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 0, /* tp_getattr */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 0, /* tp_setattr */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 0, /* tp_compare */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 (reprfunc)structseq_repr, /* tp_repr */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 0, /* tp_as_number */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 &structseq_as_sequence, /* tp_as_sequence */
42951
9620134010a5 Improve extended slicing support in builtin types and classes. Specifically:
Thomas Wouters <thomas@python.org>
parents: 42333
diff changeset
373 &structseq_as_mapping, /* tp_as_mapping */
37304
79a0f080f898 Remove unnecessary casts in type object initializers.
Georg Brandl <georg@python.org>
parents: 36675
diff changeset
374 structseq_hash, /* tp_hash */
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 0, /* tp_call */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 0, /* tp_str */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 0, /* tp_getattro */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 0, /* tp_setattro */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 0, /* tp_as_buffer */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 Py_TPFLAGS_DEFAULT, /* tp_flags */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 NULL, /* tp_doc */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 0, /* tp_traverse */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 0, /* tp_clear */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 structseq_richcompare, /* tp_richcompare */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
385 0, /* tp_weaklistoffset */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 0, /* tp_iter */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 0, /* tp_iternext */
22137
1a5110b4bd72 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 21081
diff changeset
388 structseq_methods, /* tp_methods */
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 NULL, /* tp_members */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 0, /* tp_getset */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 0, /* tp_base */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 0, /* tp_dict */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 0, /* tp_descr_get */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 0, /* tp_descr_set */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 0, /* tp_dictoffset */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 0, /* tp_init */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 0, /* tp_alloc */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 structseq_new, /* tp_new */
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 };
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
400
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
401 void
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 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
403 {
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 PyObject *dict;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 PyMemberDef* members;
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
406 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
407
37745
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
408 #ifdef Py_TRACE_REFS
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
409 /* if the type object was chained, unchain it first
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
410 before overwriting its storage */
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
411 if (type->_ob_next) {
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
412 _Py_ForgetReference((PyObject*)type);
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
413 }
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
414 #endif
353fe06dab5b Unlink the structseq type from the global list of
Martin v. Löwis <martin@v.loewis.de>
parents: 37304
diff changeset
415
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
416 n_unnamed_members = 0;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 for (i = 0; desc->fields[i].name != NULL; ++i)
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
418 if (desc->fields[i].name == PyStructSequence_UnnamedField)
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
419 n_unnamed_members++;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 n_members = i;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
421
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 memcpy(type, &_struct_sequence_template, sizeof(PyTypeObject));
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 type->tp_name = desc->name;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 type->tp_doc = desc->doc;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 type->tp_basicsize = sizeof(PyStructSequence)+
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 sizeof(PyObject*)*(n_members-1);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 type->tp_itemsize = 0;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
428
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
429 members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1);
26708
3593f2b91d7d SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents: 25808
diff changeset
430 if (members == NULL)
3593f2b91d7d SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents: 25808
diff changeset
431 return;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
432
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
433 for (i = k = 0; i < n_members; ++i) {
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
434 if (desc->fields[i].name == PyStructSequence_UnnamedField)
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
435 continue;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
436 members[k].name = desc->fields[i].name;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
437 members[k].type = T_OBJECT;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
438 members[k].offset = offsetof(PyStructSequence, ob_item)
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 + i * sizeof(PyObject*);
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
440 members[k].flags = READONLY;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
441 members[k].doc = desc->fields[i].doc;
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
442 k++;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 }
25806
0bbea4dcd9be Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents: 22978
diff changeset
444 members[k].name = NULL;
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
445
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 type->tp_members = members;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
447
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 if (PyType_Ready(type) < 0)
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 return;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 Py_INCREF(type);
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
451
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 dict = type->tp_dict;
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 PyDict_SetItemString(dict, visible_length_key,
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 PyInt_FromLong((long) desc->n_in_sequence));
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 PyDict_SetItemString(dict, real_length_key,
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
456 PyInt_FromLong((long) n_members));
25808
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
457 PyDict_SetItemString(dict, unnamed_fields_key,
fdca87c4234e Add n_unnamed_fields into the type.
Martin v. Löwis <martin@v.loewis.de>
parents: 25806
diff changeset
458 PyInt_FromLong((long) n_unnamed_members));
20540
ad2662095d77 Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 }