Skip to content

Commit ddfa1d4

Browse files
committed
remove Ptrdiff_t, use ptrdiff_t instead
There is no reason for Ptrdiff_t to exist; ptrdiff_t is a completely standard C89 type. (I don't know what the ifdef PERL_GCC_PEDANTIC -> undef HAS_PTRDIFF_T logic was about; gcc -pedantic doesn't affect ptrdiff_t.) (Also, we really don't need to probe for ptrdiff_t because we've had unguarded uses of ptrdiff_t in core (op.c, utf8.c) for at least a year and no one has complained.)
1 parent bf6e580 commit ddfa1d4

File tree

10 files changed

+23
-43
lines changed

10 files changed

+23
-43
lines changed

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5342,7 +5342,7 @@ ES |AV * |add_multi_match|NULLOK AV *multi_char_matches \
53425342
|const STRLEN cp_count
53435343
ES |void |change_engine_size \
53445344
|NN RExC_state_t *pRExC_state \
5345-
|const Ptrdiff_t size
5345+
|const ptrdiff_t size
53465346
ERS |REGEXP *|compile_wildcard \
53475347
|NN const char *subpattern \
53485348
|const STRLEN len \

handy.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,16 +717,16 @@ based on the underlying C library functions):
717717
#define strBEGINs(s1,s2) (strncmp(s1,ASSERT_IS_LITERAL(s2), sizeof(s2)-1) == 0)
718718

719719
#define memBEGINs(s1, l, s2) \
720-
( (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1 \
720+
( (ptrdiff_t) (l) >= (ptrdiff_t) sizeof(s2) - 1 \
721721
&& memEQ(s1, ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
722722
#define memBEGINPs(s1, l, s2) \
723-
( (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2) - 1 \
723+
( (ptrdiff_t) (l) > (ptrdiff_t) sizeof(s2) - 1 \
724724
&& memEQ(s1, ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
725725
#define memENDs(s1, l, s2) \
726-
( (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1 \
726+
( (ptrdiff_t) (l) >= (ptrdiff_t) sizeof(s2) - 1 \
727727
&& memEQ(s1 + (l) - (sizeof(s2) - 1), ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
728728
#define memENDPs(s1, l, s2) \
729-
( (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2) \
729+
( (ptrdiff_t) (l) > (ptrdiff_t) sizeof(s2) \
730730
&& memEQ(s1 + (l) - (sizeof(s2) - 1), ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
731731
#endif /* End of making macros private */
732732

perl.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,21 +1694,7 @@ Use L</UV> to declare variables of the maximum usable size on this platform.
16941694
# define STRUCT_OFFSET(s,m) offsetof(s,m)
16951695
#endif
16961696

1697-
/* ptrdiff_t is C11, so undef it under pedantic builds. (Actually it is
1698-
* in C89, but apparently there are platforms where it doesn't exist. See
1699-
* thread beginning at http://nntp.perl.org/group/perl.perl5.porters/251541.)
1700-
* */
1701-
#ifdef PERL_GCC_PEDANTIC
1702-
# undef HAS_PTRDIFF_T
1703-
#endif
1704-
1705-
#ifdef HAS_PTRDIFF_T
1706-
# define Ptrdiff_t ptrdiff_t
1707-
#else
1708-
# define Ptrdiff_t SSize_t
1709-
#endif
1710-
1711-
# include <string.h>
1697+
#include <string.h>
17121698

17131699
/* This comes after <stdlib.h> so we don't try to change the standard
17141700
* library prototypes; we'll use our own in proto.h instead. */

pod/perl5300delta.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ L<[GH #16461]|https://github.com/Perl/perl5/issues/16461>.
10611061

10621062
=item *
10631063

1064-
It is now forbidden to malloc more than C<PTRDIFF_T_MAX> bytes. Much
1064+
It is now forbidden to malloc more than C<PTRDIFF_MAX> bytes. Much
10651065
code (including C optimizers) assumes that all data structures will not
10661066
be larger than this, so this catches such attempts before overflow
10671067
happens.

proto.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

regcomp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,7 +6264,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
62646264
* multi-char folds, so allocate extra space for that. We can't
62656265
* make any other length assumptions, as a byte input sequence
62666266
* could shrink down. */
6267-
Ptrdiff_t current_string_nodes = STR_SZ(max_string_len
6267+
ptrdiff_t current_string_nodes = STR_SZ(max_string_len
62686268
+ ((! FOLD)
62696269
? 0
62706270
: 2 * ((UTF)
@@ -7168,7 +7168,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
71687168
Size_t new_size = size
71697169
+ (oldp - redo_p)
71707170
+ UTF8_MAXBYTES_CASE + 1;
7171-
Ptrdiff_t e_offset = redo_e - locfold_buf;
7171+
ptrdiff_t e_offset = redo_e - locfold_buf;
71727172

71737173
Renew(locfold_buf, new_size, char);
71747174
Renew(loc_correspondence, new_size, Size_t);
@@ -7445,7 +7445,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
74457445
/* Free up any over-allocated space; cast is to silence bogus
74467446
* warning in MS VC */
74477447
change_engine_size(pRExC_state,
7448-
- (Ptrdiff_t) (current_string_nodes - STR_SZ(len)));
7448+
- (ptrdiff_t) (current_string_nodes - STR_SZ(len)));
74497449

74507450
/* I (khw) don't know if you can get here with zero length, but the
74517451
* old code handled this situation by creating a zero-length EXACT
@@ -12781,7 +12781,7 @@ S_nextchar(pTHX_ RExC_state_t *pRExC_state)
1278112781
}
1278212782

1278312783
STATIC void
12784-
S_change_engine_size(pTHX_ RExC_state_t *pRExC_state, const Ptrdiff_t size)
12784+
S_change_engine_size(pTHX_ RExC_state_t *pRExC_state, const ptrdiff_t size)
1278512785
{
1278612786
/* 'size' is the delta number of smallest regnode equivalents to add or
1278712787
* subtract from the current memory allocated to the regex engine being
@@ -12820,7 +12820,7 @@ S_regnode_guts(pTHX_ RExC_state_t *pRExC_state, const STRLEN extra_size)
1282012820
PERL_ARGS_ASSERT_REGNODE_GUTS;
1282112821

1282212822
SIZE_ALIGN(RExC_size);
12823-
change_engine_size(pRExC_state, (Ptrdiff_t) 1 + extra_size);
12823+
change_engine_size(pRExC_state, (ptrdiff_t) 1 + extra_size);
1282412824
NODE_ALIGN_FILL(REGNODE_p(ret));
1282512825
return(ret);
1282612826
}
@@ -12940,7 +12940,7 @@ S_reginsert(pTHX_ RExC_state_t *pRExC_state, const U8 op,
1294012940
assert(!RExC_study_started); /* I believe we should never use reginsert once we have started
1294112941
studying. If this is wrong then we need to adjust RExC_recurse
1294212942
below like we do with RExC_open_parens/RExC_close_parens. */
12943-
change_engine_size(pRExC_state, (Ptrdiff_t) size);
12943+
change_engine_size(pRExC_state, (ptrdiff_t) size);
1294412944
src = REGNODE_p(RExC_emit);
1294512945
RExC_emit += size;
1294612946
dst = REGNODE_p(RExC_emit);

regcomp_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ static const scan_data_t zero_scan_data = {
949949
* generate any warnings */
950950
#define TO_OUTPUT_WARNINGS(loc) \
951951
( RExC_copy_start_in_constructed \
952-
&& ((xI(loc)) - RExC_precomp) > (Ptrdiff_t) RExC_latest_warn_offset)
952+
&& ((xI(loc)) - RExC_precomp) > (ptrdiff_t) RExC_latest_warn_offset)
953953

954954
/* After we've emitted a warning, we save the position in the input so we don't
955955
* output it again */

sv.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13113,9 +13113,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
1311313113
case 'l': iv = va_arg(*args, long); break;
1311413114
case 'V': iv = va_arg(*args, IV); break;
1311513115
case 'z': iv = va_arg(*args, SSize_t); break;
13116-
#ifdef HAS_PTRDIFF_T
1311713116
case 't': iv = va_arg(*args, ptrdiff_t); break;
13118-
#endif
1311913117
default: iv = va_arg(*args, int); break;
1312013118
case 'j': iv = (IV) va_arg(*args, PERL_INTMAX_T); break;
1312113119
case 'q':
@@ -13168,11 +13166,9 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
1316813166
case 'l': uv = va_arg(*args, unsigned long); break;
1316913167
case 'V': uv = va_arg(*args, UV); break;
1317013168
case 'z': uv = va_arg(*args, Size_t); break;
13171-
#ifdef HAS_PTRDIFF_T
1317213169
/* will sign extend, but there is no
1317313170
* uptrdiff_t, so oh well */
1317413171
case 't': uv = va_arg(*args, ptrdiff_t); break;
13175-
#endif
1317613172
case 'j': uv = (UV) va_arg(*args, PERL_UINTMAX_T); break;
1317713173
default: uv = va_arg(*args, unsigned); break;
1317813174
case 'q':
@@ -13730,9 +13726,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
1373013726
case 'l': *(va_arg(*args, long*)) = i; break;
1373113727
case 'V': *(va_arg(*args, IV*)) = i; break;
1373213728
case 'z': *(va_arg(*args, SSize_t*)) = i; break;
13733-
#ifdef HAS_PTRDIFF_T
1373413729
case 't': *(va_arg(*args, ptrdiff_t*)) = i; break;
13735-
#endif
1373613730
case 'j': *(va_arg(*args, PERL_INTMAX_T*)) = i; break;
1373713731
case 'q':
1373813732
#if IVSIZE >= 8

utf8.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ S_does_utf8_overflow(const U8 * const s, const U8 * e)
696696
* \xff\x80\x80\x80\x80\x80\x80\x83 = 2**32 */
697697
# define OVERFLOWS_MIN_STRING "\xff\x80\x80\x80\x80\x80\x80\x82"
698698

699-
if (e - s < (Ptrdiff_t) STRLENs(OVERFLOWS_MIN_STRING)) {
699+
if (e - s < (ptrdiff_t) STRLENs(OVERFLOWS_MIN_STRING)) {
700700
return ALMOST_CERTAINLY_OVERFLOWS; /* Not enough info to be sure */
701701
}
702702

@@ -2613,7 +2613,7 @@ Perl_utf8_length(pTHX_ const U8 * const s0, const U8 * const e)
26132613
/* Take extra care to not exceed 'e' (which would be undefined
26142614
* behavior) should the input be malformed, with a partial
26152615
* character at the end */
2616-
Ptrdiff_t expected_byte_count = UTF8SKIP(s);
2616+
ptrdiff_t expected_byte_count = UTF8SKIP(s);
26172617
if (UNLIKELY(e - s < expected_byte_count)) {
26182618
goto warn_and_return;
26192619
}
@@ -2698,7 +2698,7 @@ Perl_utf8_length(pTHX_ const U8 * const s0, const U8 * const e)
26982698

26992699
/* Here is a starter byte. Use UTF8SKIP from now on */
27002700
do {
2701-
Ptrdiff_t expected_byte_count = UTF8SKIP(s);
2701+
ptrdiff_t expected_byte_count = UTF8SKIP(s);
27022702
if (UNLIKELY(e - s < expected_byte_count)) {
27032703
break;
27042704
}

util.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ Perl_delimcpy_no_escape(char *to, const char *to_end,
613613
const int delim, I32 *retlen)
614614
{
615615
const char * delim_pos;
616-
Ptrdiff_t from_len = from_end - from;
617-
Ptrdiff_t to_len = to_end - to;
616+
ptrdiff_t from_len = from_end - from;
617+
ptrdiff_t to_len = to_end - to;
618618
SSize_t copy_len;
619619

620620
PERL_ARGS_ASSERT_DELIMCPY_NO_ESCAPE;
@@ -718,7 +718,7 @@ Perl_delimcpy(char *to, const char *to_end,
718718
const int delim, I32 *retlen)
719719
{
720720
const char * const orig_to = to;
721-
Ptrdiff_t copy_len = 0;
721+
ptrdiff_t copy_len = 0;
722722
bool stopped_early = FALSE; /* Ran out of room to copy to */
723723

724724
PERL_ARGS_ASSERT_DELIMCPY;
@@ -896,8 +896,8 @@ such occurrence.
896896
char *
897897
Perl_rninstr(const char *big, const char *bigend, const char *little, const char *lend)
898898
{
899-
const Ptrdiff_t little_len = lend - little;
900-
const Ptrdiff_t big_len = bigend - big;
899+
const ptrdiff_t little_len = lend - little;
900+
const ptrdiff_t big_len = bigend - big;
901901

902902
PERL_ARGS_ASSERT_RNINSTR;
903903

0 commit comments

Comments
 (0)