From: brjackson@blueyonder.co.uk
To: caml-list@inria.fr
Subject: Constructing all float tuples in C
Date: Fri, 5 Aug 2005 15:16:12 +0100 (BST) [thread overview]
Message-ID: <5160.195.188.213.34.1123251372.squirrel@195.188.213.34> (raw)
Apologies to anybody that received a no subject message identical to that
which is below. It seems that I forgot to include it first time round.
Hi.
I've recently been experimenting with some Glu bindings for Ocaml. I am
aware of the excellent Lablgl but wanted something closer to the C API.
Unfortunately there seems to be a problem with a particular function that
returns a tuple of three floats. I think that I'm constructing the tuple
wrong since if it is changed so that it returns a bigarray it works.
With the following code gdb reports a crash in caml_format_float when
gluUnProject is called:
(* OCAML CODE *)
external gluUnProject : float -> float -> float ->
(float, float64_elt, c_layout) Array1.t ->
(float, float64_elt, c_layout) Array1.t ->
(int, int_elt, c_layout) Array1.t ->
(float * float * float) =
"stub_gluUnProject_bytecode" "stub_gluUnProject_native"
/* C CODE */
value stub_gluUnProject_native(value v1, value v2, value v3, value v4,
value v5, value v6)
{
CAMLparam5(v1, v2, v3, v4, v5);
CAMLxparam1(v6);
CAMLlocal1(result);
result = alloc(Double_wosize * 3, Double_array_tag);
double obj[3];
fp_gluUnProject(Double_val(v1), Double_val(v2), Double_val(v3),
(double *) Data_bigarray_val(v4), (double *) Data_bigarray_val(v5),
(int *) Data_bigarray_val(v6), obj, obj+1, obj+2);
Store_double_field(result, 0, obj[0]);
Store_double_field(result, 1, obj[1]);
Store_double_field(result, 2, obj[2]);
CAMLreturn(result);
}
The values altered by fp_gluUnProject (obj[...]) are correct. If the code
is changed to the following (so that is returns a bigarray) it works:
(* OCAML CODE *)
external gluUnProject : float -> float -> float ->
(float, float64_elt, c_layout) Array1.t ->
(float, float64_elt, c_layout) Array1.t ->
(int, int_elt, c_layout) Array1.t ->
float, float64_elt, c_layout) Array1.t =
"stub_gluUnProject_bytecode" "stub_gluUnProject_native"
/* C CODE */
value stub_gluUnProject_native(value v1, value v2, value v3, value v4,
value v5, value v6)
{
CAMLparam5(v1, v2, v3, v4, v5);
CAMLxparam1(v6);
CAMLlocal1(result);
double obj[3];
fp_gluUnProject(Double_val(v1), Double_val(v2), Double_val(v3),
(double *) Data_bigarray_val(v4), (double *) Data_bigarray_val(v5),
(int *) Data_bigarray_val(v6), obj, obj+1, obj+2);
result = alloc_bigarray_dims(BIGARRAY_FLOAT64 | BIGARRAY_C_LAYOUT,
1, obj, 3);
CAMLreturn(result);
}
I've have the feeling that the problem is either blindingly obvious or I
have misunderstood sections 18.3-18.5 of the manual.
Thanks for any insight/help.
Ben Jackson.
next reply other threads:[~2005-08-05 14:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-05 14:16 brjackson [this message]
2005-08-05 14:41 ` [Caml-list] " Daniel Bünzli
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=5160.195.188.213.34.1123251372.squirrel@195.188.213.34 \
--to=brjackson@blueyonder.co.uk \
--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