Skip to content

Commit

Permalink
regen/reentr.pl: Use hash instead of code conditionals
Browse files Browse the repository at this point in the history
Fill this hash with the buffer sizes instead of using conditionals in
the code to do so.  This is in preparation for more variance in the
sizes, which would otherwise increase the number of conditionals
  • Loading branch information
khwilliamson committed Feb 28, 2024
1 parent 01fa93a commit da6fa4e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions regen/reentr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,28 @@ sub define {
# The loop also contains a lot of intrinsic logic about groups of
# functions (since functions of certain kind operate the same way).

my %small_bufsizes = (
asctime => 26,
ctime => 26,
setlocale => "REENTRANTSMALLSIZE",
getlogin => "REENTRANTSMALLSIZE",
strerror => "REENTRANTSMALLSIZE",
ttyname => "REENTRANTSMALLSIZE",
);

for my $func (@seenf) {
my $FUNC = uc $func;
my $ifdef = "# ifdef HAS_${FUNC}_R\n";
my $endif = "# endif /* HAS_${FUNC}_R */\n\n";
if (exists $seena{$func}) {
my @p = @{$seena{$func}};
if ($func =~ /^(asctime|ctime|getlogin|setlocale|strerror|ttyname)$/) {
if (exists $small_bufsizes{$func}) {
pushssif $ifdef;
push @struct, <<EOF;
char* _${func}_buffer;
size_t _${func}_size;
EOF
my $size = ($func =~ /^(asctime|ctime)$/)
? 26
: "REENTRANTSMALLSIZE";
my $size = $small_bufsizes{$func};
push @size, <<EOF;
PL_reentrant_buffer->_${func}_size = $size;
EOF
Expand Down

0 comments on commit da6fa4e

Please sign in to comment.