end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

perl v.5.38から出力される Locale 'ja_JP.eucJP' is unsupported, and may crash the interpreter.

euc-jpで作成されたコンテンツを扱うサーバのperlをver.5.28→5.38へ更新。

すると、以下の「may crash」のような強め?の警告メッセージが表示。

$ export LANG=ja_JP.eucJP
$ /path/to/bin/perl sample-test.pl
Locale 'ja_JP.eucJP' is unsupported, and may crash the interpreter.

以下のurlによれば、perl 5.38からの仕様変更による表示らしい。

https://perldoc.jp/docs/perl/5.38.0/perl5380delta.pod

次に ver.5.28と ver.5.38 の locale.c を見ると、以下の通りで、 versionにより少々の差はありますが、以前から 「We only handle single-byte locales」らしい。

perl 5.28のlocale.c 抜粋

#  ifdef MB_CUR_MAX

        /* We only handle single-byte locales (outside of UTF-8 ones; so if
         * this locale requires more than one byte, there are going to be
         * problems. */
        DEBUG_Lv(PerlIO_printf(Perl_debug_log,
                 "%s:%d: check_for_problems=%d, MB_CUR_MAX=%d\n",
                 __FILE__, __LINE__, check_for_problems, (int) MB_CUR_MAX));

        if (   check_for_problems && MB_CUR_MAX > 1
            && ! PL_in_utf8_CTYPE_locale

               /* Some platforms return MB_CUR_MAX > 1 for even the "C"
                * locale.  Just assume that the implementation for them (plus
                * for POSIX) is correct and the > 1 value is spurious.  (Since
                * these are specially handled to never be considered UTF-8
                * locales, as long as this is the only problem, everything
                * should work fine */
            && strNE(newctype, "C") && strNE(newctype, "POSIX"))
        {
            multi_byte_locale = TRUE;
        }

#  endif

perl 5.38のlocale.c 抜粋

#    ifdef MB_CUR_MAX
    /* We only handle single-byte locales (outside of UTF-8 ones); so if this
     * locale requires more than one byte, there are going to be BIG problems.
     * */
    if (MB_CUR_MAX > 1 && ! PL_in_utf8_CTYPE_locale
            /* Some platforms return MB_CUR_MAX > 1 for even the "C" locale.
             * Just assume that the implementation for them (plus for POSIX) is
             * correct and the > 1 value is spurious.  (Since these are
             * specially handled to never be considered UTF-8 locales, as long
             * as this is the only problem, everything should work fine */
        && ! isNAME_C_OR_POSIX(newctype))
    {
        DEBUG_L(PerlIO_printf(Perl_debug_log,
                              "Unsupported, MB_CUR_MAX=%d\n", (int) MB_CUR_MAX));
        Perl_ck_warner_d(aTHX_ packWARN(WARN_LOCALE),
                         "Locale '%s' is unsupported, and may crash the"
                         " interpreter.\n",
                         newctype);
    }
#    endif

暫定的に「env LANG=en_US.utf8」を加えて、実行することで、 この警告表示を回避できますが、 eucは随分、マイナーになりつつありますので 根本的には、徐々にでも utf8に移行した方がよさそう。

$ env LANG=en_US.utf8 /path/to/bin/perl sample-test.pl