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+// );
198 $arg =~ s/\s*\bNULLOK\b\s+//; # strip NULLOK with no effect
200 $ret .= join ", ", @args;
203 $ret .= "void" if !$has_context;
207 if ( $flags =~ /r/ ) {
208 push @attrs, "__attribute__noreturn__";
210 if ( $flags =~ /a/ ) {
211 push @attrs, "__attribute__malloc__";
212 $flags .= "R"; # All allocing must check return value
214 if ( $flags =~ /R/ ) {
215 push @attrs, "__attribute__warn_unused_result__";
217 if ( $flags =~ /P/ ) {
218 push @attrs, "__attribute__pure__";
220 if( $flags =~ /f/ ) {
221 my $prefix = $has_context ? 'pTHX_' : '';
222 my $args = scalar @args;
223 push @attrs, sprintf "__attribute__format__(__printf__,%s%d,%s%d)",
224 $prefix, $args - 1, $prefix, $args;
227 my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
228 push @attrs, map { sprintf( "__attribute__nonnull__(%s)", $_ ) } @pos;
232 $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
235 $ret .= ' */' if $flags =~ /m/;
236 $ret .= @attrs ? "\n\n" : "\n";
241 # generates global.sym (API export list), and populates %global with global symbols
242 sub write_global_sym {
245 my ($flags,$retval,$func,@args) = @_;
246 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
247 || $flags =~ /b/) { # public API, so export
248 $func = "Perl_$func" if $flags =~ /[pbX]/;
255 walk_table(\&write_protos, "proto.h", undef, "/* ex: set ro: */\n");
256 walk_table(\&write_global_sym, "global.sym", undef, "# ex: set ro:\n");
258 # XXX others that may need adding
262 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
264 tainting tainted stack_base stack_sp sv_arenaroot
266 curstash DBsub DBsingle DBassertion debstash
280 my ($syms, $file) = @_;
282 open(FILE, "< $file")
283 or die "embed.pl: Can't open $file: $!\n";
285 s/[ \t]*#.*//; # Delete comments.
286 if (/^\s*(\S+)\s*$/) {
288 warn "duplicate symbol $sym while processing $file\n"
289 if exists $$syms{$sym};
296 # Perl_pp_* and Perl_ck_* are in pp.sym
297 readsyms my %ppsym, 'pp.sym';
299 sub readvars(\%$$@) {
300 my ($syms, $file,$pre,$keep_pre) = @_;
302 open(FILE, "< $file")
303 or die "embed.pl: Can't open $file: $!\n";
305 s/[ \t]*#.*//; # Delete comments.
306 if (/PERLVARA?I?S?C?\($pre(\w+)/) {
308 $sym = $pre . $sym if $keep_pre;
309 warn "duplicate symbol $sym while processing $file\n"
310 if exists $$syms{$sym};
311 $$syms{$sym} = $pre || 1;
320 readvars %intrp, 'intrpvar.h','I';
321 readvars %thread, 'thrdvar.h','T';
322 readvars %globvar, 'perlvars.h','G';
325 foreach $sym (sort keys %thread) {
326 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
335 my ($from, $to) = @_;
336 my $t = int(length($from) / 8);
337 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
340 sub bincompat_var ($$) {
341 my ($pfx, $sym) = @_;
342 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
343 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
347 my ($sym,$pre,$ptr) = @_;
348 hide("PL_$sym", "($ptr$pre$sym)");
353 return hide("PL_$pre$sym", "PL_$sym");
356 safer_unlink 'embed.h';
357 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
360 print EM do_not_edit ("embed.h"), <<'END';
362 /* (Doing namespace management portably in C is really gross.) */
364 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
365 * (like warn instead of Perl_warn) for the API are not defined.
366 * Not defining the short forms is a good thing for cleaner embedding. */
368 #ifndef PERL_NO_SHORT_NAMES
370 /* Hide global symbols */
372 #if !defined(PERL_IMPLICIT_CONTEXT)
376 # Try to elimiate lots of repeated
383 # by tracking state and merging foo and bar into one block.
384 my $ifdef_state = '';
388 my $new_ifdef_state = '';
391 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
394 my ($flags,$retval,$func,@args) = @_;
395 unless ($flags =~ /[om]/) {
397 $ret .= hide($func,"S_$func");
399 elsif ($flags =~ /p/) {
400 $ret .= hide($func,"Perl_$func");
403 if ($ret ne '' && $flags !~ /A/) {
406 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
409 $new_ifdef_state = "#ifdef PERL_CORE\n";
412 if ($new_ifdef_state ne $ifdef_state) {
413 $ret = $new_ifdef_state . $ret;
417 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
418 # Close the old one ahead of opening the new one.
419 $ret = "#endif\n$ret";
421 # Remember the new state.
422 $ifdef_state = $new_ifdef_state;
430 for $sym (sort keys %ppsym) {
432 print EM hide($sym, "Perl_$sym");
437 #else /* PERL_IMPLICIT_CONTEXT */
446 my $new_ifdef_state = '';
449 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
452 my ($flags,$retval,$func,@args) = @_;
453 unless ($flags =~ /[om]/) {
454 my $args = scalar @args;
455 if ($args and $args[$args-1] =~ /\.\.\./) {
456 # we're out of luck for varargs functions under CPP
458 elsif ($flags =~ /n/) {
460 $ret .= hide($func,"S_$func");
462 elsif ($flags =~ /p/) {
463 $ret .= hide($func,"Perl_$func");
467 my $alist = join(",", @az[0..$args-1]);
468 $ret = "#define $func($alist)";
469 my $t = int(length($ret) / 8);
470 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
472 $ret .= "S_$func(aTHX";
474 elsif ($flags =~ /p/) {
475 $ret .= "Perl_$func(aTHX";
477 $ret .= "_ " if $alist;
478 $ret .= $alist . ")\n";
481 unless ($flags =~ /A/) {
484 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
487 $new_ifdef_state = "#ifdef PERL_CORE\n";
490 if ($new_ifdef_state ne $ifdef_state) {
491 $ret = $new_ifdef_state . $ret;
495 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
496 # Close the old one ahead of opening the new one.
497 $ret = "#endif\n$ret";
499 # Remember the new state.
500 $ifdef_state = $new_ifdef_state;
508 for $sym (sort keys %ppsym) {
510 if ($sym =~ /^ck_/) {
511 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
513 elsif ($sym =~ /^pp_/) {
514 print EM hide("$sym()", "Perl_$sym(aTHX)");
517 warn "Illegal symbol '$sym' in pp.sym";
523 #endif /* PERL_IMPLICIT_CONTEXT */
525 #endif /* #ifndef PERL_NO_SHORT_NAMES */
531 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
535 #if !defined(PERL_CORE)
536 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
537 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
540 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
542 /* Compatibility for various misnamed functions. All functions
543 in the API that begin with "perl_" (not "Perl_") take an explicit
544 interpreter context pointer.
545 The following are not like that, but since they had a "perl_"
546 prefix in previous versions, we provide compatibility macros.
548 # define perl_atexit(a,b) call_atexit(a,b)
549 # define perl_call_argv(a,b,c) call_argv(a,b,c)
550 # define perl_call_pv(a,b) call_pv(a,b)
551 # define perl_call_method(a,b) call_method(a,b)
552 # define perl_call_sv(a,b) call_sv(a,b)
553 # define perl_eval_sv(a,b) eval_sv(a,b)
554 # define perl_eval_pv(a,b) eval_pv(a,b)
555 # define perl_require_pv(a) require_pv(a)
556 # define perl_get_sv(a,b) get_sv(a,b)
557 # define perl_get_av(a,b) get_av(a,b)
558 # define perl_get_hv(a,b) get_hv(a,b)
559 # define perl_get_cv(a,b) get_cv(a,b)
560 # define perl_init_i18nl10n(a) init_i18nl10n(a)
561 # define perl_init_i18nl14n(a) init_i18nl14n(a)
562 # define perl_new_ctype(a) new_ctype(a)
563 # define perl_new_collate(a) new_collate(a)
564 # define perl_new_numeric(a) new_numeric(a)
566 /* varargs functions can't be handled with CPP macros. :-(
567 This provides a set of compatibility functions that don't take
568 an extra argument but grab the context pointer using the macro
571 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
572 # define croak Perl_croak_nocontext
573 # define deb Perl_deb_nocontext
574 # define die Perl_die_nocontext
575 # define form Perl_form_nocontext
576 # define load_module Perl_load_module_nocontext
577 # define mess Perl_mess_nocontext
578 # define newSVpvf Perl_newSVpvf_nocontext
579 # define sv_catpvf Perl_sv_catpvf_nocontext
580 # define sv_setpvf Perl_sv_setpvf_nocontext
581 # define warn Perl_warn_nocontext
582 # define warner Perl_warner_nocontext
583 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
584 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
587 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
589 #if !defined(PERL_IMPLICIT_CONTEXT)
590 /* undefined symbols, point them back at the usual ones */
591 # define Perl_croak_nocontext Perl_croak
592 # define Perl_die_nocontext Perl_die
593 # define Perl_deb_nocontext Perl_deb
594 # define Perl_form_nocontext Perl_form
595 # define Perl_load_module_nocontext Perl_load_module
596 # define Perl_mess_nocontext Perl_mess
597 # define Perl_newSVpvf_nocontext Perl_newSVpvf
598 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
599 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
600 # define Perl_warn_nocontext Perl_warn
601 # define Perl_warner_nocontext Perl_warner
602 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
603 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
609 close(EM) or die "Error closing EM: $!";
611 safer_unlink 'embedvar.h';
612 open(EM, '> embedvar.h')
613 or die "Can't create embedvar.h: $!\n";
616 print EM do_not_edit ("embedvar.h"), <<'END';
618 /* (Doing namespace management portably in C is really gross.) */
621 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
624 2) MULTIPLICITY # supported for compatibility
625 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
627 All other combinations of these flags are errors.
629 only #3 is supported directly, while #2 is a special
630 case of #3 (supported by redefining vTHX appropriately).
633 #if defined(MULTIPLICITY)
634 /* cases 2 and 3 above */
636 # if defined(PERL_IMPLICIT_CONTEXT)
639 # define vTHX PERL_GET_INTERP
644 for $sym (sort keys %thread) {
645 print EM multon($sym,'T','vTHX->');
650 /* cases 2 and 3 above */
654 for $sym (sort keys %intrp) {
655 print EM multon($sym,'I','vTHX->');
660 #else /* !MULTIPLICITY */
666 for $sym (sort keys %intrp) {
667 print EM multoff($sym,'I');
674 for $sym (sort keys %thread) {
675 print EM multoff($sym,'T');
680 #endif /* MULTIPLICITY */
682 #if defined(PERL_GLOBAL_STRUCT)
686 for $sym (sort keys %globvar) {
687 print EM multon($sym, 'G','my_vars->');
688 print EM multon("G$sym",'', 'my_vars->');
693 #else /* !PERL_GLOBAL_STRUCT */
697 for $sym (sort keys %globvar) {
698 print EM multoff($sym,'G');
703 #endif /* PERL_GLOBAL_STRUCT */
705 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
709 for $sym (sort @extvars) {
710 print EM hide($sym,"PL_$sym");
715 #endif /* PERL_POLLUTE */
720 close(EM) or die "Error closing EM: $!";
722 safer_unlink 'perlapi.h';
723 safer_unlink 'perlapi.c';
724 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
726 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
729 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
731 /* declare accessor functions for Perl variables */
732 #ifndef __perlapi_h__
733 #define __perlapi_h__
735 #if defined (MULTIPLICITY)
744 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
745 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
746 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
747 #define PERLVARI(v,t,i) PERLVAR(v,t)
748 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
749 #define PERLVARISC(v,i) typedef const char PL_##v##_t[sizeof(i)]; \
750 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
753 #include "intrpvar.h"
754 #include "perlvars.h"
762 #ifndef PERL_GLOBAL_STRUCT
763 EXTERN_C Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX);
764 EXTERN_C Perl_check_t** Perl_Gcheck_ptr(pTHX);
765 EXTERN_C unsigned char** Perl_Gfold_locale_ptr(pTHX);
766 #define Perl_ppaddr_ptr Perl_Gppaddr_ptr
767 #define Perl_check_ptr Perl_Gcheck_ptr
768 #define Perl_fold_locale_ptr Perl_Gfold_locale_ptr
773 #if defined(PERL_CORE)
775 /* accessor functions for Perl variables (provide binary compatibility) */
777 /* these need to be mentioned here, or most linkers won't put them in
778 the perl executable */
780 #ifndef PERL_NO_FORCE_LINK
785 EXTCONST void * const PL_force_link_funcs[];
787 EXTCONST void * const PL_force_link_funcs[] = {
792 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
793 #define PERLVARA(v,n,t) PERLVAR(v,t)
794 #define PERLVARI(v,t,i) PERLVAR(v,t)
795 #define PERLVARIC(v,t,i) PERLVAR(v,t)
796 #define PERLVARISC(v,i) PERLVAR(v,char)
798 /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one
799 * cannot cast between void pointers and function pointers without
800 * info level warnings. The PL_force_link_funcs[] would cause a few
801 * hundred of those warnings. In code one can circumnavigate this by using
802 * unions that overlay the different pointers, but in declarations one
803 * cannot use this trick. Therefore we just disable the warning here
804 * for the duration of the PL_force_link_funcs[] declaration. */
806 #if defined(__DECC) && defined(__osf__)
808 #pragma message disable (nonstandcast)
812 #include "intrpvar.h"
813 #include "perlvars.h"
815 #if defined(__DECC) && defined(__osf__)
816 #pragma message restore
829 #endif /* PERL_NO_FORCE_LINK */
831 #else /* !PERL_CORE */
835 foreach $sym (sort keys %intrp) {
836 print CAPIH bincompat_var('I',$sym);
839 foreach $sym (sort keys %thread) {
840 print CAPIH bincompat_var('T',$sym);
843 foreach $sym (sort keys %globvar) {
844 print CAPIH bincompat_var('G',$sym);
849 #endif /* !PERL_CORE */
850 #endif /* MULTIPLICITY */
852 #endif /* __perlapi_h__ */
856 close CAPIH or die "Error closing CAPIH: $!";
858 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
864 #if defined (MULTIPLICITY)
866 /* accessor functions for Perl variables (provides binary compatibility) */
875 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
876 { dVAR; return &(aTHX->v); }
877 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
878 { dVAR; return &(aTHX->v); }
880 #define PERLVARI(v,t,i) PERLVAR(v,t)
881 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
882 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
883 { dVAR; return &(aTHX->v); }
886 #include "intrpvar.h"
890 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
891 { dVAR; return &(PL_##v); }
892 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
893 { dVAR; return &(PL_##v); }
896 #define PERLVARIC(v,t,i) \
897 const t* Perl_##v##_ptr(pTHX) \
898 { return (const t *)&(PL_##v); }
899 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
900 { dVAR; return &(PL_##v); }
901 #include "perlvars.h"
909 #ifndef PERL_GLOBAL_STRUCT
910 /* A few evil special cases. Could probably macrofy this. */
913 #undef PL_fold_locale
914 Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX) {
915 static const Perl_ppaddr_t* ppaddr_ptr = PL_ppaddr;
916 return (Perl_ppaddr_t**)&ppaddr_ptr;
918 Perl_check_t** Perl_Gcheck_ptr(pTHX) {
919 static const Perl_check_t* check_ptr = PL_check;
920 return (Perl_check_t**)&check_ptr;
922 unsigned char** Perl_Gfold_locale_ptr(pTHX) {
923 static const unsigned char* fold_locale_ptr = PL_fold_locale;
924 return (unsigned char**)&fold_locale_ptr;
930 #endif /* MULTIPLICITY */
935 close(CAPI) or die "Error closing CAPI: $!";
937 # functions that take va_list* for implementing vararg functions
938 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
939 # XXX %vfuncs currently unused
941 Perl_croak Perl_vcroak
943 Perl_warner Perl_vwarner
946 Perl_load_module Perl_vload_module
949 Perl_newSVpvf Perl_vnewSVpvf
950 Perl_sv_setpvf Perl_sv_vsetpvf
951 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
952 Perl_sv_catpvf Perl_sv_vcatpvf
953 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
954 Perl_dump_indent Perl_dump_vindent
955 Perl_default_protect Perl_vdefault_protect
958 # ex: set ts=8 sts=4 sw=4 noet: