caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* getting the system architecture
@ 2007-08-02 23:09 Eric Merritt
  2007-08-03 15:18 ` [Caml-list] " Julien Moutinho
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Merritt @ 2007-08-02 23:09 UTC (permalink / raw)
  To: caml-list

Guys,

 Is there anyway to get the system architecture natively in ocaml? I
found Sys.os_type but have yet to find anything comparable for the
architecture. The alternative is to build out a function to get this
info in C but I would rather not complicate my build (or code in C ;)

Thanks,
 Eric


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] getting the system architecture
  2007-08-02 23:09 getting the system architecture Eric Merritt
@ 2007-08-03 15:18 ` Julien Moutinho
       [not found]   ` <f69c840c0708030954o5654a1ddk6628bb67a1463f5b@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Moutinho @ 2007-08-03 15:18 UTC (permalink / raw)
  To: Eric Merritt; +Cc: caml-list

On Thu, Aug 02, 2007 at 04:09:15PM -0700, Eric Merritt wrote:
>  Is there anyway to get the system architecture natively in ocaml? I
> found Sys.os_type but have yet to find anything comparable for the
> architecture.
Grepping at the Ocaml sources I see a few uses of <sys/utsname.h>,
but none of them deals with the ``machine'' field.
Apparently, they never need a runtime check of the arch.

> The alternative is to build out a function to get this
> info in C but I would rather not complicate my build
I don't know exactly how portable you want to be,
but you can also try to launch uname -m or this awful config/gnu/config.guess
either in a sub-process or in a ./configure coupled with a camlp4 definition.

> (or code in C ;)
% cat c_arch.c
#include <sys/utsname.h>

#include <caml/memory.h>
#include <caml/compatibility.h>

CAMLprim value arch_get(value unit)
{
  CAMLparam0(); /* ``unit'' is not used */
  struct utsname utsbuf;
  if (uname( &utsbuf ))
    failwith( "Arch.get" );
  CAMLreturn(copy_string( utsbuf.machine ));
}

% cat arch.ml
external get : unit -> string = "arch_get"

% cat test.ml
print_endline (Arch.get ())

% gcc -c c_arch.c
% ar rc libarch.a c_arch.o
% ocamlopt -c arch.ml
% ocamlopt -a -o arch.cmxa -cclib -larch arch.cmx
% ocamlopt -c test.ml
% ocamlopt -o test.opt -I . arch.cmxa test.cmx
% ./test.opt
i686

Hope this helps a bit.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] getting the system architecture
       [not found]   ` <f69c840c0708030954o5654a1ddk6628bb67a1463f5b@mail.gmail.com>
@ 2007-08-03 19:14     ` Julien Moutinho
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Moutinho @ 2007-08-03 19:14 UTC (permalink / raw)
  To: Eric Merritt; +Cc: caml-list

On Fri, Aug 03, 2007 at 09:54:17AM -0700, Eric Merritt wrote:
>  It actually helps a lot. I wasn't quite  expect you to do it all for
> me. Thanks, this saved me a bunch of time in doing it myself and
> figuring out the ffi which I haven't used before. I owe you one.

Just be careful to protect Ocaml values with CAMLparam*
and to declare them with CAMLlocal* if you care about your sleep;
'cause the ``due to garbage collection'' bug may be hard to find
or reproduce.

A few pointers, if you haven't them already:
http://caml.inria.fr/pub/docs/oreilly-book/html/index.html#chap-interop
http://caml.inria.fr/pub/ml-archives/caml-list/2007/01/a169d698ad11a6017c87f2d98db860e6.en.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-08-03 19:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-02 23:09 getting the system architecture Eric Merritt
2007-08-03 15:18 ` [Caml-list] " Julien Moutinho
     [not found]   ` <f69c840c0708030954o5654a1ddk6628bb67a1463f5b@mail.gmail.com>
2007-08-03 19:14     ` Julien Moutinho

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).