This file is indexed.

/usr/lib/ocaml/plugin-loader/PluginLoader.ml is in liboasis-ocaml-dev 0.3.0-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
(******************************************************************************)
(* OASIS: architecture for building OCaml libraries and applications          *)
(*                                                                            *)
(* Copyright (C) 2008-2010, OCamlCore SARL                                    *)
(*                                                                            *)
(* This library is free software; you can redistribute it and/or modify it    *)
(* under the terms of the GNU Lesser General Public License as published by   *)
(* the Free Software Foundation; either version 2.1 of the License, or (at    *)
(* your option) any later version, with the OCaml static compilation          *)
(* exception.                                                                 *)
(*                                                                            *)
(* This library is distributed in the hope that it will be useful, but        *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)
(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more         *)
(* details.                                                                   *)
(*                                                                            *)
(* You should have received a copy of the GNU Lesser General Public License   *)
(* along with this library; if not, write to the Free Software Foundation,    *)
(* Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA              *)
(******************************************************************************)

(* The content of this file started with ocsigen_loader.ml
 * from the ocsigen project (http://www.ocsigen.org).
 *
 * It was:
 * Copyright (C) 2008 Stéphane Glondu
 *)

exception Dynlink_error of string * exn
exception Findlib_error of string * exn
exception Plugin_not_found of string

(**/**)
(** TODO: Gettext related functions, to be replaced by real ones. *)
let s_ s = s
let f_ fmt = ""^^fmt
(**/**)

(* Error formatting *)

open Printf

let () =
  Printexc.register_printer
    (function
       | Dynlink_error (s, Dynlink.Error e) ->
           Some
             (sprintf (f_ "Dynlink error while loading '%s': %s")
                s (Dynlink.error_message e))

       | Findlib_error (s, Fl_package_base.No_such_package (s', msg)) ->
           let pkg =
             if s = s' then
               "'"^s^"'"
             else
               sprintf (f_ "'%s' [while trying to load '%s']") s' s
           in
           let additional =
             if msg = "" then "" else sprintf " (%s)" msg
           in
             Some
               (sprintf (f_ "Findlib package %s not found%s")
                  pkg additional)

       | Findlib_error (s, e) ->
           Some (sprintf "Findlib error while handling '%s': %s"
                   s (Printexc.to_string e))
       | Plugin_not_found nm ->
           Some (sprintf (f_ "Plugin '%s' not found") nm)
       | _ ->
           None);

module StringSet = Set.Make(String)

(* Loading files *)

module SetString = Set.Make(String)

let findlib_packages_loaded = ref SetString.empty

let add_findlib_package e =
  findlib_packages_loaded := SetString.add e !findlib_packages_loaded

let init findlib_packages_loaded =
  List.iter add_findlib_package findlib_packages_loaded;
  Findlib.init ()

type 'a t =
    {
      system: string;
      msg: ([>`Debug | `Warning | `Error] as 'a) -> string -> unit;
    }

type entry =
    {
      findlib_name: string;
      name: string;
      synopsis: string option;
      description: string option;
      version: string option;
    }

(* Using Findlib to locate files *)
let findfiles t package =
  let rev_split_blank str =
    let buf = Buffer.create 13 in
    let lst = ref [] in
      String.iter
        (function
           | ' ' ->
               if Buffer.length buf > 0 then
                 begin
                   lst := Buffer.contents buf :: !lst;
                   Buffer.clear buf
                 end
           | c ->
               Buffer.add_char buf c)
        str;
      begin
        match Buffer.contents buf with
          | "" -> ()
          | str -> lst := str :: !lst
      end;
      !lst
  in

    try
      let preds =
        [if Dynlink.is_native then "native" else "byte"]
      in
      let deps =
        List.filter
          (fun a -> not (SetString.mem a !findlib_packages_loaded))
          (Findlib.package_deep_ancestors preds [package])
      in
        t.msg
          `Debug
           (sprintf
              (f_ "Dependencies of %s: %s")
              package (String.concat ", " deps));
      let rec aux =
        function
          | [] -> []
          | a :: tl ->
              let mods =
                try
                  let raw =
                    Findlib.package_property ("plugin" :: preds) a "archive"
                  in
                    List.rev (rev_split_blank raw)
                with Not_found ->
                  begin
                    try
                      let raw = Findlib.package_property preds a "archive" in
                        List.rev_map
                          (fun fn ->
                             (* Replacing .cmx/.cmxa by .cmxs *)
                             if Dynlink.is_native &&
                                (Filename.check_suffix fn "cmx" ||
                                 Filename.check_suffix fn "cmxa") then
                               (Filename.chop_extension fn) ^ ".cmxs"
                             else
                               fn)
                          (rev_split_blank raw)
                    with Not_found ->
                      begin
                        t.msg `Error
                          (sprintf
                             (f_ "Cannot find 'archive' attribute for findlib \
                                  package %s")
                             a);
                        []
                      end
                  end
              in
              let base = Findlib.package_directory a in
                add_findlib_package a;
                (List.map (Findlib.resolve_path ~base) mods) @ (aux tl)
        in

        let res = aux deps in
          t.msg `Debug (sprintf "Object files needed: %s"
                          (String.concat ", " res));
          res

    with e ->
      raise (Findlib_error (package, e))

module SetEntry =
  Set.Make
    (struct
       type t = entry
       let compare e1 e2 =
         String.compare e1.name e2.name
     end)

let list t =
  let lst = Fl_package_base.list_packages () in
  let set =
    List.fold_left
      (fun acc pkg_str ->
         try
           let pkg = Fl_package_base.query pkg_str in
           let package_defs = pkg.Fl_package_base.package_defs in
           let plugin_system =
             Fl_metascanner.lookup "plugin_system" [] package_defs
           in
           let default_lookup var =
             try
               Some (Fl_metascanner.lookup var [] package_defs)
             with Not_found ->
               None
           in
           let default_lookup_str var dflt =
             match default_lookup var with
               | Some str -> str
               | None -> dflt
           in
             if plugin_system = t.system then
               begin
                 let entry =
                   {
                     findlib_name = pkg_str;
                     name = default_lookup_str "plugin_name" pkg_str;
                     synopsis = default_lookup "plugin_synopsis";
                     description = default_lookup "plugin_description";
                     version = default_lookup "version";
                   }
                 in
                   if SetEntry.mem entry acc then
                     t.msg `Warning
                       (sprintf
                          (f_ "Plugin '%s' already defined \
                               (findlib name: %s; directory: '%s').")
                          entry.name
                          pkg_str
                          pkg.Fl_package_base.package_dir);
                   SetEntry.add entry acc
               end
             else
               acc
         with e ->
           acc)
      SetEntry.empty
      lst
  in
    SetEntry.elements set

let load t nm =
  let entry =
    try
      List.find (fun e -> e.name = nm) (list t)
    with Not_found ->
      raise (Plugin_not_found nm)
  in
  let lst =
    findfiles t entry.findlib_name
  in
    try
      List.iter Dynlink.loadfile lst
    with e ->
      raise (Dynlink_error (nm, e))