From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id E177BBB9C for ; Thu, 22 Dec 2005 05:03:49 +0100 (CET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.195]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jBM43mma024129 for ; Thu, 22 Dec 2005 05:03:49 +0100 Received: by wproxy.gmail.com with SMTP id 68so276652wri for ; Wed, 21 Dec 2005 20:03:48 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Xe2teSy6L9MJCjQOl9ApTKjekCN5GnxZCCpVpqzyKoPe6h0cpTnsiDdf3F+vITeGkudYXkK62bffgH4c4LGeVl73wDyDEs8DBSIa6ZUBLRX9+opDXey3ZIPf0+WtpUHFfOjkA38hTNr0zp0dz3Ou+VQvI3Au59rgxmZ49cIaGpg= Received: by 10.64.149.14 with SMTP id w14mr856167qbd; Wed, 21 Dec 2005 20:03:48 -0800 (PST) Received: by 10.65.23.16 with HTTP; Wed, 21 Dec 2005 20:03:48 -0800 (PST) Message-ID: Date: Thu, 22 Dec 2005 17:03:48 +1300 From: Jonathan Roewen To: caml-list@yquem.inria.fr Subject: [Caml-list] HELP! In-place modification of caml globals... MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at nez-perce with ID 43AA25A4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 globals:01 mutable:01 char:01 mutable:01 char:01 globals:01 stdin:01 stdout:01 stderr:01 val:01 val:01 initialise:01 descriptors:01 stdin:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 Hi, I need some help, badly ;-) This is the one thing getting in my way at present, and I don't know how to fix it. I have two types: type in_channel =3D { =09mutable in_read : unit -> char; =09mutable in_input : string -> int -> int -> int; =09mutable in_seek : int -> unit; =09mutable in_tell : unit -> int; =09mutable in_close : unit -> unit; =09mutable in_length : unit -> int; } type 'a out_channel =3D { =09mutable out_write : char -> unit; =09mutable out_output : string -> int -> int -> unit; =09mutable out_seek : int -> unit; =09mutable out_tell : unit -> int; =09mutable out_close : unit -> 'a; =09mutable out_flush : unit -> unit; =09mutable out_length : unit -> int; } and three globals: let stdin =3D =09let read =3D (fun _ -> raise Input_closed) =09and input =3D (fun _ _ _ -> raise Input_closed) =09and seek =3D (fun _ -> raise Input_closed) =09and tell =3D (fun _ -> raise Input_closed) =09in create_in read input seek tell default_close default_length let stdout =3D =09let write =3D (fun _ -> raise Output_closed) =09and output =3D (fun _ _ _ -> raise Output_closed) =09and seek =3D (fun _ -> raise Output_closed) =09and tell =3D (fun _ -> raise Output_closed) =09in create_out write output seek tell default_close default_flush default= _length let stderr =3D =09let write =3D (fun _ -> raise Output_closed) =09and output =3D (fun _ _ _ -> raise Output_closed) =09and seek =3D (fun _ -> raise Output_closed) =09and tell =3D (fun _ -> raise Output_closed) =09in create_out write output seek tell default_close default_flush default= _length By default, they're all closed. What I want to do is swap them with other instances at kernel startup. So I defined two external functions: external swap_input : in_channel -> in_channel -> unit =3D "caml_ml_swap_in= put";; external swap_output : unit out_channel -> unit out_channel -> unit =3D "caml_ml_swap_output";; Which are both defined as: value caml_ml_swap_input(value to, value from) { =09/* record has 6 fields */ =09Store_field(to, 0, Field(from, 0)); =09Store_field(to, 1, Field(from, 1)); =09Store_field(to, 2, Field(from, 2)); =09Store_field(to, 3, Field(from, 3)); =09Store_field(to, 4, Field(from, 4)); =09Store_field(to, 5, Field(from, 5)); =09return Val_unit; } value caml_ml_swap_output(value to, value from) { =09/* record has 7 fields */ =09Store_field(to, 0, Field(from, 0)); =09Store_field(to, 1, Field(from, 1)); =09Store_field(to, 2, Field(from, 2)); =09Store_field(to, 3, Field(from, 3)); =09Store_field(to, 4, Field(from, 4)); =09Store_field(to, 5, Field(from, 5)); =09Store_field(to, 6, Field(from, 6)); =09return Val_unit; } Then initialise with: (* init the standard IO descriptors *) swap_input stdin kernel_stdin;; swap_output stdout kernel_stdout;; swap_output stderr kernel_stderr;; However, as soon as I try to print, I get a fatal error that output stream is closed =3D/ What's the correct way to do this? Jonathan