From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D7D86BCAE for ; Thu, 7 Jul 2005 20:06:03 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j67I63e0029673 for ; Thu, 7 Jul 2005 20:06:03 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA15692 for ; Thu, 7 Jul 2005 20:06:03 +0200 (MET DST) Received: from mail.physik.uni-muenchen.de (mail.physik.uni-muenchen.de [192.54.42.129]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j67I62vL029664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 7 Jul 2005 20:06:02 +0200 Received: from localhost (unknown [127.0.0.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 4B8D82000D for ; Thu, 7 Jul 2005 20:06:02 +0200 (CEST) Received: from mail.physik.uni-muenchen.de ([127.0.0.1]) by localhost (mail.physik.uni-muenchen.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 18935-01-39 for ; Thu, 7 Jul 2005 20:06:00 +0200 (CEST) Received: from mailhost.cip.physik.uni-muenchen.de (kaiser.cip.physik.uni-muenchen.de [141.84.136.1]) by mail.physik.uni-muenchen.de (Postfix) with ESMTP id 6160D2000A for ; Thu, 7 Jul 2005 20:06:00 +0200 (CEST) Received: from katrin.cip.physik.uni-muenchen.de (katrin.cip.physik.uni-muenchen.de [141.84.136.12]) by mailhost.cip.physik.uni-muenchen.de (Postfix) with ESMTP id 9847326E87 for ; Thu, 7 Jul 2005 20:05:59 +0200 (CEST) Received: by katrin.cip.physik.uni-muenchen.de (Postfix, from userid 3092) id 1FD9716BBA; Thu, 7 Jul 2005 20:05:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by katrin.cip.physik.uni-muenchen.de (Postfix) with ESMTP id 1B24722135 for ; Thu, 7 Jul 2005 20:05:52 +0200 (CEST) Date: Thu, 7 Jul 2005 20:05:52 +0200 (CEST) From: Thomas Fischbacher To: caml-list@inria.fr Subject: How to raise_with_arg() a tuple? Message-ID: X-BOFH: Daemons did it MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: amavisd-new at physik.uni-muenchen.de X-Miltered: at concorde with ID 42CD6F0B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42CD6F0A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; exn:01 bool:01 ocaml:01 exn:01 camlprim:01 camlparam:01 val:01 fprintf:01 stderr:01 alloc:01 val:01 ocaml:01 camlreturn:01 ocaml's:01 byterun:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Hello together, I'd like to throw an exception from within C code which provides more information to Caml than just a string. If I do it that way: === Caml === exception Test_exn of int * int external test_raise_tuple: bool -> (int*int) = "caml_test_raise_tuple" let _ = Callback.register_exception "ocaml_exn_test" (Test_exn (0,0));; === C === CAMLprim caml_test_raise_tuple(value x) { CAMLparam1(x); int cx; cx=Int_val(x); fprintf(stderr,"DDD x=%d\n",cx); CAMLlocal1(ex); ex=alloc_tuple(2); Store_field(ex,0,Val_int(2)); Store_field(ex,1,Val_int(4)); if(cx) { raise_with_arg(*caml_named_value("ocaml_exn_test"), ex); } else { CAMLreturn(ex); } } ====== ...then just returning the tuple works as expected, but throwing the tuple gives me crazy values - like Test_exn (67385386, 1408) instead of Test_exn (2,4). Does anyone have an idea what is going on here, and how to repair this? Maybe I just missed something essential in the documentation. I tried to find an example in existing OCaml libraries where this is used, but somehow I was out of luck there so far... All I found about this issue is this bit of documentation in ocaml's byterun/memory.h: ===> Your function may raise an exception or return a [value] with the [CAMLreturn] macro. Its argument is simply the [value] returned by your function. Do NOT directly return a [value] with the [return] keyword. If your function returns void, use [CAMLreturn0]. <=== ...and the definition says: ===> #define CAMLreturn(result) do{ \ caml_local_roots = caml__frame; \ return (result); \ }while(0) <=== I tried a few obvious and non-obvious things related to what I see in there, but without success so far. So, how does one do that? -- regards, tf@cip.physik.uni-muenchen.de (o_ Thomas Fischbacher - http://www.cip.physik.uni-muenchen.de/~tf //\ (lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y) V_/_ (if (= x 0) y (g g (- x 1) (* x y)))) n 1)) (Debian GNU)