From: "David Allsopp" <dra-news@metastack.com>
To: "OCaml List" <caml-list@yquem.inria.fr>
Subject: Interfacing with C question...
Date: Wed, 24 Jan 2007 17:23:36 -0000 [thread overview]
Message-ID: <002d01c73fdc$6254d430$6a7ba8c0@treble> (raw)
Sorry if this an RADBOTFM case. Rule 2 in Chapter 18 of the manual states
that all local variables of type value must be declared using CAMLlocal
macros. However, later on when demonstrating caml_callback we get the
statements:
value* format_result_closure = caml_named_value("format_result");
return strdup(String_val(caml_callback(*format_result_closure, Val_int(n))))
(I've "simplified" the opening lines for clarity here - naturally it should
be static and once only!).
Two questions arise:
1. Presumably it's OK to cache values returned by caml_named_value without
declaring them in a CAMLlocal "call" or by using register_global_root?
2. The result of caml_callback is passed straight to String_val. Therefore,
if I expand the line to:
value result = caml_callback(*format_result_closure, Val_int(n)));
return strdup(String_val(result));
then does that work ok without using CAMLlocal1(result);
Ta!
David
next reply other threads:[~2007-01-24 17:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-24 17:23 David Allsopp [this message]
2007-01-25 6:27 ` [Caml-list] " Remi Vanicat
2007-01-25 16:26 ` Hendrik Tews
2007-01-25 18:29 ` skaller
2007-01-26 0:16 ` Robert Roessler
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='002d01c73fdc$6254d430$6a7ba8c0@treble' \
--to=dra-news@metastack.com \
--cc=caml-list@yquem.inria.fr \
/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).