summaryrefslogtreecommitdiffstats
path: root/Objects/structseq.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-07-08 22:33:03 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-07-08 22:33:03 (GMT)
commitd02441ea2fcf3862c92bf990ac568d8cb1e19d48 (patch)
treecd26ccb5750523e7ff232d1400c32fc07c05e225 /Objects/structseq.c
parent8c567c540ddabce2536b0f5907ff94408e8e4410 (diff)
downloadcpython-d02441ea2fcf3862c92bf990ac568d8cb1e19d48.zip
cpython-d02441ea2fcf3862c92bf990ac568d8cb1e19d48.tar.gz
cpython-d02441ea2fcf3862c92bf990ac568d8cb1e19d48.tar.bz2
fix repr of complicated structseqs #9206
Diffstat (limited to 'Objects/structseq.c')
-rw-r--r--Objects/structseq.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 647586c..52ff301 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -35,12 +35,27 @@ PyStructSequence_New(PyTypeObject *type)
obj = PyObject_GC_NewVar(PyStructSequence, type, size);
if (obj == NULL)
return NULL;
+ /* Hack the size of the variable object, so invisible fields don't appear
+ to Python code. */
+ Py_SIZE(obj) = VISIBLE_SIZE_TP(type);
for (i = 0; i < size; i++)
obj->ob_item[i] = NULL;
return (PyObject*)obj;
}
+static void
+structseq_dealloc(PyStructSequence *obj)
+{
+ Py_ssize_t i, size;
+
+ size = REAL_SIZE(obj);
+ for (i = 0; i < size; ++i) {
+ Py_XDECREF(obj->ob_item[i]);
+ }
+ PyObject_GC_Del(obj);
+}
+
static PyObject *
structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
@@ -154,8 +169,11 @@ structseq_repr(PyStructSequence *obj)
char *cname, *crepr;
cname = typ->tp_members[i].name;
- if (cname == NULL)
+ if (cname == NULL) {
+ PyErr_Format(PyExc_SystemError, "In structseq_repr(), member %d name is NULL"
+ " for type %.500s", i, typ->tp_name);
return NULL;
+ }
val = PyStructSequence_GET_ITEM(obj, i);
repr = PyObject_Repr(val);
if (repr == NULL)
@@ -249,7 +267,7 @@ static PyTypeObject _struct_sequence_template = {
NULL, /* tp_name */
sizeof(PyStructSequence) - sizeof(PyObject *), /* tp_basicsize */
sizeof(PyObject *), /* tp_itemsize */
- 0, /* tp_dealloc */
+ (destructor)structseq_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */