summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-08-15 14:38:15 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-08-15 17:49:48 +0100
commitbd35b3c055cb4a1bda041faede018dd7d4cfc1ba (patch)
tree46e20d13903e8071612d9ae45f440aa78c59d69f
parente3f356bda1d249a65f5606d5e4729ba6f7e56189 (diff)
downloadlibguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.tar.gz
libguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.tar.xz
libguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.zip
erlang: Fix 64 bit integers in parameters.
-rw-r--r--erlang/erl-guestfs-proto.c46
-rw-r--r--generator/generator_erlang.ml16
2 files changed, 56 insertions, 6 deletions
diff --git a/erlang/erl-guestfs-proto.c b/erlang/erl-guestfs-proto.c
index 241a1940..a1f05775 100644
--- a/erlang/erl-guestfs-proto.c
+++ b/erlang/erl-guestfs-proto.c
@@ -20,11 +20,15 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <erl_interface.h>
-#include <ei.h>
+/* We should switch over to using
+ #include <ei.h>
+instead of erl_interface.
+*/
#include "error.h"
#include "full-read.h"
@@ -44,6 +48,8 @@ extern ETERM *make_table (char **r);
extern ETERM *make_bool (int r);
extern char **get_string_list (ETERM *term);
extern int get_bool (ETERM *term);
+extern int get_int (ETERM *term);
+extern int64_t get_int64 (ETERM *term);
extern void free_strings (char **r);
/* This stops things getting out of hand, but also lets us detect
@@ -269,6 +275,44 @@ get_bool (ETERM *term)
return 0;
}
+int
+get_int (ETERM *term)
+{
+ switch (ERL_TYPE (term)) {
+ case ERL_INTEGER:
+ return ERL_INT_VALUE (term);
+ case ERL_U_INTEGER:
+ return (int) ERL_INT_UVALUE (term);
+ case ERL_LONGLONG:
+ /* XXX check for overflow */
+ return (int) ERL_LL_VALUE (term);
+ case ERL_U_LONGLONG:
+ /* XXX check for overflow */
+ return (int) ERL_LL_UVALUE (term);
+ default:
+ /* XXX fail in some way */
+ return -1;
+ }
+}
+
+int64_t
+get_int64 (ETERM *term)
+{
+ switch (ERL_TYPE (term)) {
+ case ERL_INTEGER:
+ return ERL_INT_VALUE (term);
+ case ERL_U_INTEGER:
+ return ERL_INT_UVALUE (term);
+ case ERL_LONGLONG:
+ return ERL_LL_VALUE (term);
+ case ERL_U_LONGLONG:
+ return (int64_t) ERL_LL_UVALUE (term);
+ default:
+ /* XXX fail in some way */
+ return -1;
+ }
+}
+
void
free_strings (char **r)
{
diff --git a/generator/generator_erlang.ml b/generator/generator_erlang.ml
index 31561279..b2ea8b36 100644
--- a/generator/generator_erlang.ml
+++ b/generator/generator_erlang.ml
@@ -188,11 +188,15 @@ and generate_erlang_c () =
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <erl_interface.h>
-#include <ei.h>
+/* We should switch over to using
+ #include <ei.h>
+instead of erl_interface.
+*/
#include \"guestfs.h\"
@@ -208,6 +212,8 @@ extern ETERM *make_table (char **r);
extern ETERM *make_bool (int r);
extern char **get_string_list (ETERM *term);
extern int get_bool (ETERM *term);
+extern int get_int (ETERM *term);
+extern int64_t get_int64 (ETERM *term);
extern void free_strings (char **r);
#define ARG(i) (ERL_TUPLE_ELEMENT(message,(i)+1))
@@ -308,9 +314,9 @@ extern void free_strings (char **r);
| Bool n ->
pr " int %s = get_bool (ARG (%d));\n" n i
| Int n ->
- pr " int %s = ERL_INT_VALUE (ARG (%d));\n" n i
+ pr " int %s = get_int (ARG (%d));\n" n i
| Int64 n ->
- pr " int64_t %s = ERL_LL_VALUE (ARG (%d));\n" n i
+ pr " int64_t %s = get_int64 (ARG (%d));\n" n i
| Pointer (t, n) ->
assert false
) args;
@@ -336,8 +342,8 @@ extern void free_strings (char **r);
pr " optargs_s.%s = " n;
(match argt with
| OBool _ -> pr "get_bool (hd_value)"
- | OInt _ -> pr "ERL_INT_VALUE (hd_value)"
- | OInt64 _ -> pr "ERL_LL_VALUE (hd_value)"
+ | OInt _ -> pr "get_int (hd_value)"
+ | OInt64 _ -> pr "get_int64 (hd_value)"
| OString _ -> pr "erl_iolist_to_string (hd_value)"
| OStringList n -> pr "get_string_list (hd_value)"
);