From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p23L9NWa000645 for ; Thu, 3 Mar 2011 22:09:23 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlgBALKSb03RVdY0kGdsb2JhbACmXwgVAQEBAQkJDAcRBCGjPIolgh2FMC+IWwEBAwWFXASMLIQyhCU6 X-IronPort-AV: E=Sophos;i="4.62,260,1297033200"; d="scan'208";a="77043550" Received: from mail-bw0-f52.google.com ([209.85.214.52]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Mar 2011 22:08:55 +0100 Received: by bwj24 with SMTP id 24so1945037bwj.39 for ; Thu, 03 Mar 2011 13:08:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding; bh=5EM18X6sr/SUaEGhY29Dg2MOD4ZN7P/og6/uMKFZIWY=; b=cPGakvEv6fQ1eYLyVpKRe76PiGj59lvSGrSVon3SiQPXQkgF6svO3ZhpXp72wvKzvq 9wu9YPeueEhRgAH4o53UiQ7sgVfnXFA8zYZDcuZ50yMgWLyG7nRjnb5yXKsBFEVG/O+Q k9tHZik8CG3SJu4NGrkBry+XS6zsaUe/AU758= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=k+4inlEhAIlOw/a3dYFdbSkX4jqpy/CxdM2UAilI2NbuJcsIniP7JcFT9ern9POg+/ 2UQdLNUL1hJz8I+GT2x245r1lrfMgNd228QGR78JV8+dygdYKHRBJBMBkM4CPwvI5IId +4mWsB2Gs4ElMW1x5o0ohyRNM3ZFv81pnjFrk= Received: by 10.204.153.14 with SMTP id i14mr1898723bkw.173.1299186528018; Thu, 03 Mar 2011 13:08:48 -0800 (PST) Received: from lemon.local.tld (160-249-133-95.pool.ukrtel.net [95.133.249.160]) by mx.google.com with ESMTPS id 12sm1082786bki.7.2011.03.03.13.08.46 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Mar 2011 13:08:47 -0800 (PST) Date: Thu, 3 Mar 2011 23:08:18 +0200 From: ygrek To: Caml List Message-Id: <20110303230818.e9e51326.ygrekheretix@gmail.com> In-Reply-To: <3CD59A75-1250-4CFD-9E72-AE85AE96477E@wanadoo.fr> References: <3CD59A75-1250-4CFD-9E72-AE85AE96477E@wanadoo.fr> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] tips to debug ocaml programs segfaulting On Thu, 3 Mar 2011 10:19:14 -0800 Yoann Padioleau wrote: > Damn I hate unsafe unmarshallng ... This is easy to solve with small wrapper over Marshal and ensuring that every change in value type comes with change of tag. module type Value = sig type value val tag : string end exception Error module Marshal(V : Value) = struct type t = V.value let to_channel ch ?(flags=[]) x = output_string ch V.tag; Marshal.to_channel ch (x:t) flags let from_channel ch = let s = String.create (String.length V.tag) in really_input ch s 0 (String.length V.tag); if s <> V.tag then raise Error; (Marshal.from_channel ch : t) let to_string ?(flags=[]) x = V.tag ^ Marshal.to_string (x:t) flags let from_string s = let tag = String.slice s ~last:(String.length V.tag) in if tag <> V.tag then raise Error; (Marshal.from_string s (String.length V.tag) : t) end -- ygrek http://ygrek.org.ua