mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Declare ticker as int; made testbool generic for all numeric types
This commit is contained in:
parent
f023c463d7
commit
4965bc8ac4
1 changed files with 5 additions and 7 deletions
|
@ -162,7 +162,7 @@ eval_code(co, globals, locals, arg)
|
||||||
lineno = -1;
|
lineno = -1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
static ticker;
|
static int ticker;
|
||||||
|
|
||||||
/* Do periodic things */
|
/* Do periodic things */
|
||||||
|
|
||||||
|
@ -983,16 +983,14 @@ static int
|
||||||
testbool(v)
|
testbool(v)
|
||||||
object *v;
|
object *v;
|
||||||
{
|
{
|
||||||
if (is_intobject(v))
|
if (v == None)
|
||||||
return getintvalue(v) != 0;
|
return 0;
|
||||||
if (is_floatobject(v))
|
if (v->ob_type->tp_as_number != NULL)
|
||||||
return getfloatvalue(v) != 0.0;
|
return (*v->ob_type->tp_as_number->nb_nonzero)(v);
|
||||||
if (v->ob_type->tp_as_sequence != NULL)
|
if (v->ob_type->tp_as_sequence != NULL)
|
||||||
return (*v->ob_type->tp_as_sequence->sq_length)(v) != 0;
|
return (*v->ob_type->tp_as_sequence->sq_length)(v) != 0;
|
||||||
if (v->ob_type->tp_as_mapping != NULL)
|
if (v->ob_type->tp_as_mapping != NULL)
|
||||||
return (*v->ob_type->tp_as_mapping->mp_length)(v) != 0;
|
return (*v->ob_type->tp_as_mapping->mp_length)(v) != 0;
|
||||||
if (v == None)
|
|
||||||
return 0;
|
|
||||||
/* All other objects are 'true' */
|
/* All other objects are 'true' */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue