diff options
author | Guido van Rossum <guido@python.org> | 1993-11-05 10:20:10 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-11-05 10:20:10 (GMT) |
commit | 2e8f8a398e135ce4ec235c33eb64c29e6b6114ea (patch) | |
tree | 8fdd01414159567f4ce55bf31d701347a5e83e5c /Python/compile.c | |
parent | 4199facacd002fdaa2aa9c00d3bc81f9b8569862 (diff) | |
download | cpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.zip cpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.tar.gz cpython-2e8f8a398e135ce4ec235c33eb64c29e6b6114ea.tar.bz2 |
Added compare operations for functions and code objects.
(Also hash, but it doesn't work yet.)
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c index 3a6d181..565c65c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -92,6 +92,35 @@ code_repr(co) return newstringobject(buf); } +static int +code_compare(co, cp) + codeobject *co, *cp; +{ + int cmp; + cmp = cmpobject((object *)co->co_code, (object *)cp->co_code); + if (cmp) return cmp; + cmp = cmpobject(co->co_consts, cp->co_consts); + if (cmp) return cmp; + cmp = cmpobject(co->co_names, cp->co_names); + return cmp; +} + +static long +code_hash(co) + codeobject *co; +{ + long h, h1, h2, h3; + h1 = hashobject((object *)co->co_code); + if (h1 == -1) return -1; + h2 = hashobject(co->co_consts); + if (h2 == -1) return -1; + h3 = hashobject(co->co_names); + if (h3 == -1) return -1; + h = h1 ^ h2 ^ h3; + if (h == -1) h = -2; + return h; +} + typeobject Codetype = { OB_HEAD_INIT(&Typetype) 0, @@ -102,11 +131,12 @@ typeobject Codetype = { 0, /*tp_print*/ code_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ - 0, /*tp_compare*/ + code_compare, /*tp_compare*/ code_repr, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ + code_hash, /*tp_hash*/ }; codeobject * |