caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jonathan Roewen" <jonathan.roewen@gmail.com>
To: "Chris Campbell" <cyberdanx@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Converting C arrays to Ocaml arrays
Date: Tue, 11 Apr 2006 15:41:06 +1200	[thread overview]
Message-ID: <ad8cfe7e0604102041x754d0e34w9eaa2975b2fd1ace@mail.gmail.com> (raw)
In-Reply-To: <c22844d10604101342t5e5796f1g9618eb9a07cbf658@mail.gmail.com>

> CAMLprim value ml_glGenTextures(value num)
> {
>  CAMLparam1(num);
>  CAMLlocal1(ml_tex_ids);
>
>  GLuint numTextures = Int32_val(num);
>
>  GLuint *ids = (GLunit *)calloc(numTextures, sizeof(GLuint));
>  glGenTextures(numTextures, ids);
>
>  GLuint **id_ptrs = (GLuint **)calloc (numTextures+1, sizeof(GLunit *));
>  id_ptrs[numTextures] = NULL;
>
>  for (i = 0; i < numTextures; i++)
>  {
>     id_ptrs[i] = &ids[i];
>  }
>
>  ml_tex_ids = caml_alloc_array
> (&wrapper_around_copy_int32_which_takes_ptr, id_ptrs);
>
>  CAMLreturn(ml_tex_ids);
> }

This may be naive of me, but couldn't it be much simpler?

CAMLprim value ml_glGenTextures(value num)
{
 CAMLparam1(num);
 CAMLlocal1(ml_tex_ids);

 GLuint numTextures = Int_val(num);

 GLuint *ids = (GLuint *)calloc(numTextures, sizeof(GLuint));
 glGenTextures(numTextures, ids);

 ml_tex_ids = caml_alloc_array(caml_copy_int32, ids);
 CAMLreturn(ml_tex_ids);
}

I believe the array should already be null-terminated. I'd have to
check the docs to see if caml_alloc_array really depends on the values
being pointers, but for now, I'm assuming that as long as type in the
array match the type required of the function to be applied, it should
work okay.

Jonathan


  parent reply	other threads:[~2006-04-11  9:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-10 20:42 Chris Campbell
2006-04-10 21:21 ` [Caml-list] " Michael Wohlwend
2006-04-11  3:41 ` Jonathan Roewen [this message]
2006-04-11  3:46   ` Jonathan Roewen

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=ad8cfe7e0604102041x754d0e34w9eaa2975b2fd1ace@mail.gmail.com \
    --to=jonathan.roewen@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=cyberdanx@gmail.com \
    /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).