develooper Front page | perl.perl5.porters | Postings from July 2019

[perl #134302] ext/XS-APItest/t/locale.t fails to finish in VS 2019

Thread Previous
From:
Tony Cook
Date:
July 23, 2019 06:30
Subject:
[perl #134302] ext/XS-APItest/t/locale.t fails to finish in VS 2019
Message ID:
rt-4.0.24-15893-1563863399-1732.134302-75-0@perl.org
# New Ticket Created by  Tony Cook 
# Please include the string:  [perl #134302]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=134302 >


This is a bug report for perl from tony@develop-help.com,
generated with the help of perlbug 1.41 running under perl 5.31.3.


-----------------------------------------------------------------
[Please describe your issue here]

While testing perl on Windows 10 x64 I saw ext/XS-APItest/t/locale.t
failing.

On further tracing this appeared to be aborting on a setlocale() call in
t/loc_tools.pl in _trylocale().

On running the test in the debugger (after rebuild with CFG=DebugFull, and
tracking down the CRT source) I managed to get a back trace.

This appears to be failing when the CRT is internally trying to convert a
locale name of "Catal\x{e0}" from a narrow string to a wide string.

>From the CRT source in setlocale.cpp:

extern "C" static wchar_t* __cdecl call_wsetlocale(int const category, char const* const narrow_locale)
{
    if (narrow_locale == nullptr)
	return _wsetlocale(category, nullptr);

    size_t size;
    _ERRCHECK_EINVAL_ERANGE(mbstowcs_s(&size, nullptr, 0, narrow_locale, INT_MAX));

    __crt_unique_heap_ptr<wchar_t> wide_locale(_calloc_crt_t(wchar_t, size));
    if (wide_locale.get() == nullptr)
	return nullptr;

-->> exception thrown by this check
    if (_ERRCHECK_EINVAL_ERANGE(mbstowcs_s(nullptr, wide_locale.get(), size, narrow_locale, _TRUNCATE)) != 0)
	return nullptr;

    return _wsetlocale(category, wide_locale.get());
}

At the point of the exception size is zero, and wide_locale's pointer is
non-NULL, which mbstowcs_s() fails.

I suspect the first sizing mbstowcs_s() call is failing because the current locale
isn't the C locale, and the failing string isn't validly encoded in that current
locale, which messes it up for the second call.

It may be the the win32 specific code should be using _wsetlocal() instead of
setlocale() to avoid this conversion, of specifically set LC_CTYPE to the C
locale.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.31.3:

Configured by tony at Tue Jul 23 15:45:08 2019.

Summary of my perl5 (revision 5 version 31 subversion 3) configuration:
   
  Platform:
    osname=MSWin32
    osvers=10.0.17134.885
    archname=MSWin32-x64-multi-thread
    uname=''
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cl'
    ccflags ='-nologo -GF -W3 -Od -MDd -Zi -D_DEBUG -DDEBUGGING -fp:precise -DWIN32 -D_CONSOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_WINSOCK_DEPRECATED_NO_WARNINGS  -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO'
    optimize='-Od -MDd -Zi -D_DEBUG -DDEBUGGING -fp:precise'
    cppflags='-DWIN32'
    ccversion='19.20.27508.1'
    gccversion=''
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=undef
    longlongsize=8
    d_longdbl=define
    longdblsize=8
    longdblkind=0
    ivtype='__int64'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='__int64'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='link'
    ldflags ='-nologo -nodefaultlib -debug -libpath:"c:\perl\lib\CORE" -machine:AMD64 -subsystem:console,"5.02"'
    libpth="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\\lib\x64"
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrtd.lib vcruntimed.lib ucrtd.lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrtd.lib vcruntimed.lib ucrtd.lib
    libc=ucrtd.lib
    so=dll
    useshrplib=true
    libperl=perl531.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-dll -nologo -nodefaultlib -debug -libpath:"c:\perl\lib\CORE" -machine:AMD64 -subsystem:console,"5.02"'


---
@INC for perl 5.31.3:
    C:/Users/Tony/dev/perl/git/perl/lib

---
Environment for perl 5.31.3:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\\MSBuild\Current\Bin;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Microsoft SQL
Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Users\Tony\AppData\Local\Microsoft\WindowsApps;C:\Users\Tony\AppData\Local\GitHubDesktop\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;c:\sperl-5.28.1.1-64bit-portable\c\bin
    PERL_BADLANG (unset)
    SHELL (unset)


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About