From c3e72a8cc818b8777c253d4fddcf92181bf06b23 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 23 Jan 2014 03:24:53 +0200 Subject: [PATCH] mp_obj_is_callable(): Only object types can be callable. Fixes segfault on callable("string"). --- py/obj.c | 2 +- tests/basics/builtin-callable.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/basics/builtin-callable.py diff --git a/py/obj.c b/py/obj.c index c2f726bb99..660df4dfa1 100644 --- a/py/obj.c +++ b/py/obj.c @@ -66,7 +66,7 @@ void mp_obj_print_exception(mp_obj_t exc) { } bool mp_obj_is_callable(mp_obj_t o_in) { - if (MP_OBJ_IS_SMALL_INT(o_in)) { + if (!MP_OBJ_IS_OBJ(o_in)) { return false; } else { mp_obj_base_t *o = o_in; diff --git a/tests/basics/builtin-callable.py b/tests/basics/builtin-callable.py new file mode 100644 index 0000000000..caddb885cf --- /dev/null +++ b/tests/basics/builtin-callable.py @@ -0,0 +1,5 @@ +import sys +print(callable(1)) +print(callable("dfsd")) +print(callable(callable)) +print(callable(sys))