summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>1999-11-29 19:03:10 +0000
committerDamien Doligez <damien.doligez-inria.fr>1999-11-29 19:03:10 +0000
commit88d56510f2d5ed138576139085faa84eb41215b1 (patch)
tree149275c00af01dbc316a72d9c1826fba2036cbf6
parent4cfaac1befb80df0744fc8fbd80a068b94d54112 (diff)
downloadocaml-88d56510f2d5ed138576139085faa84eb41215b1.tar.gz
CAMLreturn -> CAMLreturn0, CAMLreturn()
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2619 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--byterun/memory.h57
1 files changed, 32 insertions, 25 deletions
diff --git a/byterun/memory.h b/byterun/memory.h
index 37227122ed..52039c7266 100644
--- a/byterun/memory.h
+++ b/byterun/memory.h
@@ -99,15 +99,18 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
If the function has more than 5 [value] parameters, use [CAMLparam5]
for the first 5 parameters, and one or more calls to the [CAMLxparam]
macros for the others.
+ If the function takes an array of [value]s as argument, use
+ [CAMLparamN] to declare it (or [CAMLxparamN] if you already have a
+ call to [CAMLparam] for some other arguments).
If you need local variables of type [value], declare them with one
or more calls to the [CAMLlocal] macros.
Use [CAMLlocalN] to declare an array of [value]s.
Your function may raise and exception or return a [value] with the
- [CAMLreturn] macro. Its argument is simply the [value] returned by
+ [CAMLreturn1] macro. Its argument is simply the [value] returned by
your function. Do NOT directly return a [value] with the [return]
- keyword.
+ keyword. If your function returns void, use [CAMLreturn0].
All the identifiers beginning with "caml__" are reserved by Caml.
Do not use them for anything (local or global variables, struct or
@@ -137,10 +140,14 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
CAMLparam0 (); \
CAMLxparam5 (x, y, z, t, u)
+#define CAMLparamN(x, size) \
+ CAMLparam0 (); \
+ CAMLxparamN (x, (size))
+
+
#define CAMLxparam1(x) \
struct caml__roots_block caml__roots_##x; \
void *caml__dummy_##x = ( \
- caml__frame, \
(caml__roots_##x.next = local_roots), \
(local_roots = &caml__roots_##x), \
(caml__roots_##x.nitems = 1), \
@@ -151,7 +158,6 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
#define CAMLxparam2(x, y) \
struct caml__roots_block caml__roots_##x; \
void *caml__dummy_##x = ( \
- caml__frame, \
(caml__roots_##x.next = local_roots), \
(local_roots = &caml__roots_##x), \
(caml__roots_##x.nitems = 1), \
@@ -163,7 +169,6 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
#define CAMLxparam3(x, y, z) \
struct caml__roots_block caml__roots_##x; \
void *caml__dummy_##x = ( \
- caml__frame, \
(caml__roots_##x.next = local_roots), \
(local_roots = &caml__roots_##x), \
(caml__roots_##x.nitems = 1), \
@@ -176,7 +181,6 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
#define CAMLxparam4(x, y, z, t) \
struct caml__roots_block caml__roots_##x; \
void *caml__dummy_##x = ( \
- caml__frame, \
(caml__roots_##x.next = local_roots), \
(local_roots = &caml__roots_##x), \
(caml__roots_##x.nitems = 1), \
@@ -190,7 +194,6 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
#define CAMLxparam5(x, y, z, t, u) \
struct caml__roots_block caml__roots_##x; \
void *caml__dummy_##x = ( \
- caml__frame, \
(caml__roots_##x.next = local_roots), \
(local_roots = &caml__roots_##x), \
(caml__roots_##x.nitems = 1), \
@@ -202,6 +205,16 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
(caml__roots_##x.tables [4] = &u), \
NULL)
+#define CAMLxparamN(x, size) \
+ struct caml__roots_block caml__roots_##x; \
+ void *caml__dummy_##x = ( \
+ (caml__roots_##x.next = local_roots), \
+ (local_roots = &caml__roots_##x), \
+ (caml__roots_##x.nitems = (size)), \
+ (caml__roots_##x.ntables = 1), \
+ (caml__roots_##x.tables[0] = &(x[0])), \
+ NULL)
+
#define CAMLlocal1(x) \
value x = 0; \
CAMLxparam1 (x)
@@ -223,25 +236,19 @@ extern struct caml__roots_block *local_roots; /* defined in roots.c */
CAMLxparam5 (x, y, z, t, u)
#define CAMLlocalN(x, size) \
- value x [(size)] = { 0 /* , 0, 0, ... */ }; \
- struct caml__roots_block caml__roots_##x; \
- void *caml__dummy_##x = ( \
- caml__frame, \
- (caml__roots_##x.next = local_roots), \
- (local_roots = &caml__roots_##x), \
- (caml__roots_##x.nitems = (size)), \
- (caml__roots_##x.ntables = 1), \
- (caml__roots_##x.tables [0] = &(x [0])), \
- NULL)
-
-/* WARNING: [CAMLreturn] cannot be used exactly in the same places
- as [return] : in an [if] statement, you must use a pair of braces
- even if the [CAMLreturn] "statement" is the only statement in the
- branch.
-*/
-#define CAMLreturn /*argument*/\
+ value x [(size)] = { 0, /* 0, 0, ... */ }; \
+ CAMLxparamN (x, (size))
+
+
+#define CAMLreturn0 do{ \
+ local_roots = caml__frame; \
+ return; \
+}while (0)
+
+#define CAMLreturn(result) do{ \
local_roots = caml__frame; \
- return /*argument*/
+ return (result); \
+}while(0)
/* convenience macro */
#define Store_field(block, offset, val) modify (&Field (block, offset), val)