comparison Modules/arraymodule.c @ 15396:b71459aeda95 legacy-trunk

Fix for SF bug 117402, crashes on str(array) and repr(array). This was an unfortunate consequence of somebody switching from PyArg_Parse to PyArg_ParseTuple but without changing the argument from a NULL to a tuple.
author Tim Peters <tim.peters@gmail.com>
date Fri, 10 Nov 2000 19:04:19 +0000
parents 25ddd3dc7a7a
children 54205828b1e1
comparison
equal deleted inserted replaced
15395:d265bf4ada7c 15396:b71459aeda95
1189 static int 1189 static int
1190 array_print(arrayobject *a, FILE *fp, int flags) 1190 array_print(arrayobject *a, FILE *fp, int flags)
1191 { 1191 {
1192 int ok = 0; 1192 int ok = 0;
1193 int i, len; 1193 int i, len;
1194 PyObject *t_empty = PyTuple_New(0);
1195 PyObject *v; 1194 PyObject *v;
1196 len = a->ob_size; 1195 len = a->ob_size;
1197 if (len == 0) { 1196 if (len == 0) {
1198 fprintf(fp, "array('%c')", a->ob_descr->typecode); 1197 fprintf(fp, "array('%c')", a->ob_descr->typecode);
1199 return ok; 1198 return ok;
1200 } 1199 }
1201 if (a->ob_descr->typecode == 'c') { 1200 if (a->ob_descr->typecode == 'c') {
1201 PyObject *t_empty = PyTuple_New(0);
1202 fprintf(fp, "array('c', "); 1202 fprintf(fp, "array('c', ");
1203 v = array_tostring(a, t_empty); 1203 v = array_tostring(a, t_empty);
1204 Py_DECREF(t_empty);; 1204 Py_DECREF(t_empty);
1205 ok = PyObject_Print(v, fp, 0); 1205 ok = PyObject_Print(v, fp, 0);
1206 Py_XDECREF(v); 1206 Py_XDECREF(v);
1207 fprintf(fp, ")"); 1207 fprintf(fp, ")");
1208 return ok; 1208 return ok;
1209 } 1209 }
1229 if (len == 0) { 1229 if (len == 0) {
1230 sprintf(buf, "array('%c')", a->ob_descr->typecode); 1230 sprintf(buf, "array('%c')", a->ob_descr->typecode);
1231 return PyString_FromString(buf); 1231 return PyString_FromString(buf);
1232 } 1232 }
1233 if (a->ob_descr->typecode == 'c') { 1233 if (a->ob_descr->typecode == 'c') {
1234 PyObject *t_empty = PyTuple_New(0);
1234 sprintf(buf, "array('c', "); 1235 sprintf(buf, "array('c', ");
1235 s = PyString_FromString(buf); 1236 s = PyString_FromString(buf);
1236 v = array_tostring(a, (PyObject *)NULL); 1237 v = array_tostring(a, t_empty);
1238 Py_DECREF(t_empty);
1237 t = PyObject_Repr(v); 1239 t = PyObject_Repr(v);
1238 Py_XDECREF(v); 1240 Py_XDECREF(v);
1239 PyString_ConcatAndDel(&s, t); 1241 PyString_ConcatAndDel(&s, t);
1240 PyString_ConcatAndDel(&s, PyString_FromString(")")); 1242 PyString_ConcatAndDel(&s, PyString_FromString(")"));
1241 return s; 1243 return s;