In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/8dbe7cf704038839ade17963855cf8bfad0c30a3?hp=a55b162c2ce28c963bbb5fda32a8aff3855ff15d>

- Log -----------------------------------------------------------------
commit 8dbe7cf704038839ade17963855cf8bfad0c30a3
Author: Nicholas Clark <[email protected]>
Date:   Thu Oct 15 16:26:51 2009 +0100

    In strftime(), save a malloc()/free() by using sv_usepvn_flags().

M       ext/POSIX/POSIX.xs

commit dc57de01240c08cc88678a29fcb4e2d5f23efa66
Author: Nicholas Clark <[email protected]>
Date:   Thu Oct 15 17:09:12 2009 +0100

    POSIX::strftime() should be able to handle Unicode characters in the format
    string.
    
    (Restore the intent of 9e8c01f558a03902ff2f54935fd7e6dcc7ec656c, but with 
non-
    buggy tests. Improve the implementation so that it doesn't always upgrade 
the
    format string to UTF-8.)

M       ext/POSIX/POSIX.pm
M       ext/POSIX/POSIX.xs
M       ext/POSIX/t/time.t
-----------------------------------------------------------------------

Summary of changes:
 ext/POSIX/POSIX.pm |    2 +-
 ext/POSIX/POSIX.xs |   12 ++++++++----
 ext/POSIX/t/time.t |   11 ++++++++++-
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/ext/POSIX/POSIX.pm b/ext/POSIX/POSIX.pm
index 120769c..b410fd9 100644
--- a/ext/POSIX/POSIX.pm
+++ b/ext/POSIX/POSIX.pm
@@ -4,7 +4,7 @@ use warnings;
 
 our(@ISA, %EXPORT_TAGS, @EXPORT_OK, @EXPORT, $AUTOLOAD, %SIGRT) = ();
 
-our $VERSION = "1.17";
+our $VERSION = "1.18";
 
 use AutoLoader;
 
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index 6de3588..8572367 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1781,7 +1781,7 @@ mktime(sec, min, hour, mday, mon, year, wday = 0, yday = 
0, isdst = -1)
 #     ST(0) = sv_2mortal(newSVpv(...))
 void
 strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = 
-1)
-       char *          fmt
+       SV *            fmt
        int             sec
        int             min
        int             hour
@@ -1793,10 +1793,14 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = 
-1, yday = -1, isdst = -1)
        int             isdst
     CODE:
        {
-           char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, 
yday, isdst);
+           char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, 
year, wday, yday, isdst);
            if (buf) {
-               ST(0) = sv_2mortal(newSVpv(buf, 0));
-               Safefree(buf);
+               SV *const sv = sv_newmortal();
+               sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
+               if (SvUTF8(fmt)) {
+                   SvUTF8_on(sv);
+               }
+               ST(0) = sv;
            }
        }
 
diff --git a/ext/POSIX/t/time.t b/ext/POSIX/t/time.t
index 103a161..c349646 100644
--- a/ext/POSIX/t/time.t
+++ b/ext/POSIX/t/time.t
@@ -4,7 +4,7 @@ use strict;
 
 use Config;
 use POSIX;
-use Test::More tests => 9;
+use Test::More tests => 13;
 
 # go to UTC to avoid DST issues around the world when testing.  SUS3 says that
 # null should get you UTC, but some environments want the explicit names.
@@ -39,6 +39,15 @@ my $orig_loc = setlocale(LC_TIME, "C") || die "Cannot 
setlocale() to C:  $!";
 my $jan_16 = 15 * 86400;
 is(ctime($jan_16), strftime("%a %b %d %H:%M:%S %Y\n", localtime($jan_16)),
         "get ctime() equal to strftime()");
+is(strftime("%Y\x{5e74}%m\x{6708}%d\x{65e5}", localtime($jan_16)),
+   "1970\x{5e74}01\x{6708}16\x{65e5}",
+   "strftime() can handle unicode chars in the format string");
+
+my $ss = chr 223;
+unlike($ss, qr/\w/, 'Not internally UTF-8 encoded');
+is(ord strftime($ss, localtime), 223, 'Format string has correct character');
+unlike($ss, qr/\w/, 'Still not internally UTF-8 encoded');
+
 setlocale(LC_TIME, $orig_loc) || die "Cannot setlocale() back to orig: $!";
 
 # clock() seems to have different definitions of what it does between POSIX

--
Perl5 Master Repository

Reply via email to