From 47167fbc0fc05cabd72d8e0e197f99e770e913a6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 15 May 2017 20:28:25 -0700 Subject: bugfix: use proper hashing for cptr. Since cptr objects are equal if their handles are equal, they must have a hashing function over the handle rather than over their own address. * lib.c (cobj_handle_hash_op): New function. (cptr_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op. * lib.h (cobj_handle_hash_op): Declared. * sysif.c (cptr_dl_ops): Use cobj_handle_hash_op instead of cobj_eq_hash_op. --- lib.c | 8 +++++++- lib.h | 1 + sysif.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index 03915d08..6939f817 100644 --- a/lib.c +++ b/lib.c @@ -7389,12 +7389,18 @@ val cobj_equal_handle_op(val left, val right) return (left->co.handle == right->co.handle) ? t : nil; } +cnum cobj_handle_hash_op(val obj, int *count) +{ + mem_t *handle = obj->co.handle; + return cobj_eq_hash_op(coerce(val, handle), count); +} + static struct cobj_ops cptr_ops = { cobj_equal_handle_op, cobj_print_op, cobj_destroy_stub_op, cobj_mark_op, - cobj_eq_hash_op + cobj_handle_hash_op }; val cptr(mem_t *ptr) diff --git a/lib.h b/lib.h index f1274bf1..301e46c4 100644 --- a/lib.h +++ b/lib.h @@ -258,6 +258,7 @@ void cobj_destroy_stub_op(val); void cobj_destroy_free_op(val); void cobj_mark_op(val); cnum cobj_eq_hash_op(val, int *); +cnum cobj_handle_hash_op(val, int *); struct env { obj_common; diff --git a/sysif.c b/sysif.c index e4d6de88..78dcda6c 100644 --- a/sysif.c +++ b/sysif.c @@ -1470,7 +1470,7 @@ static struct cobj_ops cptr_dl_ops = { cobj_print_op, cptr_dl_destroy_op, cobj_mark_op, - cobj_eq_hash_op + cobj_handle_hash_op }; static val dlopen_wrap(val name, val flags) -- cgit v1.2.3