File: main.ml

package info (click to toggle)
ocaml 5.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,372 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,396; asm: 5,462; makefile: 3,679; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (234 lines) | stat: -rw-r--r-- 5,759 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
(* TEST
 readonly_files = "a.ml api.ml b.ml bug.ml c.ml factorial.c pack_client.ml \
  packed1.ml plugin2.ml plugin4.ml plugin_ext.ml \
  plugin_high_arity.ml plugin.ml plugin.mli plugin_ref.ml plugin_simple.ml \
  plugin_thread.ml";
 subdirectories = "sub";
 include systhreads;
 include dynlink;
 hassysthreads;
 libraries = ""; (* We will add them manually where appropriated *)
 native-dynlink;
 ocamlopt_default_flags = "";(* Removes the -ccopt -no-pie on ised on OpenBSD *)
 setup-ocamlopt.byte-build-env;
 module = "api.ml";
 ocamlopt.byte;
 flags = "-opaque";
 module = "plugin.mli";
 ocamlopt.byte;
 flags = "";
 module = "plugin.ml";
 ocamlopt.byte;
 module = "";
 flags = "-shared";
 program = "plugin.so";
 all_modules = "plugin.cmx";
 ocamlopt.byte;
 script = "mv plugin.cmx plugin.cmx.bak";
 script;
 flags = "";
 module = "plugin2.ml";
 ocamlopt.byte;
 script = "mv plugin.cmx.bak plugin.cmx";
 script;
 module = "";
 flags = "-shared";
 program = "plugin2.so";
 all_modules = "plugin2.cmx";
 ocamlopt.byte;
 flags = "";
 module = "sub/plugin.ml";
 ocamlopt.byte;
 module = "";
 flags = "-shared";
 program = "sub/plugin.so";
 all_modules = "sub/plugin.cmx";
 ocamlopt.byte;
 cwd = "sub";
 cd;
 module = "api.mli";
 flags = "-opaque";
 ocamlopt.byte;
 flags = "";
 module = "api.ml";
 ocamlopt.byte;
 script = "mv api.cmx api.cmx.bak";
 script;
 module = "plugin3.ml";
 ocamlopt.byte;
 script = "mv api.cmx.bak api.cmx";
 script;
 cwd = "..";
 cd;
 module = "";
 flags = "-shared";
 program = "sub/plugin3.so";
 all_modules = "sub/plugin3.cmx";
 ocamlopt.byte;
 flags = "";
 module = "plugin4.ml";
 ocamlopt.byte;
 module = "";
 flags = "-shared";
 program = "plugin4.so";
 all_modules = "plugin4.cmx";
 ocamlopt.byte;
 module = "packed1.ml";
 flags = "-for-pack Mypack";
 ocamlopt.byte;
 flags = "-S -pack";
 module = "";
 program = "mypack.cmx";
 all_modules = "packed1.cmx";
 ocamlopt.byte;
 program = "mypack.so";
 flags = "-shared";
 all_modules = "mypack.cmx";
 ocamlopt.byte;
 program = "packed1.so";
 flags = "-shared";
 all_modules = "packed1.cmx";
 ocamlopt.byte;
 flags = "";
 module = "pack_client.ml";
 ocamlopt.byte;
 module = "";
 program = "pack_client.so";
 flags = "-shared";
 all_modules = "pack_client.cmx";
 ocamlopt.byte;
 flags = "";
 module = "plugin_ref.ml";
 ocamlopt.byte;
 module = "";
 program = "plugin_ref.so";
 flags = "-shared";
 all_modules = "plugin_ref.cmx";
 ocamlopt.byte;
 flags = "";
 module = "plugin_high_arity.ml";
 ocamlopt.byte;
 module = "";
 program = "plugin_high_arity.so";
 flags = "-shared";
 all_modules = "plugin_high_arity.cmx";
 ocamlopt.byte;
 flags = "-ccopt ${shared_library_cflags}";
 module = "factorial.c";
 ocamlopt.byte;
 flags = "";
 module = "plugin_ext.ml";
 ocamlopt.byte;
 module = "";
 program = "plugin_ext.so";
 flags = "-shared";
 all_modules = "factorial.${objext} plugin_ext.cmx";
 ocamlopt.byte;
 module = "plugin_simple.ml";
 flags = "";
 ocamlopt.byte;
 {
   module = "";
   program = "plugin_simple.so";
   flags = "-shared";
   all_modules = "plugin_simple.cmx";
   ocamlopt.byte;
 }{
   module = "bug.ml";
   flags = "";
   ocamlopt.byte;
   {
     module = "";
     program = "bug.so";
     flags = "-shared";
     all_modules = "bug.cmx";
     ocamlopt.byte;
   }{
     module = "plugin_thread.ml";
     flags = "";
     ocamlopt.byte;
     module = "";
     program = "plugin_thread.so";
     flags = "-shared";
     all_modules = "plugin_thread.cmx";
     ocamlopt.byte;
     program = "plugin4_unix.so";
     all_modules = "unix.cmxa plugin4.cmx";
     ocamlopt.byte;
     flags = "";
     compile_only = "true";
     all_modules = "a.ml b.ml c.ml main.ml";
     ocamlopt.byte;
     module = "";
     compile_only = "false";
     flags = "-shared";
     program = "a.so";
     all_modules = "a.cmx";
     ocamlopt.byte;
     program = "b.so";
     all_modules = "b.cmx";
     ocamlopt.byte;
     program = "c.so";
     all_modules = "c.cmx";
     ocamlopt.byte;
     program = "mylib.cmxa";
     flags = "-a";
     all_modules = "plugin.cmx plugin2.cmx";
     ocamlopt.byte;
     program = "mylib.so";
     flags = "-shared -linkall";
     all_modules = "mylib.cmxa";
     ocamlopt.byte;
     program = "${test_build_directory}/main.exe";
     libraries = "unix threads dynlink";
     flags = "-linkall";
     all_modules = "api.cmx main.cmx";
     ocamlopt.byte;
 (*
 On OpenBSD, the compiler produces warnings like
 /usr/bin/ld: warning: creating a DT_TEXTREL in a shared object.
 So the compiler output is not empty on OpenBSD so an emptiness check
 would fail on this platform.

 We thus do not check compiler output. This was not done either before the
 test was ported to ocamltest.
 *)

     arguments = "plugin.so plugin2.so plugin_thread.so";
     run;
     check-program-output;
   }
 }
*)

let () =
  Api.add_cb (fun () -> print_endline "Callback from main")

let ()  =
  Dynlink.allow_unsafe_modules true;
  for i = 1 to Array.length Sys.argv - 1 do
    let name = Sys.argv.(i) in
    Printf.printf "Loading %s\n" name; flush stdout;
    try
      if name.[0] = '-'
      then Dynlink.loadfile_private
        (String.sub name 1 (String.length name - 1))
      else Dynlink.loadfile name
    with
      | Dynlink.Error err ->
          Printf.printf "Dynlink error: %s\n"
            (Dynlink.error_message err)
      | exn ->
          Printf.printf "Error: %s\n" (Printexc.to_string exn)
  done;
  flush stdout;
  try
    let oc = open_out_bin "marshal.data" in
    Marshal.to_channel oc !Api.cbs [Marshal.Closures];
    close_out oc;
    let ic = open_in_bin "marshal.data" in
    let l = (Marshal.from_channel ic : (unit -> unit) list) in
    close_in ic;
    List.iter (fun f -> f()) l
  with Failure s ->
    Printf.printf "Failure: %s\n" s