]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Declare ticker as int; made testbool generic for all numeric types
authorGuido van Rossum <guido@python.org>
Tue, 14 May 1991 11:51:49 +0000 (11:51 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 14 May 1991 11:51:49 +0000 (11:51 +0000)
Python/ceval.c

index 99570e9860bc30728b4af8a8662de2cb5277618e..82410d5a3aba8331d1c827db3afc8db2016d947f 100644 (file)
@@ -162,7 +162,7 @@ eval_code(co, globals, locals, arg)
        lineno = -1;
        
        for (;;) {
-               static ticker;
+               static int ticker;
                
                /* Do periodic things */
                
@@ -983,16 +983,14 @@ static int
 testbool(v)
        object *v;
 {
-       if (is_intobject(v))
-               return getintvalue(v) != 0;
-       if (is_floatobject(v))
-               return getfloatvalue(v) != 0.0;
+       if (v == None)
+               return 0;
+       if (v->ob_type->tp_as_number != NULL)
+               return (*v->ob_type->tp_as_number->nb_nonzero)(v);
        if (v->ob_type->tp_as_sequence != NULL)
                return (*v->ob_type->tp_as_sequence->sq_length)(v) != 0;
        if (v->ob_type->tp_as_mapping != NULL)
                return (*v->ob_type->tp_as_mapping->mp_length)(v) != 0;
-       if (v == None)
-               return 0;
        /* All other objects are 'true' */
        return 1;
 }