caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Berke Durak <berke@altern.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] String.unescaped and some other little pitiful laments
Date: Wed, 11 Jul 2001 21:30:29 +0200	[thread overview]
Message-ID: <20010711213029.B20109@pauillac.inria.fr> (raw)
In-Reply-To: <20010710200734.B10265@localhost.localdomain>; from berke@altern.org on Tue, Jul 10, 2001 at 08:07:34PM +0200

> Also I'd like to see those horrible functions returning parameters in
> global variables be eradicated, such as those that can be found in the Str
> (regular expression) module. 

Yes, the Str module is a thorn in my side: not only the API is bad
(too much reliance on global state), but the underlying implementation
(the GNU regexp library) is awful -- on moderately complex regular
expressions, it can get really slow, or just abort on an exception.
(Stallman et al usually write better code than this!)

I'd really love to get rid of it, but as usual I'm obsessed with
backward compatibility, and couldn't find an existing regexp library
that recognizes the same regexp language as Str -- so that we could easily
keep the old Str interface as a wrapper around the new interface.

So, this is a question to the developers of alternate regexp
libraries: how hard would it be to implement an Str emulation on top
of your libraries?  If you're interested, we can pursue this
discussion by private e-mail.

> Many people on this list are talking lighthearted about functions such
> as Obj.magic. These functions are pure evil. It makes me sorry to see
> that my favorite language has an unsafe and ugly type casting
> function. Modules using such features should be flagged as
> ``evil'', and the use of these functions should not be publicly
> advocated.

But they are not!  Not by us, at least.  You'd be hard-pressed to find
any mention of the Obj module in the OCaml docs.  There are a couple
of legitimate uses of Obj.magic in the toplevel loop, and a few other
uses (e.g. in ocamlyacc-generated parsers) that could be removed with
a little more work.

But, yes, I'd advise all OCaml programmers to never, never use
Obj.magic.  In particular, this can lead to incorrect code being
generated by the ocamlopt compiler (because it fools its
type-dependent optimizations).

A few years ago, I spent a couple of hours tracking an obscure GC bug
in a program sent by an user as part of a bug report.  It turned out
to be an incorrect use of Obj.magic in the source code...  Since then,
I first grep for Obj.magic in every bug report sent to us!

> PS. What is the purpose of the "uses unsafe features" flag in .cmo
> files ?  (it can be seen in the output of the "objinfo" program in the
> tools/ directory of the compiler). I've made a test program using
> unsafe features such as Obj and Array.unsafe_get but the flag wasn't
> set.

It's poorly named.  Actually, it tracks whether the module declares
external primitives (using the "external" syntax).  It's used for
type-safe dynamic loading of compiled bytecode: the Dynlink loader
lets you check that the bytecode was compiled against a set of known
interfaces (presumably not including unsafe operations such as
Obj.magic or Array.unsafe_get), but there is also the risk that the
bytecode simply declares these operations itself using well-chosen
"external" declarations.  So, Dynlink can also track "external"
declarations and prohibit them.

- Xavier Leroy
-------------------
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-07-11 19:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-10 18:07 Berke Durak
2001-07-10 18:55 ` Markus Mottl
2001-07-11  6:44   ` Jean-Christophe Filliatre
2001-07-11  6:37 ` Jean-Christophe Filliatre
2001-07-11  7:29   ` Claude Marche
2001-07-11 18:03   ` Jerome Vouillon
2001-07-11 19:30 ` Xavier Leroy [this message]
2001-07-11 20:33   ` Markus Mottl

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=20010711213029.B20109@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=berke@altern.org \
    --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).