From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA06009 for caml-redistribution@pauillac.inria.fr; Mon, 7 Feb 2000 10:26:36 +0100 (MET) Resent-Message-Id: <200002070926.KAA06009@pauillac.inria.fr> Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA14617 for ; Thu, 3 Feb 2000 00:25:45 +0100 (MET) Received: from motgate2.mot.com (motgate2.mot.com [136.182.1.10]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id AAA18940 for ; Thu, 3 Feb 2000 00:25:43 +0100 (MET) Received: [from pobox.mot.com (pobox.mot.com [129.188.137.100]) by motgate2.mot.com (VWALL-IN-motgate2 2.0) with ESMTP id QAA03921 for ; Wed, 2 Feb 2000 16:25:42 -0700 (MST)] Received: [from cerberus.ibmoto.com ([129.38.252.34]) by pobox.mot.com (MOT-pobox 2.0) with ESMTP id QAA03322 for ; Wed, 2 Feb 2000 16:25:41 -0700 (MST)] Received: from ibmoto.com (hodaka.somerset.sps.mot.com [163.12.105.57]) by cerberus.ibmoto.com (8.9.0/8.9.0) with ESMTP id RAA13451 for ; Wed, 2 Feb 2000 17:25:38 -0600 (CST) Sender: nari@ibmoto.com Message-ID: <3898BCF1.B4FE1971@ibmoto.com> Date: Wed, 02 Feb 2000 17:25:37 -0600 From: nari Organization: Motorola/IBM Somerset PowerPC Design Center X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.6 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Extending a list on the OCAML side that is initially allocated on the C side Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-From: weis@pauillac.inria.fr Resent-Date: Mon, 7 Feb 2000 10:26:36 +0100 Resent-To: caml-redistribution@pauillac.inria.fr 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 / ---