From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Garbage collection and a reference counting library
Date: Thu, 11 Dec 2003 16:14:45 +0100 [thread overview]
Message-ID: <16344.35301.538267.517515@gargle.gargle.HOWL> (raw)
In-Reply-To: <20031211143640.GA21082@redhat.com>
Richard Jones writes:
>
> I wrote an interface to allow OCaml to call Perl code and libraries.
> (...)
> But I'm not really sure how to do this. At present the code uses the
> following subroutine to wrap up Perl SVs (the void *ptr in this case)
> in OCaml objects with an ABSTRACT_TAG. (Note also the XXX comment,
> since I'm not actually sure if this code itself is correct).
>
> static value
> Val_voidptr (void *ptr)
> {
> value rv = alloc (1, Abstract_tag); /* XXX Is this correct? */
> Field(rv, 0) = (value) ptr;
> return rv;
> }
A first remark: to be GC-friendly you have to use CAMLlocal1 to
declare rv and CAMLreturn instead of return.
Then, to be able to add a finalization function, you should use custom
blocks and not the Abstract_tag. The code then looks like
======================================================================
#define Perl_val(x) (*((void**)(Data_custom_val(x))))
void ml_perl_finalize(value v) {
perlFree(Perl_val(v));
}
static struct custom_operations perl_custom_operations = {
"...",
ml_perl_finalize,
custom_compare_default,
custom_hash_default,
custom_serialize_default,
custom_deserialize_default
};
#define ALLOC_PERL(v) \
v = alloc_custom(&perl_custom_operations,sizeof(void*),0,1)
static value
Val_voidptr (void *ptr)
{
CAMLlocal1(rv);
ALLOC_PERL(rv);
Perl_val(rv) = ptr;
CAMLreturn (rv);
}
======================================================================
Hope this helps,
--
Jean-Christophe
-------------------
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
next prev parent reply other threads:[~2003-12-11 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-11 14:36 Richard Jones
2003-12-11 15:14 ` Jean-Christophe Filliatre [this message]
2003-12-11 16:57 ` David Brown
2003-12-16 22:55 ` Damien Doligez
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=16344.35301.538267.517515@gargle.gargle.HOWL \
--to=filliatr@lri.fr \
--cc=Jean-Christophe.Filliatre@lri.fr \
--cc=caml-list@inria.fr \
--cc=rich@annexia.org \
/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