caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: art yerkes <ayerkes@speakeasy.net>
To: Andy Yang <yyu08@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Toplevel crashes when trying to call external functions
Date: Sun, 11 Jul 2004 13:14:42 -0500	[thread overview]
Message-ID: <20040711131442.4557bb6e.ayerkes@speakeasy.net> (raw)
In-Reply-To: <20040711012047.86808.qmail@web53203.mail.yahoo.com>

On Sat, 10 Jul 2004 18:20:47 -0700 (PDT)
Andy Yang <yyu08@yahoo.com> wrote:

> Hi, all
> 
> I am relatively new to Ocaml. Sorry about the spam if
> this is a trivial problem. I am trying to give call
> some external functions. 
> 
> Some codes are as follows:
> 
> value zchaff_InitManager(void)
> {
>   CAMLparam0();  
>   void * solver = SAT_InitManager();
>   value val = alloc(1, Custom_tag);
>   Int32_val(val) = (int) solver;
>   CAMLreturn ( val );
> }
> 
> void zchaff_ReadCnf(value mng, value filename)
> {
>   CAMLparam2(mng, filename);
>   void* solver = (void*)Int32_val(mng);
>   char * fn = String_val(filename);
>   read_cnf(solver, fn);  
>   CAMLreturn0;
> }
> 

These may not solve this specific problem but I think they are good
advice:

First:
17.9.2. Custom blocks must be allocated via the alloc_custom function.
(And remember that the custom block size argument is in bytes).

Second:
Passing 1 as the block size to alloc allocates a block with one word
as a tail (at offset 0), but Data_custom_val accesses a value in the
tail at offset 1.  This is probably the error you're looking for.

Third:
I don't understand why you're going through Int32_val and Val_int32
to get and set your pointer.  You probably want to write a new macro
that will access the custom area as a pointer-sized chunk on every
architecture.  Assuming pointers to be 32-bits really is a bad idea.
-- 
Hey, Adam Smith, keep your invisible hands to yourself!

-------------------
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


  reply	other threads:[~2004-07-11 18:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-11  1:20 Andy Yang
2004-07-11 18:14 ` art yerkes [this message]
2004-07-11 18:58   ` Andy Yang
2004-07-12 11:04     ` Gerd Stolpmann
2004-07-12 11:35     ` Damien Doligez
2004-07-12 13:16       ` Andy Yang
2004-07-12 13:33         ` Olivier Andrieu
2004-07-12 15:39           ` Andy Yang
2004-07-12  6:55 ` Anne Pacalet
2004-07-12  3:39 John Prevost
2004-07-12  4:46 ` Andy Yang
2004-07-12 10:55 ` Gerd Stolpmann
2004-07-12 12:03   ` Richard Jones
2004-07-12 12:55     ` Jean-Christophe Filliatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040711131442.4557bb6e.ayerkes@speakeasy.net \
    --to=ayerkes@speakeasy.net \
    --cc=caml-list@inria.fr \
    --cc=yyu08@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).