3 require 5.003; # keep this compatible, an old perl is all we may have before
7 # Get function prototypes
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.
25 Copyright (c) 1997-2002, Larry Wall
27 You may distribute under the terms of either the GNU General Public
28 License or the Artistic License, as specified in the README file.
30 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
31 This file is built by embed.pl from data in embed.fnc, embed.pl,
32 pp.sym, intrpvar.h, perlvars.h and thrdvar.h.
33 Any changes made here will be lost!
35 Edit those files and run 'make regen_headers' to effect changes.
39 if ($file =~ m:\.[ch]$:) {
40 $warning =~ s:^: * :gm;
41 $warning =~ s: +$::gm;
46 $warning =~ s:^:# :gm;
47 $warning =~ s: +$::gm;
52 open IN, "embed.fnc" or die $!;
54 # walk table providing an array of components in each line to
55 # subroutine, printing the result
58 my $filename = shift || '-';
60 defined $leader or $leader = do_not_edit ($filename);
64 if (ref $filename) { # filehandle
68 safer_unlink $filename;
69 open F, ">$filename" or die "Can't open $filename: $!";
72 print $F $leader if $leader;
73 seek IN, 0, 0; # so we may restart
86 @args = split /\s*\|\s*/, $_;
88 my @outs = &{$function}(@args);
89 print $F @outs; # $function->(@args) is not 5.003
91 print $F $trailer if $trailer;
92 unless (ref $filename) {
93 close $F or die "Error closing $filename: $!";
97 sub munge_c_files () {
100 warn "\@ARGV empty, nothing to do\n";
105 $functions->{$_[2]} = \@_ if $_[@_-1] =~ /\.\.\./;
110 # if (/^#\s*include\s+"perl.h"/) {
111 # my $file = uc $ARGV;
113 # print "#define PERL_IN_$file\n";
119 # if (exists $functions->{$f}) {
120 # my $flags = $functions->{$f}[0];
121 # $repl = "Perl_$repl" if $flags =~ /p/;
122 # unless ($flags =~ /n/) {
124 # $repl .= "_ " if @{$functions->{$f}} > 3;
126 # warn("$ARGV:$.:$repl\n");
130 s{(\b(\w+)[ \t]*\([ \t]*(?!aTHX))}
134 if (exists $functions->{$f}) {
136 warn("$ARGV:$.:$`#$repl#$'");
141 close ARGV if eof; # restart $.
149 my $wrote_protected = 0;
158 my ($flags,$retval,$func,@args) = @_;
159 $ret .= '/* ' if $flags =~ /m/;
161 $retval = "STATIC $retval";
165 $retval = "PERL_CALLCONV $retval";
167 $func = "Perl_$func";
170 $ret .= "$retval\t$func(";
171 unless ($flags =~ /n/) {
173 $ret .= "_ " if @args;
176 $ret .= join ", ", @args;
179 $ret .= "void" if $flags =~ /n/;
182 $ret .= " __attribute__((noreturn))" if $flags =~ /r/;
183 if( $flags =~ /f/ ) {
184 my $prefix = $flags =~ /n/ ? '' : 'pTHX_';
185 my $args = scalar @args;
186 $ret .= "\n#ifdef CHECK_FORMAT\n";
187 $ret .= sprintf " __attribute__((format(printf,%s%d,%s%d)))",
188 $prefix, $args - 1, $prefix, $args;
189 $ret .= "\n#endif\n";
192 $ret .= ' */' if $flags =~ /m/;
198 # generates global.sym (API export list), and populates %global with global symbols
199 sub write_global_sym {
202 my ($flags,$retval,$func,@args) = @_;
203 if ($flags =~ /A/ && $flags !~ /[xm]/) { # public API, so export
204 $func = "Perl_$func" if $flags =~ /p/;
211 walk_table(\&write_protos, "proto.h", undef);
212 walk_table(\&write_global_sym, "global.sym", undef);
214 # XXX others that may need adding
218 my @extvars = qw(sv_undef sv_yes sv_no na dowarn
220 tainting tainted stack_base stack_sp sv_arenaroot
222 curstash DBsub DBsingle DBassertion debstash
236 my ($syms, $file) = @_;
238 open(FILE, "< $file")
239 or die "embed.pl: Can't open $file: $!\n";
241 s/[ \t]*#.*//; # Delete comments.
242 if (/^\s*(\S+)\s*$/) {
244 warn "duplicate symbol $sym while processing $file\n"
245 if exists $$syms{$sym};
252 # Perl_pp_* and Perl_ck_* are in pp.sym
253 readsyms my %ppsym, 'pp.sym';
255 sub readvars(\%$$@) {
256 my ($syms, $file,$pre,$keep_pre) = @_;
258 open(FILE, "< $file")
259 or die "embed.pl: Can't open $file: $!\n";
261 s/[ \t]*#.*//; # Delete comments.
262 if (/PERLVARA?I?C?\($pre(\w+)/) {
264 $sym = $pre . $sym if $keep_pre;
265 warn "duplicate symbol $sym while processing $file\n"
266 if exists $$syms{$sym};
267 $$syms{$sym} = $pre || 1;
276 readvars %intrp, 'intrpvar.h','I';
277 readvars %thread, 'thrdvar.h','T';
278 readvars %globvar, 'perlvars.h','G';
281 foreach $sym (sort keys %thread) {
282 warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym};
291 my ($from, $to) = @_;
292 my $t = int(length($from) / 8);
293 "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
296 sub bincompat_var ($$) {
297 my ($pfx, $sym) = @_;
298 my $arg = ($pfx eq 'G' ? 'NULL' : 'aTHX');
299 undefine("PL_$sym") . hide("PL_$sym", "(*Perl_${pfx}${sym}_ptr($arg))");
303 my ($sym,$pre,$ptr) = @_;
304 hide("PL_$sym", "($ptr$pre$sym)");
309 return hide("PL_$pre$sym", "PL_$sym");
312 safer_unlink 'embed.h';
313 open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
315 print EM do_not_edit ("embed.h"), <<'END';
317 /* (Doing namespace management portably in C is really gross.) */
319 /* NO_EMBED is no longer supported. i.e. EMBED is always active--
320 * but you can define PERL_HIDE_SHORT_NAMES to achieve the same. */
322 #ifndef PERL_HIDE_SHORT_NAMES
324 /* Hide global symbols */
326 #if !defined(PERL_IMPLICIT_CONTEXT)
334 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
337 my ($flags,$retval,$func,@args) = @_;
338 unless ($flags =~ /[om]/) {
340 $ret .= hide($func,"S_$func");
342 elsif ($flags =~ /p/) {
343 $ret .= hide($func,"Perl_$func");
346 unless ($flags =~ /A/) {
348 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
350 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
357 for $sym (sort keys %ppsym) {
359 print EM hide($sym, "Perl_$sym");
364 #else /* PERL_IMPLICIT_CONTEXT */
374 $ret .= "$arg\n" if $arg =~ /^#\s*(if|ifn?def|else|endif)\b/;
377 my ($flags,$retval,$func,@args) = @_;
378 unless ($flags =~ /[om]/) {
379 my $args = scalar @args;
380 if ($args and $args[$args-1] =~ /\.\.\./) {
381 # we're out of luck for varargs functions under CPP
383 elsif ($flags =~ /n/) {
385 $ret .= hide($func,"S_$func");
387 elsif ($flags =~ /p/) {
388 $ret .= hide($func,"Perl_$func");
392 my $alist = join(",", @az[0..$args-1]);
393 $ret = "#define $func($alist)";
394 my $t = int(length($ret) / 8);
395 $ret .= "\t" x ($t < 4 ? 4 - $t : 1);
397 $ret .= "S_$func(aTHX";
399 elsif ($flags =~ /p/) {
400 $ret .= "Perl_$func(aTHX";
402 $ret .= "_ " if $alist;
403 $ret .= $alist . ")\n";
406 unless ($flags =~ /A/) {
408 $ret = "#if defined(PERL_CORE) || defined(PERL_EXT)\n$ret#endif\n";
410 $ret = "#ifdef PERL_CORE\n$ret#endif\n";
417 for $sym (sort keys %ppsym) {
419 if ($sym =~ /^ck_/) {
420 print EM hide("$sym(a)", "Perl_$sym(aTHX_ a)");
422 elsif ($sym =~ /^pp_/) {
423 print EM hide("$sym()", "Perl_$sym(aTHX)");
426 warn "Illegal symbol '$sym' in pp.sym";
432 #endif /* PERL_IMPLICIT_CONTEXT */
434 #endif /* #ifndef PERL_HIDE_SHORT_NAMES */
440 /* Compatibility stubs. Compile extensions with -DPERL_NOCOMPAT to
444 #if !defined(PERL_CORE)
445 # define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,PTR2IV(ptr))
446 # define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,PTR2IV(ptr))
449 #if !defined(PERL_CORE) && !defined(PERL_NOCOMPAT)
451 /* Compatibility for various misnamed functions. All functions
452 in the API that begin with "perl_" (not "Perl_") take an explicit
453 interpreter context pointer.
454 The following are not like that, but since they had a "perl_"
455 prefix in previous versions, we provide compatibility macros.
457 # define perl_atexit(a,b) call_atexit(a,b)
458 # define perl_call_argv(a,b,c) call_argv(a,b,c)
459 # define perl_call_pv(a,b) call_pv(a,b)
460 # define perl_call_method(a,b) call_method(a,b)
461 # define perl_call_sv(a,b) call_sv(a,b)
462 # define perl_eval_sv(a,b) eval_sv(a,b)
463 # define perl_eval_pv(a,b) eval_pv(a,b)
464 # define perl_require_pv(a) require_pv(a)
465 # define perl_get_sv(a,b) get_sv(a,b)
466 # define perl_get_av(a,b) get_av(a,b)
467 # define perl_get_hv(a,b) get_hv(a,b)
468 # define perl_get_cv(a,b) get_cv(a,b)
469 # define perl_init_i18nl10n(a) init_i18nl10n(a)
470 # define perl_init_i18nl14n(a) init_i18nl14n(a)
471 # define perl_new_ctype(a) new_ctype(a)
472 # define perl_new_collate(a) new_collate(a)
473 # define perl_new_numeric(a) new_numeric(a)
475 /* varargs functions can't be handled with CPP macros. :-(
476 This provides a set of compatibility functions that don't take
477 an extra argument but grab the context pointer using the macro
480 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_HIDE_SHORT_NAMES)
481 # define croak Perl_croak_nocontext
482 # define deb Perl_deb_nocontext
483 # define die Perl_die_nocontext
484 # define form Perl_form_nocontext
485 # define load_module Perl_load_module_nocontext
486 # define mess Perl_mess_nocontext
487 # define newSVpvf Perl_newSVpvf_nocontext
488 # define sv_catpvf Perl_sv_catpvf_nocontext
489 # define sv_setpvf Perl_sv_setpvf_nocontext
490 # define warn Perl_warn_nocontext
491 # define warner Perl_warner_nocontext
492 # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
493 # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
496 #endif /* !defined(PERL_CORE) && !defined(PERL_NOCOMPAT) */
498 #if !defined(PERL_IMPLICIT_CONTEXT)
499 /* undefined symbols, point them back at the usual ones */
500 # define Perl_croak_nocontext Perl_croak
501 # define Perl_die_nocontext Perl_die
502 # define Perl_deb_nocontext Perl_deb
503 # define Perl_form_nocontext Perl_form
504 # define Perl_load_module_nocontext Perl_load_module
505 # define Perl_mess_nocontext Perl_mess
506 # define Perl_newSVpvf_nocontext Perl_newSVpvf
507 # define Perl_sv_catpvf_nocontext Perl_sv_catpvf
508 # define Perl_sv_setpvf_nocontext Perl_sv_setpvf
509 # define Perl_warn_nocontext Perl_warn
510 # define Perl_warner_nocontext Perl_warner
511 # define Perl_sv_catpvf_mg_nocontext Perl_sv_catpvf_mg
512 # define Perl_sv_setpvf_mg_nocontext Perl_sv_setpvf_mg
517 close(EM) or die "Error closing EM: $!";
519 safer_unlink 'embedvar.h';
520 open(EM, '> embedvar.h')
521 or die "Can't create embedvar.h: $!\n";
523 print EM do_not_edit ("embedvar.h"), <<'END';
525 /* (Doing namespace management portably in C is really gross.) */
528 The following combinations of MULTIPLICITY and PERL_IMPLICIT_CONTEXT
531 2) MULTIPLICITY # supported for compatibility
532 3) MULTIPLICITY && PERL_IMPLICIT_CONTEXT
534 All other combinations of these flags are errors.
536 only #3 is supported directly, while #2 is a special
537 case of #3 (supported by redefining vTHX appropriately).
540 #if defined(MULTIPLICITY)
541 /* cases 2 and 3 above */
543 # if defined(PERL_IMPLICIT_CONTEXT)
546 # define vTHX PERL_GET_INTERP
551 for $sym (sort keys %thread) {
552 print EM multon($sym,'T','vTHX->');
557 /* cases 2 and 3 above */
561 for $sym (sort keys %intrp) {
562 print EM multon($sym,'I','vTHX->');
567 #else /* !MULTIPLICITY */
573 for $sym (sort keys %intrp) {
574 print EM multoff($sym,'I');
581 for $sym (sort keys %thread) {
582 print EM multoff($sym,'T');
587 #endif /* MULTIPLICITY */
589 #if defined(PERL_GLOBAL_STRUCT)
593 for $sym (sort keys %globvar) {
594 print EM multon($sym,'G','PL_Vars.');
599 #else /* !PERL_GLOBAL_STRUCT */
603 for $sym (sort keys %globvar) {
604 print EM multoff($sym,'G');
609 #endif /* PERL_GLOBAL_STRUCT */
611 #ifdef PERL_POLLUTE /* disabled by default in 5.6.0 */
615 for $sym (sort @extvars) {
616 print EM hide($sym,"PL_$sym");
621 #endif /* PERL_POLLUTE */
624 close(EM) or die "Error closing EM: $!";
626 safer_unlink 'perlapi.h';
627 safer_unlink 'perlapi.c';
628 open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
629 open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
631 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
633 /* declare accessor functions for Perl variables */
634 #ifndef __perlapi_h__
635 #define __perlapi_h__
637 #if defined (MULTIPLICITY)
645 #define PERLVAR(v,t) EXTERN_C t* Perl_##v##_ptr(pTHX);
646 #define PERLVARA(v,n,t) typedef t PL_##v##_t[n]; \
647 EXTERN_C PL_##v##_t* Perl_##v##_ptr(pTHX);
648 #define PERLVARI(v,t,i) PERLVAR(v,t)
649 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
652 #include "intrpvar.h"
653 #include "perlvars.h"
662 #if defined(PERL_CORE)
664 /* accessor functions for Perl variables (provide binary compatibility) */
666 /* these need to be mentioned here, or most linkers won't put them in
667 the perl executable */
669 #ifndef PERL_NO_FORCE_LINK
674 EXT void *PL_force_link_funcs[];
676 EXT void *PL_force_link_funcs[] = {
681 #define PERLVAR(v,t) (void*)Perl_##v##_ptr,
682 #define PERLVARA(v,n,t) PERLVAR(v,t)
683 #define PERLVARI(v,t,i) PERLVAR(v,t)
684 #define PERLVARIC(v,t,i) PERLVAR(v,t)
687 #include "intrpvar.h"
688 #include "perlvars.h"
699 #endif /* PERL_NO_FORCE_LINK */
701 #else /* !PERL_CORE */
705 foreach $sym (sort keys %intrp) {
706 print CAPIH bincompat_var('I',$sym);
709 foreach $sym (sort keys %thread) {
710 print CAPIH bincompat_var('T',$sym);
713 foreach $sym (sort keys %globvar) {
714 print CAPIH bincompat_var('G',$sym);
719 #endif /* !PERL_CORE */
720 #endif /* MULTIPLICITY */
722 #endif /* __perlapi_h__ */
725 close CAPIH or die "Error closing CAPIH: $!";
727 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
733 #if defined (MULTIPLICITY)
735 /* accessor functions for Perl variables (provides binary compatibility) */
743 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
744 { return &(aTHX->v); }
745 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
746 { return &(aTHX->v); }
748 #define PERLVARI(v,t,i) PERLVAR(v,t)
749 #define PERLVARIC(v,t,i) PERLVAR(v, const t)
752 #include "intrpvar.h"
756 #define PERLVAR(v,t) t* Perl_##v##_ptr(pTHX) \
757 { return &(PL_##v); }
758 #define PERLVARA(v,n,t) PL_##v##_t* Perl_##v##_ptr(pTHX) \
759 { return &(PL_##v); }
761 #define PERLVARIC(v,t,i) const t* Perl_##v##_ptr(pTHX) \
762 { return (const t *)&(PL_##v); }
763 #include "perlvars.h"
772 #endif /* MULTIPLICITY */
775 close(CAPI) or die "Error closing CAPI: $!";
777 # functions that take va_list* for implementing vararg functions
778 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs
779 # XXX %vfuncs currently unused
781 Perl_croak Perl_vcroak
783 Perl_warner Perl_vwarner
786 Perl_load_module Perl_vload_module
789 Perl_newSVpvf Perl_vnewSVpvf
790 Perl_sv_setpvf Perl_sv_vsetpvf
791 Perl_sv_setpvf_mg Perl_sv_vsetpvf_mg
792 Perl_sv_catpvf Perl_sv_vcatpvf
793 Perl_sv_catpvf_mg Perl_sv_vcatpvf_mg
794 Perl_dump_indent Perl_dump_vindent
795 Perl_default_protect Perl_vdefault_protect