This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
upgrade bytes_to_uni
authorAndy Lester <andy@petdance.com>
Fri, 12 May 2006 00:21:23 +0000 (19:21 -0500)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 12 May 2006 15:48:43 +0000 (15:48 +0000)
Message-ID: <20060512052123.GA21648@petdance.com>

p4raw-id: //depot/perl@28180

embed.fnc
embed.h
pp_pack.c
proto.h

index 1d98dff..3fa7b93 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1224,6 +1224,7 @@ sR        |const char *|get_num   |NN const char *ppat|NN I32 *lenptr
 ns     |bool   |need_utf8      |NN const char *pat|NN const char *patend
 ns     |char   |first_symbol   |NN const char *pat|NN const char *patend
 sR     |char * |sv_exp_grow    |NN SV *sv|STRLEN needed
+sR     |char * |bytes_to_uni   |NN const U8 *start|STRLEN len|NN char *dest
 #endif
 
 #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT)
diff --git a/embed.h b/embed.h
index 9383ce6..9f2d04f 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define need_utf8              S_need_utf8
 #define first_symbol           S_first_symbol
 #define sv_exp_grow            S_sv_exp_grow
+#define bytes_to_uni           S_bytes_to_uni
 #endif
 #endif
 #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT)
 #define need_utf8              S_need_utf8
 #define first_symbol           S_first_symbol
 #define sv_exp_grow(a,b)       S_sv_exp_grow(aTHX_ a,b)
+#define bytes_to_uni(a,b,c)    S_bytes_to_uni(aTHX_ a,b,c)
 #endif
 #endif
 #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT)
index 5deede9..3fa0e74 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -702,21 +702,21 @@ next_uni_uu(pTHX_ const char **s, const char *end, I32 *out)
     return TRUE;
 }
 
-STATIC void
-bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char **dest) {
-    U8 buffer[UTF8_MAXLEN];
+STATIC char *
+S_bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char *dest) {
     const U8 * const end = start + len;
-    char *d = *dest;
+
     while (start < end) {
+       U8 buffer[UTF8_MAXLEN];
         const int length =
            uvuni_to_utf8_flags(buffer, NATIVE_TO_UNI(*start), 0) - buffer;
        switch(length) {
          case 1:
-           *d++ = buffer[0];
+           *dest++ = buffer[0];
            break;
          case 2:
-           *d++ = buffer[0];
-           *d++ = buffer[1];
+           *dest++ = buffer[0];
+           *dest++ = buffer[1];
            break;
          default:
            Perl_croak(aTHX_ "Perl bug: value %d UTF-8 expands to %d bytes",
@@ -724,12 +724,13 @@ bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char **dest) {
        }
        start++;
     }
-    *dest = d;
+    return dest;
 }
 
 #define PUSH_BYTES(utf8, cur, buf, len)                                \
 STMT_START {                                                   \
-    if (utf8) bytes_to_uni(aTHX_ (U8 *) buf, len, &(cur));     \
+    if (utf8)                                                  \
+       (cur) = bytes_to_uni((U8 *) buf, len, (cur));           \
     else {                                                     \
        Copy(buf, cur, len, char);                              \
        (cur) += (len);                                         \
@@ -764,7 +765,7 @@ STMT_START {                                        \
 STMT_START {                                   \
     if (utf8) {                                        \
        const U8 au8 = (byte);                  \
-       bytes_to_uni(aTHX_ &au8, 1, &(s));      \
+       (s) = bytes_to_uni(&au8, 1, (s));       \
     } else *(U8 *)(s)++ = (byte);              \
 } STMT_END
 
@@ -3052,7 +3053,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                                len+(endb-buffer)*UTF8_EXPAND);
                        end = start+SvLEN(cat);
                    }
-                   bytes_to_uni(aTHX_ buffer, endb-buffer, &cur);
+                   cur = bytes_to_uni(buffer, endb-buffer, cur);
                } else {
                    if (cur >= end) {
                        *cur = '\0';
diff --git a/proto.h b/proto.h
index 5ab1d5e..43a749a 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -3335,6 +3335,11 @@ STATIC char *    S_sv_exp_grow(pTHX_ SV *sv, STRLEN needed)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
 
+STATIC char *  S_bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char *dest)
+                       __attribute__warn_unused_result__
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_3);
+
 #endif
 
 #if defined(PERL_IN_PP_CTL_C) || defined(PERL_DECL_PROT)