This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate the definitions for magic vtables from data in a regen script.
[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
21my @sig =
22 (
23 'sv' => {get => 'get', set => 'set', len => 'len'},
24 'env' => {set => 'set_all_env', clear => 'clear_all_env'},
25 'envelem' => {set => 'setenv', clear => 'clearenv'},
26 'sigelem' => {get => 'getsig', set => 'setsig', clear => 'clearsig',
27 cond => '#ifndef PERL_MICRO'},
28 'pack' => {len => 'sizepack', clear => 'wipepack'},
29 'packelem' => {get => 'getpack', set => 'setpack', clear => 'clearpack'},
30 'dbline' => {set => 'setdbline'},
31 'isa' => {set => 'setisa', clear => 'clearisa'},
32 'isaelem' => {set => 'setisa'},
33 'arylen' => {get => 'getarylen', set => 'setarylen', const => 1},
34 'arylen_p' => {free => 'freearylen_p'},
35 'mglob' => {set => 'setmglob'},
36 'nkeys' => {get => 'getnkeys', set => 'setnkeys'},
37 'taint' => {get => 'gettaint', set => 'settaint'},
38 'substr' => {get => 'getsubstr', set => 'setsubstr'},
39 'vec' => {get => 'getvec', set => 'setvec'},
40 'pos' => {get => 'getpos', set => 'setpos'},
41 'bm' => {set => 'setregexp'},
42 'fm' => {set => 'setregexp'},
43 'uvar' => {get => 'getuvar', set => 'setuvar'},
44 'defelem' => {get => 'getdefelem', set => 'setdefelem'},
45 'regexp' => {set => 'setregexp'},
46 'regdata' => {len => 'regdata_cnt'},
47 'regdatum' => {get => 'regdatum_get', set => 'regdatum_set'},
48 'amagic' => {set => 'setamagic', free => 'setamagic'},
49 'amagicelem' => {set => 'setamagic', free => 'setamagic'},
50 'backref' => {free => 'killbackrefs'},
51 'ovrld' => {free => 'freeovrld'},
52 'utf8' => {set => 'setutf8'},
53 'collxfrm' => {set => 'setcollxfrm',
54 cond => '#ifdef USE_LOCALE_COLLATE'},
55 'hintselem' => {set => 'sethint', clear => 'clearhint'},
56 'hints' => {clear => 'clearhints'},
57);
58
59my $h = open_new('mg_vtable.h', '>',
60 { by => 'regen/mg_vtable.pl', file => 'mg_vtable.h',
61 style => '*' });
62
63print $h <<'EOH';
64/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
65 * pointer to data, whereas we're assigning pointers to functions, which are
66 * not the same beast. ANSI doesn't allow the assignment from one to the other.
67 * (although most, but not all, compilers are prepared to do it)
68 */
69
70/* args are:
71 vtable
72 get
73 set
74 len
75 clear
76 free
77 copy
78 dup
79 local
80*/
81
82EOH
83
84while (my ($name, $data) = splice @sig, 0, 2) {
85 my $funcs = join ",\n ", map {
86 $data->{$_} ? "Perl_magic_$data->{$_}" : 0;
87 } qw(get set len clear free copy dup local);
88
89 my $set_macro = $data->{const} ? 'MGVTBL_SET_CONST_MAGIC_GET' : 'MGVTBL_SET';
90
91 print $h "$data->{cond}\n" if $data->{cond};
92 print $h <<"EOT";
93$set_macro(
94 PL_vtbl_$name,
95 $funcs
96);
97EOT
98 print $h "#endif\n" if $data->{cond};
99 print $h "\n";
100}
101
102read_only_bottom_close_and_rename($h);