From 9807b34043075d31ca76d6f10b62f553f9f298fe Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 20 Nov 2015 18:50:54 +0100 Subject: [PATCH] Fix equal? comparison of closures. Even though you're not supposed to compare closures (the spec says it's undefined), CHICKEN supports this to a degree. Two closures are compared in such a way that the slots must be identical. In other words, the function address and all the variables that are closed over are eq? to one another on both sides. The current implementation had an off-by-one which caused it to omit the comparison of the last slot, which holds either the last argument or the lambda-info in case we've compiled with lambda info. This caused the equal? procedure to behave differently depending on whether the code was compiled with the -no-lambda-info option or without it. Thanks to Mario Goulart for finding this in ticket #1041. --- NEWS | 2 ++ runtime.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 4527b44..1332673 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,8 @@ - Runtime system: - Compiled programs with large literals won't crash on startup (#1221). + - Comparisons of closures now behave in a stable way, whether or not + the code was compiled with the -no-lambda-info option (#1041). - Compiler: - Specializations on implicit "or" types like "number" or "boolean" now diff --git a/runtime.c b/runtime.c index 2d477c0..0d1deac 100644 --- a/runtime.c +++ b/runtime.c @@ -4012,7 +4012,7 @@ C_regparm C_word C_fcall C_equalp(C_word x, C_word y) if(bits & C_SPECIALBLOCK_BIT) { /* do not recurse into closures */ if(C_header_bits(x) == C_CLOSURE_TYPE) - return !C_memcmp((void *)x, (void *)y, n * sizeof(C_word)); + return !C_memcmp(C_data_pointer(x), C_data_pointer(y), n * sizeof(C_word)); else if(C_block_item(x, 0) != C_block_item(y, 0)) return 0; else ++i; -- 2.1.4