diff options
author | Yves Orton <demerphq@gmail.com> | 2023-01-31 05:09:43 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-02-19 11:27:50 +0800 |
commit | d6a7165bd44b5bdf2dc544680b8f167b6ad3351f (patch) | |
tree | d596453e74e8f1f140e5cce3eabbbf4cdf0ec5e4 /regen | |
parent | b8837dad4db9806bc61659d5230a35b90655c07b (diff) | |
download | perl-d6a7165bd44b5bdf2dc544680b8f167b6ad3351f.tar.gz |
embed.pl - sort and dedupe flags in embef.fnc as part of tidy
This ensures we use a canonical string for each possible flag variant,
which makes it easier to search for flags with a given flag signature.
It also exposed a mutex bug in flag handling which caused
PerlEnv_putenv to be improperly marked as static, when it is in fact
static inline.
To validate there aren't any issues like this remaining in the script
I set it up so the flags were shuffled during processing and ran
embed.pl in a loop for a while and none of the output files changed,
so I assume there are no further such issues.
This patch also includes some basic validation of the flags so that if
someone misses a line continuation the following lines are not treated
as a new definition without any flags. I also ran perltidy on it
according to the rules contained within the file.
Diffstat (limited to 'regen')
-rw-r--r-- | regen/HeaderParser.pm | 18 | ||||
-rwxr-xr-x | regen/embed.pl | 7 |
2 files changed, 17 insertions, 8 deletions
diff --git a/regen/HeaderParser.pm b/regen/HeaderParser.pm index 0089ae7035..7272a596c8 100644 --- a/regen/HeaderParser.pm +++ b/regen/HeaderParser.pm @@ -502,7 +502,7 @@ sub _normalize_if_elif { # calls parse_fh() sub parse_text { my ($self, $text)= @_; - local $self->{parse_source} = "(buffer)"; + local $self->{parse_source}= "(buffer)"; open my $fh, "<", \$text or die "Failed to open buffer for read: $!"; return $self->parse_fh($fh); @@ -517,7 +517,7 @@ sub parse_fh { my @cond; my @cond_line; my $last_cond; - local $self->{parse_source} = $self->{parse_source} || "(unknown)"; + local $self->{parse_source}= $self->{parse_source} || "(unknown)"; my $cb= $self->{pre_process_content}; $self->{orig_content}= ""; my $line_num= 1; @@ -689,6 +689,20 @@ sub tidy_embed_fnc_entry { $line =~ s/\s+\z//; ($line)= expand($line); my ($flags, $ret, $name, @args)= split /\s*\|\s*/, $line; + my %flag_seen; + $flags= join "", grep !$flag_seen{$_}++, sort split //, $flags; + if ($flags =~ s/^#//) { + $flags .= "#"; + } + if ($flags eq "#") { + die "Not allowed to use only '#' for flags" + . "in 'embed.fnc' at line $line_data->{start_line_num}"; + } + if (!$flags) { + die "Missing flags in function definition" + . " in 'embed.fnc' at line $line_data->{start_line_num}\n" + . "Did you a forget a line continuation on the previous line?\n"; + } for ($ret, @args) { s/(\w)\*/$1 */g; s/\*\s+(\w)/*$1/g; diff --git a/regen/embed.pl b/regen/embed.pl index 81798816de..1c2fe4a5f9 100755 --- a/regen/embed.pl +++ b/regen/embed.pl @@ -128,12 +128,7 @@ sub generate_proto_h { die_at_end "$plain_func: u flag only usable with m" if $flags =~ /u/ && $flags !~ /m/; - my ($static_flag, @extra_static_flags)= do { - # the seen filter can be removed once flag dedupe - # is done in tidy_embed.pl - my %seen; - grep !$seen{$_}++, $flags =~/([SsIi])/g; - }; + my ($static_flag, @extra_static_flags)= $flags =~/([SsIi])/g; if (@extra_static_flags) { my $flags_str = join ", ", $static_flag, @extra_static_flags; |