English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Debugging a C / Ocaml interface problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-02-19 (17:18)
From: John Whitington <john@c...>
Subject: Debugging a C / Ocaml interface problem
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  

The minimal broken main C program:

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

Here are those functions:

int fromFile(char* filename)

void removeAttachedFiles(int pdf)

void setMetadataFromByteArray(int pdf, char* data, int len)
   CAMLparam0 ();
   CAMLlocal1 (bytestream);
   bytestream = alloc_bigarray_dims(BIGARRAY_UINT8 |  
BIGARRAY_C_LAYOUT, 1, data, len);
Val_int(pdf), bytestream);

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

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  

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