1
From: Stephane Glondu <steph@glondu.net>
2
Date: Thu, 21 Apr 2011 18:39:31 +0200
3
Subject: Avoid multiple declarations in generated .c files in -output-obj
5
In -output-obj mode, <caml/mlvalues.h> (which contains some
6
primitives) is included in the generated .c file, leading to errors
7
when compiling with g++ (multiple declarations).
9
There are probably better implementations (in particular, in this one,
10
care must be taken when changing the list of primitives available in
11
mlvalues.h), but this is a small and (not too) intrusive patch.
13
Signed-off-by: Stephane Glondu <steph@glondu.net>
15
bytecomp/bytelink.ml | 17 +++++++++++++++--
16
bytecomp/symtable.ml | 8 +++++---
17
bytecomp/symtable.mli | 2 +-
18
3 files changed, 21 insertions(+), 6 deletions(-)
20
diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml
21
index 4a6426d..47903c4 100644
22
--- a/bytecomp/bytelink.ml
23
+++ b/bytecomp/bytelink.ml
24
@@ -400,6 +400,19 @@ let output_cds_file outfile =
28
+(* List of primitives declared in caml/mlvalues.h, to avoid duplicate
29
+ declarations in generated .c files *)
31
+let mlvalues_primitives = [
32
+ "caml_get_public_method";
33
+ "caml_hash_variant";
34
+ "caml_string_length";
36
+ "caml_Store_double_val";
41
(* Output a bytecode executable as a C file *)
43
let link_bytecode_as_c tolink outfile =
44
@@ -442,7 +455,7 @@ CAMLextern void caml_startup_code(\n\
45
(Marshal.to_string sections []);
46
output_string outchan "\n};\n\n";
47
(* The table of primitives *)
48
- Symtable.output_primitive_table outchan;
49
+ Symtable.output_primitive_table outchan mlvalues_primitives;
51
output_string outchan "\n\
52
void caml_startup(char ** argv)\n\
53
@@ -516,7 +529,7 @@ let link objfiles output_name =
55
typedef long value;\n\
57
- Symtable.output_primitive_table poc;
58
+ Symtable.output_primitive_table poc [];
62
diff --git a/bytecomp/symtable.ml b/bytecomp/symtable.ml
63
index 37def29..70958ee 100644
64
--- a/bytecomp/symtable.ml
65
+++ b/bytecomp/symtable.ml
66
@@ -112,15 +112,17 @@ let output_primitive_names outchan =
70
-let output_primitive_table outchan =
71
+let output_primitive_table outchan blacklist =
72
let prim = all_primitives() in
73
for i = 0 to Array.length prim - 1 do
74
- fprintf outchan "extern value %s();\n" prim.(i)
76
+ if not (List.mem p blacklist) then
77
+ fprintf outchan "extern value %s();\n" p
79
fprintf outchan "typedef value (*primitive)();\n";
80
fprintf outchan "primitive caml_builtin_cprim[] = {\n";
81
for i = 0 to Array.length prim - 1 do
82
- fprintf outchan " %s,\n" prim.(i)
83
+ fprintf outchan " (primitive)%s,\n" prim.(i)
85
fprintf outchan " (primitive) 0 };\n";
86
fprintf outchan "const char * caml_names_of_builtin_cprim[] = {\n";
87
diff --git a/bytecomp/symtable.mli b/bytecomp/symtable.mli
88
index 2b1583f..316381e 100644
89
--- a/bytecomp/symtable.mli
90
+++ b/bytecomp/symtable.mli
91
@@ -24,7 +24,7 @@ val require_primitive: string -> unit
92
val initial_global_table: unit -> Obj.t array
93
val output_global_map: out_channel -> unit
94
val output_primitive_names: out_channel -> unit
95
-val output_primitive_table: out_channel -> unit
96
+val output_primitive_table: out_channel -> string list -> unit
97
val data_global_map: unit -> Obj.t
98
val data_primitive_names: unit -> string