From: "William D. Neumann" <wneumann@cs.unm.edu>
To: Julien Michel <julien.michel@etu.univ-orleans.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Unix module troubles & Time functions
Date: Tue, 18 Jul 2006 09:33:19 -0600 (MDT) [thread overview]
Message-ID: <Pine.LNX.4.62.0607180925100.12730@io.cs.unm.edu> (raw)
In-Reply-To: <20060718121035.hy7o1wa1cmhus4g0@webmailetu.univ-orleans.fr>
On Tue, 18 Jul 2006, Julien Michel wrote:
> and trying to compile this way:
> ocamlc -custom -o main unix.cma *ml
> returns this error while executing on my target:
> Fatal error: unknown C primitive `unix_dup\'
>
> What can be wrong with my system so that I cannot use the Unix.module?
Well, you don't have the dup functionality available. Possibly other
things are missing as well. You cauld look into how the Unix build is
configured and modify it to skip the functionality you don't have (or
better yet raise an exception). But that might be more work than you
need.
> The Gettimeofday unix function usually works well on my target, is there another
> way for having access to it with Caml?
Yes. You can write your own interface to the gettimeofday function
(that's all the Unix module's function is).
timer.c
====================================================================
#include <sys/time.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
CAMLprim value my_gettimeofday(value unit)
{
struct timeval tp;
if (gettimeofday(&tp, NULL) == -1) caml_failwith("gettimeofday:
failure");
return copy_double((double) tp.tv_sec + (double) tp.tv_usec / 1e6);
}
====================================================================
timer.ml
====================================================================
external timeofday : unit -> float = "my_gettimeofday"
let _ =
let t1 = timeofday ()
and t2 = Unix.gettimeofday () in
Printf.printf "mytime: %f, utime: %f\n" t1 t2;;
====================================================================
[414] 9:24AM% ocamlc timer.c
[415] 9:29AM% ocamlc -custom -o timer.bc timer.o unix.cma timer.ml
[416] 9:29AM% ./timer.bc
mytime: 1153236588.033843, utime: 1153236588.033860
(Note, you won't have the Unix module, so you don't need the unix.cma part
when you compile your use of the new timeofday function, I just neede it
to compare to the Unix.gettimeofday function)
Read chapter 18 of the OCaml manual for more info on interfacing OCaml
with C.
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
next prev parent reply other threads:[~2006-07-18 15:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-18 10:10 Julien Michel
2006-07-18 11:59 ` [Caml-list] " Jean-Christophe Filliatre
2006-07-18 13:27 ` Julien Michel
2006-07-18 15:33 ` William D. Neumann [this message]
2006-07-19 10:03 Julien Michel
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.LNX.4.62.0607180925100.12730@io.cs.unm.edu \
--to=wneumann@cs.unm.edu \
--cc=caml-list@yquem.inria.fr \
--cc=julien.michel@etu.univ-orleans.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