Skip to content

Commit 2e142e0

Browse files
committed
regen/embed.pl: Avoid use of hard-coded list
The list consists of exactly the functions that have the O flag set in embed.fnc. No need to keep this data twice. The entries are trivially generatable from existing entries as we go along And those generated entries have the added advantage of not using the short name, so potentially less name space pollution
1 parent c3a0c7d commit 2e142e0

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

embed.h

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,23 @@
4949
# define sv_setptrref(rv,ptr) sv_setref_iv(rv,NULL,PTR2IV(ptr))
5050
# if !defined(PERL_NOCOMPAT)
5151

52-
/* Compatibility for various misnamed functions. All functions
53-
in the API that begin with "perl_" (not "Perl_") take an explicit
54-
interpreter context pointer.
55-
The following are not like that, but since they had a "perl_"
56-
prefix in previous versions, we provide compatibility macros.
57-
*/
58-
# define perl_atexit(a,b) call_atexit(a,b)
59-
# define perl_call_argv(a,b,c) call_argv(a,b,c)
60-
# define perl_call_method(a,b) call_method(a,b)
61-
# define perl_call_pv(a,b) call_pv(a,b)
62-
# define perl_call_sv(a,b) call_sv(a,b)
63-
# define perl_eval_pv(a,b) eval_pv(a,b)
64-
# define perl_eval_sv(a,b) eval_sv(a,b)
65-
# define perl_get_av(a,b) get_av(a,b)
66-
# define perl_get_cv(a,b) get_cv(a,b)
67-
# define perl_get_hv(a,b) get_hv(a,b)
68-
# define perl_get_sv(a,b) get_sv(a,b)
69-
# define perl_init_i18nl10n(a) init_i18nl10n(a)
70-
# define perl_require_pv(a) require_pv(a)
52+
/* Compatibility for this renamed function. */
53+
# define perl_atexit(a,b) Perl_call_atexit(aTHX_ a,b)
54+
55+
/* Compatibility for these functions that had a 'perl_' prefix before
56+
* 'Perl_' became the standard */
57+
# define perl_call_argv(a,b,c) Perl_call_argv(aTHX_ a,b,c)
58+
# define perl_call_method(a,b) Perl_call_method(aTHX_ a,b)
59+
# define perl_call_pv(a,b) Perl_call_pv(aTHX_ a,b)
60+
# define perl_call_sv(a,b) Perl_call_sv(aTHX_ a,b)
61+
# define perl_eval_pv(a,b) Perl_eval_pv(aTHX_ a,b)
62+
# define perl_eval_sv(a,b) Perl_eval_sv(aTHX_ a,b)
63+
# define perl_get_av(a,b) Perl_get_av(aTHX_ a,b)
64+
# define perl_get_cv(a,b) Perl_get_cv(aTHX_ a,b)
65+
# define perl_get_hv(a,b) Perl_get_hv(aTHX_ a,b)
66+
# define perl_get_sv(a,b) Perl_get_sv(aTHX_ a,b)
67+
# define perl_init_i18nl10n(a) Perl_init_i18nl10n(aTHX_ a)
68+
# define perl_require_pv(a) Perl_require_pv(aTHX_ a)
7169

7270
/* Before C99, macros could not wrap varargs functions. This
7371
provides a set of compatibility functions that don't take an

regen/embed.pl

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ BEGIN
5555
);
5656
my %has_compat_macro;
5757
$has_compat_macro{$_} = 1 for @have_compatibility_macros;
58+
my %perl_compats; # Have 'perl_' prefix
5859

5960
my $unflagged_pointers;
6061
my @az = ('a'..'z');
@@ -848,7 +849,19 @@ sub embed_h {
848849
die "Can't use W without other args (currently)";
849850
}
850851
}
851-
$ret .= ")\n";
852+
$ret .= ")";
853+
854+
# For functions that have an old 'perl_' name, create an entry
855+
# here while we have all the information, for output later
856+
# (when not under NO_SHORT_NAMES)
857+
if ($flags =~ /O/) {
858+
my $extra_entry = $ret;
859+
$extra_entry =~ s/define /define perl_/;
860+
$perl_compats{$extra_entry} = 1;
861+
}
862+
863+
$ret .= "\n";
864+
852865
if($has_compat_macro{$func}) {
853866
# Make older ones available only when !MULTIPLICITY or
854867
# PERL_CORE or PERL_WANT_VARARGS. These should not be
@@ -860,6 +873,7 @@ sub embed_h {
860873
. $ret
861874
. "#${ind}endif\n";
862875
}
876+
863877
}
864878
$ret = "#${ind}ifndef NO_MATHOMS\n$ret#${ind}endif\n"
865879
if $flags =~ /b/;
@@ -915,25 +929,15 @@ sub generate_embed_h {
915929
916930
#if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
917931
918-
/* Compatibility for various misnamed functions. All functions
919-
in the API that begin with "perl_" (not "Perl_") take an explicit
920-
interpreter context pointer.
921-
The following are not like that, but since they had a "perl_"
922-
prefix in previous versions, we provide compatibility macros.
923-
*/
924-
# define perl_atexit(a,b) call_atexit(a,b)
925-
END
932+
/* Compatibility for this renamed function. */
933+
# define perl_atexit(a,b) Perl_call_atexit(aTHX_ a,b)
926934
927-
foreach (@$all) {
928-
my $embed= $_->{embed} or next;
929-
my ($flags, $retval, $func, $args) =
930-
@{$embed}{qw(flags return_type name args)};
931-
next unless $flags =~ /O/;
935+
/* Compatibility for these functions that had a 'perl_' prefix before
936+
* 'Perl_' became the standard */
937+
END
932938

933-
my $alist = join ",", @az[0..$#$args];
934-
my $ret = "# define perl_$func($alist) ";
935-
print $em add_indent($ret,"$func($alist)\n");
936-
}
939+
# These have been saved up for now
940+
print $em map { "$_\n" } sort keys %perl_compats;
937941

938942
print $em <<~'END';
939943

0 commit comments

Comments
 (0)