caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joel Reymont <joelr1@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: [Caml-list] problem with array access in a c function
Date: Sun, 15 May 2011 15:50:34 +0200	[thread overview]
Message-ID: <88F79E1B-2D9F-4A17-A6B7-060074FF77E9@gmail.com> (raw)

The types are at the bottom here, in the Poll module:

https://github.com/wagerlabs/ocaml-zmq/blob/master/src/ZMQ.ml

The C function in question is caml_zmq_poll_of_pollitem_array here:

https://github.com/wagerlabs/ocaml-zmq/blob/master/src/poll.c

I can grab the number of elements in the array just fine, e.g.
	
	int n = Wosize_val(pollitem_array); 

This will give me n of 1 or 2, depending on the number of tuples in the array. 

This sets current_elem to 0x400 (1024)

	current_elem = Field(pollitem_array, n); 

This returns 1

	int block = Is_block(current_elem); 

And this crashes

	int tag = Tag_val(current_elem); 

Subsequent attempts to pull out the custom data crash as well. 

Interestingly enough, Field(current_value, 0) and Field(current_value, 1) are 8 bytes apart. 

I'm on a 64-bit machine and I expect tuple elements to be pointers since one is a custom block and the other a variant.

What am I doing wrong?

	Thanks, Joel

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------





             reply	other threads:[~2011-05-15 13:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-15 13:50 Joel Reymont [this message]
2011-05-15 13:59 ` [Caml-list] " Joel Reymont

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=88F79E1B-2D9F-4A17-A6B7-060074FF77E9@gmail.com \
    --to=joelr1@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).