summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2012-10-07 06:54:40 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2012-10-07 06:54:40 +0000
commitd924f9f9240c778ee3faf8dc43af1b3a9288cbdc (patch)
treedfe462f2d274bced8036bc355ac821a77a28dcdf
parenta731103898a084de5ee5b520b518b087415b9f6c (diff)
Refactoring of the computations of the actual size of a struct caml_ba_array
(related to PR#5516 and PR#5761). git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12993 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--otherlibs/bigarray/bigarray.h7
-rw-r--r--otherlibs/bigarray/bigarray_stubs.c20
2 files changed, 10 insertions, 17 deletions
diff --git a/otherlibs/bigarray/bigarray.h b/otherlibs/bigarray/bigarray.h
index f6552107a..ed63fc4b3 100644
--- a/otherlibs/bigarray/bigarray.h
+++ b/otherlibs/bigarray/bigarray.h
@@ -81,6 +81,13 @@ struct caml_ba_array {
#endif
};
+/* Size of struct caml_ba_array, in bytes, without dummy first dimension */
+#if (__STDC_VERSION__ >= 199901L)
+#define SIZEOF_BA_ARRAY sizeof(struct caml_ba_array)
+#else
+#define SIZEOF_BA_ARRAY (sizeof(struct caml_ba_array) - sizeof(intnat))
+#endif
+
#define Caml_ba_array_val(v) ((struct caml_ba_array *) Data_custom_val(v))
#define Caml_ba_data_val(v) (Caml_ba_array_val(v)->data)
diff --git a/otherlibs/bigarray/bigarray_stubs.c b/otherlibs/bigarray/bigarray_stubs.c
index 33d4ffb02..b1062f813 100644
--- a/otherlibs/bigarray/bigarray_stubs.c
+++ b/otherlibs/bigarray/bigarray_stubs.c
@@ -160,12 +160,7 @@ caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim)
if (data == NULL && size != 0) caml_raise_out_of_memory();
flags |= CAML_BA_MANAGED;
}
- /* PR#5516: use C99's flexible array types if possible */
-#if (__STDC_VERSION__ >= 199901L)
- asize = sizeof(struct caml_ba_array) + num_dims * sizeof(intnat);
-#else
- asize = sizeof(struct caml_ba_array) + (num_dims - 1) * sizeof(intnat);
-#endif
+ asize = SIZEOF_BA_ARRAY + num_dims * sizeof(intnat);
res = caml_alloc_custom(&caml_ba_ops, asize, size, CAML_BA_MAX_MEMORY);
b = Caml_ba_array_val(res);
b->data = data;
@@ -779,12 +774,7 @@ static void caml_ba_serialize(value v,
}
/* Compute required size in OCaml heap. Assumes struct caml_ba_array
is exactly 4 + num_dims words */
- /* PR#5516: use C99's flexible array types if possible */
-#if (__STDC_VERSION__ >= 199901L)
- Assert(sizeof(struct caml_ba_array) == 4 * sizeof(value));
-#else
- Assert(sizeof(struct caml_ba_array) == 5 * sizeof(value));
-#endif
+ Assert(SIZEOF_BA_ARRAY == 4 * sizeof(value));
*wsize_32 = (4 + b->num_dims) * 4;
*wsize_64 = (4 + b->num_dims) * 8;
}
@@ -852,11 +842,7 @@ uintnat caml_ba_deserialize(void * dst)
caml_ba_deserialize_longarray(b->data, num_elts); break;
}
/* PR#5516: use C99's flexible array types if possible */
-#if (__STDC_VERSION__ >= 199901L)
- return sizeof(struct caml_ba_array) + b->num_dims * sizeof(intnat);
-#else
- return sizeof(struct caml_ba_array) + (b->num_dims - 1) * sizeof(intnat);
-#endif
+ return SIZEOF_BA_ARRAY + b->num_dims * sizeof(intnat);
}
/* Create / update proxy to indicate that b2 is a sub-array of b1 */