Hello

Say I have a C struct that looks like this:

  struct thing {
    void *buffer;
    unsigned long length;
  }

This struct is used to pass values of multiple types to a function. For
example, given

  struct thing *t = malloc(...);
  unsigned long len;

you do something like

  int x = 42;
  len = sizeof(int);
  t->length = len;
  t->buffer = malloc(len);
  memcpy(t->buffer, &x, len);

or

  char *s = "foo";
  len = strlen(s);
  t->length = len;
  t->buffer = malloc(len);
  memcpy(t->buffer, s, len);

In OCaml I'm representing the struct as

  module Thing = struct
    type t
    type t = thing structure
    let t : t typ = structure "thing"
    let buffer = field t "buffer" (ptr void)
    let length = field t "length" ulong
  end

What I couldn't figure out was how do do the equivalent of the memcpy()
step using Ctypes. I've found Stubs.memcpy but it doesn't seem to be
exported.

Can this kind of thing be done directly using Ctypes or should I write a
stub to handle this case?

Thanks in advance,
Andre

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Ctypes mailing list
[email protected]
http://lists.ocaml.org/listinfo/ctypes

Reply via email to