From 9ce02c4cc3cd485fd0f9778e68995c136b843945 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 24 Jul 2001 09:05:25 +0000 Subject: [PATCH] Ajout comparaisons et hashing sur les handles (PR#439). A tester git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3596 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- otherlibs/win32unix/unixsupport.c | 25 ++++++++++++++++++++++++- otherlibs/win32unix/unixsupport.h | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/otherlibs/win32unix/unixsupport.c b/otherlibs/win32unix/unixsupport.c index fa957d4de..69d3106be 100644 --- a/otherlibs/win32unix/unixsupport.c +++ b/otherlibs/win32unix/unixsupport.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "unixsupport.h" #include "cst2constr.h" #include @@ -24,9 +25,31 @@ /* Heap-allocation of Windows file handles */ +static int win_handle_compare(value v1, value v2) +{ + HANDLE h1 = Handle_val(v1); + HANDLE h2 = Handle_val(v2); + return h1 == h2 ? 0 : h1 < h2 ? -1 : 1; +} + +static long win_handle_hash(value v) +{ + return (long) Handle_val(v); +} + +static struct custom_operations win_handle_ops = { + "_handle", + custom_finalize_default, + win_handle_compare, + win_handle_hash, + custom_serialize_default, + custom_deserialize_default +}; + value win_alloc_handle(HANDLE h) { - value res = alloc_small(sizeof(HANDLE) / sizeof(value), Abstract_tag); + value res = + alloc_custom(&win_handle_ops, sizeof(HANDLE), 0, 1); Handle_val(res) = h; return res; } diff --git a/otherlibs/win32unix/unixsupport.h b/otherlibs/win32unix/unixsupport.h index e97c2543e..303f8905a 100644 --- a/otherlibs/win32unix/unixsupport.h +++ b/otherlibs/win32unix/unixsupport.h @@ -21,7 +21,7 @@ #include #include -#define Handle_val(v) (*((HANDLE *)(v))) +#define Handle_val(v) (*((HANDLE *) Data_custom_val(v))) extern value win_alloc_handle(HANDLE);