3 require 5.003; # keep this compatible, an old perl is all we may have before
7 # See database of global and static function prototypes in embed.fnc
8 # This is used to generate prototype headers under various configurations,
9 # export symbols lists for different platforms, and macros to provide an
10 # implicit interpreter context argument.
20 Copyright (c) 1997-2002, Larry Wall
22 You may distribute under the terms of either the GNU General Public
23 License or the Artistic License, as specified in the README file.
25 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
26 This file is built by embed.pl from data in embed.fnc, embed.pl,
27 pp.sym, intrpvar.h, perlvars.h and thrdvar.h.
28 Any changes made here will be lost!
30 Edit those files and run 'make regen_headers' to effect changes.
34 if ($file =~ m:\.[ch]$:) {
35 $warning =~ s:^: * :gm;
36 $warning =~ s: +$::gm;
41 $warning =~ s:^:# :gm;
42 $warning =~ s: +$::gm;
47 open IN, "embed.fnc" or die $!;
49 # walk table providing an array of components in each line to
50 # subroutine, printing the result
53 my $filename = shift || '-';
54 my $leader = shift || do_not_edit ($filename);
58 if (ref $filename) { # filehandle
63 open F, ">$filename" or die "Can't open $filename: $!";
66 print $F $leader if $leader;
67 seek IN, 0, 0; # so we may restart
80 @args = split /\s*\|\s*/, $_;
82 my @outs = &{$function}(@args);
83 print $F @outs; # $function->(@args) is not 5.003
85 print $F $trailer if $trailer;
86 close $F unless ref $filename;
89 sub munge_c_files () {
92 warn "\@ARGV empty, nothing to do\n";
97 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
102 # if (/^#\s*include\s+"perl.h"/) {
103 # my $file = uc $ARGV;
105 # print "#define PERL_IN_$file\n";
111 # if (exists $functions->{$f}) {
112 # my $flags = $functions->{$f}[0];
113 # $repl = "Perl_$repl" if $flags =~ /p/;
114 # unless ($flags =~ /n/) {
116 # $repl .= "_ " if @{$functions->{$f}} > 3;
118 # warn("$ARGV:$.:$repl\n");
122 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
126 if (exists $functions->{$f}) {
128 warn("$ARGV:$.:$`#$repl#$'");
133 close ARGV if eof; # restart $.
141 my $wrote_protected = 0;
150 my ($flags,$retval,$func,@args) = @_;
151 $ret .= '/* ' if $flags =~ /m/;
153 $retval = "STATIC $retval";
157 $retval = "PERL_CALLCONV $retval";
159 $func = "Perl_$func";
162 $ret .= "$retval\t$func(";
163 unless ($flags =~ /n/) {
165 $ret .= "_ " if @args;
168 $ret .= join ", ", @args;
171 $ret .= "void" if $flags =~ /n/;
174 $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
175 if( $flags =~ /f/ ) {
176 my $prefix = $flags =~ /n/ ? '' : 'pTHX_';
177 my $args = scalar @args;
178 $ret .= "\n#ifdef CHECK_FORMAT\n";
179 $ret .= sprintf " __attribute__((format(printf,%s%d,%s%d)))",
180 $prefix, $args - 1, $prefix, $args;
181 $ret .= "\n#endif\n";
184 $ret .= ' */' if $flags =~ /m/;
190 # generates global.sym (API export list), and populates %global with global symbols
191 sub write_global_sym {
194 my ($flags,$retval,$func,@args) = @_;
195 if ($flags =~ /A/ && $flags !~ /[xm]/) { # public API, so export
196 $func = "Perl_$func" if $flags =~ /p/;
203 walk_table(\&write_protos, "proto.h");
204 walk_table(\&write_global_sym, "global.sym");
206 # XXX others that may need adding
210 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
212 tainting tainted stack_base stack_sp sv_arenaroot
214 curstash DBsub DBsingle debstash
228 my ($syms, $file) = @_;
230 open(FILE, "< $file")
231 or die "embed.pl: Can't open $file: $!\n";
233 s/[ \t]*#.*//; # Delete comments.
234 if (/^\s*(\S+)\s*$/) {
236 warn "duplicate symbol $sym while processing $file\n"
237 if exists $$syms{$sym};
244 # Perl_pp_* and Perl_ck_* are in pp.sym
245 readsyms my %ppsym, 'pp.sym';
247 sub readvars(\%$$@) {
248 my ($syms, $file,$pre,$keep_pre) = @_;
250 open(FILE, "< $file")
251 or die "embed.pl: Can't open $file: $!\n";
253 s/[ \t]*#.*//; # Delete comments.
254 if (/PERLVARA?I?C?\($pre(\w+)/) {
256 $sym = $pre . $sym if $keep_pre;
257 warn "duplicate symbol $sym while processing $file\n"
258 if exists $$syms{$sym};
259 $$syms{$sym} = $pre || 1;
268 readvars %intrp, 'intrpvar.h','I';
269 readvars %thread, 'thrdvar.h','T';
270 readvars %globvar, 'perlvars.h','G';
273 foreach $sym (sort keys %thread) {
274 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
283 my ($from, $to) = @_;
284 my $t = int(length($from) / 8);
285 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
288 sub bincompat_var ($$) {
289 my ($pfx, $sym) = @_;
290 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
291 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
295 my ($sym,$pre,$ptr) = @_;
296 hide("PL_$sym", "($ptr$pre$sym)");
301 return hide("PL_$pre$sym", "PL_$sym");
305 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
307 print EM do_not_edit ("embed.h"), <<'END';
309 /* (Doing namespace management portably in C is really gross.) */
311 /* NO_EMBED is no longer supported. i.e. EMBED is always active. */
313 /* Hide global symbols */
315 #if !defined(PERL_IMPLICIT_CONTEXT)
323 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
326 my ($flags,$retval,$func,@args) = @_;
327 unless ($flags =~ /[om]/) {
329 $ret .= hide($func,"S_$func");
331 elsif ($flags =~ /p/) {
332 $ret .= hide($func,"Perl_$func");
339 for $sym (sort keys %ppsym) {
341 print EM hide($sym, "Perl_$sym");
346 #else /* PERL_IMPLICIT_CONTEXT */
356 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
359 my ($flags,$retval,$func,@args) = @_;
360 unless ($flags =~ /[om]/) {
361 my $args = scalar @args;
362 if ($args and $args[$args-1] =~ /\.\.\./) {
363 # we're out of luck for varargs functions under CPP
365 elsif ($flags =~ /n/) {
367 $ret .= hide($func,"S_$func");
369 elsif ($flags =~ /p/) {
370 $ret .= hide($func,"Perl_$func");
374 my $alist = join(",", @az[0..$args-1]);
375 $ret = "#define $func($alist)";
376 my $t = int(length($ret) / 8);
377 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
379 $ret .= "S_$func(aTHX";
381 elsif ($flags =~ /p/) {
382 $ret .= "Perl_$func(aTHX";
384 $ret .= "_ " if $alist;
385 $ret .= $alist . ")\n";
392 for $sym (sort keys %ppsym) {
394 if ($sym =~ /^ck_/) {
395 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
397 elsif ($sym =~ /^pp_/) {
398 print EM hide("$sym()", "Perl_$sym(aTHX)");
401 warn "Illegal symbol '$sym' in pp.sym";
407 #endif /* PERL_IMPLICIT_CONTEXT */
413 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
417 #if !defined(PERL_CORE)
418 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
419 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
422 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
424 /* Compatibility for various misnamed functions. All functions
425 in the API that begin with "perl_" (not "Perl_") take an explicit
426 interpreter context pointer.
427 The following are not like that, but since they had a "perl_"
428 prefix in previous versions, we provide compatibility macros.
430 # define perl_atexit(a,b) call_atexit(a,b)
431 # define perl_call_argv(a,b,c) call_argv(a,b,c)
432 # define perl_call_pv(a,b) call_pv(a,b)
433 # define perl_call_method(a,b) call_method(a,b)
434 # define perl_call_sv(a,b) call_sv(a,b)
435 # define perl_eval_sv(a,b) eval_sv(a,b)
436 # define perl_eval_pv(a,b) eval_pv(a,b)
437 # define perl_require_pv(a) require_pv(a)
438 # define perl_get_sv(a,b) get_sv(a,b)
439 # define perl_get_av(a,b) get_av(a,b)
440 # define perl_get_hv(a,b) get_hv(a,b)
441 # define perl_get_cv(a,b) get_cv(a,b)
442 # define perl_init_i18nl10n(a) init_i18nl10n(a)
443 # define perl_init_i18nl14n(a) init_i18nl14n(a)
444 # define perl_new_ctype(a) new_ctype(a)
445 # define perl_new_collate(a) new_collate(a)
446 # define perl_new_numeric(a) new_numeric(a)
448 /* varargs functions can't be handled with CPP macros. :-(
449 This provides a set of compatibility functions that don't take
450 an extra argument but grab the context pointer using the macro
453 #if defined(PERL_IMPLICIT_CONTEXT)
454 # define croak Perl_croak_nocontext
455 # define deb Perl_deb_nocontext
456 # define die Perl_die_nocontext
457 # define form Perl_form_nocontext
458 # define load_module Perl_load_module_nocontext
459 # define mess Perl_mess_nocontext
460 # define newSVpvf Perl_newSVpvf_nocontext
461 # define sv_catpvf Perl_sv_catpvf_nocontext
462 # define sv_setpvf Perl_sv_setpvf_nocontext
463 # define warn Perl_warn_nocontext
464 # define warner Perl_warner_nocontext
465 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
466 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
469 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
471 #if !defined(PERL_IMPLICIT_CONTEXT)
472 /* undefined symbols, point them back at the usual ones */
473 # define Perl_croak_nocontext Perl_croak
474 # define Perl_die_nocontext Perl_die
475 # define Perl_deb_nocontext Perl_deb
476 # define Perl_form_nocontext Perl_form
477 # define Perl_load_module_nocontext Perl_load_module
478 # define Perl_mess_nocontext Perl_mess
479 # define Perl_newSVpvf_nocontext Perl_newSVpvf
480 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
481 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
482 # define Perl_warn_nocontext Perl_warn
483 # define Perl_warner_nocontext Perl_warner
484 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
485 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
493 open(EM, '> embedvar.h')
494 or die "Can't create embedvar.h: $!\n";
496 print EM do_not_edit ("embedvar.h"), <<'END';
498 /* (Doing namespace management portably in C is really gross.) */
501 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
504 2) MULTIPLICITY # supported for compatibility
505 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
507 All other combinations of these flags are errors.
509 only #3 is supported directly, while #2 is a special
510 case of #3 (supported by redefining vTHX appropriately).
513 #if defined(MULTIPLICITY)
514 /* cases 2 and 3 above */
516 # if defined(PERL_IMPLICIT_CONTEXT)
519 # define vTHX PERL_GET_INTERP
524 for $sym (sort keys %thread) {
525 print EM multon($sym,'T','vTHX->');
530 /* cases 2 and 3 above */
534 for $sym (sort keys %intrp) {
535 print EM multon($sym,'I','vTHX->');
540 #else /* !MULTIPLICITY */
546 for $sym (sort keys %intrp) {
547 print EM multoff($sym,'I');
554 for $sym (sort keys %thread) {
555 print EM multoff($sym,'T');
560 #endif /* MULTIPLICITY */
562 #if defined(PERL_GLOBAL_STRUCT)
566 for $sym (sort keys %globvar) {
567 print EM multon($sym,'G','PL_Vars.');
572 #else /* !PERL_GLOBAL_STRUCT */
576 for $sym (sort keys %globvar) {
577 print EM multoff($sym,'G');
582 #endif /* PERL_GLOBAL_STRUCT */
584 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
588 for $sym (sort @extvars) {
589 print EM hide($sym,"PL_$sym");
594 #endif /* PERL_POLLUTE */
601 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
602 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
604 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
606 /* declare accessor functions for Perl variables */
607 #ifndef __perlapi_h__
608 #define __perlapi_h__
610 #if defined (MULTIPLICITY)
618 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
619 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
620 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
621 #define PERLVARI(v,t,i) PERLVAR(v,t)
622 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
625 #include "intrpvar.h"
626 #include "perlvars.h"
635 #if defined(PERL_CORE)
637 /* accessor functions for Perl variables (provide binary compatibility) */
639 /* these need to be mentioned here, or most linkers won't put them in
640 the perl executable */
642 #ifndef PERL_NO_FORCE_LINK
647 EXT void *PL_force_link_funcs[];
649 EXT void *PL_force_link_funcs[] = {
654 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
655 #define PERLVARA(v,n,t) PERLVAR(v,t)
656 #define PERLVARI(v,t,i) PERLVAR(v,t)
657 #define PERLVARIC(v,t,i) PERLVAR(v,t)
660 #include "intrpvar.h"
661 #include "perlvars.h"
672 #endif /* PERL_NO_FORCE_LINK */
674 #else /* !PERL_CORE */
678 foreach $sym (sort keys %intrp) {
679 print CAPIH bincompat_var('I',$sym);
682 foreach $sym (sort keys %thread) {
683 print CAPIH bincompat_var('T',$sym);
686 foreach $sym (sort keys %globvar) {
687 print CAPIH bincompat_var('G',$sym);
692 #endif /* !PERL_CORE */
693 #endif /* MULTIPLICITY */
695 #endif /* __perlapi_h__ */
700 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
706 #if defined (MULTIPLICITY)
708 /* accessor functions for Perl variables (provides binary compatibility) */
716 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
717 { return &(aTHX->v); }
718 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
719 { return &(aTHX->v); }
721 #define PERLVARI(v,t,i) PERLVAR(v,t)
722 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
725 #include "intrpvar.h"
729 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
730 { return &(PL_##v); }
731 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
732 { return &(PL_##v); }
734 #define PERLVARIC(v,t,i) const t* Perl_##v##_ptr(pTHX) \
735 { return (const t *)&(PL_##v); }
736 #include "perlvars.h"
745 #endif /* MULTIPLICITY */
750 # functions that take va_list* for implementing vararg functions
751 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
752 # XXX %vfuncs currently unused
754 Perl_croak Perl_vcroak
756 Perl_warner Perl_vwarner
759 Perl_load_module Perl_vload_module
762 Perl_newSVpvf Perl_vnewSVpvf
763 Perl_sv_setpvf Perl_sv_vsetpvf
764 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
765 Perl_sv_catpvf Perl_sv_vcatpvf
766 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
767 Perl_dump_indent Perl_dump_vindent
768 Perl_default_protect Perl_vdefault_protect