From: nari <nari@ibmoto.com>
To: caml-list@inria.fr
Subject: Extending a list on the OCAML side that is initially allocated on the C side
Date: Wed, 02 Feb 2000 17:25:37 -0600 [thread overview]
Message-ID: <3898BCF1.B4FE1971@ibmoto.com> (raw)
Hi,
I have an OCAML and C function as follows
**************OCAML side*****************
let simple_list_test m = m @ [100]
let _ =
Callback.register "simple_list_test" simple_list_test;
***********************************************
*************C side***********************
main(int argc, char *argv[])
{
int *list, *new_list;
fprintf (stderr,"Initializing OCAML\n");
caml_main(argv);
fprintf (stderr,"Initializing OCAML Done\n");
list = (int *) calloc(10, sizeof(int));
new_list = call_caml_simple_list_test(list);
/* I expect eleven elements in list after the call to ocaml and expect
100
to be printed out */
printf("The last element is %d\n", new_list[10]);
}
int * call_caml_simple_list_test(int *list)
{
static value * closure_f = NULL;
value ret_val;
if (closure_f == NULL) {
closure_f = caml_named_value("simple_list_test");
}
ret_val = callback(*closure_f, (value) list);
return (int *)ret_val;
}
**********************End C side*****************
My understanding (from documentation) is that since "list" is allocated
on the "C" side, it is outside the heap of the ocaml garbage collector
and
all I have to do is to cast the pointer to a caml 'value' type.
I get a core dump (segmentation fault) with the above code.
How can I modify or extend the list (or for that matter, any record)
on the OCAML side and then send the C side back a pointer that I can
dereference.
Thanx.
--
**************************************************
Narayanan Krishnamurthy (Nari)
The Somerset PowerPC Design Center,
Architecture and Systems Platforms
Motorola Inc. Semiconductor Products Sector
7700 W. Parmer Lane, Austin, TX 78729
Loc/MD: TX32/PL30 _
email : nari@ibmoto.com / \ email: r44117@email.mot.com
Ph : (512) 996-4863 |O O| Fax : (512) 996-7432
************************| I |**********************
\ o /
---
next reply other threads:[~2000-02-07 9:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-02-02 23:25 nari [this message]
2000-02-07 13:30 ` Michel Quercia
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=3898BCF1.B4FE1971@ibmoto.com \
--to=nari@ibmoto.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