hivex_value_type: Returns -1 on error. Fix documentation.
[hivex.git] / generator / generator.ml
index 1131f54..5a0ab6e 100755 (executable)
@@ -990,7 +990,7 @@ On error this returns NULL and sets errno.\n\n"
        | RLenType ->
            pr "\
 Returns 0 on success.
-On error this returns NULL and sets errno.\n\n"
+On error this returns -1 and sets errno.\n\n"
        | RLenTypeVal ->
            pr "\
 The value is returned as an array of bytes (of length C<len>).
@@ -1321,6 +1321,32 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 "
 
+(* Generate the linker script which controls the visibility of
+ * symbols in the public ABI and ensures no other symbols get
+ * exported accidentally.
+ *)
+and generate_linker_script () =
+  generate_header HashStyle GPLv2plus;
+
+  let globals = [
+    "hivex_visit";
+    "hivex_visit_node"
+  ] in
+
+  let functions =
+    List.map (fun (name, _, _, _) -> "hivex_" ^ name)
+      functions in
+  let globals = List.sort compare (globals @ functions) in
+
+  pr "{\n";
+  pr "    global:\n";
+  List.iter (pr "        %s;\n") globals;
+  pr "\n";
+
+  pr "    local:\n";
+  pr "        *;\n";
+  pr "};\n"
+
 and generate_ocaml_interface () =
   generate_header OCamlStyle LGPLv2plus;
 
@@ -1493,7 +1519,29 @@ and generate_ocaml_c () =
 #include <caml/memory.h>
 #include <caml/mlvalues.h>
 #include <caml/signals.h>
+
+#ifdef HAVE_CAML_UNIXSUPPORT_H
 #include <caml/unixsupport.h>
+#else
+extern value unix_error_of_code (int errcode);
+#endif
+
+#ifndef HAVE_CAML_RAISE_WITH_ARGS
+static void
+caml_raise_with_args (value tag, int nargs, value args[])
+{
+  CAMLparam1 (tag);
+  CAMLxparamN (args, nargs);
+  value bucket;
+  int i;
+
+  bucket = caml_alloc_small (1 + nargs, 0);
+  Field(bucket, 0) = tag;
+  for (i = 0; i < nargs; i++) Field(bucket, 1 + i) = args[i];
+  caml_raise(bucket);
+  CAMLnoreturn;
+}
+#endif
 
 #include <hivex.h>
 
@@ -1901,7 +1949,7 @@ XSLoader::load ('Win::Hivex');
 
 =item open
 
- $h = Win::Hivex::open ($filename,";
+ $h = Win::Hivex->open ($filename,";
 
   List.iter (
     fun (_, flag, _) ->
@@ -2393,7 +2441,7 @@ DESTROY (h)
             pr "      size_t len;\n";
             pr "      hive_type type;\n";
             pr " PPCODE:\n";
-             pr "      r = hivex_%s (%s, &len, &type);\n"
+             pr "      r = hivex_%s (%s, &type, &len);\n"
               name (String.concat ", " c_params);
             free_args ();
              pr "      if (r == -1)\n";
@@ -2409,7 +2457,7 @@ DESTROY (h)
             pr "      size_t len;\n";
             pr "      hive_type type;\n";
             pr " PPCODE:\n";
-             pr "      r = hivex_%s (%s, &len, &type);\n"
+             pr "      r = hivex_%s (%s, &type, &len);\n"
               name (String.concat ", " c_params);
             free_args ();
              pr "      if (r == NULL)\n";
@@ -2417,7 +2465,7 @@ DESTROY (h)
               name;
             pr "      EXTEND (SP, 2);\n";
             pr "      PUSHs (sv_2mortal (newSViv (type)));\n";
-            pr "      PUSHs (sv_2mortal (newSVpv (r, len)));\n";
+            pr "      PUSHs (sv_2mortal (newSVpvn (r, len)));\n";
             pr "      free (r);\n";
 
         | RInt64 ->
@@ -2500,6 +2548,8 @@ Run it from the top source directory using the command
   output_to "lib/hivex.h" generate_c_header;
   output_to "lib/hivex.pod" generate_c_pod;
 
+  output_to "lib/hivex.syms" generate_linker_script;
+
   output_to "ocaml/hivex.mli" generate_ocaml_interface;
   output_to "ocaml/hivex.ml" generate_ocaml_implementation;
   output_to "ocaml/hivex_c.c" generate_ocaml_c;