Mercurial > cpython-lru_cache-weakref
annotate Objects/structseq.c @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | 87fbbf22adf3 |
| children | cab14be0ada1 |
| 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 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
16 #define VISIBLE_SIZE(op) Py_SIZE(op) |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43100
diff
changeset
|
17 #define VISIBLE_SIZE_TP(tp) PyLong_AsLong( \ |
|
20540
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 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43100
diff
changeset
|
20 #define REAL_SIZE_TP(tp) PyLong_AsLong( \ |
|
20540
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)) |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
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 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43100
diff
changeset
|
24 #define UNNAMED_FIELDS_TP(tp) PyLong_AsLong( \ |
|
25808
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)) |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
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; |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
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); |
|
48848
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
35 if (obj == NULL) |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
36 return NULL; |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
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 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 return (PyObject*) obj; |
|
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 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
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 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 size = REAL_SIZE(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 for (i = 0; i < size; ++i) { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 Py_XDECREF(obj->ob_item[i]); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 } |
|
22978
363c7fc174ac
Remove PyMalloc_New and PyMalloc_Del.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22446
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 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 return VISIBLE_SIZE(obj); |
|
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 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 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
|
64 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
|
65 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 Py_INCREF(obj->ob_item[i]); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 return obj->ob_item[i]; |
|
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 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 PyTupleObject *np; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
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 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 if (low < 0) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 low = 0; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 if (high > VISIBLE_SIZE(obj)) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 high = VISIBLE_SIZE(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 if (high < low) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 high = low; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 np = (PyTupleObject *)PyTuple_New(high-low); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 if (np == NULL) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 for(i = low; i < high; ++i) { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 PyObject *v = obj->ob_item[i]; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 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
|
89 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
|
90 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 return (PyObject *) np; |
|
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 * |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
95 structseq_subscript(PyStructSequence *self, PyObject *item) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
96 { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
97 if (PyIndex_Check(item)) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
98 Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
99 if (i == -1 && PyErr_Occurred()) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
100 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
101 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
102 if (i < 0) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
103 i += VISIBLE_SIZE(self); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
104 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
105 if (i < 0 || i >= VISIBLE_SIZE(self)) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
106 PyErr_SetString(PyExc_IndexError, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
107 "tuple index out of range"); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
108 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
109 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
110 Py_INCREF(self->ob_item[i]); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
111 return self->ob_item[i]; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
112 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
113 else if (PySlice_Check(item)) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
114 Py_ssize_t start, stop, step, slicelen, cur, i; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
115 PyObject *result; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
116 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
117 if (PySlice_GetIndicesEx((PySliceObject *)item, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
118 VISIBLE_SIZE(self), &start, &stop, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
119 &step, &slicelen) < 0) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
120 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
121 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
122 if (slicelen <= 0) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
123 return PyTuple_New(0); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
124 result = PyTuple_New(slicelen); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
125 if (result == NULL) |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
126 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
127 for (cur = start, i = 0; i < slicelen; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
128 cur += step, i++) { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
129 PyObject *v = self->ob_item[cur]; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
130 Py_INCREF(v); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
131 PyTuple_SET_ITEM(result, i, v); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
132 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
133 return result; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
134 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
135 else { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
136 PyErr_SetString(PyExc_TypeError, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
137 "structseq index must be integer"); |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
138 return NULL; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
139 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
140 } |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
141 |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
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 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 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
|
146 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
|
147 PyObject *ob; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 PyStructSequence *res = NULL; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
149 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
|
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 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
152 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
|
153 kwlist, &arg, &dict)) |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
156 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
|
157 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
158 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
|
159 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
|
160 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
161 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
162 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
|
163 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
|
164 "%.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
|
165 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
|
166 Py_DECREF(arg); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
170 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
|
171 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
|
172 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
|
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 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 "%.500s() takes an at least %zd-sequence (%zd-sequence given)", |
| 36511 | 179 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
|
180 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
|
181 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
|
182 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
183 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
184 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
|
185 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
|
186 "%.500s() takes an at most %zd-sequence (%zd-sequence given)", |
| 36511 | 187 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
|
188 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
|
189 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
|
190 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
191 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
192 else { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
193 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
|
194 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
|
195 "%.500s() takes a %zd-sequence (%zd-sequence given)", |
| 36511 | 196 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
|
197 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
|
198 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
|
199 } |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 res = (PyStructSequence*) PyStructSequence_New(type); |
|
26708
3593f2b91d7d
SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents:
25808
diff
changeset
|
203 if (res == NULL) { |
|
3593f2b91d7d
SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents:
25808
diff
changeset
|
204 return NULL; |
|
3593f2b91d7d
SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents:
25808
diff
changeset
|
205 } |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
215 else { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
216 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
|
217 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
218 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
|
219 res->ob_item[i] = ob; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
222 Py_DECREF(arg); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 return (PyObject*) res; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 make_tuple(PyStructSequence *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 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
|
230 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 structseq_repr(PyStructSequence *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 { |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
235 /* buffer and type size were chosen well considered. */ |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
236 #define REPR_BUFFER_SIZE 512 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
237 #define TYPE_MAXSIZE 100 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
238 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
239 PyObject *tup; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
240 PyTypeObject *typ = Py_TYPE(obj); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
241 int i, removelast = 0; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
242 Py_ssize_t len; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
243 char buf[REPR_BUFFER_SIZE]; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
244 char *endofbuf, *pbuf = buf; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
245 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
246 /* pointer to end of writeable buffer; safes space for "...)\0" */ |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
247 endofbuf= &buf[REPR_BUFFER_SIZE-5]; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
248 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
249 if ((tup = make_tuple(obj)) == NULL) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
250 return NULL; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
251 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
252 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
253 /* "typename(", limited to TYPE_MAXSIZE */ |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
254 len = strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE : |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
255 strlen(typ->tp_name); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
256 strncpy(pbuf, typ->tp_name, len); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
257 pbuf += len; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
258 *pbuf++ = '('; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
259 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
260 for (i=0; i < VISIBLE_SIZE(obj); i++) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
261 PyObject *val, *repr; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
262 char *cname, *crepr; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
263 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
264 cname = typ->tp_members[i].name; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
265 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
266 val = PyTuple_GetItem(tup, i); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
267 if (cname == NULL || val == NULL) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
268 return NULL; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
269 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
270 repr = PyObject_Repr(val); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
271 if (repr == NULL) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
272 Py_DECREF(tup); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
273 return NULL; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
274 } |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
44674
diff
changeset
|
275 crepr = _PyUnicode_AsString(repr); |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
276 if (crepr == NULL) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
277 Py_DECREF(tup); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
278 Py_DECREF(repr); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
279 return NULL; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
280 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
281 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
282 /* + 3: keep space for "=" and ", " */ |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
283 len = strlen(cname) + strlen(crepr) + 3; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
284 if ((pbuf+len) <= endofbuf) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
285 strcpy(pbuf, cname); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
286 pbuf += strlen(cname); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
287 *pbuf++ = '='; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
288 strcpy(pbuf, crepr); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
289 pbuf += strlen(crepr); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
290 *pbuf++ = ','; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
291 *pbuf++ = ' '; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
292 removelast = 1; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
293 Py_DECREF(repr); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
294 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
295 else { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
296 strcpy(pbuf, "..."); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
297 pbuf += 3; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
298 removelast = 0; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
299 Py_DECREF(repr); |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
300 break; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
301 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
302 } |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 Py_DECREF(tup); |
|
44674
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
304 if (removelast) { |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
305 /* overwrite last ", " */ |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
306 pbuf-=2; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
307 } |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
308 *pbuf++ = ')'; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
309 *pbuf = '\0'; |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
310 |
|
1154158a199f
Merged revisions 59933-59951 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
311 return PyUnicode_FromString(buf); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 structseq_concat(PyStructSequence *obj, PyObject *b) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 result = PySequence_Concat(tup, b); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 } |
|
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 static PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
325 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
|
326 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 result = PySequence_Repeat(tup, n); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
332 } |
|
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 static int |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 structseq_contains(PyStructSequence *obj, PyObject *o) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 PyObject *tup; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 int result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 tup = make_tuple(obj); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
340 if (!tup) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
341 return -1; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
342 result = PySequence_Contains(tup, o); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 } |
|
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 static long |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 structseq_hash(PyObject *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 PyObject *tup; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 long result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 tup = make_tuple((PyStructSequence*) obj); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
353 if (!tup) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
354 return -1; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 result = PyObject_Hash(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 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
|
362 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 tup = make_tuple((PyStructSequence*) obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 result = PyObject_RichCompare(tup, o2, op); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
370 static PyObject * |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
371 structseq_reduce(PyStructSequence* self) |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
372 { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
373 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
|
374 PyObject* dict; |
|
22168
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
375 PyObject* result; |
|
36519
d6d415df0df0
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36511
diff
changeset
|
376 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
|
377 int i; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
378 |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 tup = PyTuple_New(n_visible_fields); |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
383 if (!tup) { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
384 return NULL; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
385 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
386 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 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
|
391 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
392 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
393 for (i = 0; i < n_visible_fields; i++) { |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
394 Py_INCREF(self->ob_item[i]); |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
395 PyTuple_SET_ITEM(tup, i, self->ob_item[i]); |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
396 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
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 for (; i < n_fields; i++) { |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
399 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
|
400 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
|
401 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
|
402 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
403 |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
404 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
|
405 |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
406 Py_DECREF(tup); |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
407 Py_DECREF(dict); |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
408 |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
409 return result; |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
410 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
411 |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 static PySequenceMethods structseq_as_sequence = { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
413 (lenfunc)structseq_length, |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 (binaryfunc)structseq_concat, /* sq_concat */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
415 (ssizeargfunc)structseq_repeat, /* sq_repeat */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
35999
diff
changeset
|
416 (ssizeargfunc)structseq_item, /* sq_item */ |
|
43100
4e6b4ba60c3b
Remove the simple slicing API. All slicing is now done with slice objects.
Thomas Wouters <thomas@python.org>
parents:
42954
diff
changeset
|
417 0, /* sq_slice */ |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 0, /* sq_ass_item */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 0, /* sq_ass_slice */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 (objobjproc)structseq_contains, /* sq_contains */ |
|
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 |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
423 static PyMappingMethods structseq_as_mapping = { |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
424 (lenfunc)structseq_length, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
425 (binaryfunc)structseq_subscript, |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
426 }; |
|
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
427 |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
428 static PyMethodDef structseq_methods[] = { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
429 {"__reduce__", (PyCFunction)structseq_reduce, |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
430 METH_NOARGS, NULL}, |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
431 {NULL, NULL} |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
432 }; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
433 |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 static PyTypeObject _struct_sequence_template = { |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
39610
diff
changeset
|
435 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
|
436 NULL, /* tp_name */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
437 0, /* tp_basicsize */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
438 0, /* tp_itemsize */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 (destructor)structseq_dealloc, /* tp_dealloc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
440 0, /* tp_print */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
441 0, /* tp_getattr */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
442 0, /* tp_setattr */ |
|
51271
87fbbf22adf3
Merged revisions 69214 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48848
diff
changeset
|
443 0, /* tp_reserved */ |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 (reprfunc)structseq_repr, /* tp_repr */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
445 0, /* tp_as_number */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
446 &structseq_as_sequence, /* tp_as_sequence */ |
|
42954
27f0289b6835
Merge the trunk changes in. Breaks socket.ssl for now.
Thomas Wouters <thomas@python.org>
parents:
42334
diff
changeset
|
447 &structseq_as_mapping, /* tp_as_mapping */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
448 structseq_hash, /* tp_hash */ |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
449 0, /* tp_call */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
450 0, /* tp_str */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
451 0, /* tp_getattro */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
452 0, /* tp_setattro */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
453 0, /* tp_as_buffer */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
454 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
455 NULL, /* tp_doc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
456 0, /* tp_traverse */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
457 0, /* tp_clear */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
458 structseq_richcompare, /* tp_richcompare */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
459 0, /* tp_weaklistoffset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
460 0, /* tp_iter */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
461 0, /* tp_iternext */ |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
462 structseq_methods, /* tp_methods */ |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
463 NULL, /* tp_members */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
464 0, /* tp_getset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
465 0, /* tp_base */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
466 0, /* tp_dict */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
467 0, /* tp_descr_get */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
468 0, /* tp_descr_set */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
469 0, /* tp_dictoffset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
470 0, /* tp_init */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
471 0, /* tp_alloc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
472 structseq_new, /* tp_new */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
473 }; |
|
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 void |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
476 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
|
477 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
478 PyObject *dict; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
479 PyMemberDef* members; |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
480 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
|
481 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
482 #ifdef Py_TRACE_REFS |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
483 /* if the type object was chained, unchain it first |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
484 before overwriting its storage */ |
|
42334
e70cdce0e8b2
Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
39610
diff
changeset
|
485 if (type->ob_base.ob_base._ob_next) { |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
486 _Py_ForgetReference((PyObject*)type); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
487 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
488 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36675
diff
changeset
|
489 |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
490 n_unnamed_members = 0; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
491 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
|
492 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
|
493 n_unnamed_members++; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
494 n_members = i; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
495 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
496 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
|
497 type->tp_name = desc->name; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
498 type->tp_doc = desc->doc; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
499 type->tp_basicsize = sizeof(PyStructSequence)+ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
500 sizeof(PyObject*)*(n_members-1); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
501 type->tp_itemsize = 0; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
502 |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
503 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
|
504 if (members == NULL) |
|
3593f2b91d7d
SF # 654974, fix unchecked return values in structseq
Neal Norwitz <nnorwitz@gmail.com>
parents:
25808
diff
changeset
|
505 return; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
506 |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
507 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
|
508 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
|
509 continue; |
|
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 + i * sizeof(PyObject*); |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
514 members[k].flags = READONLY; |
|
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
515 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
|
516 k++; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
517 } |
|
25806
0bbea4dcd9be
Add PyStructSequence_UnnamedField. Add stat_float_times.
Martin v. Löwis <martin@v.loewis.de>
parents:
22978
diff
changeset
|
518 members[k].name = NULL; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
519 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
520 type->tp_members = members; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
521 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
522 if (PyType_Ready(type) < 0) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
523 return; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
524 Py_INCREF(type); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
525 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
526 dict = type->tp_dict; |
|
48848
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
527 #define SET_DICT_FROM_INT(key, value) \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
528 do { \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
529 PyObject *v = PyLong_FromLong((long) value); \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
530 if (v != NULL) { \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
531 PyDict_SetItemString(dict, key, v); \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
532 Py_DECREF(v); \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
533 } \ |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
534 } while (0) |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
535 |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
536 SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence); |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
537 SET_DICT_FROM_INT(real_length_key, n_members); |
|
5c75a33ef5b2
Merged revisions 66006 via svnmerge from
Neal Norwitz <nnorwitz@gmail.com>
parents:
48660
diff
changeset
|
538 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
|
539 } |
