~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to debian/patches/0010-Avoid-multiple-declarations-in-generated-.c-files-in.patch

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 21:35:08 UTC
  • mfrom: (1.1.11 upstream) (12.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110421213508-kg34453aqmb0moha
* Fixes related to -output-obj with g++ (in debian/patches):
  - add Declare-primitive-name-table-as-const-char
  - add Avoid-multiple-declarations-in-generated-.c-files-in
  - fix Embed-bytecode-in-C-object-when-using-custom: the closing
    brace for extern "C" { ... } was missing in some cases

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 
 
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).
 
8
 
 
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.
 
12
 
 
13
Signed-off-by: Stephane Glondu <steph@glondu.net>
 
14
---
 
15
 bytecomp/bytelink.ml  |   17 +++++++++++++++--
 
16
 bytecomp/symtable.ml  |    8 +++++---
 
17
 bytecomp/symtable.mli |    2 +-
 
18
 3 files changed, 21 insertions(+), 6 deletions(-)
 
19
 
 
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 =
 
25
     remove_file outfile;
 
26
     raise x
 
27
 
 
28
+(* List of primitives declared in caml/mlvalues.h, to avoid duplicate
 
29
+   declarations in generated .c files *)
 
30
+
 
31
+let mlvalues_primitives = [
 
32
+  "caml_get_public_method";
 
33
+  "caml_hash_variant";
 
34
+  "caml_string_length";
 
35
+  "caml_Double_val";
 
36
+  "caml_Store_double_val";
 
37
+  "caml_Int64_val";
 
38
+  "caml_atom_table";
 
39
+]
 
40
+
 
41
 (* Output a bytecode executable as a C file *)
 
42
 
 
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;
 
50
     (* The entry point *)
 
51
     output_string outchan "\n\
 
52
 void caml_startup(char ** argv)\n\
 
53
@@ -516,7 +529,7 @@ let link objfiles output_name =
 
54
         #else\n\
 
55
         typedef long value;\n\
 
56
         #endif\n";
 
57
-      Symtable.output_primitive_table poc;
 
58
+      Symtable.output_primitive_table poc [];
 
59
       output_string poc "\
 
60
         #ifdef __cplusplus\n\
 
61
         }\n\
 
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 =
 
67
 
 
68
 open Printf
 
69
 
 
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)
 
75
+    let p = prim.(i) in
 
76
+    if not (List.mem p blacklist) then
 
77
+      fprintf outchan "extern value %s();\n" p
 
78
   done;
 
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)
 
84
   done;
 
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
 
99
 
 
100
--