Skip to content

Commit 3a7b25b

Browse files
committed
Move some ARGS_ASSERT macros to function start
Historically the asserts had to be placed after any declarations because of limitations in the C89 Standard that have been removed in C99 which we are now following. Placing the assertions at the function beginning is clearer, and stops any issues with the code below it using a variable prior to its assertion.
1 parent 43eccc5 commit 3a7b25b

File tree

4 files changed

+44
-58
lines changed

4 files changed

+44
-58
lines changed

regexec.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -626,14 +626,13 @@ S_isFOO_utf8_lc(pTHX_ const U8 classnum, const U8* character, const U8* e)
626626
STATIC U8 *
627627
S_find_span_end(U8 * s, const U8 * send, const U8 span_byte)
628628
{
629+
PERL_ARGS_ASSERT_FIND_SPAN_END;
630+
assert(send >= s);
631+
629632
/* Returns the position of the first byte in the sequence between 's' and
630633
* 'send-1' inclusive that isn't 'span_byte'; returns 'send' if none found.
631634
* */
632635

633-
PERL_ARGS_ASSERT_FIND_SPAN_END;
634-
635-
assert(send >= s);
636-
637636
if ((STRLEN) (send - s) >= PERL_WORDSIZE
638637
+ PERL_WORDSIZE * PERL_IS_SUBWORD_ADDR(s)
639638
- (PTR2nat(s) & PERL_WORD_BOUNDARY_MASK))
@@ -700,16 +699,15 @@ S_find_span_end(U8 * s, const U8 * send, const U8 span_byte)
700699
STATIC U8 *
701700
S_find_next_masked(U8 * s, const U8 * send, const U8 byte, const U8 mask)
702701
{
702+
PERL_ARGS_ASSERT_FIND_NEXT_MASKED;
703+
assert(send >= s);
704+
assert((byte & mask) == byte);
705+
703706
/* Returns the position of the first byte in the sequence between 's'
704707
* and 'send-1' inclusive that when ANDed with 'mask' yields 'byte';
705708
* returns 'send' if none found. It uses word-level operations instead of
706709
* byte to speed up the process */
707710

708-
PERL_ARGS_ASSERT_FIND_NEXT_MASKED;
709-
710-
assert(send >= s);
711-
assert((byte & mask) == byte);
712-
713711
#ifndef EBCDIC
714712

715713
if ((STRLEN) (send - s) >= PERL_WORDSIZE
@@ -778,17 +776,16 @@ S_find_next_masked(U8 * s, const U8 * send, const U8 byte, const U8 mask)
778776
STATIC U8 *
779777
S_find_span_end_mask(U8 * s, const U8 * send, const U8 span_byte, const U8 mask)
780778
{
779+
PERL_ARGS_ASSERT_FIND_SPAN_END_MASK;
780+
assert(send >= s);
781+
assert((span_byte & mask) == span_byte);
782+
781783
/* Returns the position of the first byte in the sequence between 's' and
782784
* 'send-1' inclusive that when ANDed with 'mask' isn't 'span_byte'.
783785
* 'span_byte' should have been ANDed with 'mask' in the call of this
784786
* function. Returns 'send' if none found. Works like find_span_end(),
785787
* except for the AND */
786788

787-
PERL_ARGS_ASSERT_FIND_SPAN_END_MASK;
788-
789-
assert(send >= s);
790-
assert((span_byte & mask) == span_byte);
791-
792789
if ((STRLEN) (send - s) >= PERL_WORDSIZE
793790
+ PERL_WORDSIZE * PERL_IS_SUBWORD_ADDR(s)
794791
- (PTR2nat(s) & PERL_WORD_BOUNDARY_MASK))
@@ -11793,10 +11790,6 @@ Perl_isSCRIPT_RUN(pTHX_ const U8 * s, const U8 * send, const bool utf8_target)
1179311790
bool retval = true;
1179411791
SCX_enum * ret_script = NULL;
1179511792

11796-
assert(send >= s);
11797-
11798-
PERL_ARGS_ASSERT_ISSCRIPT_RUN;
11799-
1180011793
/* All code points in 0..255 are either Common or Latin, so must be a
1180111794
* script run. We can return immediately unless we need to know which
1180211795
* script it is. */

toke.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,16 +1886,15 @@ Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn, bool curstash)
18861886
STATIC void
18871887
S_incline(pTHX_ const char *s, const char *end)
18881888
{
1889+
PERL_ARGS_ASSERT_INCLINE;
1890+
assert(end >= s);
1891+
18891892
const char *t;
18901893
const char *n;
18911894
const char *e;
18921895
line_t line_num;
18931896
UV uv;
18941897

1895-
PERL_ARGS_ASSERT_INCLINE;
1896-
1897-
assert(end >= s);
1898-
18991898
COPLINE_INC_WITH_HERELINES;
19001899
if (!PL_rsfp && !PL_parser->filtered && PL_lex_state == LEX_NORMAL
19011900
&& s+1 == PL_bufend && *s == ';') {
@@ -2855,6 +2854,10 @@ Perl_get_and_check_backslash_N_name(pTHX_ const char* s,
28552854
const bool is_utf8,
28562855
const char ** error_msg)
28572856
{
2857+
PERL_ARGS_ASSERT_GET_AND_CHECK_BACKSLASH_N_NAME;
2858+
assert(e >= s);
2859+
assert(s > (char *) 3);
2860+
28582861
/* <s> points to first character of interior of \N{}, <e> to one beyond the
28592862
* interior, hence to the "}". Finds what the name resolves to, returning
28602863
* an SV* containing it; NULL if no valid one found.
@@ -2875,12 +2878,6 @@ Perl_get_and_check_backslash_N_name(pTHX_ const char* s,
28752878
const char* context = s - 3;
28762879
STRLEN context_len = e - context + 1; /* include all of \N{...} */
28772880

2878-
2879-
PERL_ARGS_ASSERT_GET_AND_CHECK_BACKSLASH_N_NAME;
2880-
2881-
assert(e >= s);
2882-
assert(s > (char *) 3);
2883-
28842881
while (s < e && isBLANK(*s)) {
28852882
s++;
28862883
}

utf8.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,10 @@ S_does_utf8_overflow(const U8 * const s, const U8 * e)
724724
STRLEN
725725
Perl_is_utf8_char_helper_(const U8 * const s, const U8 * e, const U32 flags)
726726
{
727+
PERL_ARGS_ASSERT_IS_UTF8_CHAR_HELPER_;
728+
assert(e > s);
729+
assert(0 == (flags & ~UTF8_DISALLOW_ILLEGAL_INTERCHANGE));
730+
727731
SSize_t len, full_len;
728732

729733
/* An internal helper function.
@@ -751,12 +755,6 @@ Perl_is_utf8_char_helper_(const U8 * const s, const U8 * e, const U32 flags)
751755
* determined with just the first one or two bytes.
752756
*
753757
*/
754-
755-
PERL_ARGS_ASSERT_IS_UTF8_CHAR_HELPER_;
756-
757-
assert(e > s);
758-
assert(0 == (flags & ~UTF8_DISALLOW_ILLEGAL_INTERCHANGE));
759-
760758
full_len = UTF8SKIP(s);
761759

762760
len = e - s;
@@ -841,6 +839,10 @@ Size_t
841839
Perl_is_utf8_FF_helper_(const U8 * const s0, const U8 * const e,
842840
const bool require_partial)
843841
{
842+
PERL_ARGS_ASSERT_IS_UTF8_FF_HELPER_;
843+
assert(s0 < e);
844+
assert(*s0 == I8_TO_NATIVE_UTF8(0xFF));
845+
844846
/* This is called to determine if the UTF-8 sequence starting at s0 and
845847
* continuing for up to one full character of bytes, but looking no further
846848
* than 'e - 1', is legal. *s0 must be 0xFF (or whatever the native
@@ -867,11 +869,6 @@ Perl_is_utf8_FF_helper_(const U8 * const s0, const U8 * const e,
867869
const U8 *s = s0 + 1;
868870
const U8 *send = e;
869871

870-
PERL_ARGS_ASSERT_IS_UTF8_FF_HELPER_;
871-
872-
assert(s0 < e);
873-
assert(*s0 == I8_TO_NATIVE_UTF8(0xFF));
874-
875872
send = s + MIN(UTF8_MAXBYTES - 1, e - s);
876873
while (s < send) {
877874
if (! UTF8_IS_CONTINUATION(*s)) {
@@ -4247,6 +4244,9 @@ STATIC UV
42474244
S_turkic_fc(pTHX_ const U8 * const p, const U8 * const e,
42484245
U8 * ustrp, STRLEN *lenp)
42494246
{
4247+
PERL_ARGS_ASSERT_TURKIC_FC;
4248+
assert(e > p);
4249+
42504250
/* Returns 0 if the foldcase of the input UTF-8 encoded sequence from
42514251
* p0..e-1 according to Turkic rules is the same as for non-Turkic.
42524252
* Otherwise, it returns the first code point of the Turkic foldcased
@@ -4257,9 +4257,6 @@ S_turkic_fc(pTHX_ const U8 * const p, const U8 * const e,
42574257
* I WITH DOT ABOVE form a case pair, as do 'I' and LATIN SMALL LETTER
42584258
* DOTLESS I */
42594259

4260-
PERL_ARGS_ASSERT_TURKIC_FC;
4261-
assert(e > p);
4262-
42634260
if (UNLIKELY(*p == 'I')) {
42644261
*lenp = 2;
42654262
ustrp[0] = UTF8_TWO_BYTE_HI(LATIN_SMALL_LETTER_DOTLESS_I);
@@ -4282,15 +4279,15 @@ STATIC UV
42824279
S_turkic_lc(pTHX_ const U8 * const p0, const U8 * const e,
42834280
U8 * ustrp, STRLEN *lenp)
42844281
{
4282+
PERL_ARGS_ASSERT_TURKIC_LC;
4283+
assert(e > p0);
4284+
42854285
/* Returns 0 if the lowercase of the input UTF-8 encoded sequence from
42864286
* p0..e-1 according to Turkic rules is the same as for non-Turkic.
42874287
* Otherwise, it returns the first code point of the Turkic lowercased
42884288
* sequence, and the entire sequence will be stored in *ustrp. ustrp will
42894289
* contain *lenp bytes */
42904290

4291-
PERL_ARGS_ASSERT_TURKIC_LC;
4292-
assert(e > p0);
4293-
42944291
/* A 'I' requires context as to what to do */
42954292
if (UNLIKELY(*p0 == 'I')) {
42964293
const U8 * p = p0 + 1;
@@ -4328,6 +4325,9 @@ STATIC UV
43284325
S_turkic_uc(pTHX_ const U8 * const p, const U8 * const e,
43294326
U8 * ustrp, STRLEN *lenp)
43304327
{
4328+
PERL_ARGS_ASSERT_TURKIC_UC;
4329+
assert(e > p);
4330+
43314331
/* Returns 0 if the upper or title-case of the input UTF-8 encoded sequence
43324332
* from p0..e-1 according to Turkic rules is the same as for non-Turkic.
43334333
* Otherwise, it returns the first code point of the Turkic upper or
@@ -4338,9 +4338,6 @@ S_turkic_uc(pTHX_ const U8 * const p, const U8 * const e,
43384338
* I WITH DOT ABOVE form a case pair, as do 'I' and LATIN SMALL LETTER
43394339
* DOTLESS I */
43404340

4341-
PERL_ARGS_ASSERT_TURKIC_UC;
4342-
assert(e > p);
4343-
43444341
if (*p == 'i') {
43454342
*lenp = 2;
43464343
ustrp[0] = UTF8_TWO_BYTE_HI(LATIN_CAPITAL_LETTER_I_WITH_DOT_ABOVE);

util.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,13 @@ Perl_delimcpy_no_escape(char *to, const char *to_end,
612612
const char *from, const char *from_end,
613613
const int delim, I32 *retlen)
614614
{
615+
PERL_ARGS_ASSERT_DELIMCPY_NO_ESCAPE;
616+
615617
const char * delim_pos;
616618
ptrdiff_t from_len = from_end - from;
617619
ptrdiff_t to_len = to_end - to;
618620
SSize_t copy_len;
619621

620-
PERL_ARGS_ASSERT_DELIMCPY_NO_ESCAPE;
621-
622622
assert(from_len >= 0);
623623
assert(to_len >= 0);
624624

@@ -717,14 +717,14 @@ Perl_delimcpy(char *to, const char *to_end,
717717
const char *from, const char *from_end,
718718
const int delim, I32 *retlen)
719719
{
720-
const char * const orig_to = to;
721-
ptrdiff_t copy_len = 0;
722-
bool stopped_early = FALSE; /* Ran out of room to copy to */
723-
724720
PERL_ARGS_ASSERT_DELIMCPY;
725721
assert(from_end >= from);
726722
assert(to_end >= to);
727723

724+
const char * const orig_to = to;
725+
ptrdiff_t copy_len = 0;
726+
bool stopped_early = FALSE; /* Ran out of room to copy to */
727+
728728
/* Don't use the loop for the trivial case of the first character being the
729729
* delimiter; otherwise would have to worry inside the loop about backing
730730
* up before the start of 'from' */
@@ -1099,6 +1099,9 @@ a littlestr of "ab\n", SvTAIL matches as:
10991099
char *
11001100
Perl_fbm_instr(pTHX_ unsigned char *big, unsigned char *bigend, SV *littlestr, U32 flags)
11011101
{
1102+
PERL_ARGS_ASSERT_FBM_INSTR;
1103+
assert(bigend >= big);
1104+
11021105
unsigned char *s;
11031106
STRLEN l;
11041107
const unsigned char *little = (const unsigned char *)SvPV_const(littlestr,l);
@@ -1107,10 +1110,6 @@ Perl_fbm_instr(pTHX_ unsigned char *big, unsigned char *bigend, SV *littlestr, U
11071110
bool valid = SvVALID(littlestr);
11081111
bool tail = valid ? cBOOL(SvTAIL(littlestr)) : FALSE;
11091112

1110-
PERL_ARGS_ASSERT_FBM_INSTR;
1111-
1112-
assert(bigend >= big);
1113-
11141113
if ((STRLEN)(bigend - big) < littlelen) {
11151114
if ( tail
11161115
&& ((STRLEN)(bigend - big) == littlelen - 1)

0 commit comments

Comments
 (0)