From: ygrek <ygrekheretix@gmail.com>
To: Caml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] tips to debug ocaml programs segfaulting
Date: Thu, 3 Mar 2011 23:08:18 +0200 [thread overview]
Message-ID: <20110303230818.e9e51326.ygrekheretix@gmail.com> (raw)
In-Reply-To: <3CD59A75-1250-4CFD-9E72-AE85AE96477E@wanadoo.fr>
On Thu, 3 Mar 2011 10:19:14 -0800
Yoann Padioleau <padator@wanadoo.fr> 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
next prev parent reply other threads:[~2011-03-03 21:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-03 17:56 Yoann Padioleau
2011-03-03 18:10 ` Yoann Padioleau
2011-03-03 18:19 ` Yoann Padioleau
2011-03-03 21:08 ` ygrek [this message]
2011-03-03 18:24 ` Guillaume Yziquel
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=20110303230818.e9e51326.ygrekheretix@gmail.com \
--to=ygrekheretix@gmail.com \
--cc=caml-list@yquem.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