1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
#!/usr/bin/perl -w
require 5.003;
my @extvars = qw(sv_undef sv_yes sv_no na dowarn
curcop compiling
tainting tainted stack_base stack_sp sv_arenaroot
curstash DBsub DBsingle debstash
rsfp
stdingv
);
sub readsyms (\%$) {
my ($syms, $file) = @_;
%$syms = ();
local (*FILE, $_);
open(FILE, "< $file")
or die "embed.pl: Can't open $file: $!\n";
while (<FILE>) {
s/[ \t]*#.*//; # Delete comments.
if (/^\s*(\S+)\s*$/) {
$$syms{$1} = 1;
}
}
close(FILE);
}
readsyms %global, 'global.sym';
readsyms %interp, 'interp.sym';
sub readvars(\%$$) {
my ($syms, $file,$pre) = @_;
%$syms = ();
local (*FILE, $_);
open(FILE, "< $file")
or die "embed.pl: Can't open $file: $!\n";
while (<FILE>) {
s/[ \t]*#.*//; # Delete comments.
if (/PERLVARI?C?\($pre(\w+)/) {
$$syms{$1} = 1;
}
}
close(FILE);
}
my %intrp;
my %thread;
readvars %intrp, 'intrpvar.h','I';
readvars %thread, 'thrdvar.h','T';
readvars %globvar, 'perlvars.h','G';
foreach my $sym (sort keys %intrp)
{
warn "$sym not in interp.sym\n" unless exists $interp{$sym};
if (exists $global{$sym})
{
delete $global{$sym};
warn "$sym in global.sym as well as interp\n";
}
}
foreach my $sym (sort keys %globvar)
{
if (exists $global{$sym})
{
delete $global{$sym};
warn "$sym in global.sym as well as perlvars.h\n";
}
}
foreach my $sym (keys %interp)
{
warn "extra $sym in interp.sym\n"
unless exists $intrp{$sym} || exists $thread{$sym};
}
foreach my $sym (sort keys %thread)
{
warn "$sym in intrpvar.h\n" if exists $intrp{$sym};
if (exists $global{$sym})
{
delete $global{$sym};
warn "$sym in global.sym as well as thread\n";
}
}
sub hide ($$) {
my ($from, $to) = @_;
my $t = int(length($from) / 8);
"#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n";
}
sub embed ($) {
my ($sym) = @_;
hide($sym, "Perl_$sym");
}
sub embedvar ($) {
my ($sym) = @_;
# hide($sym, "Perl_$sym");
return '';
}
sub multon ($$$) {
my ($sym,$pre,$ptr) = @_;
hide("PL_$sym", "($ptr$pre$sym)");
}
sub multoff ($$) {
my ($sym,$pre) = @_;
return hide("PL_$pre$sym", "PL_$sym");
}
unlink 'embed.h';
open(EM, '> embed.h')
or die "Can't create embed.h: $!\n";
print EM <<'END';
/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
This file is built by embed.pl from global.sym, intrpvar.h,
and thrdvar.h. Any changes made here will be lost!
*/
/* (Doing namespace management portably in C is really gross.) */
/* EMBED has no run-time penalty, but helps keep the Perl namespace
from colliding with that used by other libraries pulled in
by extensions or by embedding perl. Allow a cc -DNO_EMBED
override, however, to keep binary compatability with previous
versions of perl.
*/
#ifndef NO_EMBED
# define EMBED 1
#endif
/* Hide global symbols? */
#ifdef EMBED
END
for $sym (sort keys %global) {
print EM embed($sym);
}
print EM <<'END';
#endif /* EMBED */
END
close(EM);
unlink 'embedvar.h';
open(EM, '> embedvar.h')
or die "Can't create embedvar.h: $!\n";
print EM <<'END';
/* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
This file is built by embed.pl from global.sym, intrpvar.h,
and thrdvar.h. Any changes made here will be lost!
*/
/* (Doing namespace management portably in C is really gross.) */
/* EMBED has no run-time penalty, but helps keep the Perl namespace
from colliding with that used by other libraries pulled in
by extensions or by embedding perl. Allow a cc -DNO_EMBED
override, however, to keep binary compatability with previous
versions of perl.
*/
/* Put interpreter-specific symbols into a struct? */
#ifdef MULTIPLICITY
#ifndef USE_THREADS
/* If we do not have threads then per-thread vars are per-interpreter */
END
for $sym (sort keys %thread) {
print EM multon($sym,'T','PL_curinterp->');
}
print EM <<'END';
#endif /* !USE_THREADS */
/* These are always per-interpreter if there is more than one */
END
for $sym (sort keys %intrp) {
print EM multon($sym,'I','PL_curinterp->');
}
print EM <<'END';
#else /* !MULTIPLICITY */
END
for $sym (sort keys %intrp) {
print EM multoff($sym,'I');
}
print EM <<'END';
#ifndef USE_THREADS
END
for $sym (sort keys %thread) {
print EM multoff($sym,'T');
}
print EM <<'END';
#endif /* USE_THREADS */
/* Hide what would have been interpreter-specific symbols? */
#ifdef EMBED
END
for $sym (sort keys %intrp) {
print EM embedvar($sym);
}
print EM <<'END';
#ifndef USE_THREADS
END
for $sym (sort keys %thread) {
print EM embedvar($sym);
}
print EM <<'END';
#endif /* USE_THREADS */
#endif /* EMBED */
#endif /* MULTIPLICITY */
/* Now same trickey for per-thread variables */
#ifdef USE_THREADS
END
for $sym (sort keys %thread) {
print EM multon($sym,'T','thr->');
}
print EM <<'END';
#endif /* USE_THREADS */
#ifdef PERL_GLOBAL_STRUCT
END
for $sym (sort keys %globvar) {
print EM multon($sym,'G','PL_Vars.');
}
print EM <<'END';
#else /* !PERL_GLOBAL_STRUCT */
END
for $sym (sort keys %globvar) {
print EM multoff($sym,'G');
}
print EM <<'END';
#ifdef EMBED
END
for $sym (sort keys %globvar) {
print EM embedvar($sym);
}
print EM <<'END';
#endif /* EMBED */
#endif /* PERL_GLOBAL_STRUCT */
END
print EM <<'END';
#ifndef MIN_PERL_DEFINE
END
for $sym (sort @extvars) {
print EM hide($sym,"PL_$sym");
}
print EM <<'END';
#endif /* MIN_PERL_DEFINE */
END
close(EM);
|