caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: Paul Steckler <steck@stecksoft.com>
Cc: "caml-list@yquem.inria.fr" <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Windows filenames and Unicode
Date: Wed, 29 Sep 2010 07:58:32 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D92AEBCD@Remus.metastack.local> (raw)
In-Reply-To: <AANLkTimXMWGQ=_7vCbLo7yP_14pU4Ld8jqBA0iq9-69T@mail.gmail.com>

Paul Steckler wrote:
> On Wed, Sep 29, 2010 at 4:23 PM, David Allsopp <dra-news@metastack.com>
> wrote:
> > A way (but not foolproof on Windows 7 and Windows 2008 R2 because you
> > can disable it) would be to wrap the GetShortPathName Windows API
> > function[1] which will convert the pathname to its DOS 8.3 format which
> > will not contain Unicode characters. Another way might be to wrap the
> > Unicode version of CreateFileEx and convert the result into a handle
> > compatible with the standard library functions but I reckon that could be
> > tricky!
> 
> For Linux, I was planning on enforcing the invariant that all strings
> inside my program are UTF-8.
> For Windows, I could use the same invariant, and modify the OCaml runtime
> so that all calls to Windows file primitives have those strings translated
> to UTF-16 (and return values translated back to UTF-8).  That is, I'd have
> to build a custom version of OCaml and wrap CreateFile, etc. with such
> Unicode translation functions.

Rather than hacking the OCaml runtime (the relevant code is {byte,asm}run/sys.c, btw) personally I'd produce a separate module of my own with two implementations - one for Linux which just uses the built-in primitives and then one for Windows using WinAPI functions directly. A cursory glance at the runtime code suggests that hacking wide support onto the runtime is not a "one-liner".

> All this is made slightly more complicated by the fact that I'm using the
> MinGW version of OCaml.

Shouldn't make it (too much) harder - I use the MinGW build of OCaml without issue for C stubs, after a slightly steep learning-curve. The w32api package in Cygwin provides all of the headers and link libraries for Windows libraries (it's installed by default with the gcc-mingw). If you ever have to link with more exotic libraries, dlltool is (sort of) your friend (it with a little bit of help allows you to generate the .a files needed for the DLL you're linking with - 3rd party libraries on Windows tend only to ship the MSVC .lib files)

> Hmmm, I shouldn't have to do this.  Are there plans afoot to modernize
> OCaml's string-handling?

Can o' worms, I expect! Windows (by which I mean Windows NT) took the simplest route of 16-bit wchars for Unicode but it's not necessarily the best way of programming in general... the problem with going Unicode is *how* you go Unicode.


David


  parent reply	other threads:[~2010-09-29  7:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-29  5:05 Paul Steckler
2010-09-29  6:23 ` [Caml-list] " David Allsopp
2010-09-29  7:26   ` Paul Steckler
2010-09-29  7:56     ` Michael Ekstrand
2010-09-29  7:58     ` David Allsopp [this message]
2010-09-29  8:14     ` Jerome Vouillon
2010-09-30 19:27     ` ygrek

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=E51C5B015DBD1348A1D85763337FB6D92AEBCD@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=steck@stecksoft.com \
    /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).