@@ -30,7 +30,7 @@ PyObject *
3030PyStructSequence_New (PyTypeObject * type )
3131{
3232 PyStructSequence * obj ;
33-
33+
3434 obj = PyObject_New (PyStructSequence , type );
3535 Py_SIZE (obj ) = VISIBLE_SIZE_TP (type );
3636
@@ -230,11 +230,64 @@ make_tuple(PyStructSequence *obj)
230230static PyObject *
231231structseq_repr (PyStructSequence * obj )
232232{
233- PyObject * tup , * str ;
234- tup = make_tuple (obj );
235- str = PyObject_Repr (tup );
233+ PyObject * tup , * val , * repr ;
234+ PyTypeObject * typ = Py_TYPE (obj );
235+ int i , len ;
236+ char buf [250 + 5 ]; /* "...)\0" */
237+ char * cname , * crepr ;
238+ char * pbuf = buf ;
239+ char * endbuf = & buf [250 ];
240+
241+ strncpy (pbuf , typ -> tp_name , 50 );
242+ pbuf += strlen (typ -> tp_name ) > 50 ? 50 : strlen (typ -> tp_name );
243+ * pbuf ++ = '(' ;
244+
245+ if ((tup = make_tuple (obj )) == NULL ) {
246+ return NULL ;
247+ }
248+ for (i = 0 ; i < VISIBLE_SIZE (obj ); i ++ ) {
249+ cname = typ -> tp_members [i ].name ;
250+ val = PyTuple_GetItem (tup , i );
251+ if (cname == NULL || val == NULL ) {
252+ return NULL ;
253+ }
254+ repr = PyObject_Repr (val );
255+ if (repr == NULL ) {
256+ Py_DECREF (tup );
257+ return NULL ;
258+ }
259+ crepr = PyString_AsString (repr );
260+ if (crepr == NULL ) {
261+ Py_DECREF (tup );
262+ Py_DECREF (repr );
263+ return NULL ;
264+ }
265+ len = strlen (cname ) + strlen (crepr ) + 3 ;
266+ if ((pbuf + len ) < endbuf ) {
267+ strcpy (pbuf , cname );
268+ pbuf += strlen (cname );
269+ * pbuf ++ = '=' ;
270+ strcpy (pbuf , crepr );
271+ pbuf += strlen (crepr );
272+ * pbuf ++ = ',' ;
273+ * pbuf ++ = ' ' ;
274+ Py_DECREF (repr );
275+ }
276+ else {
277+ strcpy (pbuf , "..." );
278+ pbuf += 5 ;
279+ Py_DECREF (repr );
280+ break ;
281+ }
282+ }
236283 Py_DECREF (tup );
237- return str ;
284+
285+ pbuf -= 2 ;
286+ * pbuf ++ = ')' ;
287+ * pbuf = '\0' ;
288+
289+ repr = PyString_FromString (buf );
290+ return repr ;
238291}
239292
240293static PyObject *
0 commit comments