[m-rev.] for review: unicode paths on windows

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Dec 14 14:41:52 AEDT 2011


On Wed, 14 Dec 2011, Peter Wang wrote:

> Branches: main, 11.07
>
> Support Unicode file paths on Windows with C back-ends.
>
> This works by calling the wide-character versions of file functions,
> e.g. _wfopen instead of fopen.  To do so we have to convert between the
> internal string representation (UTF-8) and that used by the Windows API
> (UTF-16).
>
> library/io.m:
> 	Add functions to convert path string representation on Windows.
>
> 	Call Unicode-aware functions in io.open_input, etc.
>
> 	Call Unicode-aware functions in io.file_modification_time,
> 	io.file_type, io.check_file_accessibility, io.file_id, io.make_temp,
> 	io.remove_file, io.rename_file.
>
> library/dir.m:
> 	Call Unicode-aware functions in dir.make_single_directory and
> 	fold predicates.
>
> diff --git a/library/dir.m b/library/dir.m
> index 984fb1d..3c4a4a0 100644
> --- a/library/dir.m
> +++ b/library/dir.m
> @@ -1092,7 +1092,7 @@ dir.make_single_directory(DirName, Result, !IO) :-
>         may_not_duplicate],
> "
> #if defined(MR_WIN32)
> -    if (CreateDirectory(DirName, NULL)) {
> +    if (CreateDirectoryW(ML_utf8_to_wide(DirName), NULL)) {
>         Result = ML_make_mkdir_res_ok();
>     } else {
>         int error;
> @@ -1627,16 +1627,17 @@ dir.open(DirName, Res, !IO) :-
>         terminates, will_not_modify_trail, does_not_affect_liveness],
> "
> #if defined(MR_WIN32)
> -    WIN32_FIND_DATA file_data;
> -    ML_DIR_STREAM Dir;
> -    LPTSTR FirstFileName;
> -    char *dir_pattern;
> -    MR_Integer is_readable;
> +    WIN32_FIND_DATAW    file_data;
> +    ML_DIR_STREAM       Dir;
> +    LPTSTR              FirstFileName;
> +    char                *dir_pattern;
> +    MR_Integer          is_readable;
> +    char                *filename;
>
>     ML_check_dir_readable(DirName, &is_readable, &Result);
>     if (is_readable) {
>         dir_pattern = ML_make_path_name(DirName, MR_make_string_const(""*""));
> -        Dir = FindFirstFile(dir_pattern, &file_data);
> +        Dir = FindFirstFileW(ML_utf8_to_wide(dir_pattern), &file_data);

I suggest that you explicitly deallocate the result of the call to
ML_utf8_to_wide after the call to FindFirstFile using MR_GC_free.
(Any anywhere else that function is called.)
Doing so will be a bit nicer for the nogc grades.

Looks okay otherwise.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list