caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jun P. FURUSE" <Jun.Furuse@inria.fr>
To: bpr@best.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Segfault in a native code multi-threaded program
Date: Mon, 20 Aug 2001 18:54:13 +0200 (CEST)	[thread overview]
Message-ID: <20010820.185413.84976020.Jun.Furuse@inria.fr> (raw)
In-Reply-To: <Pine.BSF.4.21.0108170940130.18517-100000@shell5.ba.best.com>

Hello,

> > > <hint for next ocaml ;)> > 
> >   It would be very nice to be able to rely on Marshal as safely as on
> >   ocaml typing. Just to be sure that if I expect an int * string, I will
> >   effectively receive an int * string or raise an exception. It could
> >   probably be done using the same tricks as used in printf formatters.
> > 
> > </hint for next ocaml ;)>
> 
> A more type safe marshaling framework is way up there on my list of
> desired enhancements. I think this will be part of the extensional
> polymorphism enhancements that you can see now in G'Caml. 

Yes. I did not announce this feature since it did not work in the last
version. I quickly fixed it and replaced the source archive at

	 http://pauillac.inria.fr/~furuse/generics/index.html

As always, I have to warn that this is quite experimental and
therefore may contain MANY BUGS... And it is based on O'Caml 2.02.

This "safe value I/O" facility consists of two primitive functions,
export_value and import_value. They can be replacements of the
O'Caml's original value I/O functions, output_value and input_value:

	# export_value;;
	- : out_channel -> $a -> unit = <fun>
	# import_value;;
	- : in_channel -> $a = <fun>

export_value primitive writes an ML value with its encoded type
information to the channel. import_value read its value and type
information and checks it matches with the current type context. If
the type of output value is more general than the expected type, it
permits the value importation. Otherwise, it raises an exception:

	# let oc = open_out_bin "foo.dat" in
	  export_value oc (1,"hello");;
	- : unit = ()

It writes out the value (1,"hello") and the fingerprint of its type
int * string. The import_value primitive compares this fingerprint
with the expected type: 

	# let ic = open_in_bin "foo.dat" in 
	  (import_value ic : int * string);;
	- : int * string = 1, "hello"
	
	# let ic = open_in_bin "foo.dat" in 
	  (import_value ic : int * float);;
	- : int * string = 1, "hello"
	Uncaught exception: Extern.Type_match_failure(...)

Programs exchanging values need not to be same. Moreover, you hackers
may be able to exchange values safely even between different types, 
if their type definition structures are isomorphic to each other except
differences of their names. For example, these two type definitions
have isomorphic:  

	type 'a tree = Branch of 'a tree * 'a tree  
		     | Leaf of 'a
	
	type 'a arbre = Branche of 'a arbre * 'a arbre
		      | Feuille of 'a

The drawback is that your programs must carry the digests of data types
(= fingerprints) at run time. This costs some amount of space, but
it is usually small compared to the other part.

Regards,
-----------------------------------------------------------------------
Jun P. Furuse 					 Jun.Furuse@inria.fr
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-08-20 16:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-16  8:08 David Mentre
2001-08-16 12:45 ` Vitaly Lugovsky
2001-08-17  8:09   ` David Mentre
2001-08-17 16:54     ` Brian Rogoff
2001-08-20  9:12       ` David Mentre
2001-08-20 16:54       ` Jun P. FURUSE [this message]
2001-08-18 23:15     ` John Max Skaller
2001-08-19  0:24       ` John Gerard Malecki
2001-08-19 18:18         ` [Caml-list] Ocaml ffi release 1.2.2 dsfox
     [not found] ` <3B7C5A74.15141D95@maxtal.com.au>
     [not found]   ` <qtlitfm6ajh.fsf@pochi.inria.fr>
     [not found]     ` <3B7F0C99.FEDEAA86@maxtal.com.au>
     [not found]       ` <qtl3d6m4vkt.fsf@pochi.inria.fr>
2001-08-21 19:20         ` [Caml-list] Segfault in a native code program using pm variants John Max Skaller
2001-08-23  8:54           ` Xavier Leroy
2001-08-20 12:57 [Caml-list] Segfault in a native code multi-threaded program Krishnaswami, Neel

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=20010820.185413.84976020.Jun.Furuse@inria.fr \
    --to=jun.furuse@inria.fr \
    --cc=bpr@best.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;
as well as URLs for NNTP newsgroup(s).