3 require 5.003; # keep this compatible, an old perl is all we may have before
7 # Get function prototypes
8 require 'regen_lib.pl';
12 # See database of global and static function prototypes in embed.fnc
13 # This is used to generate prototype headers under various configurations,
14 # export symbols lists for different platforms, and macros to provide an
15 # implicit interpreter context argument.
22 my $years = '1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005';
24 $years =~ s/1999,/1999,\n / if length $years > 40;
30 Copyright (C) $years, by Larry Wall and others
32 You may distribute under the terms of either the GNU General Public
33 License or the Artistic License, as specified in the README file.
35 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
36 This file is built by embed.pl from data in embed.fnc, embed.pl,
37 pp.sym, intrpvar.h, perlvars.h and thrdvar.h.
38 Any changes made here will be lost!
40 Edit those files and run 'make regen_headers' to effect changes.
44 $warning .= <<EOW if $file eq 'perlapi.c';
46 Up to the threshold of the door there mounted a flight of twenty-seven
47 broad stairs, hewn by some unknown art of the same black stone. This
48 was the only entrance to the tower.
53 if ($file =~ m:\.[ch]$:) {
54 $warning =~ s:^: * :gm;
55 $warning =~ s: +$::gm;
60 $warning =~ s:^:# :gm;
61 $warning =~ s: +$::gm;
66 open IN, "embed.fnc" or die $!;
68 # walk table providing an array of components in each line to
69 # subroutine, printing the result
72 my $filename = shift || '-';
74 defined $leader or $leader = do_not_edit ($filename);
78 if (ref $filename) { # filehandle
82 safer_unlink $filename;
83 open F, ">$filename" or die "Can't open $filename: $!";
87 print $F $leader if $leader;
88 seek IN, 0, 0; # so we may restart
102 @args = split /\s*\|\s*/, $_;
104 my @outs = &{$function}(@args);
105 print $F @outs; # $function->(@args) is not 5.003
107 print $F $trailer if $trailer;
108 unless (ref $filename) {
109 close $F or die "Error closing $filename: $!";
113 sub munge_c_files () {
116 warn "\@ARGV empty, nothing to do\n";
121 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
126 # if (/^#\s*include\s+"perl.h"/) {
127 # my $file = uc $ARGV;
129 # print "#define PERL_IN_$file\n";
135 # if (exists $functions->{$f}) {
136 # my $flags = $functions->{$f}[0];
137 # $repl = "Perl_$repl" if $flags =~ /p/;
138 # unless ($flags =~ /n/) {
140 # $repl .= "_ " if @{$functions->{$f}} > 3;
142 # warn("$ARGV:$.:$repl\n");
146 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
150 if (exists $functions->{$f}) {
152 warn("$ARGV:$.:$`#$repl#$'");
157 close ARGV if eof; # restart $.
165 my $wrote_protected = 0;
174 my ($flags,$retval,$func,@args) = @_;
176 my $has_context = ( $flags !~ /n/ );
177 $ret .= '/* ' if $flags =~ /m/;
179 $retval = "STATIC $retval";
183 $retval = "PERL_CALLCONV $retval";
185 $func = "Perl_$func";
188 $ret .= "$retval\t$func(";
189 if ( $has_context ) {
190 $ret .= @args ? "pTHX_ " : "pTHX";
194 for my $arg ( @args ) {
196 push( @nonnull, $n ) if ( $arg =~ s/\s*\bNN\b\s+// );
198 $ret .= join ", ", @args;
201 $ret .= "void" if !$has_context;
204 $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
205 $ret .= "\n\t\t\t__attribute__((malloc)) __attribute__((warn_unused_result))" if $flags =~ /a/;
206 $ret .= "\n\t\t\t__attribute__((pure))" if $flags =~ /P/;
207 if( $flags =~ /f/ ) {
208 my $prefix = $has_context ? 'pTHX_' : '';
209 my $args = scalar @args;
210 $ret .= sprintf "\n\t\t\t__attribute__format__(__printf__,%s%d,%s%d)",
211 $prefix, $args - 1, $prefix, $args;
213 $ret .= "\n\t\t\t__attribute__((nonnull))" if $flags =~ /N/;
215 my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
216 $ret .= sprintf( "\n\t\t\t__attribute__((nonnull(%s)))", join( ",", @pos ) );
219 $ret .= ' */' if $flags =~ /m/;
225 # generates global.sym (API export list), and populates %global with global symbols
226 sub write_global_sym {
229 my ($flags,$retval,$func,@args) = @_;
230 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
231 || $flags =~ /b/) { # public API, so export
232 $func = "Perl_$func" if $flags =~ /[pbX]/;
239 walk_table(\&write_protos, "proto.h", undef);
240 walk_table(\&write_global_sym, "global.sym", undef);
242 # XXX others that may need adding
246 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
248 tainting tainted stack_base stack_sp sv_arenaroot
250 curstash DBsub DBsingle debstash
264 my ($syms, $file) = @_;
266 open(FILE, "< $file")
267 or die "embed.pl: Can't open $file: $!\n";
269 s/[ \t]*#.*//; # Delete comments.
270 if (/^\s*(\S+)\s*$/) {
272 warn "duplicate symbol $sym while processing $file\n"
273 if exists $$syms{$sym};
280 # Perl_pp_* and Perl_ck_* are in pp.sym
281 readsyms my %ppsym, 'pp.sym';
283 sub readvars(\%$$@) {
284 my ($syms, $file,$pre,$keep_pre) = @_;
286 open(FILE, "< $file")
287 or die "embed.pl: Can't open $file: $!\n";
289 s/[ \t]*#.*//; # Delete comments.
290 if (/PERLVARA?I?C?\($pre(\w+)/) {
292 $sym = $pre . $sym if $keep_pre;
293 warn "duplicate symbol $sym while processing $file\n"
294 if exists $$syms{$sym};
295 $$syms{$sym} = $pre || 1;
304 readvars %intrp, 'intrpvar.h','I';
305 readvars %thread, 'thrdvar.h','T';
306 readvars %globvar, 'perlvars.h','G';
309 foreach $sym (sort keys %thread) {
310 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
319 my ($from, $to) = @_;
320 my $t = int(length($from) / 8);
321 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
324 sub bincompat_var ($$) {
325 my ($pfx, $sym) = @_;
326 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
327 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
331 my ($sym,$pre,$ptr) = @_;
332 hide("PL_$sym", "($ptr$pre$sym)");
337 return hide("PL_$pre$sym", "PL_$sym");
340 safer_unlink 'embed.h';
341 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
344 print EM do_not_edit ("embed.h"), <<'END';
346 /* (Doing namespace management portably in C is really gross.) */
348 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
349 * (like warn instead of Perl_warn) for the API are not defined.
350 * Not defining the short forms is a good thing for cleaner embedding. */
352 #ifndef PERL_NO_SHORT_NAMES
354 /* Hide global symbols */
356 #if !defined(PERL_IMPLICIT_CONTEXT)
360 # Try to elimiate lots of repeated
367 # by tracking state and merging foo and bar into one block.
368 my $ifdef_state = '';
372 my $new_ifdef_state = '';
375 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
378 my ($flags,$retval,$func,@args) = @_;
379 unless ($flags =~ /[om]/) {
381 $ret .= hide($func,"S_$func");
383 elsif ($flags =~ /p/) {
384 $ret .= hide($func,"Perl_$func");
387 if ($ret ne '' && $flags !~ /A/) {
390 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
393 $new_ifdef_state = "#ifdef PERL_CORE\n";
396 if ($new_ifdef_state ne $ifdef_state) {
397 $ret = $new_ifdef_state . $ret;
401 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
402 # Close the old one ahead of opening the new one.
403 $ret = "#endif\n$ret";
405 # Remember the new state.
406 $ifdef_state = $new_ifdef_state;
414 for $sym (sort keys %ppsym) {
416 print EM hide($sym, "Perl_$sym");
421 #else /* PERL_IMPLICIT_CONTEXT */
430 my $new_ifdef_state = '';
433 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
436 my ($flags,$retval,$func,@args) = @_;
437 unless ($flags =~ /[om]/) {
438 my $args = scalar @args;
439 if ($args and $args[$args-1] =~ /\.\.\./) {
440 # we're out of luck for varargs functions under CPP
442 elsif ($flags =~ /n/) {
444 $ret .= hide($func,"S_$func");
446 elsif ($flags =~ /p/) {
447 $ret .= hide($func,"Perl_$func");
451 my $alist = join(",", @az[0..$args-1]);
452 $ret = "#define $func($alist)";
453 my $t = int(length($ret) / 8);
454 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
456 $ret .= "S_$func(aTHX";
458 elsif ($flags =~ /p/) {
459 $ret .= "Perl_$func(aTHX";
461 $ret .= "_ " if $alist;
462 $ret .= $alist . ")\n";
465 unless ($flags =~ /A/) {
468 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
471 $new_ifdef_state = "#ifdef PERL_CORE\n";
474 if ($new_ifdef_state ne $ifdef_state) {
475 $ret = $new_ifdef_state . $ret;
479 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
480 # Close the old one ahead of opening the new one.
481 $ret = "#endif\n$ret";
483 # Remember the new state.
484 $ifdef_state = $new_ifdef_state;
492 for $sym (sort keys %ppsym) {
494 if ($sym =~ /^ck_/) {
495 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
497 elsif ($sym =~ /^pp_/) {
498 print EM hide("$sym()", "Perl_$sym(aTHX)");
501 warn "Illegal symbol '$sym' in pp.sym";
507 #endif /* PERL_IMPLICIT_CONTEXT */
509 #endif /* #ifndef PERL_NO_SHORT_NAMES */
515 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
519 #if !defined(PERL_CORE)
520 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
521 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
524 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
526 /* Compatibility for various misnamed functions. All functions
527 in the API that begin with "perl_" (not "Perl_") take an explicit
528 interpreter context pointer.
529 The following are not like that, but since they had a "perl_"
530 prefix in previous versions, we provide compatibility macros.
532 # define perl_atexit(a,b) call_atexit(a,b)
533 # define perl_call_argv(a,b,c) call_argv(a,b,c)
534 # define perl_call_pv(a,b) call_pv(a,b)
535 # define perl_call_method(a,b) call_method(a,b)
536 # define perl_call_sv(a,b) call_sv(a,b)
537 # define perl_eval_sv(a,b) eval_sv(a,b)
538 # define perl_eval_pv(a,b) eval_pv(a,b)
539 # define perl_require_pv(a) require_pv(a)
540 # define perl_get_sv(a,b) get_sv(a,b)
541 # define perl_get_av(a,b) get_av(a,b)
542 # define perl_get_hv(a,b) get_hv(a,b)
543 # define perl_get_cv(a,b) get_cv(a,b)
544 # define perl_init_i18nl10n(a) init_i18nl10n(a)
545 # define perl_init_i18nl14n(a) init_i18nl14n(a)
546 # define perl_new_ctype(a) new_ctype(a)
547 # define perl_new_collate(a) new_collate(a)
548 # define perl_new_numeric(a) new_numeric(a)
550 /* varargs functions can't be handled with CPP macros. :-(
551 This provides a set of compatibility functions that don't take
552 an extra argument but grab the context pointer using the macro
555 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
556 # define croak Perl_croak_nocontext
557 # define deb Perl_deb_nocontext
558 # define die Perl_die_nocontext
559 # define form Perl_form_nocontext
560 # define load_module Perl_load_module_nocontext
561 # define mess Perl_mess_nocontext
562 # define newSVpvf Perl_newSVpvf_nocontext
563 # define sv_catpvf Perl_sv_catpvf_nocontext
564 # define sv_setpvf Perl_sv_setpvf_nocontext
565 # define warn Perl_warn_nocontext
566 # define warner Perl_warner_nocontext
567 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
568 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
571 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
573 #if !defined(PERL_IMPLICIT_CONTEXT)
574 /* undefined symbols, point them back at the usual ones */
575 # define Perl_croak_nocontext Perl_croak
576 # define Perl_die_nocontext Perl_die
577 # define Perl_deb_nocontext Perl_deb
578 # define Perl_form_nocontext Perl_form
579 # define Perl_load_module_nocontext Perl_load_module
580 # define Perl_mess_nocontext Perl_mess
581 # define Perl_newSVpvf_nocontext Perl_newSVpvf
582 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
583 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
584 # define Perl_warn_nocontext Perl_warn
585 # define Perl_warner_nocontext Perl_warner
586 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
587 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
592 close(EM) or die "Error closing EM: $!";
594 safer_unlink 'embedvar.h';
595 open(EM, '> embedvar.h')
596 or die "Can't create embedvar.h: $!\n";
599 print EM do_not_edit ("embedvar.h"), <<'END';
601 /* (Doing namespace management portably in C is really gross.) */
604 The following combinations of MULTIPLICITY, USE_5005THREADS
605 and PERL_IMPLICIT_CONTEXT are supported:
607 2) MULTIPLICITY # supported for compatibility
608 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
609 4) USE_5005THREADS && PERL_IMPLICIT_CONTEXT
610 5) MULTIPLICITY && USE_5005THREADS && PERL_IMPLICIT_CONTEXT
612 All other combinations of these flags are errors.
614 #3, #4, #5, and #6 are supported directly, while #2 is a special
615 case of #3 (supported by redefining vTHX appropriately).
618 #if defined(MULTIPLICITY)
619 /* cases 2, 3 and 5 above */
621 # if defined(PERL_IMPLICIT_CONTEXT)
624 # define vTHX PERL_GET_INTERP
629 for $sym (sort keys %thread) {
630 print EM multon($sym,'T','vTHX->');
635 # if defined(USE_5005THREADS)
640 for $sym (sort keys %intrp) {
641 print EM multon($sym,'I','PERL_GET_INTERP->');
646 # else /* !USE_5005THREADS */
647 /* cases 2 and 3 above */
651 for $sym (sort keys %intrp) {
652 print EM multon($sym,'I','vTHX->');
657 # endif /* USE_5005THREADS */
659 #else /* !MULTIPLICITY */
661 /* cases 1 and 4 above */
665 for $sym (sort keys %intrp) {
666 print EM multoff($sym,'I');
671 # if defined(USE_5005THREADS)
676 for $sym (sort keys %thread) {
677 print EM multon($sym,'T','aTHX->');
682 # else /* !USE_5005THREADS */
687 for $sym (sort keys %thread) {
688 print EM multoff($sym,'T');
693 # endif /* USE_5005THREADS */
694 #endif /* MULTIPLICITY */
696 #if defined(PERL_GLOBAL_STRUCT)
700 for $sym (sort keys %globvar) {
701 print EM multon($sym,'G','PL_Vars.');
706 #else /* !PERL_GLOBAL_STRUCT */
710 for $sym (sort keys %globvar) {
711 print EM multoff($sym,'G');
716 #endif /* PERL_GLOBAL_STRUCT */
718 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
722 for $sym (sort @extvars) {
723 print EM hide($sym,"PL_$sym");
728 #endif /* PERL_POLLUTE */
731 close(EM) or die "Error closing EM: $!";
733 safer_unlink 'perlapi.h';
734 safer_unlink 'perlapi.c';
735 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
737 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
740 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
742 /* declare accessor functions for Perl variables */
743 #ifndef __perlapi_h__
744 #define __perlapi_h__
746 #if defined (MULTIPLICITY)
754 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
755 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
756 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
757 #define PERLVARI(v,t,i) PERLVAR(v,t)
758 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
761 #include "intrpvar.h"
762 #include "perlvars.h"
771 #if defined(PERL_CORE)
773 /* accessor functions for Perl variables (provide binary compatibility) */
775 /* these need to be mentioned here, or most linkers won't put them in
776 the perl executable */
778 #ifndef PERL_NO_FORCE_LINK
783 EXT void *PL_force_link_funcs[];
785 EXT void *PL_force_link_funcs[] = {
790 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
791 #define PERLVARA(v,n,t) PERLVAR(v,t)
792 #define PERLVARI(v,t,i) PERLVAR(v,t)
793 #define PERLVARIC(v,t,i) PERLVAR(v,t)
796 #include "intrpvar.h"
797 #include "perlvars.h"
808 #endif /* PERL_NO_FORCE_LINK */
810 #else /* !PERL_CORE */
814 foreach $sym (sort keys %intrp) {
815 print CAPIH bincompat_var('I',$sym);
818 foreach $sym (sort keys %thread) {
819 print CAPIH bincompat_var('T',$sym);
822 foreach $sym (sort keys %globvar) {
823 print CAPIH bincompat_var('G',$sym);
828 #endif /* !PERL_CORE */
829 #endif /* MULTIPLICITY */
831 #endif /* __perlapi_h__ */
834 close CAPIH or die "Error closing CAPIH: $!";
836 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
842 #if defined (MULTIPLICITY)
844 /* accessor functions for Perl variables (provides binary compatibility) */
852 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
853 { return &(aTHX->v); }
854 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
855 { return &(aTHX->v); }
857 #define PERLVARI(v,t,i) PERLVAR(v,t)
858 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
861 #include "intrpvar.h"
865 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
866 { return &(PL_##v); }
867 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
868 { return &(PL_##v); }
870 #define PERLVARIC(v,t,i) const t* Perl_##v##_ptr(pTHX) \
871 { return (const t *)&(PL_##v); }
872 #include "perlvars.h"
881 #endif /* MULTIPLICITY */
884 close(CAPI) or die "Error closing CAPI: $!";
886 # functions that take va_list* for implementing vararg functions
887 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
888 # XXX %vfuncs currently unused
890 Perl_croak Perl_vcroak
892 Perl_warner Perl_vwarner
895 Perl_load_module Perl_vload_module
898 Perl_newSVpvf Perl_vnewSVpvf
899 Perl_sv_setpvf Perl_sv_vsetpvf
900 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
901 Perl_sv_catpvf Perl_sv_vcatpvf
902 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
903 Perl_dump_indent Perl_dump_vindent
904 Perl_default_protect Perl_vdefault_protect