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.
24 if ($file eq 'embed.h') {
25 $years = '1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003';
26 } elsif ($file eq 'embedvar.h') {
27 $years = '1999, 2000, 2001, 2002, 2003';
28 } elsif ($file eq 'global.sym') {
29 $years = '1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003';
30 } elsif ($file eq 'perlapi.c') {
31 $years = '1999, 2000, 2001';
32 } elsif ($file eq 'perlapi.h') {
33 $years = '1999, 2000, 2001, 2002, 2003';
34 } elsif ($file eq 'proto.h') {
35 $years = '1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003';
38 $years =~ s/1999,/1999,\n / if length $years > 40;
44 Copyright (C) $years, by Larry Wall and others
46 You may distribute under the terms of either the GNU General Public
47 License or the Artistic License, as specified in the README file.
49 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
50 This file is built by embed.pl from data in embed.fnc, embed.pl,
51 pp.sym, intrpvar.h, perlvars.h and thrdvar.h.
52 Any changes made here will be lost!
54 Edit those files and run 'make regen_headers' to effect changes.
58 $warning .= <<EOW if $file eq 'perlapi.c';
60 Up to the threshold of the door there mounted a flight of twenty-seven
61 broad stairs, hewn by some unknown art of the same black stone. This
62 was the only entrance to the tower.
67 if ($file =~ m:\.[ch]$:) {
68 $warning =~ s:^: * :gm;
69 $warning =~ s: +$::gm;
74 $warning =~ s:^:# :gm;
75 $warning =~ s: +$::gm;
80 open IN, "embed.fnc" or die $!;
82 # walk table providing an array of components in each line to
83 # subroutine, printing the result
86 my $filename = shift || '-';
88 defined $leader or $leader = do_not_edit ($filename);
92 if (ref $filename) { # filehandle
96 safer_unlink $filename;
97 open F, ">$filename" or die "Can't open $filename: $!";
100 print $F $leader if $leader;
101 seek IN, 0, 0; # so we may restart
114 @args = split /\s*\|\s*/, $_;
116 my @outs = &{$function}(@args);
117 print $F @outs; # $function->(@args) is not 5.003
119 print $F $trailer if $trailer;
120 unless (ref $filename) {
121 close $F or die "Error closing $filename: $!";
125 sub munge_c_files () {
128 warn "\@ARGV empty, nothing to do\n";
133 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
138 # if (/^#\s*include\s+"perl.h"/) {
139 # my $file = uc $ARGV;
141 # print "#define PERL_IN_$file\n";
147 # if (exists $functions->{$f}) {
148 # my $flags = $functions->{$f}[0];
149 # $repl = "Perl_$repl" if $flags =~ /p/;
150 # unless ($flags =~ /n/) {
152 # $repl .= "_ " if @{$functions->{$f}} > 3;
154 # warn("$ARGV:$.:$repl\n");
158 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
162 if (exists $functions->{$f}) {
164 warn("$ARGV:$.:$`#$repl#$'");
169 close ARGV if eof; # restart $.
177 my $wrote_protected = 0;
186 my ($flags,$retval,$func,@args) = @_;
187 $ret .= '/* ' if $flags =~ /m/;
189 $retval = "STATIC $retval";
193 $retval = "PERL_CALLCONV $retval";
195 $func = "Perl_$func";
198 $ret .= "$retval\t$func(";
199 unless ($flags =~ /n/) {
201 $ret .= "_ " if @args;
204 $ret .= join ", ", @args;
207 $ret .= "void" if $flags =~ /n/;
210 $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
211 if( $flags =~ /f/ ) {
212 my $prefix = $flags =~ /n/ ? '' : 'pTHX_';
213 my $args = scalar @args;
214 $ret .= sprintf "\n\t__attribute__format__(__printf__,%s%d,%s%d)",
215 $prefix, $args - 1, $prefix, $args;
218 $ret .= ' */' if $flags =~ /m/;
224 # generates global.sym (API export list), and populates %global with global symbols
225 sub write_global_sym {
228 my ($flags,$retval,$func,@args) = @_;
229 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
230 || $flags =~ /b/) { # public API, so export
231 $func = "Perl_$func" if $flags =~ /[pbX]/;
238 walk_table(\&write_protos, "proto.h", undef);
239 walk_table(\&write_global_sym, "global.sym", undef);
241 # XXX others that may need adding
245 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
247 tainting tainted stack_base stack_sp sv_arenaroot
249 curstash DBsub DBsingle DBassertion debstash
263 my ($syms, $file) = @_;
265 open(FILE, "< $file")
266 or die "embed.pl: Can't open $file: $!\n";
268 s/[ \t]*#.*//; # Delete comments.
269 if (/^\s*(\S+)\s*$/) {
271 warn "duplicate symbol $sym while processing $file\n"
272 if exists $$syms{$sym};
279 # Perl_pp_* and Perl_ck_* are in pp.sym
280 readsyms my %ppsym, 'pp.sym';
282 sub readvars(\%$$@) {
283 my ($syms, $file,$pre,$keep_pre) = @_;
285 open(FILE, "< $file")
286 or die "embed.pl: Can't open $file: $!\n";
288 s/[ \t]*#.*//; # Delete comments.
289 if (/PERLVARA?I?C?\($pre(\w+)/) {
291 $sym = $pre . $sym if $keep_pre;
292 warn "duplicate symbol $sym while processing $file\n"
293 if exists $$syms{$sym};
294 $$syms{$sym} = $pre || 1;
303 readvars %intrp, 'intrpvar.h','I';
304 readvars %thread, 'thrdvar.h','T';
305 readvars %globvar, 'perlvars.h','G';
308 foreach $sym (sort keys %thread) {
309 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
318 my ($from, $to) = @_;
319 my $t = int(length($from) / 8);
320 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
323 sub bincompat_var ($$) {
324 my ($pfx, $sym) = @_;
325 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
326 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
330 my ($sym,$pre,$ptr) = @_;
331 hide("PL_$sym", "($ptr$pre$sym)");
336 return hide("PL_$pre$sym", "PL_$sym");
339 safer_unlink 'embed.h';
340 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
342 print EM do_not_edit ("embed.h"), <<'END';
344 /* (Doing namespace management portably in C is really gross.) */
346 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
347 * (like warn instead of Perl_warn) for the API are not defined.
348 * Not defining the short forms is a good thing for cleaner embedding. */
350 #ifndef PERL_NO_SHORT_NAMES
352 /* Hide global symbols */
354 #if !defined(PERL_IMPLICIT_CONTEXT)
362 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
365 my ($flags,$retval,$func,@args) = @_;
366 unless ($flags =~ /[om]/) {
368 $ret .= hide($func,"S_$func");
370 elsif ($flags =~ /p/) {
371 $ret .= hide($func,"Perl_$func");
374 if ($ret ne '' && $flags !~ /A/) {
376 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
378 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
385 for $sym (sort keys %ppsym) {
387 print EM hide($sym, "Perl_$sym");
392 #else /* PERL_IMPLICIT_CONTEXT */
402 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
405 my ($flags,$retval,$func,@args) = @_;
406 unless ($flags =~ /[om]/) {
407 my $args = scalar @args;
408 if ($args and $args[$args-1] =~ /\.\.\./) {
409 # we're out of luck for varargs functions under CPP
411 elsif ($flags =~ /n/) {
413 $ret .= hide($func,"S_$func");
415 elsif ($flags =~ /p/) {
416 $ret .= hide($func,"Perl_$func");
420 my $alist = join(",", @az[0..$args-1]);
421 $ret = "#define $func($alist)";
422 my $t = int(length($ret) / 8);
423 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
425 $ret .= "S_$func(aTHX";
427 elsif ($flags =~ /p/) {
428 $ret .= "Perl_$func(aTHX";
430 $ret .= "_ " if $alist;
431 $ret .= $alist . ")\n";
434 unless ($flags =~ /A/) {
436 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
438 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
445 for $sym (sort keys %ppsym) {
447 if ($sym =~ /^ck_/) {
448 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
450 elsif ($sym =~ /^pp_/) {
451 print EM hide("$sym()", "Perl_$sym(aTHX)");
454 warn "Illegal symbol '$sym' in pp.sym";
460 #endif /* PERL_IMPLICIT_CONTEXT */
462 #endif /* #ifndef PERL_NO_SHORT_NAMES */
468 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
472 #if !defined(PERL_CORE)
473 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
474 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
477 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
479 /* Compatibility for various misnamed functions. All functions
480 in the API that begin with "perl_" (not "Perl_") take an explicit
481 interpreter context pointer.
482 The following are not like that, but since they had a "perl_"
483 prefix in previous versions, we provide compatibility macros.
485 # define perl_atexit(a,b) call_atexit(a,b)
486 # define perl_call_argv(a,b,c) call_argv(a,b,c)
487 # define perl_call_pv(a,b) call_pv(a,b)
488 # define perl_call_method(a,b) call_method(a,b)
489 # define perl_call_sv(a,b) call_sv(a,b)
490 # define perl_eval_sv(a,b) eval_sv(a,b)
491 # define perl_eval_pv(a,b) eval_pv(a,b)
492 # define perl_require_pv(a) require_pv(a)
493 # define perl_get_sv(a,b) get_sv(a,b)
494 # define perl_get_av(a,b) get_av(a,b)
495 # define perl_get_hv(a,b) get_hv(a,b)
496 # define perl_get_cv(a,b) get_cv(a,b)
497 # define perl_init_i18nl10n(a) init_i18nl10n(a)
498 # define perl_init_i18nl14n(a) init_i18nl14n(a)
499 # define perl_new_ctype(a) new_ctype(a)
500 # define perl_new_collate(a) new_collate(a)
501 # define perl_new_numeric(a) new_numeric(a)
503 /* varargs functions can't be handled with CPP macros. :-(
504 This provides a set of compatibility functions that don't take
505 an extra argument but grab the context pointer using the macro
508 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
509 # define croak Perl_croak_nocontext
510 # define deb Perl_deb_nocontext
511 # define die Perl_die_nocontext
512 # define form Perl_form_nocontext
513 # define load_module Perl_load_module_nocontext
514 # define mess Perl_mess_nocontext
515 # define newSVpvf Perl_newSVpvf_nocontext
516 # define sv_catpvf Perl_sv_catpvf_nocontext
517 # define sv_setpvf Perl_sv_setpvf_nocontext
518 # define warn Perl_warn_nocontext
519 # define warner Perl_warner_nocontext
520 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
521 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
524 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
526 #if !defined(PERL_IMPLICIT_CONTEXT)
527 /* undefined symbols, point them back at the usual ones */
528 # define Perl_croak_nocontext Perl_croak
529 # define Perl_die_nocontext Perl_die
530 # define Perl_deb_nocontext Perl_deb
531 # define Perl_form_nocontext Perl_form
532 # define Perl_load_module_nocontext Perl_load_module
533 # define Perl_mess_nocontext Perl_mess
534 # define Perl_newSVpvf_nocontext Perl_newSVpvf
535 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
536 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
537 # define Perl_warn_nocontext Perl_warn
538 # define Perl_warner_nocontext Perl_warner
539 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
540 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
545 close(EM) or die "Error closing EM: $!";
547 safer_unlink 'embedvar.h';
548 open(EM, '> embedvar.h')
549 or die "Can't create embedvar.h: $!\n";
551 print EM do_not_edit ("embedvar.h"), <<'END';
553 /* (Doing namespace management portably in C is really gross.) */
556 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
559 2) MULTIPLICITY # supported for compatibility
560 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
562 All other combinations of these flags are errors.
564 only #3 is supported directly, while #2 is a special
565 case of #3 (supported by redefining vTHX appropriately).
568 #if defined(MULTIPLICITY)
569 /* cases 2 and 3 above */
571 # if defined(PERL_IMPLICIT_CONTEXT)
574 # define vTHX PERL_GET_INTERP
579 for $sym (sort keys %thread) {
580 print EM multon($sym,'T','vTHX->');
585 /* cases 2 and 3 above */
589 for $sym (sort keys %intrp) {
590 print EM multon($sym,'I','vTHX->');
595 #else /* !MULTIPLICITY */
601 for $sym (sort keys %intrp) {
602 print EM multoff($sym,'I');
609 for $sym (sort keys %thread) {
610 print EM multoff($sym,'T');
615 #endif /* MULTIPLICITY */
617 #if defined(PERL_GLOBAL_STRUCT)
621 for $sym (sort keys %globvar) {
622 print EM multon($sym,'G','PL_Vars.');
627 #else /* !PERL_GLOBAL_STRUCT */
631 for $sym (sort keys %globvar) {
632 print EM multoff($sym,'G');
637 #endif /* PERL_GLOBAL_STRUCT */
639 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
643 for $sym (sort @extvars) {
644 print EM hide($sym,"PL_$sym");
649 #endif /* PERL_POLLUTE */
652 close(EM) or die "Error closing EM: $!";
654 safer_unlink 'perlapi.h';
655 safer_unlink 'perlapi.c';
656 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
657 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
659 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
661 /* declare accessor functions for Perl variables */
662 #ifndef __perlapi_h__
663 #define __perlapi_h__
665 #if defined (MULTIPLICITY)
673 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
674 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
675 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
676 #define PERLVARI(v,t,i) PERLVAR(v,t)
677 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
680 #include "intrpvar.h"
681 #include "perlvars.h"
690 #if defined(PERL_CORE)
692 /* accessor functions for Perl variables (provide binary compatibility) */
694 /* these need to be mentioned here, or most linkers won't put them in
695 the perl executable */
697 #ifndef PERL_NO_FORCE_LINK
702 EXT void *PL_force_link_funcs[];
704 EXT void *PL_force_link_funcs[] = {
709 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
710 #define PERLVARA(v,n,t) PERLVAR(v,t)
711 #define PERLVARI(v,t,i) PERLVAR(v,t)
712 #define PERLVARIC(v,t,i) PERLVAR(v,t)
715 #include "intrpvar.h"
716 #include "perlvars.h"
727 #endif /* PERL_NO_FORCE_LINK */
729 #else /* !PERL_CORE */
733 foreach $sym (sort keys %intrp) {
734 print CAPIH bincompat_var('I',$sym);
737 foreach $sym (sort keys %thread) {
738 print CAPIH bincompat_var('T',$sym);
741 foreach $sym (sort keys %globvar) {
742 print CAPIH bincompat_var('G',$sym);
747 #endif /* !PERL_CORE */
748 #endif /* MULTIPLICITY */
750 #endif /* __perlapi_h__ */
753 close CAPIH or die "Error closing CAPIH: $!";
755 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
761 #if defined (MULTIPLICITY)
763 /* accessor functions for Perl variables (provides binary compatibility) */
771 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
772 { return &(aTHX->v); }
773 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
774 { return &(aTHX->v); }
776 #define PERLVARI(v,t,i) PERLVAR(v,t)
777 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
780 #include "intrpvar.h"
784 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
785 { return &(PL_##v); }
786 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
787 { return &(PL_##v); }
789 #define PERLVARIC(v,t,i) const t* Perl_##v##_ptr(pTHX) \
790 { return (const t *)&(PL_##v); }
791 #include "perlvars.h"
800 #endif /* MULTIPLICITY */
803 close(CAPI) or die "Error closing CAPI: $!";
805 # functions that take va_list* for implementing vararg functions
806 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
807 # XXX %vfuncs currently unused
809 Perl_croak Perl_vcroak
811 Perl_warner Perl_vwarner
814 Perl_load_module Perl_vload_module
817 Perl_newSVpvf Perl_vnewSVpvf
818 Perl_sv_setpvf Perl_sv_vsetpvf
819 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
820 Perl_sv_catpvf Perl_sv_vcatpvf
821 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
822 Perl_dump_indent Perl_dump_vindent
823 Perl_default_protect Perl_vdefault_protect