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 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
131 if (exists $functions->{$f}) {
133 warn("$ARGV:$.:$`#$repl#$'");
138 close ARGV if eof; # restart $.
146 my $wrote_protected = 0;
155 my ($flags,$retval,$func,@args) = @_;
157 my $has_context = ( $flags !~ /n/ );
158 $ret .= '/* ' if $flags =~ /m/;
160 $retval = "STATIC $retval";
164 $retval = "PERL_CALLCONV $retval";
166 $func = "Perl_$func";
169 $ret .= "$retval\t$func(";
170 if ( $has_context ) {
171 $ret .= @args ? "pTHX_ " : "pTHX";
175 for my $arg ( @args ) {
177 if ( $arg =~ /\*/ && $arg !~ /\b(NN|NULLOK)\b/ ) {
178 warn "$func: $arg needs NN or NULLOK\n";
179 our $unflagged_pointers;
180 ++$unflagged_pointers;
182 push( @nonnull, $n ) if ( $arg =~ s/\s*\bNN\b\s+// );
183 $arg =~ s/\s*\bNULLOK\b\s+//; # strip NULLOK with no effect
185 # Make sure each arg has at least a type and a var name.
186 # An arg of "int" is valid C, but want it to be "int foo".
188 $temp_arg =~ s/\*//g;
189 $temp_arg =~ s/\s*\bstruct\b\s*/ /g;
190 if ( ($temp_arg ne "...") && ($temp_arg !~ /\w+\s+\w+/) ) {
191 warn "$func: $arg doesn't have a name\n";
194 $ret .= join ", ", @args;
197 $ret .= "void" if !$has_context;
201 if ( $flags =~ /r/ ) {
202 push @attrs, "__attribute__noreturn__";
204 if ( $flags =~ /a/ ) {
205 push @attrs, "__attribute__malloc__";
206 $flags .= "R"; # All allocing must check return value
208 if ( $flags =~ /R/ ) {
209 push @attrs, "__attribute__warn_unused_result__";
211 if ( $flags =~ /P/ ) {
212 push @attrs, "__attribute__pure__";
214 if( $flags =~ /f/ ) {
215 my $prefix = $has_context ? 'pTHX_' : '';
216 my $args = scalar @args;
217 push @attrs, sprintf "__attribute__format__(__printf__,%s%d,%s%d)",
218 $prefix, $args - 1, $prefix, $args;
221 my @pos = map { $has_context ? "pTHX_$_" : $_ } @nonnull;
222 push @attrs, map { sprintf( "__attribute__nonnull__(%s)", $_ ) } @pos;
226 $ret .= join( "\n", map { "\t\t\t$_" } @attrs );
229 $ret .= ' */' if $flags =~ /m/;
230 $ret .= @attrs ? "\n\n" : "\n";
235 # generates global.sym (API export list)
238 sub write_global_sym {
241 my ($flags,$retval,$func,@args) = @_;
242 # If a function is defined twice, for example before and after an
243 # #else, only process the flags on the first instance for global.sym
244 return $ret if $seen{$func}++;
245 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
246 || $flags =~ /b/) { # public API, so export
247 $func = "Perl_$func" if $flags =~ /[pbX]/;
256 our $unflagged_pointers;
257 walk_table(\&write_protos, "proto.h", undef, "/* ex: set ro: */\n");
258 warn "$unflagged_pointers pointer arguments to clean up\n" if $unflagged_pointers;
259 walk_table(\&write_global_sym, "global.sym", undef, "# ex: set ro:\n");
261 # XXX others that may need adding
265 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
267 tainting tainted stack_base stack_sp sv_arenaroot
269 curstash DBsub DBsingle DBassertion debstash
283 my ($syms, $file) = @_;
285 open(FILE, "< $file")
286 or die "embed.pl: Can't open $file: $!\n";
288 s/[ \t]*#.*//; # Delete comments.
289 if (/^\s*(\S+)\s*$/) {
291 warn "duplicate symbol $sym while processing $file\n"
292 if exists $$syms{$sym};
299 # Perl_pp_* and Perl_ck_* are in pp.sym
300 readsyms my %ppsym, 'pp.sym';
302 sub readvars(\%$$@) {
303 my ($syms, $file,$pre,$keep_pre) = @_;
305 open(FILE, "< $file")
306 or die "embed.pl: Can't open $file: $!\n";
308 s/[ \t]*#.*//; # Delete comments.
309 if (/PERLVARA?I?S?C?\($pre(\w+)/) {
311 $sym = $pre . $sym if $keep_pre;
312 warn "duplicate symbol $sym while processing $file\n"
313 if exists $$syms{$sym};
314 $$syms{$sym} = $pre || 1;
323 readvars %intrp, 'intrpvar.h','I';
324 readvars %thread, 'thrdvar.h','T';
325 readvars %globvar, 'perlvars.h','G';
328 foreach $sym (sort keys %thread) {
329 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
338 my ($from, $to) = @_;
339 my $t = int(length($from) / 8);
340 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
343 sub bincompat_var ($$) {
344 my ($pfx, $sym) = @_;
345 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
346 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
350 my ($sym,$pre,$ptr) = @_;
351 hide("PL_$sym", "($ptr$pre$sym)");
356 return hide("PL_$pre$sym", "PL_$sym");
359 safer_unlink 'embed.h';
360 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
363 print EM do_not_edit ("embed.h"), <<'END';
365 /* (Doing namespace management portably in C is really gross.) */
367 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
368 * (like warn instead of Perl_warn) for the API are not defined.
369 * Not defining the short forms is a good thing for cleaner embedding. */
371 #ifndef PERL_NO_SHORT_NAMES
373 /* Hide global symbols */
375 #if !defined(PERL_IMPLICIT_CONTEXT)
379 # Try to elimiate lots of repeated
386 # by tracking state and merging foo and bar into one block.
387 my $ifdef_state = '';
391 my $new_ifdef_state = '';
394 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
397 my ($flags,$retval,$func,@args) = @_;
398 unless ($flags =~ /[om]/) {
400 $ret .= hide($func,"S_$func");
402 elsif ($flags =~ /p/) {
403 $ret .= hide($func,"Perl_$func");
406 if ($ret ne '' && $flags !~ /A/) {
409 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
412 $new_ifdef_state = "#ifdef PERL_CORE\n";
415 if ($new_ifdef_state ne $ifdef_state) {
416 $ret = $new_ifdef_state . $ret;
420 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
421 # Close the old one ahead of opening the new one.
422 $ret = "#endif\n$ret";
424 # Remember the new state.
425 $ifdef_state = $new_ifdef_state;
433 for $sym (sort keys %ppsym) {
435 print EM hide($sym, "Perl_$sym");
440 #else /* PERL_IMPLICIT_CONTEXT */
449 my $new_ifdef_state = '';
452 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
455 my ($flags,$retval,$func,@args) = @_;
456 unless ($flags =~ /[om]/) {
457 my $args = scalar @args;
458 if ($args and $args[$args-1] =~ /\.\.\./) {
459 # we're out of luck for varargs functions under CPP
461 elsif ($flags =~ /n/) {
463 $ret .= hide($func,"S_$func");
465 elsif ($flags =~ /p/) {
466 $ret .= hide($func,"Perl_$func");
470 my $alist = join(",", @az[0..$args-1]);
471 $ret = "#define $func($alist)";
472 my $t = int(length($ret) / 8);
473 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
475 $ret .= "S_$func(aTHX";
477 elsif ($flags =~ /p/) {
478 $ret .= "Perl_$func(aTHX";
480 $ret .= "_ " if $alist;
481 $ret .= $alist . ")\n";
484 unless ($flags =~ /A/) {
487 = "#if defined(PERL_CORE) || defined(PERL_EXT)\n";
490 $new_ifdef_state = "#ifdef PERL_CORE\n";
493 if ($new_ifdef_state ne $ifdef_state) {
494 $ret = $new_ifdef_state . $ret;
498 if ($ifdef_state && $new_ifdef_state ne $ifdef_state) {
499 # Close the old one ahead of opening the new one.
500 $ret = "#endif\n$ret";
502 # Remember the new state.
503 $ifdef_state = $new_ifdef_state;
511 for $sym (sort keys %ppsym) {
513 if ($sym =~ /^ck_/) {
514 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
516 elsif ($sym =~ /^pp_/) {
517 print EM hide("$sym()", "Perl_$sym(aTHX)");
520 warn "Illegal symbol '$sym' in pp.sym";
526 #endif /* PERL_IMPLICIT_CONTEXT */
528 #endif /* #ifndef PERL_NO_SHORT_NAMES */
534 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
538 #if !defined(PERL_CORE)
539 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
540 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
543 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
545 /* Compatibility for various misnamed functions. All functions
546 in the API that begin with "perl_" (not "Perl_") take an explicit
547 interpreter context pointer.
548 The following are not like that, but since they had a "perl_"
549 prefix in previous versions, we provide compatibility macros.
551 # define perl_atexit(a,b) call_atexit(a,b)
552 # define perl_call_argv(a,b,c) call_argv(a,b,c)
553 # define perl_call_pv(a,b) call_pv(a,b)
554 # define perl_call_method(a,b) call_method(a,b)
555 # define perl_call_sv(a,b) call_sv(a,b)
556 # define perl_eval_sv(a,b) eval_sv(a,b)
557 # define perl_eval_pv(a,b) eval_pv(a,b)
558 # define perl_require_pv(a) require_pv(a)
559 # define perl_get_sv(a,b) get_sv(a,b)
560 # define perl_get_av(a,b) get_av(a,b)
561 # define perl_get_hv(a,b) get_hv(a,b)
562 # define perl_get_cv(a,b) get_cv(a,b)
563 # define perl_init_i18nl10n(a) init_i18nl10n(a)
564 # define perl_init_i18nl14n(a) init_i18nl14n(a)
565 # define perl_new_ctype(a) new_ctype(a)
566 # define perl_new_collate(a) new_collate(a)
567 # define perl_new_numeric(a) new_numeric(a)
569 /* varargs functions can't be handled with CPP macros. :-(
570 This provides a set of compatibility functions that don't take
571 an extra argument but grab the context pointer using the macro
574 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
575 # define croak Perl_croak_nocontext
576 # define deb Perl_deb_nocontext
577 # define die Perl_die_nocontext
578 # define form Perl_form_nocontext
579 # define load_module Perl_load_module_nocontext
580 # define mess Perl_mess_nocontext
581 # define newSVpvf Perl_newSVpvf_nocontext
582 # define sv_catpvf Perl_sv_catpvf_nocontext
583 # define sv_setpvf Perl_sv_setpvf_nocontext
584 # define warn Perl_warn_nocontext
585 # define warner Perl_warner_nocontext
586 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
587 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
590 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
592 #if !defined(PERL_IMPLICIT_CONTEXT)
593 /* undefined symbols, point them back at the usual ones */
594 # define Perl_croak_nocontext Perl_croak
595 # define Perl_die_nocontext Perl_die
596 # define Perl_deb_nocontext Perl_deb
597 # define Perl_form_nocontext Perl_form
598 # define Perl_load_module_nocontext Perl_load_module
599 # define Perl_mess_nocontext Perl_mess
600 # define Perl_newSVpvf_nocontext Perl_newSVpvf
601 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
602 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
603 # define Perl_warn_nocontext Perl_warn
604 # define Perl_warner_nocontext Perl_warner
605 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
606 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
612 close(EM) or die "Error closing EM: $!";
614 safer_unlink 'embedvar.h';
615 open(EM, '> embedvar.h')
616 or die "Can't create embedvar.h: $!\n";
619 print EM do_not_edit ("embedvar.h"), <<'END';
621 /* (Doing namespace management portably in C is really gross.) */
624 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
627 2) MULTIPLICITY # supported for compatibility
628 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
630 All other combinations of these flags are errors.
632 only #3 is supported directly, while #2 is a special
633 case of #3 (supported by redefining vTHX appropriately).
636 #if defined(MULTIPLICITY)
637 /* cases 2 and 3 above */
639 # if defined(PERL_IMPLICIT_CONTEXT)
642 # define vTHX PERL_GET_INTERP
647 for $sym (sort keys %thread) {
648 print EM multon($sym,'T','vTHX->');
653 /* cases 2 and 3 above */
657 for $sym (sort keys %intrp) {
658 print EM multon($sym,'I','vTHX->');
663 #else /* !MULTIPLICITY */
669 for $sym (sort keys %intrp) {
670 print EM multoff($sym,'I');
677 for $sym (sort keys %thread) {
678 print EM multoff($sym,'T');
683 #endif /* MULTIPLICITY */
685 #if defined(PERL_GLOBAL_STRUCT)
689 for $sym (sort keys %globvar) {
690 print EM multon($sym, 'G','my_vars->');
691 print EM multon("G$sym",'', 'my_vars->');
696 #else /* !PERL_GLOBAL_STRUCT */
700 for $sym (sort keys %globvar) {
701 print EM multoff($sym,'G');
706 #endif /* PERL_GLOBAL_STRUCT */
708 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
712 for $sym (sort @extvars) {
713 print EM hide($sym,"PL_$sym");
718 #endif /* PERL_POLLUTE */
723 close(EM) or die "Error closing EM: $!";
725 safer_unlink 'perlapi.h';
726 safer_unlink 'perlapi.c';
727 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
729 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
732 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
734 /* declare accessor functions for Perl variables */
735 #ifndef __perlapi_h__
736 #define __perlapi_h__
738 #if defined (MULTIPLICITY)
747 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
748 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
749 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
750 #define PERLVARI(v,t,i) PERLVAR(v,t)
751 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
752 #define PERLVARISC(v,i) typedef const char PL_##v##_t[sizeof(i)]; \
753 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
756 #include "intrpvar.h"
757 #include "perlvars.h"
765 #ifndef PERL_GLOBAL_STRUCT
766 EXTERN_C Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX);
767 EXTERN_C Perl_check_t** Perl_Gcheck_ptr(pTHX);
768 EXTERN_C unsigned char** Perl_Gfold_locale_ptr(pTHX);
769 #define Perl_ppaddr_ptr Perl_Gppaddr_ptr
770 #define Perl_check_ptr Perl_Gcheck_ptr
771 #define Perl_fold_locale_ptr Perl_Gfold_locale_ptr
776 #if defined(PERL_CORE)
778 /* accessor functions for Perl variables (provide binary compatibility) */
780 /* these need to be mentioned here, or most linkers won't put them in
781 the perl executable */
783 #ifndef PERL_NO_FORCE_LINK
788 EXTCONST void * const PL_force_link_funcs[];
790 EXTCONST void * const PL_force_link_funcs[] = {
795 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
796 #define PERLVARA(v,n,t) PERLVAR(v,t)
797 #define PERLVARI(v,t,i) PERLVAR(v,t)
798 #define PERLVARIC(v,t,i) PERLVAR(v,t)
799 #define PERLVARISC(v,i) PERLVAR(v,char)
801 /* In Tru64 (__DEC && __osf__) the cc option -std1 causes that one
802 * cannot cast between void pointers and function pointers without
803 * info level warnings. The PL_force_link_funcs[] would cause a few
804 * hundred of those warnings. In code one can circumnavigate this by using
805 * unions that overlay the different pointers, but in declarations one
806 * cannot use this trick. Therefore we just disable the warning here
807 * for the duration of the PL_force_link_funcs[] declaration. */
809 #if defined(__DECC) && defined(__osf__)
811 #pragma message disable (nonstandcast)
815 #include "intrpvar.h"
816 #include "perlvars.h"
818 #if defined(__DECC) && defined(__osf__)
819 #pragma message restore
832 #endif /* PERL_NO_FORCE_LINK */
834 #else /* !PERL_CORE */
838 foreach $sym (sort keys %intrp) {
839 print CAPIH bincompat_var('I',$sym);
842 foreach $sym (sort keys %thread) {
843 print CAPIH bincompat_var('T',$sym);
846 foreach $sym (sort keys %globvar) {
847 print CAPIH bincompat_var('G',$sym);
852 #endif /* !PERL_CORE */
853 #endif /* MULTIPLICITY */
855 #endif /* __perlapi_h__ */
859 close CAPIH or die "Error closing CAPIH: $!";
861 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
867 #if defined (MULTIPLICITY)
869 /* accessor functions for Perl variables (provides binary compatibility) */
878 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
879 { dVAR; return &(aTHX->v); }
880 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
881 { dVAR; return &(aTHX->v); }
883 #define PERLVARI(v,t,i) PERLVAR(v,t)
884 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
885 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
886 { dVAR; return &(aTHX->v); }
889 #include "intrpvar.h"
893 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
894 { dVAR; return &(PL_##v); }
895 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
896 { dVAR; return &(PL_##v); }
899 #define PERLVARIC(v,t,i) \
900 const t* Perl_##v##_ptr(pTHX) \
901 { return (const t *)&(PL_##v); }
902 #define PERLVARISC(v,i) PL_##v##_t* Perl_##v##_ptr(pTHX) \
903 { dVAR; return &(PL_##v); }
904 #include "perlvars.h"
912 #ifndef PERL_GLOBAL_STRUCT
913 /* A few evil special cases. Could probably macrofy this. */
916 #undef PL_fold_locale
917 Perl_ppaddr_t** Perl_Gppaddr_ptr(pTHX) {
918 static const Perl_ppaddr_t* ppaddr_ptr = PL_ppaddr;
919 return (Perl_ppaddr_t**)&ppaddr_ptr;
921 Perl_check_t** Perl_Gcheck_ptr(pTHX) {
922 static const Perl_check_t* check_ptr = PL_check;
923 return (Perl_check_t**)&check_ptr;
925 unsigned char** Perl_Gfold_locale_ptr(pTHX) {
926 static const unsigned char* fold_locale_ptr = PL_fold_locale;
927 return (unsigned char**)&fold_locale_ptr;
933 #endif /* MULTIPLICITY */
938 close(CAPI) or die "Error closing CAPI: $!";
940 # functions that take va_list* for implementing vararg functions
941 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
942 # XXX %vfuncs currently unused
944 Perl_croak Perl_vcroak
946 Perl_warner Perl_vwarner
949 Perl_load_module Perl_vload_module
952 Perl_newSVpvf Perl_vnewSVpvf
953 Perl_sv_setpvf Perl_sv_vsetpvf
954 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
955 Perl_sv_catpvf Perl_sv_vcatpvf
956 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
957 Perl_dump_indent Perl_dump_vindent
958 Perl_default_protect Perl_vdefault_protect
961 # ex: set ts=8 sts=4 sw=4 noet: