This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tr///: return Size_t count rather than I32
authorDavid Mitchell <davem@iabyn.com>
Fri, 19 Jan 2018 12:45:37 +0000 (12:45 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 19 Jan 2018 13:47:39 +0000 (13:47 +0000)
Change the signature of all the internal do_trans*() functions to return
Size_t rather than I32, so that the count returned by tr//// can cope with
strings longer than 2Gb.

doop.c
embed.fnc
pp.c
proto.h

diff --git a/doop.c b/doop.c
index 22431ef..38b0286 100644 (file)
--- a/doop.c
+++ b/doop.c
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_simple(pTHX_ SV * const sv)
 {
 S_do_trans_simple(pTHX_ SV * const sv)
 {
-    I32 matches = 0;
+    Size_t matches = 0;
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv,len);
     U8 * const send = s+len;
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv,len);
     U8 * const send = s+len;
@@ -114,13 +114,13 @@ S_do_trans_simple(pTHX_ SV * const sv)
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_count(pTHX_ SV * const sv)
 {
     STRLEN len;
     const U8 *s = (const U8*)SvPV_nomg_const(sv, len);
     const U8 * const send = s + len;
 S_do_trans_count(pTHX_ SV * const sv)
 {
     STRLEN len;
     const U8 *s = (const U8*)SvPV_nomg_const(sv, len);
     const U8 * const send = s + len;
-    I32 matches = 0;
+    Size_t matches = 0;
     const OPtrans_map * const tbl = (OPtrans_map*)cPVOP->op_pv;
 
     PERL_ARGS_ASSERT_DO_TRANS_COUNT;
     const OPtrans_map * const tbl = (OPtrans_map*)cPVOP->op_pv;
 
     PERL_ARGS_ASSERT_DO_TRANS_COUNT;
@@ -159,13 +159,13 @@ S_do_trans_count(pTHX_ SV * const sv)
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_complex(pTHX_ SV * const sv)
 {
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv, len);
     U8 * const send = s+len;
 S_do_trans_complex(pTHX_ SV * const sv)
 {
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv, len);
     U8 * const send = s+len;
-    I32 matches = 0;
+    Size_t matches = 0;
     const OPtrans_map * const tbl = (OPtrans_map*)cPVOP->op_pv;
 
     PERL_ARGS_ASSERT_DO_TRANS_COMPLEX;
     const OPtrans_map * const tbl = (OPtrans_map*)cPVOP->op_pv;
 
     PERL_ARGS_ASSERT_DO_TRANS_COMPLEX;
@@ -283,7 +283,7 @@ S_do_trans_complex(pTHX_ SV * const sv)
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_simple_utf8(pTHX_ SV * const sv)
 {
     U8 *s;
 S_do_trans_simple_utf8(pTHX_ SV * const sv)
 {
     U8 *s;
@@ -291,7 +291,7 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
     U8 *d;
     U8 *start;
     U8 *dstart, *dend;
     U8 *d;
     U8 *start;
     U8 *dstart, *dend;
-    I32 matches = 0;
+    Size_t matches = 0;
     const I32 grows = PL_op->op_private & OPpTRANS_GROWS;
     STRLEN len;
     SV* const  rv =
     const I32 grows = PL_op->op_private & OPpTRANS_GROWS;
     STRLEN len;
     SV* const  rv =
@@ -392,13 +392,13 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_count_utf8(pTHX_ SV * const sv)
 {
     const U8 *s;
     const U8 *start = NULL;
     const U8 *send;
 S_do_trans_count_utf8(pTHX_ SV * const sv)
 {
     const U8 *s;
     const U8 *start = NULL;
     const U8 *send;
-    I32 matches = 0;
+    Size_t matches = 0;
     STRLEN len;
     SV* const  rv =
 #ifdef USE_ITHREADS
     STRLEN len;
     SV* const  rv =
 #ifdef USE_ITHREADS
@@ -443,12 +443,12 @@ S_do_trans_count_utf8(pTHX_ SV * const sv)
  * or may not be utf8.
  */
 
  * or may not be utf8.
  */
 
-STATIC I32
+STATIC Size_t
 S_do_trans_complex_utf8(pTHX_ SV * const sv)
 {
     U8 *start, *send;
     U8 *d;
 S_do_trans_complex_utf8(pTHX_ SV * const sv)
 {
     U8 *start, *send;
     U8 *d;
-    I32 matches = 0;
+    Size_t matches = 0;
     const I32 squash   = PL_op->op_private & OPpTRANS_SQUASH;
     const I32 del      = PL_op->op_private & OPpTRANS_DELETE;
     const I32 grows    = PL_op->op_private & OPpTRANS_GROWS;
     const I32 squash   = PL_op->op_private & OPpTRANS_SQUASH;
     const I32 del      = PL_op->op_private & OPpTRANS_DELETE;
     const I32 grows    = PL_op->op_private & OPpTRANS_GROWS;
@@ -611,7 +611,7 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
  * Returns a count of number of characters translated
  */
 
  * Returns a count of number of characters translated
  */
 
-I32
+Size_t
 Perl_do_trans(pTHX_ SV *sv)
 {
     STRLEN len;
 Perl_do_trans(pTHX_ SV *sv)
 {
     STRLEN len;
index cd654dd..b9351be 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -521,7 +521,7 @@ p   |Off_t  |do_sysseek     |NN GV* gv|Off_t pos|int whence
 : Defined in doio.c, used only in pp_sys.c
 pR     |Off_t  |do_tell        |NN GV* gv
 : Defined in doop.c, used only in pp.c
 : Defined in doio.c, used only in pp_sys.c
 pR     |Off_t  |do_tell        |NN GV* gv
 : Defined in doop.c, used only in pp.c
-p      |I32    |do_trans       |NN SV* sv
+p      |Size_t |do_trans       |NN SV* sv
 : Used in my.c and pp.c
 p      |UV     |do_vecget      |NN SV* sv|STRLEN offset|int size
 : Defined in doop.c, used only in mg.c (with /* XXX slurp this routine */)
 : Used in my.c and pp.c
 p      |UV     |do_vecget      |NN SV* sv|STRLEN offset|int size
 : Defined in doop.c, used only in mg.c (with /* XXX slurp this routine */)
@@ -2091,12 +2091,12 @@ Adp     |int    |nothreadhook
 p      |void   |init_constants
 
 #if defined(PERL_IN_DOOP_C)
 p      |void   |init_constants
 
 #if defined(PERL_IN_DOOP_C)
-sR     |I32    |do_trans_simple        |NN SV * const sv
-sR     |I32    |do_trans_count         |NN SV * const sv
-sR     |I32    |do_trans_complex       |NN SV * const sv
-sR     |I32    |do_trans_simple_utf8   |NN SV * const sv
-sR     |I32    |do_trans_count_utf8    |NN SV * const sv
-sR     |I32    |do_trans_complex_utf8  |NN SV * const sv
+sR     |Size_t |do_trans_simple        |NN SV * const sv
+sR     |Size_t |do_trans_count         |NN SV * const sv
+sR     |Size_t |do_trans_complex       |NN SV * const sv
+sR     |Size_t |do_trans_simple_utf8   |NN SV * const sv
+sR     |Size_t |do_trans_count_utf8    |NN SV * const sv
+sR     |Size_t |do_trans_complex_utf8  |NN SV * const sv
 #endif
 
 #if defined(PERL_IN_GV_C)
 #endif
 
 #if defined(PERL_IN_GV_C)
diff --git a/pp.c b/pp.c
index 4b1ccbb..d50ad7d 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -689,8 +689,8 @@ PP(pp_trans)
        PUSHs(newsv);
     }
     else {
        PUSHs(newsv);
     }
     else {
-       I32 i = do_trans(sv);
-       mPUSHi(i);
+       Size_t i = do_trans(sv);
+       mPUSHi((UV)i);
     }
     RETURN;
 }
     }
     RETURN;
 }
diff --git a/proto.h b/proto.h
index 8e0c669..042a4ee 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -822,7 +822,7 @@ PERL_CALLCONV Off_t Perl_do_tell(pTHX_ GV* gv)
 #define PERL_ARGS_ASSERT_DO_TELL       \
        assert(gv)
 
 #define PERL_ARGS_ASSERT_DO_TELL       \
        assert(gv)
 
-PERL_CALLCONV I32      Perl_do_trans(pTHX_ SV* sv);
+PERL_CALLCONV Size_t   Perl_do_trans(pTHX_ SV* sv);
 #define PERL_ARGS_ASSERT_DO_TRANS      \
        assert(sv)
 PERL_CALLCONV UV       Perl_do_vecget(pTHX_ SV* sv, STRLEN offset, int size);
 #define PERL_ARGS_ASSERT_DO_TRANS      \
        assert(sv)
 PERL_CALLCONV UV       Perl_do_vecget(pTHX_ SV* sv, STRLEN offset, int size);
@@ -4542,32 +4542,32 @@ STATIC IO *     S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **s
        assert(gv); assert(mode); assert(saveifp); assert(saveofp); assert(savefd); assert(savetype)
 #endif
 #if defined(PERL_IN_DOOP_C)
        assert(gv); assert(mode); assert(saveifp); assert(saveofp); assert(savefd); assert(savetype)
 #endif
 #if defined(PERL_IN_DOOP_C)
-STATIC I32     S_do_trans_complex(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_complex(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX      \
        assert(sv)
 
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX      \
        assert(sv)
 
-STATIC I32     S_do_trans_complex_utf8(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_complex_utf8(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX_UTF8 \
        assert(sv)
 
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX_UTF8 \
        assert(sv)
 
-STATIC I32     S_do_trans_count(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_count(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COUNT        \
        assert(sv)
 
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COUNT        \
        assert(sv)
 
-STATIC I32     S_do_trans_count_utf8(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_count_utf8(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COUNT_UTF8   \
        assert(sv)
 
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_COUNT_UTF8   \
        assert(sv)
 
-STATIC I32     S_do_trans_simple(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_simple(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE       \
        assert(sv)
 
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE       \
        assert(sv)
 
-STATIC I32     S_do_trans_simple_utf8(pTHX_ SV * const sv)
+STATIC Size_t  S_do_trans_simple_utf8(pTHX_ SV * const sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE_UTF8  \
        assert(sv)
                        __attribute__warn_unused_result__;
 #define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE_UTF8  \
        assert(sv)