From ca318bba0d97c66d8fb14a089d8fa269a0e1b424 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Mon, 13 Jan 2014 16:29:14 +0200
Subject: [PATCH] mp_obj_equal(): Compare small and long ints properly.

By dispatching to long int methods.
---
 py/obj.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/py/obj.c b/py/obj.c
index 2759437fd7..206bf7a24a 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -108,9 +108,15 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
                 return val == 0;
             } else if (o2 == mp_const_true) {
                 return val == 1;
-            } else {
-                return false;
+            } else if (MP_OBJ_IS_TYPE(o2, &int_type)) {
+                // If o2 is long int, dispatch to its virtual methods
+                mp_obj_base_t *o = o2;
+                if (o->type->binary_op != NULL) {
+                    mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o2, o1);
+                    return r == mp_const_true ? true : false;
+                }
             }
+            return false;
         }
     } else if (MP_OBJ_IS_QSTR(o1) || MP_OBJ_IS_QSTR(o2)) {
         return false;