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;
27 -*- buffer-read-only: t -*-
31 Copyright (C) $years, by Larry Wall and others
33 You may distribute under the terms of either the GNU General Public
34 License or the Artistic License, as specified in the README file.
36 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
37 This file is built by embed.pl from data in embed.fnc, embed.pl,
38 pp.sym, intrpvar.h, perlvars.h and thrdvar.h.
39 Any changes made here will be lost!
41 Edit those files and run 'make regen_headers' to effect changes.
45 $warning .= <<EOW if $file eq 'perlapi.c';
47 Up to the threshold of the door there mounted a flight of twenty-seven
48 broad stairs, hewn by some unknown art of the same black stone. This
49 was the only entrance to the tower.
54 if ($file =~ m:\.[ch]$:) {
55 $warning =~ s:^: * :gm;
56 $warning =~ s: +$::gm;
61 $warning =~ s:^:# :gm;
62 $warning =~ s: +$::gm;
67 open IN, "embed.fnc" or die $!;
69 # walk table providing an array of components in each line to
70 # subroutine, printing the result
73 my $filename = shift || '-';
75 defined $leader or $leader = do_not_edit ($filename);
79 if (ref $filename) { # filehandle
83 safer_unlink $filename if $filename ne '/dev/null';
84 open F, ">$filename" or die "Can't open $filename: $!";
88 print $F $leader if $leader;
89 seek IN, 0, 0; # so we may restart
103 @args = split /\s*\|\s*/, $_;
105 my @outs = &{$function}(@args);
106 print $F @outs; # $function->(@args) is not 5.003
108 print $F $trailer if $trailer;
109 unless (ref $filename) {
110 close $F or die "Error closing $filename: $!";
114 sub munge_c_files () {
117 warn "\@ARGV empty, nothing to do\n";
122 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
124 } '/dev/null', '', '';
127 # if (/^#\s*include\s+"perl.h"/) {
128 # my $file = uc $ARGV;
130 # print "#define PERL_IN_$file\n";
136 # if (exists $functions->{$f}) {
137 # my $flags = $functions->{$f}[0];
138 # $repl = "Perl_$repl" if $flags =~ /p/;
139 # unless ($flags =~ /n/) {
141 # $repl .= "_ " if @{$functions->{$f}} > 3;
143 # warn("$ARGV:$.:$repl\n");
147 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
151 if (exists $functions->{$f}) {
153 warn("$ARGV:$.:$`#$repl#$'");
158 close ARGV if eof; # restart $.
166 my $wrote_protected = 0;
175 my ($flags,$retval,$func,@args) = @_;
177 my $has_context = ( $flags !~ /n/ );
178 $ret .= '/* ' if $flags =~ /m/;
180 $retval = "STATIC $retval";
184 $retval = "PERL_CALLCONV $retval";
186 $func = "Perl_$func";
189 $ret .= "$retval\t$func(";
190 if ( $has_context ) {
191 $ret .= @args ? "pTHX_ " : "pTHX";
195 for my $arg ( @args ) {
197 push( @nonnull, $n ) if ( $arg =~ s/\s*\bNN\b\s+// );
199 $ret .= join ", ", @args;
202 $ret .= "void" if !$has_context;
206 if ( $flags =~ /r/ ) {
207 push @attrs, "__attribute__((noreturn))";
209 if ( $flags =~ /a/ ) {
210 push @attrs, "__attribute__((malloc))";
211 $flags .= "R"; # All allocing must check return value
213 if ( $flags =~ /R/ ) {
214 push @attrs, "__attribute__((warn_unused_result))";
216 if ( $flags =~ /P/ ) {
217 push @attrs, "__attribute__((pure))";
219 if( $flags =~ /f/ ) {
220 my $prefix = $has_context ? 'pTHX_' : '';
221 my $args = scalar @args;
222 push @attrs, sprintf "__attribute__format__(__printf__,%s%d,%s%d)",
223 $prefix, $args - 1, $prefix, $args;
226 my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
227 push @attrs, sprintf( "__attribute__((nonnull(%s)))", join( ",", @pos ) );
231 $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
234 $ret .= ' */' if $flags =~ /m/;
235 $ret .= @attrs ? "\n\n" : "\n";
240 # generates global.sym (API export list), and populates %global with global symbols
241 sub write_global_sym {
244 my ($flags,$retval,$func,@args) = @_;
245 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
246 || $flags =~ /b/) { # public API, so export
247 $func = "Perl_$func" if $flags =~ /[pbX]/;
254 walk_table(\&write_protos, "proto.h", undef, "/* ex: set ro: */\n");
255 walk_table(\&write_global_sym, "global.sym", undef, "# ex: set ro:\n");
257 # XXX others that may need adding
261 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
263 tainting tainted stack_base stack_sp sv_arenaroot
265 curstash DBsub DBsingle DBassertion debstash
279 my ($syms, $file) = @_;
281 open(FILE, "< $file")
282 or die "embed.pl: Can't open $file: $!\n";
284 s/[ \t]*#.*//; # Delete comments.
285 if (/^\s*(\S+)\s*$/) {
287 warn "duplicate symbol $sym while processing $file\n"
288 if exists $$syms{$sym};
295 # Perl_pp_* and Perl_ck_* are in pp.sym
296 readsyms my %ppsym, 'pp.sym';
298 sub readvars(\%$$@) {
299 my ($syms, $file,$pre,$keep_pre) = @_;
301 open(FILE, "< $file")
302 or die "embed.pl: Can't open $file: $!\n";
304 s/[ \t]*#.*//; # Delete comments.
305 if (/PERLVARA?I?S?C?\($pre(\w+)/) {
307 $sym = $pre . $sym if $keep_pre;
308 warn "duplicate symbol $sym while processing $file\n"
309 if exists $$syms{$sym};
310 $$syms{$sym} = $pre || 1;
319 readvars %intrp, 'intrpvar.h','I';
320 readvars %thread, 'thrdvar.h','T';
321 readvars %globvar, 'perlvars.h','G';
324 foreach $sym (sort keys %thread) {
325 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
334 my ($from, $to) = @_;
335 my $t = int(length($from) / 8);
336 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
339 sub bincompat_var ($$) {
340 my ($pfx, $sym) = @_;
341 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
342 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
346 my ($sym,$pre,$ptr) = @_;
347 hide("PL_$sym", "($ptr$pre$sym)");
352 return hide("PL_$pre$sym", "PL_$sym");
355 safer_unlink 'embed.h';
356 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
359 print EM do_not_edit ("embed.h"), <<'END';
361 /* (Doing namespace management portably in C is really gross.) */
363 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
364 * (like warn instead of Perl_warn) for the API are not defined.
365 * Not defining the short forms is a good thing for cleaner embedding. */
367 #ifndef PERL_NO_SHORT_NAMES
369 /* Hide global symbols */
371 #if !defined(PERL_IMPLICIT_CONTEXT)
375 # Try to elimiate lots of repeated
382 # by tracking state and merging foo and bar into one block.
383 my $ifdef_state = '';
387 my $new_ifdef_state = '';
390 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
393 my ($flags,$retval,$func,@args) = @_;
394 unless ($flags =~ /[om]/) {
396 $ret .= hide($func,"S_$func");
398 elsif ($flags =~ /p/) {
399 $ret .= hide($func,"Perl_$func");
402 if ($ret ne '' && $flags !~ /A/) {
405 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
408 $new_ifdef_state = "#ifdef PERL_CORE\n";
411 if ($new_ifdef_state ne $ifdef_state) {
412 $ret = $new_ifdef_state . $ret;
416 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
417 # Close the old one ahead of opening the new one.
418 $ret = "#endif\n$ret";
420 # Remember the new state.
421 $ifdef_state = $new_ifdef_state;
429 for $sym (sort keys %ppsym) {
431 print EM hide($sym, "Perl_$sym");
436 #else /* PERL_IMPLICIT_CONTEXT */
445 my $new_ifdef_state = '';
448 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
451 my ($flags,$retval,$func,@args) = @_;
452 unless ($flags =~ /[om]/) {
453 my $args = scalar @args;
454 if ($args and $args[$args-1] =~ /\.\.\./) {
455 # we're out of luck for varargs functions under CPP
457 elsif ($flags =~ /n/) {
459 $ret .= hide($func,"S_$func");
461 elsif ($flags =~ /p/) {
462 $ret .= hide($func,"Perl_$func");
466 my $alist = join(",", @az[0..$args-1]);
467 $ret = "#define $func($alist)";
468 my $t = int(length($ret) / 8);
469 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
471 $ret .= "S_$func(aTHX";
473 elsif ($flags =~ /p/) {
474 $ret .= "Perl_$func(aTHX";
476 $ret .= "_ " if $alist;
477 $ret .= $alist . ")\n";
480 unless ($flags =~ /A/) {
483 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
486 $new_ifdef_state = "#ifdef PERL_CORE\n";
489 if ($new_ifdef_state ne $ifdef_state) {
490 $ret = $new_ifdef_state . $ret;
494 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
495 # Close the old one ahead of opening the new one.
496 $ret = "#endif\n$ret";
498 # Remember the new state.
499 $ifdef_state = $new_ifdef_state;
507 for $sym (sort keys %ppsym) {
509 if ($sym =~ /^ck_/) {
510 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
512 elsif ($sym =~ /^pp_/) {
513 print EM hide("$sym()", "Perl_$sym(aTHX)");
516 warn "Illegal symbol '$sym' in pp.sym";
522 #endif /* PERL_IMPLICIT_CONTEXT */
524 #endif /* #ifndef PERL_NO_SHORT_NAMES */
530 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
534 #if !defined(PERL_CORE)
535 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
536 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
539 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
541 /* Compatibility for various misnamed functions. All functions
542 in the API that begin with "perl_" (not "Perl_") take an explicit
543 interpreter context pointer.
544 The following are not like that, but since they had a "perl_"
545 prefix in previous versions, we provide compatibility macros.
547 # define perl_atexit(a,b) call_atexit(a,b)
548 # define perl_call_argv(a,b,c) call_argv(a,b,c)
549 # define perl_call_pv(a,b) call_pv(a,b)
550 # define perl_call_method(a,b) call_method(a,b)
551 # define perl_call_sv(a,b) call_sv(a,b)
552 # define perl_eval_sv(a,b) eval_sv(a,b)
553 # define perl_eval_pv(a,b) eval_pv(a,b)
554 # define perl_require_pv(a) require_pv(a)
555 # define perl_get_sv(a,b) get_sv(a,b)
556 # define perl_get_av(a,b) get_av(a,b)
557 # define perl_get_hv(a,b) get_hv(a,b)
558 # define perl_get_cv(a,b) get_cv(a,b)
559 # define perl_init_i18nl10n(a) init_i18nl10n(a)
560 # define perl_init_i18nl14n(a) init_i18nl14n(a)
561 # define perl_new_ctype(a) new_ctype(a)
562 # define perl_new_collate(a) new_collate(a)
563 # define perl_new_numeric(a) new_numeric(a)
565 /* varargs functions can't be handled with CPP macros. :-(
566 This provides a set of compatibility functions that don't take
567 an extra argument but grab the context pointer using the macro
570 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
571 # define croak Perl_croak_nocontext
572 # define deb Perl_deb_nocontext
573 # define die Perl_die_nocontext
574 # define form Perl_form_nocontext
575 # define load_module Perl_load_module_nocontext
576 # define mess Perl_mess_nocontext
577 # define newSVpvf Perl_newSVpvf_nocontext
578 # define sv_catpvf Perl_sv_catpvf_nocontext
579 # define sv_setpvf Perl_sv_setpvf_nocontext
580 # define warn Perl_warn_nocontext
581 # define warner Perl_warner_nocontext
582 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
583 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
586 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
588 #if !defined(PERL_IMPLICIT_CONTEXT)
589 /* undefined symbols, point them back at the usual ones */
590 # define Perl_croak_nocontext Perl_croak
591 # define Perl_die_nocontext Perl_die
592 # define Perl_deb_nocontext Perl_deb
593 # define Perl_form_nocontext Perl_form
594 # define Perl_load_module_nocontext Perl_load_module
595 # define Perl_mess_nocontext Perl_mess
596 # define Perl_newSVpvf_nocontext Perl_newSVpvf
597 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
598 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
599 # define Perl_warn_nocontext Perl_warn
600 # define Perl_warner_nocontext Perl_warner
601 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
602 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
608 close(EM) or die "Error closing EM: $!";
610 safer_unlink 'embedvar.h';
611 open(EM, '> embedvar.h')
612 or die "Can't create embedvar.h: $!\n";
615 print EM do_not_edit ("embedvar.h"), <<'END';
617 /* (Doing namespace management portably in C is really gross.) */
620 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
623 2) MULTIPLICITY # supported for compatibility
624 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
626 All other combinations of these flags are errors.
628 only #3 is supported directly, while #2 is a special
629 case of #3 (supported by redefining vTHX appropriately).
632 #if defined(MULTIPLICITY)
633 /* cases 2 and 3 above */
635 # if defined(PERL_IMPLICIT_CONTEXT)
638 # define vTHX PERL_GET_INTERP
643 for $sym (sort keys %thread) {
644 print EM multon($sym,'T','vTHX->');
649 /* cases 2 and 3 above */
653 for $sym (sort keys %intrp) {
654 print EM multon($sym,'I','vTHX->');
659 #else /* !MULTIPLICITY */
665 for $sym (sort keys %intrp) {
666 print EM multoff($sym,'I');
673 for $sym (sort keys %thread) {
674 print EM multoff($sym,'T');
679 #endif /* MULTIPLICITY */
681 #if defined(PERL_GLOBAL_STRUCT)
685 for $sym (sort keys %globvar) {
686 print EM multon($sym, 'G','my_vars->');
687 print EM multon("G$sym",'', 'my_vars->');
692 #else /* !PERL_GLOBAL_STRUCT */
696 for $sym (sort keys %globvar) {
697 print EM multoff($sym,'G');
702 #endif /* PERL_GLOBAL_STRUCT */
704 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
708 for $sym (sort @extvars) {
709 print EM hide($sym,"PL_$sym");
714 #endif /* PERL_POLLUTE */
719 close(EM) or die "Error closing EM: $!";
721 safer_unlink 'perlapi.h';
722 safer_unlink 'perlapi.c';
723 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
725 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
728 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
730 /* declare accessor functions for Perl variables */
731 #ifndef __perlapi_h__
732 #define __perlapi_h__
734 #if defined (MULTIPLICITY)
743 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
744 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
745 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
746 #define PERLVARI(v,t,i) PERLVAR(v,t)
747 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
748 #define PERLVARISC(v,i) typedef const char PL_##v##_t[sizeof(i)]; \
749 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
752 #include "intrpvar.h"
753 #include "perlvars.h"
761 #ifndef PERL_GLOBAL_STRUCT
762 EXTERN_C Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX);
763 EXTERN_C Perl_check_t** Perl_Gcheck_ptr(pTHX);
764 EXTERN_C unsigned char** Perl_Gfold_locale_ptr(pTHX);
765 #define Perl_ppaddr_ptr Perl_Gppaddr_ptr
766 #define Perl_check_ptr Perl_Gcheck_ptr
767 #define Perl_fold_locale_ptr Perl_Gfold_locale_ptr
772 #if defined(PERL_CORE)
774 /* accessor functions for Perl variables (provide binary compatibility) */
776 /* these need to be mentioned here, or most linkers won't put them in
777 the perl executable */
779 #ifndef PERL_NO_FORCE_LINK
784 EXTCONST void * const PL_force_link_funcs[];
786 EXTCONST void * const PL_force_link_funcs[] = {
791 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
792 #define PERLVARA(v,n,t) PERLVAR(v,t)
793 #define PERLVARI(v,t,i) PERLVAR(v,t)
794 #define PERLVARIC(v,t,i) PERLVAR(v,t)
795 #define PERLVARISC(v,i) PERLVAR(v,char)
798 #include "intrpvar.h"
799 #include "perlvars.h"
811 #endif /* PERL_NO_FORCE_LINK */
813 #else /* !PERL_CORE */
817 foreach $sym (sort keys %intrp) {
818 print CAPIH bincompat_var('I',$sym);
821 foreach $sym (sort keys %thread) {
822 print CAPIH bincompat_var('T',$sym);
825 foreach $sym (sort keys %globvar) {
826 print CAPIH bincompat_var('G',$sym);
831 #endif /* !PERL_CORE */
832 #endif /* MULTIPLICITY */
834 #endif /* __perlapi_h__ */
838 close CAPIH or die "Error closing CAPIH: $!";
840 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
846 #if defined (MULTIPLICITY)
848 /* accessor functions for Perl variables (provides binary compatibility) */
857 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
858 { dVAR; return &(aTHX->v); }
859 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
860 { dVAR; return &(aTHX->v); }
862 #define PERLVARI(v,t,i) PERLVAR(v,t)
863 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
864 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
865 { dVAR; return &(aTHX->v); }
868 #include "intrpvar.h"
872 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
873 { dVAR; return &(PL_##v); }
874 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
875 { dVAR; return &(PL_##v); }
878 #define PERLVARIC(v,t,i) \
879 const t* Perl_##v##_ptr(pTHX) \
880 { return (const t *)&(PL_##v); }
881 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
882 { dVAR; return &(PL_##v); }
883 #include "perlvars.h"
891 #ifndef PERL_GLOBAL_STRUCT
892 /* A few evil special cases. Could probably macrofy this. */
895 #undef PL_fold_locale
896 Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX) {
897 static const Perl_ppaddr_t* ppaddr_ptr = PL_ppaddr;
898 return (Perl_ppaddr_t**)&ppaddr_ptr;
900 Perl_check_t** Perl_Gcheck_ptr(pTHX) {
901 static const Perl_check_t* check_ptr = PL_check;
902 return (Perl_check_t**)&check_ptr;
904 unsigned char** Perl_Gfold_locale_ptr(pTHX) {
905 static const unsigned char* fold_locale_ptr = PL_fold_locale;
906 return (unsigned char**)&fold_locale_ptr;
912 #endif /* MULTIPLICITY */
917 close(CAPI) or die "Error closing CAPI: $!";
919 # functions that take va_list* for implementing vararg functions
920 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
921 # XXX %vfuncs currently unused
923 Perl_croak Perl_vcroak
925 Perl_warner Perl_vwarner
928 Perl_load_module Perl_vload_module
931 Perl_newSVpvf Perl_vnewSVpvf
932 Perl_sv_setpvf Perl_sv_vsetpvf
933 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
934 Perl_sv_catpvf Perl_sv_vcatpvf
935 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
936 Perl_dump_indent Perl_dump_vindent
937 Perl_default_protect Perl_vdefault_protect