This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients brett.cannon, christian.heimes, gvanrossum
Date 2008-01-13.22:41:19
SpamBayes Score 0.022955572
Marked as misclassified No
Message-id <1200264081.76.0.669683012812.issue1816@psf.upfronthosting.co.za>
In-reply-to
Content
Does anybody see a problem with this repr slot implementation for
structseq? It gives this output:

>>> os.stat(".")
<posix.stat_result st_mode=16832, st_ino=11666571L, st_dev=65025L,
st_nlink=20, st_uid=1000, st_gid=1000, st_size=4096L,
st_atime=1200261754, st_mtime=1200261721, st_ctime=1200261721>

static PyObject *
structseq_repr(PyStructSequence *obj)
{
	PyObject *tup, *val, *repr;
	PyTypeObject *typ = Py_TYPE(obj);
	int i, len;
	char buf[250+5]; /* "...>\0" */
	char *cname, *crepr;
	char *pbuf = buf;
 	char *endbuf = &buf[250];

	*pbuf++ = '<';
	strncpy(pbuf, typ->tp_name, 50);
	pbuf += strlen(typ->tp_name) > 50 ? 50 : strlen(typ->tp_name);
	*pbuf++ = ' ';

	if ((tup = make_tuple(obj)) == NULL) {
		return NULL;
	}
	for (i=0; i < VISIBLE_SIZE(obj); i++) {
		cname = typ->tp_members[i].name;
		val = PyTuple_GetItem(tup, i);
		if (cname == NULL || val == NULL) {
			return NULL;
		}
		repr = PyObject_Repr(val);
		if (repr == NULL) {
			Py_DECREF(tup);
			return NULL;
		}
		crepr = PyString_AsString(repr);
		if (crepr == NULL) {
			Py_DECREF(tup);
			Py_DECREF(repr);
			return NULL;
		}
		len = strlen(cname) + strlen(crepr) + 3;
		if ((pbuf+len) < endbuf) {
			strcpy(pbuf, cname);
			pbuf += strlen(cname);
			*pbuf++ = '=';
			strcpy(pbuf, crepr);
			pbuf += strlen(crepr);
			*pbuf++ = ',';
			*pbuf++ = ' ';
			Py_DECREF(repr);
		}
		else {
			strcpy(pbuf, "...");
			pbuf += 5;
			Py_DECREF(repr);
			break;
		}
	}
	Py_DECREF(tup);

	pbuf-=2;
	*pbuf++ = '>';
	*pbuf = '\0';

	repr = PyString_FromString(buf);
	return repr;
}
History
Date User Action Args
2008-01-13 22:41:21christian.heimessetspambayes_score: 0.0229556 -> 0.022955572
recipients: + christian.heimes, gvanrossum, brett.cannon
2008-01-13 22:41:21christian.heimessetspambayes_score: 0.0229556 -> 0.0229556
messageid: <1200264081.76.0.669683012812.issue1816@psf.upfronthosting.co.za>
2008-01-13 22:41:20christian.heimeslinkissue1816 messages
2008-01-13 22:41:19christian.heimescreate