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-0dff7051ff02master
parent
3dbeaba251
commit
9ce02c4cc3
|
@ -17,6 +17,7 @@
|
|||
#include <alloc.h>
|
||||
#include <memory.h>
|
||||
#include <fail.h>
|
||||
#include <custom.h>
|
||||
#include "unixsupport.h"
|
||||
#include "cst2constr.h"
|
||||
#include <errno.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <direct.h>
|
||||
#include <process.h>
|
||||
|
||||
#define Handle_val(v) (*((HANDLE *)(v)))
|
||||
#define Handle_val(v) (*((HANDLE *) Data_custom_val(v)))
|
||||
|
||||
extern value win_alloc_handle(HANDLE);
|
||||
|
||||
|
|
Loading…
Reference in New Issue