Mercurial > cpython-lru_cache-weakref
annotate Objects/structseq.c @ 24042:63fbbed10714 legacy-trunk
Simplify HTTPSConnection constructor.
See discussion in SF bug 458463.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Fri, 28 Jun 2002 23:38:14 +0000 |
| parents | 363c7fc174ac |
| children | 0bbea4dcd9be |
| 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"; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #define VISIBLE_SIZE(op) ((op)->ob_size) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #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
|
13 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
|
14 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 #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
|
16 PyDict_GetItemString((tp)->tp_dict, real_length_key)) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 #define REAL_SIZE(op) REAL_SIZE_TP((op)->ob_type) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
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 PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 PyStructSequence_New(PyTypeObject *type) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 PyStructSequence *obj; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
22978
363c7fc174ac
Remove PyMalloc_New and PyMalloc_Del.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22446
diff
changeset
|
25 obj = PyObject_New(PyStructSequence, type); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 obj->ob_size = VISIBLE_SIZE_TP(type); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 return (PyObject*) obj; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 static void |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 structseq_dealloc(PyStructSequence *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 int i, size; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 size = REAL_SIZE(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 for (i = 0; i < size; ++i) { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 Py_XDECREF(obj->ob_item[i]); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 } |
|
22978
363c7fc174ac
Remove PyMalloc_New and PyMalloc_Del.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22446
diff
changeset
|
40 PyObject_Del(obj); |
|
20540
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 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 static int |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 structseq_length(PyStructSequence *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 return VISIBLE_SIZE(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 static PyObject* |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 structseq_item(PyStructSequence *obj, int i) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 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
|
53 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
|
54 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 Py_INCREF(obj->ob_item[i]); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 return obj->ob_item[i]; |
|
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* |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 structseq_slice(PyStructSequence *obj, int low, int high) |
|
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 PyTupleObject *np; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 int i; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 if (low < 0) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 low = 0; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 if (high > VISIBLE_SIZE(obj)) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 high = VISIBLE_SIZE(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 if (high < low) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 high = low; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 np = (PyTupleObject *)PyTuple_New(high-low); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 if (np == NULL) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 for(i = low; i < high; ++i) { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 PyObject *v = obj->ob_item[i]; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 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
|
78 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
|
79 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 return (PyObject *) np; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 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
|
85 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 PyObject *ob; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 PyStructSequence *res = 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
|
90 int len, min_len, 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
|
91 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
|
92 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
93 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
|
94 kwlist, &arg, &dict)) |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
97 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
|
98 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
99 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
|
100 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
|
101 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
102 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
103 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
|
104 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
|
105 "%.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
|
106 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
|
107 Py_DECREF(arg); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 return NULL; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
111 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
|
112 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
|
113 max_len = REAL_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
|
114 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 "%.500s() takes an at least %d-sequence (%d-sequence given)", |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
119 type->tp_name, min_len, len); |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
120 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
|
121 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
|
122 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
123 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
124 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
|
125 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
|
126 "%.500s() takes an at most %d-sequence (%d-sequence given)", |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
127 type->tp_name, max_len, len); |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
128 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
|
129 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
|
130 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
131 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
132 else { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
133 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
|
134 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
|
135 "%.500s() takes a %d-sequence (%d-sequence given)", |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
136 type->tp_name, min_len, len); |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
137 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
|
138 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
|
139 } |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 res = (PyStructSequence*) PyStructSequence_New(type); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
148 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
|
149 if (dict && (ob = PyDict_GetItemString( |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
150 dict, type->tp_members[i].name))) { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
151 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
152 else { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
153 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
|
154 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
155 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
|
156 res->ob_item[i] = ob; |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
159 Py_DECREF(arg); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 return (PyObject*) res; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 make_tuple(PyStructSequence *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 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
|
167 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 structseq_repr(PyStructSequence *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 PyObject *tup, *str; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 str = PyObject_Repr(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 return str; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 structseq_concat(PyStructSequence *obj, PyObject *b) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 result = PySequence_Concat(tup, b); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 structseq_repeat(PyStructSequence *obj, int n) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 result = PySequence_Repeat(tup, n); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 } |
|
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 static int |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 structseq_contains(PyStructSequence *obj, PyObject *o) |
|
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 PyObject *tup; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 int result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 tup = make_tuple(obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 result = PySequence_Contains(tup, o); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 static long |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 structseq_hash(PyObject *obj) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 PyObject *tup; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 long result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 tup = make_tuple((PyStructSequence*) obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 result = PyObject_Hash(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 return result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 } |
|
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 static PyObject * |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 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
|
223 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 PyObject *tup, *result; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 tup = make_tuple((PyStructSequence*) obj); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 result = PyObject_RichCompare(tup, o2, op); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 Py_DECREF(tup); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 return result; |
|
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 |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
231 static PyObject * |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
232 structseq_reduce(PyStructSequence* self) |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
233 { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
234 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
|
235 PyObject* dict; |
|
22168
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
236 PyObject* result; |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
237 long n_fields, n_visible_fields; |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
238 int i; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
239 |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
240 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
|
241 n_visible_fields = VISIBLE_SIZE(self); |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
242 tup = PyTuple_New(n_visible_fields); |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
243 if (!tup) { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
244 return NULL; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
245 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
246 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
247 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
|
248 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
|
249 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
|
250 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
|
251 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
252 |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
253 for (i = 0; i < n_visible_fields; i++) { |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
254 Py_INCREF(self->ob_item[i]); |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
255 PyTuple_SET_ITEM(tup, i, self->ob_item[i]); |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
256 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
257 |
|
22166
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
258 for (; i < n_fields; i++) { |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
259 PyDict_SetItemString(dict, self->ob_type->tp_members[i].name, |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
260 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
|
261 } |
|
837951ecdce9
After some thinking, I decided to move all of this across onto
Michael W. Hudson <mwh@python.net>
parents:
22137
diff
changeset
|
262 |
|
22168
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
263 result = Py_BuildValue("(O(OO))", self->ob_type, tup, dict); |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
264 |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
265 Py_DECREF(tup); |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
266 Py_DECREF(dict); |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
267 |
|
68831ac5495b
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
22166
diff
changeset
|
268 return result; |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
269 } |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
270 |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 static PySequenceMethods structseq_as_sequence = { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 (inquiry)structseq_length, |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 (binaryfunc)structseq_concat, /* sq_concat */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
274 (intargfunc)structseq_repeat, /* sq_repeat */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 (intargfunc)structseq_item, /* sq_item */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 (intintargfunc)structseq_slice, /* sq_slice */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 0, /* sq_ass_item */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 0, /* sq_ass_slice */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 (objobjproc)structseq_contains, /* sq_contains */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 }; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
282 static PyMethodDef structseq_methods[] = { |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
283 {"__reduce__", (PyCFunction)structseq_reduce, |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
284 METH_NOARGS, NULL}, |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
285 {NULL, NULL} |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
286 }; |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
287 |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
288 static PyTypeObject _struct_sequence_template = { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
289 PyObject_HEAD_INIT(&PyType_Type) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
290 0, /* ob_size */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
291 NULL, /* tp_name */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 0, /* tp_basicsize */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 0, /* tp_itemsize */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 (destructor)structseq_dealloc, /* tp_dealloc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 0, /* tp_print */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 0, /* tp_getattr */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 0, /* tp_setattr */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 0, /* tp_compare */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 (reprfunc)structseq_repr, /* tp_repr */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 0, /* tp_as_number */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 &structseq_as_sequence, /* tp_as_sequence */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 0, /* tp_as_mapping */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 (hashfunc)structseq_hash, /* tp_hash */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 0, /* tp_call */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 0, /* tp_str */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 0, /* tp_getattro */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 0, /* tp_setattro */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 0, /* tp_as_buffer */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
310 NULL, /* tp_doc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 0, /* tp_traverse */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 0, /* tp_clear */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 structseq_richcompare, /* tp_richcompare */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
314 0, /* tp_weaklistoffset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
315 0, /* tp_iter */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
316 0, /* tp_iternext */ |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
317 structseq_methods, /* tp_methods */ |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 NULL, /* tp_members */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 0, /* tp_getset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 0, /* tp_base */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 0, /* tp_dict */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 0, /* tp_descr_get */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 0, /* tp_descr_set */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 0, /* tp_dictoffset */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 0, /* tp_init */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 0, /* tp_alloc */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
327 structseq_new, /* tp_new */ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 }; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 void |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 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
|
332 { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 PyObject *dict; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 PyMemberDef* members; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 int n_members, i; |
|
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 for (i = 0; desc->fields[i].name != NULL; ++i) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 ; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 n_members = i; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 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
|
342 type->tp_name = desc->name; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 type->tp_doc = desc->doc; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 type->tp_basicsize = sizeof(PyStructSequence)+ |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 sizeof(PyObject*)*(n_members-1); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 type->tp_itemsize = 0; |
|
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 members = PyMem_NEW(PyMemberDef, n_members+1); |
|
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 for (i = 0; i < n_members; ++i) { |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 members[i].name = desc->fields[i].name; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
352 members[i].type = T_OBJECT; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 members[i].offset = offsetof(PyStructSequence, ob_item) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 + i * sizeof(PyObject*); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 members[i].flags = READONLY; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 members[i].doc = desc->fields[i].doc; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
357 } |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 members[n_members].name = NULL; |
|
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 type->tp_members = members; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
362 if (PyType_Ready(type) < 0) |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 return; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 Py_INCREF(type); |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 dict = type->tp_dict; |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
367 PyDict_SetItemString(dict, visible_length_key, |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 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
|
369 PyDict_SetItemString(dict, real_length_key, |
|
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 PyInt_FromLong((long) n_members)); |
|
22137
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
371 PyDict_SetItemString(dict, "__safe_for_unpickling__", |
|
1a5110b4bd72
backport my checkin of
Michael W. Hudson <mwh@python.net>
parents:
21081
diff
changeset
|
372 PyInt_FromLong(1)); |
|
20540
ad2662095d77
Missing file structseq.c for SF patch #462296
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 } |
