Skip to content

Commit c15d579

Browse files
committed
regen/embed.pl Move some code to earlier
Prior to this commit, the code created an array describing an input argument, adding it to a list of all the arguments, and later went through that list using a grep to reconstruct some information that had been lost (because the array didn't include all the needed relevant information), and placed the result in its final form. This commit moves the calculation of the final form to earlier, where it first is encountered. This means all the information is available, and no grep is needed. Code review revealed a subtlety here. The moved code has an if $nullok but prior to this commit, there were two different $nullok variables, with slightly different meanings. Prior to this commit, the moved code was using the second $nullok; afterwards, the first one. Hence, even though the name is the same, before and after, it is a different variable, with a (slightly) different meaning. The second $nullok was populated by the grep, and meant that the argument did not have either a NN nor a NZ modifier. The first $nullok meant simply that the arg had a NULLOK modifier. After the commit the single $nullok means that the arg had a NULLOK modifier. This change actually has no effect (as demonstrated by the fact that this commit doesn't change the generated proto.h). The moved code is executed only for an argument where $type_asserts{$argtype} exists. This hash is constant, and has been populated so that only pointer arguments have entries. NZ is not valid for pointer arguments, so we know that both before and after this commit, the arg did not have an NZ modifier. Also it is illegal to specify both NN and NULLOK, so both before and after this commit, the arg did not have a NN modifier. And both before and after this commit the arg does have a NULLOK modifier.
1 parent cf9624c commit c15d579

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

regen/embed.pl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ sub generate_proto_h {
284284
&& defined $argtype
285285
&& exists $type_asserts{$argtype})
286286
{
287-
push @typed_args, [ $argtype, $argname ];
287+
my $type_assert =
288+
$type_asserts{$argtype} =~ s/__arg__/$argname/gr;
289+
$type_assert = "!$argname || $type_assert" if $nullok;
290+
push @typed_args, $type_assert;
288291
}
289292
}
290293
}
@@ -372,12 +375,7 @@ sub generate_proto_h {
372375
push @asserts, "assert($names_of_nn[$ix])";
373376
}
374377

375-
foreach (@typed_args) {
376-
my ($argtype, $argname) = @$_;
377-
my $nullok = !grep { $_ eq $argname } @names_of_nn;
378-
my $type_assert =
379-
$type_asserts{$argtype} =~ s/__arg__/$argname/gr;
380-
$type_assert = "!$argname || $type_assert" if $nullok;
378+
foreach my $type_assert (@typed_args) {
381379
push @asserts, "assert($type_assert)";
382380
}
383381

0 commit comments

Comments
 (0)