This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replace PL_vtbl_* with an array PL_magic_vtables.
[perl5.git] / regen / mg_vtable.pl
CommitLineData
8b09643d
NC
1#!/usr/bin/perl -w
2#
3# Regenerate (overwriting only if changed):
4#
5# mg_vtable.h
6#
7# from information stored in this file.
8#
9# Accepts the standard regen_lib -q and -v args.
10#
11# This script is normally invoked from regen.pl.
12
13use strict;
14require 5.004;
15
16BEGIN {
17 # Get function prototypes
18 require 'regen/regen_lib.pl';
19}
20
0a1f728a 21# These have a subtly different "namespace" from the magic types.
8b09643d
NC
22my @sig =
23 (
24 'sv' => {get => 'get', set => 'set', len => 'len'},
25 'env' => {set => 'set_all_env', clear => 'clear_all_env'},
26 'envelem' => {set => 'setenv', clear => 'clearenv'},
27 'sigelem' => {get => 'getsig', set => 'setsig', clear => 'clearsig',
28 cond => '#ifndef PERL_MICRO'},
29 'pack' => {len => 'sizepack', clear => 'wipepack'},
30 'packelem' => {get => 'getpack', set => 'setpack', clear => 'clearpack'},
31 'dbline' => {set => 'setdbline'},
32 'isa' => {set => 'setisa', clear => 'clearisa'},
33 'isaelem' => {set => 'setisa'},
34 'arylen' => {get => 'getarylen', set => 'setarylen', const => 1},
35 'arylen_p' => {free => 'freearylen_p'},
36 'mglob' => {set => 'setmglob'},
37 'nkeys' => {get => 'getnkeys', set => 'setnkeys'},
38 'taint' => {get => 'gettaint', set => 'settaint'},
39 'substr' => {get => 'getsubstr', set => 'setsubstr'},
40 'vec' => {get => 'getvec', set => 'setvec'},
41 'pos' => {get => 'getpos', set => 'setpos'},
42 'bm' => {set => 'setregexp'},
43 'fm' => {set => 'setregexp'},
44 'uvar' => {get => 'getuvar', set => 'setuvar'},
45 'defelem' => {get => 'getdefelem', set => 'setdefelem'},
46 'regexp' => {set => 'setregexp'},
47 'regdata' => {len => 'regdata_cnt'},
48 'regdatum' => {get => 'regdatum_get', set => 'regdatum_set'},
49 'amagic' => {set => 'setamagic', free => 'setamagic'},
50 'amagicelem' => {set => 'setamagic', free => 'setamagic'},
51 'backref' => {free => 'killbackrefs'},
52 'ovrld' => {free => 'freeovrld'},
53 'utf8' => {set => 'setutf8'},
54 'collxfrm' => {set => 'setcollxfrm',
55 cond => '#ifdef USE_LOCALE_COLLATE'},
56 'hintselem' => {set => 'sethint', clear => 'clearhint'},
57 'hints' => {clear => 'clearhints'},
58);
59
60my $h = open_new('mg_vtable.h', '>',
61 { by => 'regen/mg_vtable.pl', file => 'mg_vtable.h',
62 style => '*' });
63
ca298f7d
NC
64{
65 my @names = map {"want_vtbl_$_"} grep {!ref $_} @sig;
66 local $" = ",\n ";
67 print $h <<"EOH";
68enum { /* pass one of these to get_vtbl */
69 @names
70};
71
72EOH
73}
74
8b09643d
NC
75print $h <<'EOH';
76/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
77 * pointer to data, whereas we're assigning pointers to functions, which are
78 * not the same beast. ANSI doesn't allow the assignment from one to the other.
79 * (although most, but not all, compilers are prepared to do it)
80 */
81
0ffb5b03 82/* order is:
8b09643d
NC
83 get
84 set
85 len
86 clear
87 free
88 copy
89 dup
90 local
91*/
92
b7b5e578
NC
93#ifdef DOINIT
94EXT_MGVTBL PL_magic_vtables[] = {
8b09643d
NC
95EOH
96
b7b5e578
NC
97my @vtable_names;
98
8b09643d 99while (my ($name, $data) = splice @sig, 0, 2) {
b7b5e578 100 push @vtable_names, $name;
0a1f728a 101 my @funcs = map {
8b09643d
NC
102 $data->{$_} ? "Perl_magic_$data->{$_}" : 0;
103 } qw(get set len clear free copy dup local);
104
0a1f728a 105 $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const};
0ffb5b03 106 my $funcs = join ", ", @funcs;
8b09643d 107
b7b5e578
NC
108 # Because we can't have a , after the last {...}
109 my $comma = @sig ? ',' : '';
110
8b09643d 111 print $h "$data->{cond}\n" if $data->{cond};
b7b5e578
NC
112 print $h " { $funcs }$comma\n";
113 print $h <<"EOH" if $data->{cond};
0ffb5b03 114#else
b7b5e578 115 { 0, 0, 0, 0, 0, 0, 0, 0 }$comma
0ffb5b03 116#endif
b7b5e578 117EOH
8b09643d
NC
118}
119
b7b5e578
NC
120print $h <<'EOH';
121};
122#else
123EXT_MGVTBL PL_magic_vtables[];
124#endif
125
126EOH
127
128
129print $h "#define PL_vtbl_$_ PL_magic_vtables[want_vtbl_$_]\n"
130 foreach sort @vtable_names;
131
8b09643d 132read_only_bottom_close_and_rename($h);