caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Whitington <john@coherentgraphics.co.uk>
To: caml-list@yquem.inria.fr
Subject: Debugging a C / Ocaml interface problem
Date: Thu, 19 Feb 2009 17:18:19 +0000	[thread overview]
Message-ID: <15903958-833F-4698-94AB-DF517CBBCEF2@coherentgraphics.co.uk> (raw)

Hi Folks,

I'm interfacing our Ocaml PDF stuff to C (threads passim), so main  
programs in C can use the tools.

Here's a bug which I can't track down. A value somewhere in the (pure)  
caml code is changing from one type constructor to another, breaking  
the code. So some tag in a block is being trampled on?

I've gone through all the rules in the manual, and can't find anything  
wrong.

The minimal broken main C program:

caml_startup(argv);
int hello3 = fromFile("hello.pdf");
removeAttachedFiles(hello3);
char data[] = {1,2,3,4,5,6,7,8,9,0};
setMetadataFromByteArray(hello3, data, 10);


Here are those functions:

int fromFile(char* filename)
{
   return(Int_val(caml_callback(*caml_named_value("fromFile"),  
caml_copy_string(filename))));
}

void removeAttachedFiles(int pdf)
{
   caml_callback(*caml_named_value("removeAttachedFiles"),  
Val_int(pdf));
   return;
}

void setMetadataFromByteArray(int pdf, char* data, int len)
{
   CAMLparam0 ();
   CAMLlocal1 (bytestream);
   bytestream = alloc_bigarray_dims(BIGARRAY_UINT8 |  
BIGARRAY_C_LAYOUT, 1, data, len);
   caml_callback2(*caml_named_value("setMetadataFromByteArray"),  
Val_int(pdf), bytestream);
   CAMLreturn0;
}


And here are the types of the caml functions called by those C  
functions:

val fromFile : string -> int

val removeAttachedFiles : int -> unit

val setMetadataFromByteArray : int -> (int,  
Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t -> unit

All the functions work ok in other circumstances (i.e not in this  
combination).


The failure occurs inside the Caml function setMetadataFromByteArray -  
Pdf.Indirect 27 is changing to Pdf.Integer 27 (Pdf.Indirect and  
Pdf.Integer are two constructors of the same type).

Can anyone spot anything wrong in the above? Something Bigarray- 
related perhaps?

Any suggestions as to how I might go about further debugging this?

With Thanks,

-- 
John Whitington
Coherent Graphics Ltd
http://www.coherentpdf.com/




             reply	other threads:[~2009-02-19 17:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-19 17:18 John Whitington [this message]
2009-02-19 17:34 ` [Caml-list] " Basile STARYNKEVITCH
2009-02-19 17:43   ` John Whitington

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=15903958-833F-4698-94AB-DF517CBBCEF2@coherentgraphics.co.uk \
    --to=john@coherentgraphics.co.uk \
    --cc=caml-list@yquem.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).