caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] perplexing marshaling exception
@ 2003-05-30  2:36 Lex Stein
  2003-05-30  3:53 ` Lex Stein
  0 siblings, 1 reply; 3+ messages in thread
From: Lex Stein @ 2003-05-30  2:36 UTC (permalink / raw)
  To: caml-list


Hello, I'm having a curious and perplexing problem with unmarshaling
(Marshal module).

I have two executables that differ in that one is built from a C main
routine that calls into Caml closures via callback() and a second that is
built from code that makes these same calls from Caml directly. Both of
these programs call Caml routines that read/write records to Berkeley-DB
(BDB) via a homegrown Caml interface to the BDB C library. Here's a
diagram:

1: main program (C) | DB read/write (Caml) | BDB (C)
2: DB read/write (Caml) | BDB (C)

In 1, the main program does very little that's interesting. The only
values that it passes to its callbacks are copy_string()'ed pathnames
representing the location of the database. In 2, these same strings are
arguments to Caml source code calls to the same Caml routines that the C
code calls in case 1.

However, I get an error when I call from C (case 1) that I don't get in
case 2.

In case 1, in the DB read/write Caml code, when I try to unmarshal a
string retrieved from BDB, I get:

Fatal error: exception Failure("input_value: unknown custom block identifier")
(Program not linked with -g, cannot print stack backtrace)

In case 2, when I try to do this, I get no such error. (Also of interest
is the claim that the program was not linked with -g. This just isn't
true. However, this isn't my main concern).

Any idea what's going on here? Why unmarshal is failing when I have a C
main program?

Much appreciated!

Lex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] perplexing marshaling exception
  2003-05-30  2:36 [Caml-list] perplexing marshaling exception Lex Stein
@ 2003-05-30  3:53 ` Lex Stein
  2003-06-01 16:00   ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Lex Stein @ 2003-05-30  3:53 UTC (permalink / raw)
  To: caml-list


Hello, I've replicated this mysterious behaviour in a small, simple
example. Interestingly, the problem pops up for values with Custom_tag,
but not for unboxed, String_tag, or whatever bools are:

spruce:/home/lair/stein/th/db_test(215) cat foo1.ml

let test _ =
        let k = Nativeint.zero in
        let s = Marshal.to_string k [] in
        let s1 = Marshal.from_string s 0 in
        ();;

let _ = Callback.register "c_test" test;;

spruce:/home/lair/stein/th/db_test(216) cat doc1.c

#include <stdio.h>
#include <assert.h>
#include <caml/callback.h>

int main (int argc, char **argv) {

        static value * clos;

        caml_startup (argv);
        clos = caml_named_value ("c_test");
        assert (clos != NULL);

        callback (*clos, Val_unit);

        return (0);

}
spruce:/home/lair/stein/th/db_test(217) make doc1
ocamlc -g -custom -output-obj -I /home/lair/stein/th/ocamlbdb/ -o
foo1_caml.o foo1.cmo
foo1_caml.c: In function `caml_startup':
foo1_caml.c:1082: warning: implicit declaration of function
`caml_startup_code'
gcc -g -DDEBUG    -o doc1 doc1.o foo1_caml.o \
        -L/usr/local/lib/ocaml/ -lcamlrun -lm -ldl -lstr
spruce:/home/lair/stein/th/db_test(218) ./doc1
Fatal error: exception Failure("input_value: unknown custom block
identifier")
(Program not linked with -g, cannot print stack backtrace)

Now change the line "let k = Nativeint.zero in" in foo1.ml to
"let k = 0 in" and redo those steps. No exception will be raised.

The marshaling documentation says that marshal can handle interesting,
boxed types like Nativeints, Int32s, and Int64s. What am I doing wrong
here?

Thanks
Lex

On Thu, 29 May 2003, Lex Stein wrote:

>
> Hello, I'm having a curious and perplexing problem with unmarshaling
> (Marshal module).
>
> I have two executables that differ in that one is built from a C main
> routine that calls into Caml closures via callback() and a second that is
> built from code that makes these same calls from Caml directly. Both of
> these programs call Caml routines that read/write records to Berkeley-DB
> (BDB) via a homegrown Caml interface to the BDB C library. Here's a
> diagram:
>
> 1: main program (C) | DB read/write (Caml) | BDB (C)
> 2: DB read/write (Caml) | BDB (C)
>
> In 1, the main program does very little that's interesting. The only
> values that it passes to its callbacks are copy_string()'ed pathnames
> representing the location of the database. In 2, these same strings are
> arguments to Caml source code calls to the same Caml routines that the C
> code calls in case 1.
>
> However, I get an error when I call from C (case 1) that I don't get in
> case 2.
>
> In case 1, in the DB read/write Caml code, when I try to unmarshal a
> string retrieved from BDB, I get:
>
> Fatal error: exception Failure("input_value: unknown custom block identifier")
> (Program not linked with -g, cannot print stack backtrace)
>
> In case 2, when I try to do this, I get no such error. (Also of interest
> is the claim that the program was not linked with -g. This just isn't
> true. However, this isn't my main concern).
>
> Any idea what's going on here? Why unmarshal is failing when I have a C
> main program?
>
> Much appreciated!
>
> Lex
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] perplexing marshaling exception
  2003-05-30  3:53 ` Lex Stein
@ 2003-06-01 16:00   ` Xavier Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2003-06-01 16:00 UTC (permalink / raw)
  To: Lex Stein; +Cc: caml-list

> 
> Hello, I've replicated this mysterious behaviour in a small, simple
> example. Interestingly, the problem pops up for values with Custom_tag,
> but not for unboxed, String_tag, or whatever bools are:

You found a bug in the "ocamlc -output-obj" machinery.  The trivial patch
below (for file byterun/startup.c) fixes it.

- Xavier Leroy

--- startup.c   2002/09/03 13:56:36     1.55
+++ startup.c   2003/06/01 15:57:34
@@ -420,6 +420,7 @@
   value res;
 
   init_ieee_floats();
+  init_custom_operations();
 #ifdef DEBUG
   verb_gc = 63;
 #endif

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-06-01 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-30  2:36 [Caml-list] perplexing marshaling exception Lex Stein
2003-05-30  3:53 ` Lex Stein
2003-06-01 16:00   ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).