Skip to content

Commit 6947433

Browse files
committed
embed.pl - add a way to declare a parameter should be non-zero
This autogenerates the required asserts to validate a parameter is non-zero. It uses it to replace the check in regrepeat() as a first example.
1 parent 3bbe14f commit 6947433

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

embed.fnc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@
600600
: know "I have defined whether NULL is OK or not" rather than having neither
601601
: NULL or NULLOK, which is ambiguous.
602602
:
603+
: Numeric arguments may also be prefixed with NZ, which will cause the
604+
: appropriate asserts to be generated to validate that this is the case.
605+
:
603606
: Flags should be sorted asciibetically.
604607
:
605608
: Please keep the next line *BLANK*
@@ -5319,7 +5322,7 @@ WERS |I32 |regrepeat |NN regexp *prog \
53195322
|NN const regnode *p \
53205323
|NN char *loceol \
53215324
|NN regmatch_info * const reginfo \
5322-
|I32 max
5325+
|NZ I32 max
53235326
ERS |bool |regtry |NN regmatch_info *reginfo \
53245327
|NN char **startposp
53255328
ERS |bool |reginclass |NULLOK regexp * const prog \

proto.h

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

regen/embed.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ sub generate_proto_h {
222222
}
223223
my $nn = ( $arg =~ s/\s*\bNN\b\s+// );
224224
push( @nonnull, $n ) if $nn;
225+
my $nz = ( $arg =~ s/\s*\bNZ\b\s+// );
225226

226227
my $nullok = ( $arg =~ s/\s*\bNULLOK\b\s+// ); # strip NULLOK with no effect
227228

@@ -234,7 +235,7 @@ sub generate_proto_h {
234235
&& ($temp_arg !~ /\w+\s+(\w+)(?:\[\d+\])?\s*$/) ) {
235236
die_at_end "$func: $arg ($n) doesn't have a name\n";
236237
}
237-
if (defined $1 && $nn && !($commented_out && !$binarycompat)) {
238+
if (defined $1 && ($nn||$nz) && !($commented_out && !$binarycompat)) {
238239
push @names_of_nn, $1;
239240
}
240241
}

regexec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10061,8 +10061,6 @@ S_regrepeat(pTHX_ regexp *prog, char **startposp, const regnode *p,
1006110061
unsigned int to_complement = 0; /* Invert the result? */
1006210062
char_class_number_ classnum;
1006310063

10064-
assert(max);
10065-
1006610064
PERL_ARGS_ASSERT_REGREPEAT;
1006710065

1006810066
/* This routine is structured so that we switch on the input OP. Each OP

0 commit comments

Comments
 (0)