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, 2004';
26 } elsif ($file eq 'embedvar.h') {
27 $years = '1999, 2000, 2001, 2002, 2003, 2004';
28 } elsif ($file eq 'global.sym') {
29 $years = '1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004';
30 } elsif ($file eq 'perlapi.c') {
31 $years = '1999, 2000, 2001';
32 } elsif ($file eq 'perlapi.h') {
33 $years = '1999, 2000, 2001, 2002, 2003, 2004';
34 } elsif ($file eq 'proto.h') {
35 $years = '1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004';
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: $!";
101 print $F $leader if $leader;
102 seek IN, 0, 0; # so we may restart
116 @args = split /\s*\|\s*/, $_;
118 my @outs = &{$function}(@args);
119 print $F @outs; # $function->(@args) is not 5.003
121 print $F $trailer if $trailer;
122 unless (ref $filename) {
123 close $F or die "Error closing $filename: $!";
127 sub munge_c_files () {
130 warn "\@ARGV empty, nothing to do\n";
135 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
140 # if (/^#\s*include\s+"perl.h"/) {
141 # my $file = uc $ARGV;
143 # print "#define PERL_IN_$file\n";
149 # if (exists $functions->{$f}) {
150 # my $flags = $functions->{$f}[0];
151 # $repl = "Perl_$repl" if $flags =~ /p/;
152 # unless ($flags =~ /n/) {
154 # $repl .= "_ " if @{$functions->{$f}} > 3;
156 # warn("$ARGV:$.:$repl\n");
160 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
164 if (exists $functions->{$f}) {
166 warn("$ARGV:$.:$`#$repl#$'");
171 close ARGV if eof; # restart $.
179 my $wrote_protected = 0;
188 my ($flags,$retval,$func,@args) = @_;
189 $ret .= '/* ' if $flags =~ /m/;
191 $retval = "STATIC $retval";
195 $retval = "PERL_CALLCONV $retval";
197 $func = "Perl_$func";
200 $ret .= "$retval\t$func(";
201 unless ($flags =~ /n/) {
203 $ret .= "_ " if @args;
206 $ret .= join ", ", @args;
209 $ret .= "void" if $flags =~ /n/;
212 $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
213 if( $flags =~ /f/ ) {
214 my $prefix = $flags =~ /n/ ? '' : 'pTHX_';
215 my $args = scalar @args;
216 $ret .= sprintf "\n\t__attribute__format__(__printf__,%s%d,%s%d)",
217 $prefix, $args - 1, $prefix, $args;
220 $ret .= ' */' if $flags =~ /m/;
226 # generates global.sym (API export list), and populates %global with global symbols
227 sub write_global_sym {
230 my ($flags,$retval,$func,@args) = @_;
231 if ($flags =~ /[AX]/ && $flags !~ /[xm]/
232 || $flags =~ /b/) { # public API, so export
233 $func = "Perl_$func" if $flags =~ /[pbX]/;
240 walk_table(\&write_protos, "proto.h", undef);
241 walk_table(\&write_global_sym, "global.sym", undef);
243 # XXX others that may need adding
247 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
249 tainting tainted stack_base stack_sp sv_arenaroot
251 curstash DBsub DBsingle debstash
265 my ($syms, $file) = @_;
267 open(FILE, "< $file")
268 or die "embed.pl: Can't open $file: $!\n";
270 s/[ \t]*#.*//; # Delete comments.
271 if (/^\s*(\S+)\s*$/) {
273 warn "duplicate symbol $sym while processing $file\n"
274 if exists $$syms{$sym};
281 # Perl_pp_* and Perl_ck_* are in pp.sym
282 readsyms my %ppsym, 'pp.sym';
284 sub readvars(\%$$@) {
285 my ($syms, $file,$pre,$keep_pre) = @_;
287 open(FILE, "< $file")
288 or die "embed.pl: Can't open $file: $!\n";
290 s/[ \t]*#.*//; # Delete comments.
291 if (/PERLVARA?I?C?\($pre(\w+)/) {
293 $sym = $pre . $sym if $keep_pre;
294 warn "duplicate symbol $sym while processing $file\n"
295 if exists $$syms{$sym};
296 $$syms{$sym} = $pre || 1;
305 readvars %intrp, 'intrpvar.h','I';
306 readvars %thread, 'thrdvar.h','T';
307 readvars %globvar, 'perlvars.h','G';
310 foreach $sym (sort keys %thread) {
311 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
320 my ($from, $to) = @_;
321 my $t = int(length($from) / 8);
322 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
325 sub bincompat_var ($$) {
326 my ($pfx, $sym) = @_;
327 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
328 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
332 my ($sym,$pre,$ptr) = @_;
333 hide("PL_$sym", "($ptr$pre$sym)");
338 return hide("PL_$pre$sym", "PL_$sym");
341 safer_unlink 'embed.h';
342 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
345 print EM do_not_edit ("embed.h"), <<'END';
347 /* (Doing namespace management portably in C is really gross.) */
349 /* By defining PERL_NO_SHORT_NAMES (not done by default) the short forms
350 * (like warn instead of Perl_warn) for the API are not defined.
351 * Not defining the short forms is a good thing for cleaner embedding. */
353 #ifndef PERL_NO_SHORT_NAMES
355 /* Hide global symbols */
357 #if !defined(PERL_IMPLICIT_CONTEXT)
365 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
368 my ($flags,$retval,$func,@args) = @_;
369 unless ($flags =~ /[om]/) {
371 $ret .= hide($func,"S_$func");
373 elsif ($flags =~ /p/) {
374 $ret .= hide($func,"Perl_$func");
377 if ($ret ne '' && $flags !~ /A/) {
379 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
381 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
388 for $sym (sort keys %ppsym) {
390 print EM hide($sym, "Perl_$sym");
395 #else /* PERL_IMPLICIT_CONTEXT */
405 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
408 my ($flags,$retval,$func,@args) = @_;
409 unless ($flags =~ /[om]/) {
410 my $args = scalar @args;
411 if ($args and $args[$args-1] =~ /\.\.\./) {
412 # we're out of luck for varargs functions under CPP
414 elsif ($flags =~ /n/) {
416 $ret .= hide($func,"S_$func");
418 elsif ($flags =~ /p/) {
419 $ret .= hide($func,"Perl_$func");
423 my $alist = join(",", @az[0..$args-1]);
424 $ret = "#define $func($alist)";
425 my $t = int(length($ret) / 8);
426 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
428 $ret .= "S_$func(aTHX";
430 elsif ($flags =~ /p/) {
431 $ret .= "Perl_$func(aTHX";
433 $ret .= "_ " if $alist;
434 $ret .= $alist . ")\n";
437 unless ($flags =~ /A/) {
439 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
441 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
448 for $sym (sort keys %ppsym) {
450 if ($sym =~ /^ck_/) {
451 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
453 elsif ($sym =~ /^pp_/) {
454 print EM hide("$sym()", "Perl_$sym(aTHX)");
457 warn "Illegal symbol '$sym' in pp.sym";
463 #endif /* PERL_IMPLICIT_CONTEXT */
465 #endif /* #ifndef PERL_NO_SHORT_NAMES */
471 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
475 #if !defined(PERL_CORE)
476 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
477 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
480 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
482 /* Compatibility for various misnamed functions. All functions
483 in the API that begin with "perl_" (not "Perl_") take an explicit
484 interpreter context pointer.
485 The following are not like that, but since they had a "perl_"
486 prefix in previous versions, we provide compatibility macros.
488 # define perl_atexit(a,b) call_atexit(a,b)
489 # define perl_call_argv(a,b,c) call_argv(a,b,c)
490 # define perl_call_pv(a,b) call_pv(a,b)
491 # define perl_call_method(a,b) call_method(a,b)
492 # define perl_call_sv(a,b) call_sv(a,b)
493 # define perl_eval_sv(a,b) eval_sv(a,b)
494 # define perl_eval_pv(a,b) eval_pv(a,b)
495 # define perl_require_pv(a) require_pv(a)
496 # define perl_get_sv(a,b) get_sv(a,b)
497 # define perl_get_av(a,b) get_av(a,b)
498 # define perl_get_hv(a,b) get_hv(a,b)
499 # define perl_get_cv(a,b) get_cv(a,b)
500 # define perl_init_i18nl10n(a) init_i18nl10n(a)
501 # define perl_init_i18nl14n(a) init_i18nl14n(a)
502 # define perl_new_ctype(a) new_ctype(a)
503 # define perl_new_collate(a) new_collate(a)
504 # define perl_new_numeric(a) new_numeric(a)
506 /* varargs functions can't be handled with CPP macros. :-(
507 This provides a set of compatibility functions that don't take
508 an extra argument but grab the context pointer using the macro
511 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_SHORT_NAMES)
512 # define croak Perl_croak_nocontext
513 # define deb Perl_deb_nocontext
514 # define die Perl_die_nocontext
515 # define form Perl_form_nocontext
516 # define load_module Perl_load_module_nocontext
517 # define mess Perl_mess_nocontext
518 # define newSVpvf Perl_newSVpvf_nocontext
519 # define sv_catpvf Perl_sv_catpvf_nocontext
520 # define sv_setpvf Perl_sv_setpvf_nocontext
521 # define warn Perl_warn_nocontext
522 # define warner Perl_warner_nocontext
523 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
524 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
527 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
529 #if !defined(PERL_IMPLICIT_CONTEXT)
530 /* undefined symbols, point them back at the usual ones */
531 # define Perl_croak_nocontext Perl_croak
532 # define Perl_die_nocontext Perl_die
533 # define Perl_deb_nocontext Perl_deb
534 # define Perl_form_nocontext Perl_form
535 # define Perl_load_module_nocontext Perl_load_module
536 # define Perl_mess_nocontext Perl_mess
537 # define Perl_newSVpvf_nocontext Perl_newSVpvf
538 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
539 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
540 # define Perl_warn_nocontext Perl_warn
541 # define Perl_warner_nocontext Perl_warner
542 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
543 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
548 close(EM) or die "Error closing EM: $!";
550 safer_unlink 'embedvar.h';
551 open(EM, '> embedvar.h')
552 or die "Can't create embedvar.h: $!\n";
555 print EM do_not_edit ("embedvar.h"), <<'END';
557 /* (Doing namespace management portably in C is really gross.) */
560 The following combinations of MULTIPLICITY, USE_5005THREADS
561 and PERL_IMPLICIT_CONTEXT are supported:
563 2) MULTIPLICITY # supported for compatibility
564 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
565 4) USE_5005THREADS && PERL_IMPLICIT_CONTEXT
566 5) MULTIPLICITY && USE_5005THREADS && PERL_IMPLICIT_CONTEXT
568 All other combinations of these flags are errors.
570 #3, #4, #5, and #6 are supported directly, while #2 is a special
571 case of #3 (supported by redefining vTHX appropriately).
574 #if defined(MULTIPLICITY)
575 /* cases 2, 3 and 5 above */
577 # if defined(PERL_IMPLICIT_CONTEXT)
580 # define vTHX PERL_GET_INTERP
585 for $sym (sort keys %thread) {
586 print EM multon($sym,'T','vTHX->');
591 # if defined(USE_5005THREADS)
596 for $sym (sort keys %intrp) {
597 print EM multon($sym,'I','PERL_GET_INTERP->');
602 # else /* !USE_5005THREADS */
603 /* cases 2 and 3 above */
607 for $sym (sort keys %intrp) {
608 print EM multon($sym,'I','vTHX->');
613 # endif /* USE_5005THREADS */
615 #else /* !MULTIPLICITY */
617 /* cases 1 and 4 above */
621 for $sym (sort keys %intrp) {
622 print EM multoff($sym,'I');
627 # if defined(USE_5005THREADS)
632 for $sym (sort keys %thread) {
633 print EM multon($sym,'T','aTHX->');
638 # else /* !USE_5005THREADS */
643 for $sym (sort keys %thread) {
644 print EM multoff($sym,'T');
649 # endif /* USE_5005THREADS */
650 #endif /* MULTIPLICITY */
652 #if defined(PERL_GLOBAL_STRUCT)
656 for $sym (sort keys %globvar) {
657 print EM multon($sym,'G','PL_Vars.');
662 #else /* !PERL_GLOBAL_STRUCT */
666 for $sym (sort keys %globvar) {
667 print EM multoff($sym,'G');
672 #endif /* PERL_GLOBAL_STRUCT */
674 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
678 for $sym (sort @extvars) {
679 print EM hide($sym,"PL_$sym");
684 #endif /* PERL_POLLUTE */
687 close(EM) or die "Error closing EM: $!";
689 safer_unlink 'perlapi.h';
690 safer_unlink 'perlapi.c';
691 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
693 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
696 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
698 /* declare accessor functions for Perl variables */
699 #ifndef __perlapi_h__
700 #define __perlapi_h__
702 #if defined (MULTIPLICITY)
710 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
711 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
712 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
713 #define PERLVARI(v,t,i) PERLVAR(v,t)
714 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
717 #include "intrpvar.h"
718 #include "perlvars.h"
727 #if defined(PERL_CORE)
729 /* accessor functions for Perl variables (provide binary compatibility) */
731 /* these need to be mentioned here, or most linkers won't put them in
732 the perl executable */
734 #ifndef PERL_NO_FORCE_LINK
739 EXT void *PL_force_link_funcs[];
741 EXT void *PL_force_link_funcs[] = {
746 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
747 #define PERLVARA(v,n,t) PERLVAR(v,t)
748 #define PERLVARI(v,t,i) PERLVAR(v,t)
749 #define PERLVARIC(v,t,i) PERLVAR(v,t)
752 #include "intrpvar.h"
753 #include "perlvars.h"
764 #endif /* PERL_NO_FORCE_LINK */
766 #else /* !PERL_CORE */
770 foreach $sym (sort keys %intrp) {
771 print CAPIH bincompat_var('I',$sym);
774 foreach $sym (sort keys %thread) {
775 print CAPIH bincompat_var('T',$sym);
778 foreach $sym (sort keys %globvar) {
779 print CAPIH bincompat_var('G',$sym);
784 #endif /* !PERL_CORE */
785 #endif /* MULTIPLICITY */
787 #endif /* __perlapi_h__ */
790 close CAPIH or die "Error closing CAPIH: $!";
792 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
798 #if defined (MULTIPLICITY)
800 /* accessor functions for Perl variables (provides binary compatibility) */
808 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
809 { return &(aTHX->v); }
810 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
811 { return &(aTHX->v); }
813 #define PERLVARI(v,t,i) PERLVAR(v,t)
814 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
817 #include "intrpvar.h"
821 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
822 { return &(PL_##v); }
823 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
824 { return &(PL_##v); }
826 #define PERLVARIC(v,t,i) const t* Perl_##v##_ptr(pTHX) \
827 { return (const t *)&(PL_##v); }
828 #include "perlvars.h"
837 #endif /* MULTIPLICITY */
840 close(CAPI) or die "Error closing CAPI: $!";
842 # functions that take va_list* for implementing vararg functions
843 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
844 # XXX %vfuncs currently unused
846 Perl_croak Perl_vcroak
848 Perl_warner Perl_vwarner
851 Perl_load_module Perl_vload_module
854 Perl_newSVpvf Perl_vnewSVpvf
855 Perl_sv_setpvf Perl_sv_vsetpvf
856 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
857 Perl_sv_catpvf Perl_sv_vcatpvf
858 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
859 Perl_dump_indent Perl_dump_vindent
860 Perl_default_protect Perl_vdefault_protect