From: Xavier.Redon@eudil.fr (Xavier.Redon)
To: caml-list@inria.fr
Subject: A list of finalized values ?
Date: Thu, 6 May 1999 22:36:29 +0200 (MET DST) [thread overview]
Message-ID: <199905062036.WAA27067@servnx.priv.eudil.fr> (raw)
I try to build a list of finalized values in C and use it under Caml.
If I use alloc_final with used=0 and max=1, no problem, that works.
But if I try with used=1 and max=1000 the custom top level enter in
a endless loop (presumably in the GC).
There are the sources of an small example :
I must do a very basic error but I had spend a lot of time
seeking it ... If you have a hint send it also to Xavier.Redon@eudil.fr
I'm not sure I'm yet in the mailing list.
Essai.mli:
====================================
type t
val int_list : unit -> t list
val int_convert : t -> int
====================================
Essai.ml:
====================================
type entier
type t = entier
external int_list : unit -> entier list = "int_list" ;;
external int_convert : entier -> int = "int_get" ;;
====================================
Essai.c:
====================================
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
void int_free(value integer)
{
int *temp=(int *)Field(integer,1);
if(temp!=NULL) free(temp);
}
value int_list(void)
{
CAMLlocal1(result);
int i;
result=Val_int(0);
for(i=0;i<10;i++){
CAMLlocal2(subelement,temp);
int *integer=malloc(sizeof(int));
*integer=i;
subelement=alloc_final(2,int_free,1,100);
Store_field(subelement,1,(value)integer);
temp=alloc(2,0);
Store_field(temp,0,subelement);
Store_field(temp,1,result);
result=temp;
}
CAMLreturn result;
}
value int_get(value integer)
{
CAMLparam1(integer);
CAMLreturn Val_int(*(int *)Field(integer,1));
}
====================================
PS:
The CAMLxxx macros generate a very long list of warnings when compiled
with -Wall. CAMLreturn is not very safe : try if(cond) CAMLreturn result :-)
next reply other threads:[~1999-05-07 7:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-06 20:36 Xavier.Redon [this message]
1999-05-07 15:32 ` Xavier Leroy
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=199905062036.WAA27067@servnx.priv.eudil.fr \
--to=xavier.redon@eudil.fr \
--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