diff options
author | Guido van Rossum <guido@python.org> | 1993-05-12 08:24:20 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-05-12 08:24:20 (GMT) |
commit | 6ac258d381b5300e3ec935404a111e8dff4617d4 (patch) | |
tree | 476a8c807f8f91cc5c259af586b3470201a9c2c1 /Objects/object.c | |
parent | ad4fcd49fc5c9ec93743f93da518b84e0634ea59 (diff) | |
download | cpython-6ac258d381b5300e3ec935404a111e8dff4617d4.zip cpython-6ac258d381b5300e3ec935404a111e8dff4617d4.tar.gz cpython-6ac258d381b5300e3ec935404a111e8dff4617d4.tar.bz2 |
* 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
Diffstat (limited to 'Objects/object.c')
-rw-r--r-- | Objects/object.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c index 9a8d4b3..e28158e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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. |