From afa590cde00a228a062461847a116d70145ef77f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 30 Aug 2018 12:13:35 +0200 Subject: [PATCH] Add Val_opt_const & Val_const_ptr_t Counterparts of Val_opt & Val_ptr_t, but with constness for the pointer. --- libvirt/libvirt_c_epilogue.c | 16 ++++++++++++++++ libvirt/libvirt_c_prologue.c | 2 ++ 2 files changed, 18 insertions(+) diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c index fa592c9..c7284b1 100644 --- a/libvirt/libvirt_c_epilogue.c +++ b/libvirt/libvirt_c_epilogue.c @@ -45,6 +45,22 @@ Val_opt (void *ptr, Val_ptr_t Val_ptr) CAMLreturn (optv); } +static value +Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr) +{ + CAMLparam0 (); + CAMLlocal2 (optv, ptrv); + + if (ptr) { /* Some ptr */ + optv = caml_alloc (1, 0); + ptrv = Val_ptr (ptr); + Store_field (optv, 0, ptrv); + } else /* None */ + optv = Val_int (0); + + CAMLreturn (optv); +} + #if 0 static value option_default (value option, value deflt) diff --git a/libvirt/libvirt_c_prologue.c b/libvirt/libvirt_c_prologue.c index 710c0d6..c82bd5f 100644 --- a/libvirt/libvirt_c_prologue.c +++ b/libvirt/libvirt_c_prologue.c @@ -23,6 +23,8 @@ static char *Optstring_val (value strv); typedef value (*Val_ptr_t) (void *); static value Val_opt (void *ptr, Val_ptr_t Val_ptr); +typedef value (*Val_const_ptr_t) (const void *); +static value Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr); /*static value option_default (value option, value deflt);*/ static void _raise_virterror (const char *fn) Noreturn; static value Val_virterror (virErrorPtr err); -- 1.8.3.1