mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
* pythonrun.c: Print exception type+arg *after* stack trace instead of
before it. * ceval.c, object.c: moved testbool() to object.c (now extern visible) * stringobject.c: fix bugs in and rationalize string resize in formatstring() * tokenizer.[ch]: fix non-working code for lines longer than BUFSIZ
This commit is contained in:
parent
ad4fcd49fc
commit
6ac258d381
7 changed files with 95 additions and 81 deletions
|
|
@ -213,6 +213,29 @@ setattr(v, name, w)
|
|||
}
|
||||
}
|
||||
|
||||
/* Test a value used as condition, e.g., in a for or if statement.
|
||||
Return -1 if an error occurred */
|
||||
|
||||
int
|
||||
testbool(v)
|
||||
object *v;
|
||||
{
|
||||
int res;
|
||||
if (v == None)
|
||||
res = 0;
|
||||
else if (v->ob_type->tp_as_number != NULL)
|
||||
res = (*v->ob_type->tp_as_number->nb_nonzero)(v);
|
||||
else if (v->ob_type->tp_as_mapping != NULL)
|
||||
res = (*v->ob_type->tp_as_mapping->mp_length)(v);
|
||||
else if (v->ob_type->tp_as_sequence != NULL)
|
||||
res = (*v->ob_type->tp_as_sequence->sq_length)(v);
|
||||
else
|
||||
res = 1;
|
||||
if (res > 0)
|
||||
res = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
NoObject is usable as a non-NULL undefined value, used by the macro None.
|
||||
|
|
|
|||
|
|
@ -491,13 +491,13 @@ formatstring(format, args)
|
|||
err_badcall();
|
||||
return NULL;
|
||||
}
|
||||
reslen = rescnt = 100;
|
||||
fmt = getstringvalue(format);
|
||||
fmtcnt = getstringsize(format);
|
||||
reslen = rescnt = fmtcnt + 100;
|
||||
result = newsizedstringobject((char *)NULL, reslen);
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
res = getstringvalue(result);
|
||||
fmt = getstringvalue(format);
|
||||
fmtcnt = getstringsize(format);
|
||||
if (is_tupleobject(args)) {
|
||||
arglen = gettuplesize(args);
|
||||
argidx = 0;
|
||||
|
|
@ -509,12 +509,11 @@ formatstring(format, args)
|
|||
while (--fmtcnt >= 0) {
|
||||
if (*fmt != '%') {
|
||||
if (--rescnt < 0) {
|
||||
rescnt = reslen;
|
||||
reslen = reslen * 2; /* Maybe less when big? */
|
||||
rescnt = fmtcnt + 100;
|
||||
reslen += rescnt;
|
||||
if (resizestring(&result, reslen) < 0)
|
||||
return NULL;
|
||||
res = getstringvalue(result) + rescnt;
|
||||
rescnt = reslen - rescnt;
|
||||
res = getstringvalue(result) + reslen - rescnt;
|
||||
}
|
||||
*res++ = *fmt++;
|
||||
}
|
||||
|
|
@ -692,12 +691,12 @@ formatstring(format, args)
|
|||
if (width < len)
|
||||
width = len;
|
||||
if (rescnt < width + (sign != '\0')) {
|
||||
rescnt = reslen;
|
||||
reslen = reslen + width + 100;
|
||||
reslen -= rescnt;
|
||||
rescnt = width + fmtcnt + 100;
|
||||
reslen += rescnt;
|
||||
if (resizestring(&result, reslen) < 0)
|
||||
return NULL;
|
||||
res = getstringvalue(result) + rescnt;
|
||||
rescnt = reslen - rescnt;
|
||||
res = getstringvalue(result) + reslen - rescnt;
|
||||
}
|
||||
if (sign) {
|
||||
*res++ = sign;
|
||||
|
|
|
|||
|
|
@ -137,4 +137,5 @@ static typeobject Xxtype = {
|
|||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash*/
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue