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 DBassertion 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?S?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 and PERL_IMPLICIT_CONTEXT
607 2) MULTIPLICITY # supported for compatibility
608 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
610 All other combinations of these flags are errors.
612 only #3 is supported directly, while #2 is a special
613 case of #3 (supported by redefining vTHX appropriately).
616 #if defined(MULTIPLICITY)
617 /* cases 2 and 3 above */
619 # if defined(PERL_IMPLICIT_CONTEXT)
622 # define vTHX PERL_GET_INTERP
627 for $sym (sort keys %thread) {
628 print EM multon($sym,'T','vTHX->');
633 /* cases 2 and 3 above */
637 for $sym (sort keys %intrp) {
638 print EM multon($sym,'I','vTHX->');
643 #else /* !MULTIPLICITY */
649 for $sym (sort keys %intrp) {
650 print EM multoff($sym,'I');
657 for $sym (sort keys %thread) {
658 print EM multoff($sym,'T');
663 #endif /* MULTIPLICITY */
665 #if defined(PERL_GLOBAL_STRUCT)
669 for $sym (sort keys %globvar) {
670 print EM multon($sym, 'G','my_vars->');
671 print EM multon("G$sym",'', 'my_vars->');
676 #else /* !PERL_GLOBAL_STRUCT */
680 for $sym (sort keys %globvar) {
681 print EM multoff($sym,'G');
686 #endif /* PERL_GLOBAL_STRUCT */
688 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
692 for $sym (sort @extvars) {
693 print EM hide($sym,"PL_$sym");
698 #endif /* PERL_POLLUTE */
701 close(EM) or die "Error closing EM: $!";
703 safer_unlink 'perlapi.h';
704 safer_unlink 'perlapi.c';
705 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
707 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
710 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
712 /* declare accessor functions for Perl variables */
713 #ifndef __perlapi_h__
714 #define __perlapi_h__
716 #if defined (MULTIPLICITY)
725 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
726 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
727 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
728 #define PERLVARI(v,t,i) PERLVAR(v,t)
729 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
730 #define PERLVARISC(v,i) typedef const char PL_##v##_t[sizeof(i)]; \
731 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
734 #include "intrpvar.h"
735 #include "perlvars.h"
743 #ifndef PERL_GLOBAL_STRUCT
744 EXTERN_C Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX);
745 EXTERN_C Perl_check_t** Perl_Gcheck_ptr(pTHX);
746 EXTERN_C unsigned char** Perl_Gfold_locale_ptr(pTHX);
747 #define Perl_ppaddr_ptr Perl_Gppaddr_ptr
748 #define Perl_check_ptr Perl_Gcheck_ptr
749 #define Perl_fold_locale_ptr Perl_Gfold_locale_ptr
754 #if defined(PERL_CORE)
756 /* accessor functions for Perl variables (provide binary compatibility) */
758 /* these need to be mentioned here, or most linkers won't put them in
759 the perl executable */
761 #ifndef PERL_NO_FORCE_LINK
766 EXTCONST void * const PL_force_link_funcs[];
768 EXTCONST void * const PL_force_link_funcs[] = {
773 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
774 #define PERLVARA(v,n,t) PERLVAR(v,t)
775 #define PERLVARI(v,t,i) PERLVAR(v,t)
776 #define PERLVARIC(v,t,i) PERLVAR(v,t)
777 #define PERLVARISC(v,i) PERLVAR(v,char)
780 #include "intrpvar.h"
781 #include "perlvars.h"
793 #endif /* PERL_NO_FORCE_LINK */
795 #else /* !PERL_CORE */
799 foreach $sym (sort keys %intrp) {
800 print CAPIH bincompat_var('I',$sym);
803 foreach $sym (sort keys %thread) {
804 print CAPIH bincompat_var('T',$sym);
807 foreach $sym (sort keys %globvar) {
808 print CAPIH bincompat_var('G',$sym);
813 #endif /* !PERL_CORE */
814 #endif /* MULTIPLICITY */
816 #endif /* __perlapi_h__ */
819 close CAPIH or die "Error closing CAPIH: $!";
821 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
827 #if defined (MULTIPLICITY)
829 /* accessor functions for Perl variables (provides binary compatibility) */
838 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
839 { dVAR; return &(aTHX->v); }
840 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
841 { dVAR; return &(aTHX->v); }
843 #define PERLVARI(v,t,i) PERLVAR(v,t)
844 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
845 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
846 { dVAR; return &(aTHX->v); }
849 #include "intrpvar.h"
853 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
854 { dVAR; return &(PL_##v); }
855 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
856 { dVAR; return &(PL_##v); }
859 #define PERLVARIC(v,t,i) \
860 const t* Perl_##v##_ptr(pTHX) \
861 { return (const t *)&(PL_##v); }
862 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
863 { dVAR; return &(PL_##v); }
864 #include "perlvars.h"
872 #ifndef PERL_GLOBAL_STRUCT
873 /* A few evil special cases. Could probably macrofy this. */
876 #undef PL_fold_locale
877 Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX) {
878 static const Perl_ppaddr_t* ppaddr_ptr = PL_ppaddr;
879 return (Perl_ppaddr_t**)&ppaddr_ptr;
881 Perl_check_t** Perl_Gcheck_ptr(pTHX) {
882 static const Perl_check_t* check_ptr = PL_check;
883 return (Perl_check_t**)&check_ptr;
885 unsigned char** Perl_Gfold_locale_ptr(pTHX) {
886 static const unsigned char* fold_locale_ptr = PL_fold_locale;
887 return (unsigned char**)&fold_locale_ptr;
893 #endif /* MULTIPLICITY */
896 close(CAPI) or die "Error closing CAPI: $!";
898 # functions that take va_list* for implementing vararg functions
899 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
900 # XXX %vfuncs currently unused
902 Perl_croak Perl_vcroak
904 Perl_warner Perl_vwarner
907 Perl_load_module Perl_vload_module
910 Perl_newSVpvf Perl_vnewSVpvf
911 Perl_sv_setpvf Perl_sv_vsetpvf
912 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
913 Perl_sv_catpvf Perl_sv_vcatpvf
914 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
915 Perl_dump_indent Perl_dump_vindent
916 Perl_default_protect Perl_vdefault_protect