caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mikhail Fedotov <mikhail@kittown.com>
To: art yerkes <ayerkes@on-demand-tech.com>
Cc: Jean-Baptiste.Rouquier@inrialpes.fr, caml-list@inria.fr
Subject: Re[4]: [Caml-list] interfacing C and OCaml
Date: Fri, 27 Jun 2003 17:14:14 +0400	[thread overview]
Message-ID: <1635699383.20030627171414@kittown.com> (raw)
In-Reply-To: <20030627075713.5791e800.ayerkes@on-demand-tech.com>

Hello art,

Friday, June 27, 2003, 4:57:13 PM, you wrote:

>> Sorry, I've made a mistake myself. I've been talking mostly about "void" vs "value"
>> issue in your examples, but this is already addressed in the manual by stating that
>> the primitive function must return value. The documentation lacks introduction into
>> the macroses "CAMLprim", "CAMLextern" etc, but they are not strictly required now
>> if you are not dealing with Windows DLLs.

ay> In my experience, it's completely safe to use the macros no matter where the
ay> code is called from.  You can omit them only when that would be safe, (i.e.
ay> you don't allocate anything into the caml heap).  You can get away with not
ay> being nice to the GC only when you don't do anything that can trigger the
ay> collector.  This means that if you do any alloc, alloc_tuple, copy_string, 
ay> etc., then you must use them.  It's not only for windows DLLs.

Hmpf. I've made one more mistake by not being specific enough. You are
talking about the CAMLparam/CAMLlocal macroses, and I'm talking about
CAMLprim/CAMLextern macroses; those that I'm talking about are used
as a prefix to a function name/type, not inside the body.

If you have a "unit"-type function, you still need it to have a return
value of type "value" with the value "Val_unit". This was en error in
the first example if you would want to export that function to OCaml.

If you don't use CAMLprim macroses you are introducing the risk that
you code will need to be changed for someone to use.

BTW, if you are calling one C function from another one with passing
or returning values, you can escape from the need to use
CAMLparam/CAMLlocal by passing a pointer to the values that are
already CAMLparam-ed in the calling function, i.e. use "value*" type
for function parameters for the functions that you don't need to
export.

-- 
Best regards,
 Mikhail                            mailto:mikhail@kittown.com

-------------------
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:[~2003-06-27 13:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-26 14:42 Jung Woon Ho
2003-06-26 15:14 ` Lex Stein
2003-06-26 19:02 ` Jean-Baptiste Rouquier
2003-06-27  5:24   ` Re[2]: " Mikhail Fedotov
2003-06-27  8:31     ` Jean-Baptiste Rouquier
2003-06-27  8:59       ` Re[2]: " Mikhail Fedotov
2003-06-27 12:57         ` art yerkes
2003-06-27 13:14           ` Mikhail Fedotov [this message]
2003-06-27 17:45             ` Re[4]: " art yerkes

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=1635699383.20030627171414@kittown.com \
    --to=mikhail@kittown.com \
    --cc=Jean-Baptiste.Rouquier@inrialpes.fr \
    --cc=ayerkes@on-demand-tech.com \
    --cc=caml-list@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).