caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2005-08-05 14:06 brjackson
  0 siblings, 0 replies; only message in thread
From: brjackson @ 2005-08-05 14:06 UTC (permalink / raw)
  To: caml-list

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.

Bob Jackson.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-08-05 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-05 14:06 brjackson

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