caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jerome Vouillon <vouillon@clipper.ens.fr>
To: Frank Christoph <christo@nextsolution.co.jp>
Cc: caml-list@pauillac.inria.fr
Subject: Re: Need help: O'Caml C Interface
Date: Tue, 24 Sep 1996 15:36:36 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.3.89.9609241403.A29179-0100000@nave> (raw)
In-Reply-To: <9609231509.AA03139@sparc3.nextsolution.co.jp>


> value ocaml_getCharWidth(value code)
> {
>   double x, y;
>   Push_roots(r,1);
> 
>   r[0] = alloc_tuple(2);
>   getCharWidth(Int_val(code),&x,&y);
>   Store_double_val(Field(r[0],0),x);
>   Store_double_val(Field(r[0],1),y);
>   Pop_roots();
>   return r[0];
> }

I would write it this way:

value ocaml_getCharWidth(value code)
{
  double x, y;
  value res;
  Push_roots(r,2);

  getCharWidth(Int_val(code),&x,&y);
  r[0] = copy_double(x);
  r[1] = copy_double(y);
  res = alloc_tuple(2);
  Field(res, 0) = r[0];
  Field(res, 1) = r[1];
  Pop_roots();
  return res;
}

Store_double_val is used to store a double in an array of double values 
(which is a special kind of array). In other cases, you have to use 
copy_double to allocate a block containing the double.
So, your code failed because Field(r[0],0) was not a pointer to an array,
but an uninitialized pointer. 
*_roots are used to keep a pointer to both double values. Indeed, these
values can be moved by copy_double or alloc_tuple. The tuple is allocated
last, so that it can be directly filled (without having to use function
modify).

   Jerome










  reply	other threads:[~1996-09-24 16:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-23 15:09 Frank Christoph
1996-09-24 13:36 ` Jerome Vouillon [this message]
1996-09-24 14:45 Juan Jose Quintela Carreira
1996-09-24 17:11 ` Jerome Vouillon

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=Pine.3.89.9609241403.A29179-0100000@nave \
    --to=vouillon@clipper.ens.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=christo@nextsolution.co.jp \
    /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).