Commit | Line | Data |
5f05dabc |
1 | #!/usr/bin/perl -w |
e50aee73 |
2 | |
5f05dabc |
3 | require 5.003; |
4 | |
709f4e38 |
5 | # XXX others that may need adding |
6 | # warnhook |
7 | # hints |
8 | # copline |
84fee439 |
9 | my @extvars = qw(sv_undef sv_yes sv_no na dowarn |
10 | curcop compiling |
11 | tainting tainted stack_base stack_sp sv_arenaroot |
256a4781 |
12 | no_modify |
84fee439 |
13 | curstash DBsub DBsingle debstash |
14 | rsfp |
15 | stdingv |
6b88bc9c |
16 | defgv |
17 | errgv |
3070f6ec |
18 | rsfp_filters |
19 | perldb |
709f4e38 |
20 | diehook |
21 | dirty |
22 | perl_destruct_level |
84fee439 |
23 | ); |
24 | |
5f05dabc |
25 | sub readsyms (\%$) { |
26 | my ($syms, $file) = @_; |
5f05dabc |
27 | local (*FILE, $_); |
28 | open(FILE, "< $file") |
29 | or die "embed.pl: Can't open $file: $!\n"; |
30 | while (<FILE>) { |
31 | s/[ \t]*#.*//; # Delete comments. |
32 | if (/^\s*(\S+)\s*$/) { |
22c35a8c |
33 | my $sym = $1; |
34 | warn "duplicate symbol $sym while processing $file\n" |
35 | if exists $$syms{$sym}; |
36 | $$syms{$sym} = 1; |
5f05dabc |
37 | } |
38 | } |
39 | close(FILE); |
40 | } |
41 | |
42 | readsyms %global, 'global.sym'; |
22c35a8c |
43 | readsyms %global, 'pp.sym'; |
5f05dabc |
44 | |
c6af7a1a |
45 | sub readvars(\%$$@) { |
46 | my ($syms, $file,$pre,$keep_pre) = @_; |
d4cce5f1 |
47 | local (*FILE, $_); |
48 | open(FILE, "< $file") |
49 | or die "embed.pl: Can't open $file: $!\n"; |
50 | while (<FILE>) { |
51 | s/[ \t]*#.*//; # Delete comments. |
3fe35a81 |
52 | if (/PERLVARI?C?\($pre(\w+)/) { |
22c35a8c |
53 | my $sym = $1; |
c6af7a1a |
54 | $sym = $pre . $sym if $keep_pre; |
22c35a8c |
55 | warn "duplicate symbol $sym while processing $file\n" |
56 | if exists $$syms{$sym}; |
57 | $$syms{$sym} = 1; |
d4cce5f1 |
58 | } |
59 | } |
60 | close(FILE); |
61 | } |
62 | |
63 | my %intrp; |
64 | my %thread; |
65 | |
66 | readvars %intrp, 'intrpvar.h','I'; |
67 | readvars %thread, 'thrdvar.h','T'; |
22239a37 |
68 | readvars %globvar, 'perlvars.h','G'; |
c6af7a1a |
69 | readvars %objvar, 'intrpvar.h','pi', 1; |
d4cce5f1 |
70 | |
71 | foreach my $sym (sort keys %intrp) |
72 | { |
d4cce5f1 |
73 | if (exists $global{$sym}) |
74 | { |
75 | delete $global{$sym}; |
22c35a8c |
76 | warn "$sym in {global,pp}.sym as well as intrpvar.h\n"; |
d4cce5f1 |
77 | } |
78 | } |
79 | |
22239a37 |
80 | foreach my $sym (sort keys %globvar) |
81 | { |
82 | if (exists $global{$sym}) |
83 | { |
84 | delete $global{$sym}; |
22c35a8c |
85 | warn "$sym in {global,pp}.sym as well as perlvars.h\n"; |
22239a37 |
86 | } |
87 | } |
88 | |
d4cce5f1 |
89 | foreach my $sym (sort keys %thread) |
90 | { |
34b58025 |
91 | warn "$sym in intrpvar.h as well as thrdvar.h\n" if exists $intrp{$sym}; |
d4cce5f1 |
92 | if (exists $global{$sym}) |
93 | { |
94 | delete $global{$sym}; |
22c35a8c |
95 | warn "$sym in {global,pp}.sym as well as thrdvar.h\n"; |
d4cce5f1 |
96 | } |
97 | } |
98 | |
c6af7a1a |
99 | sub undefine ($) { |
100 | my ($sym) = @_; |
101 | "#undef $sym\n"; |
102 | } |
103 | |
5f05dabc |
104 | sub hide ($$) { |
105 | my ($from, $to) = @_; |
106 | my $t = int(length($from) / 8); |
107 | "#define $from" . "\t" x ($t < 3 ? 3 - $t : 1) . "$to\n"; |
108 | } |
c6af7a1a |
109 | |
5f05dabc |
110 | sub embed ($) { |
111 | my ($sym) = @_; |
112 | hide($sym, "Perl_$sym"); |
113 | } |
c6af7a1a |
114 | |
22c35a8c |
115 | sub embedobj ($) { |
116 | my ($sym) = @_; |
117 | hide($sym, $sym =~ /^perl_/i ? "CPerlObj::$sym" : "CPerlObj::Perl_$sym"); |
118 | } |
c6af7a1a |
119 | |
120 | sub objxsub_func ($) { |
121 | my ($sym) = @_; |
122 | undefine($sym) . hide($sym, $sym =~ /^perl_/i |
123 | ? "pPerl->$sym" |
124 | : "pPerl->Perl_$sym"); |
125 | } |
126 | |
127 | sub objxsub_var ($) { |
128 | my ($sym) = @_; |
129 | undefine("PL_$sym") . hide("PL_$sym", "pPerl->PL_$sym"); |
130 | } |
131 | |
3280af22 |
132 | sub embedvar ($) { |
133 | my ($sym) = @_; |
134 | # hide($sym, "Perl_$sym"); |
135 | return ''; |
136 | } |
137 | |
d4cce5f1 |
138 | sub multon ($$$) { |
139 | my ($sym,$pre,$ptr) = @_; |
3280af22 |
140 | hide("PL_$sym", "($ptr$pre$sym)"); |
5f05dabc |
141 | } |
d4cce5f1 |
142 | sub multoff ($$) { |
143 | my ($sym,$pre) = @_; |
533c011a |
144 | return hide("PL_$pre$sym", "PL_$sym"); |
5f05dabc |
145 | } |
146 | |
147 | unlink 'embed.h'; |
148 | open(EM, '> embed.h') |
149 | or die "Can't create embed.h: $!\n"; |
e50aee73 |
150 | |
151 | print EM <<'END'; |
76b72cf1 |
152 | /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
22c35a8c |
153 | This file is built by embed.pl from global.sym, pp.sym, intrpvar.h, |
c6af7a1a |
154 | perlvars.h and thrdvar.h. Any changes made here will be lost! |
76b72cf1 |
155 | */ |
e50aee73 |
156 | |
157 | /* (Doing namespace management portably in C is really gross.) */ |
158 | |
22c35a8c |
159 | /* NO_EMBED is no longer supported. i.e. EMBED is always active. */ |
820c3be9 |
160 | |
22c35a8c |
161 | /* Hide global symbols */ |
5f05dabc |
162 | |
22c35a8c |
163 | #if !defined(PERL_OBJECT) |
e50aee73 |
164 | |
e50aee73 |
165 | END |
166 | |
5f05dabc |
167 | for $sym (sort keys %global) { |
dc86dda3 |
168 | print EM embed($sym); |
e50aee73 |
169 | } |
170 | |
e50aee73 |
171 | print EM <<'END'; |
172 | |
22c35a8c |
173 | #else /* PERL_OBJECT */ |
174 | |
175 | END |
176 | |
177 | # XXX these should be in a *.sym file |
c6af7a1a |
178 | my @staticfuncs = qw( |
22c35a8c |
179 | perl_init_i18nl10n |
180 | perl_init_i18nl14n |
181 | perl_new_collate |
182 | perl_new_ctype |
183 | perl_new_numeric |
184 | perl_set_numeric_local |
185 | perl_set_numeric_standard |
186 | perl_construct |
187 | perl_destruct |
188 | perl_atexit |
189 | perl_free |
190 | perl_parse |
191 | perl_run |
192 | perl_get_sv |
193 | perl_get_av |
194 | perl_get_hv |
195 | perl_get_cv |
196 | perl_call_argv |
197 | perl_call_pv |
198 | perl_call_method |
199 | perl_call_sv |
200 | perl_eval_pv |
201 | perl_eval_sv |
202 | perl_require_pv |
203 | |
204 | hsplit |
205 | hfreeentries |
206 | more_he |
207 | new_he |
208 | del_he |
209 | save_hek |
210 | mess_alloc |
211 | gv_init_sv |
212 | save_scalar_at |
213 | asIV |
214 | asUV |
215 | more_sv |
216 | more_xiv |
217 | more_xnv |
218 | more_xpv |
219 | more_xrv |
220 | new_xiv |
221 | new_xnv |
222 | new_xpv |
223 | new_xrv |
224 | del_xiv |
225 | del_xnv |
226 | del_xpv |
227 | del_xrv |
22c35a8c |
228 | sv_unglob |
22c35a8c |
229 | avhv_index_sv |
230 | do_report_used |
231 | do_clean_objs |
232 | do_clean_named_objs |
233 | do_clean_all |
234 | not_a_number |
235 | my_safemalloc |
236 | visit |
237 | qsortsv |
238 | sortcv |
239 | save_magic |
240 | magic_methpack |
241 | magic_methcall |
242 | magic_methcall |
243 | doform |
244 | doencodes |
245 | refto |
246 | seed |
247 | docatch |
248 | dofindlabel |
249 | doparseform |
250 | dopoptoeval |
251 | dopoptolabel |
252 | dopoptoloop |
253 | dopoptosub |
254 | dopoptosub_at |
255 | save_lines |
256 | doeval |
bda4119b |
257 | sv_ncmp |
258 | sv_i_ncmp |
259 | amagic_ncmp |
260 | amagic_i_ncmp |
22c35a8c |
261 | amagic_cmp |
262 | amagic_cmp_locale |
263 | mul128 |
264 | is_an_int |
265 | div128 |
266 | runops_standard |
267 | runops_debug |
268 | check_uni |
269 | force_next |
270 | force_version |
271 | force_word |
272 | tokeq |
273 | scan_const |
274 | scan_formline |
275 | scan_heredoc |
276 | scan_ident |
277 | scan_inputsymbol |
278 | scan_pat |
279 | scan_str |
280 | scan_subst |
281 | scan_trans |
282 | scan_word |
283 | skipspace |
284 | checkcomma |
285 | force_ident |
286 | incline |
287 | intuit_method |
288 | intuit_more |
289 | lop |
290 | missingterm |
291 | no_op |
292 | set_csh |
293 | sublex_done |
294 | sublex_push |
295 | sublex_start |
296 | uni |
297 | filter_gets |
298 | new_constant |
299 | ao |
300 | depcom |
301 | win32_textfilter |
302 | incl_perldb |
303 | isa_lookup |
304 | get_db_sub |
305 | list_assignment |
306 | bad_type |
307 | modkids |
308 | no_fh_allowed |
309 | scalarboolean |
310 | too_few_arguments |
311 | too_many_arguments |
312 | null |
313 | pad_findlex |
314 | newDEFSVOP |
315 | gv_ename |
316 | cv_clone2 |
317 | find_beginning |
318 | forbid_setid |
319 | incpush |
320 | init_interp |
321 | init_ids |
322 | init_debugger |
323 | init_lexer |
324 | init_main_stash |
325 | init_perllib |
326 | init_postdump_symbols |
327 | init_predump_symbols |
328 | my_exit_jump |
329 | nuke_stacks |
330 | open_script |
331 | usage |
332 | validate_suid |
333 | emulate_eaccess |
334 | reg |
335 | reganode |
336 | regatom |
337 | regbranch |
338 | regc |
339 | reguni |
340 | regclass |
341 | regclassutf8 |
342 | regcurly |
343 | reg_node |
344 | regpiece |
345 | reginsert |
346 | regoptail |
347 | regset |
348 | regtail |
349 | regwhite |
350 | nextchar |
351 | dumpuntil |
352 | scan_commit |
353 | study_chunk |
354 | add_data |
355 | re_croak2 |
eb1ab10a |
356 | regpposixcc |
4327152a |
357 | clear_re |
22c35a8c |
358 | regmatch |
359 | regrepeat |
360 | regrepeat_hard |
361 | regtry |
362 | reginclass |
363 | reginclassutf8 |
364 | regcppush |
365 | regcppop |
366 | regcp_set_to |
367 | cache_re |
9661b544 |
368 | restore_pos |
22c35a8c |
369 | reghop |
370 | reghopmaybe |
371 | dump |
372 | do_aspawn |
373 | debprof |
374 | bset_obj_store |
375 | new_logop |
bda4119b |
376 | simplify_sort |
35cd451c |
377 | is_handle_constructor |
22c35a8c |
378 | do_trans_CC_simple |
379 | do_trans_CC_count |
380 | do_trans_CC_complex |
381 | do_trans_UU_simple |
382 | do_trans_UU_count |
383 | do_trans_UU_complex |
384 | do_trans_UC_simple |
385 | do_trans_CU_simple |
386 | do_trans_UC_trivial |
387 | do_trans_CU_trivial |
388 | unwind_handler_stack |
389 | restore_magic |
390 | restore_rsfp |
391 | restore_expect |
392 | restore_lex_expect |
393 | yydestruct |
394 | del_sv |
395 | fprintf |
396 | ); |
397 | |
c6af7a1a |
398 | for $sym (sort(keys(%global),@staticfuncs)) { |
22c35a8c |
399 | print EM embedobj($sym); |
400 | } |
401 | |
402 | print EM <<'END'; |
403 | |
404 | #endif /* PERL_OBJECT */ |
e50aee73 |
405 | |
db5cf5a9 |
406 | /* compatibility stubs */ |
407 | |
408 | #define sv_setptrobj(rv,ptr,name) sv_setref_iv(rv,name,(IV)ptr) |
409 | #define sv_setptrref(rv,ptr) sv_setref_iv(rv,Nullch,(IV)ptr) |
410 | |
d4cce5f1 |
411 | END |
412 | |
413 | close(EM); |
414 | |
415 | unlink 'embedvar.h'; |
416 | open(EM, '> embedvar.h') |
417 | or die "Can't create embedvar.h: $!\n"; |
418 | |
419 | print EM <<'END'; |
420 | /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
22c35a8c |
421 | This file is built by embed.pl from global.sym, pp.sym, intrpvar.h, |
c6af7a1a |
422 | perlvars.h and thrdvar.h. Any changes made here will be lost! |
d4cce5f1 |
423 | */ |
424 | |
425 | /* (Doing namespace management portably in C is really gross.) */ |
426 | |
5f05dabc |
427 | /* Put interpreter-specific symbols into a struct? */ |
e50aee73 |
428 | |
429 | #ifdef MULTIPLICITY |
430 | |
d4cce5f1 |
431 | #ifndef USE_THREADS |
432 | /* If we do not have threads then per-thread vars are per-interpreter */ |
433 | |
e50aee73 |
434 | END |
435 | |
d4cce5f1 |
436 | for $sym (sort keys %thread) { |
8f872242 |
437 | print EM multon($sym,'T','PL_curinterp->'); |
d4cce5f1 |
438 | } |
439 | |
440 | print EM <<'END'; |
441 | |
442 | #endif /* !USE_THREADS */ |
443 | |
444 | /* These are always per-interpreter if there is more than one */ |
445 | |
446 | END |
447 | |
448 | for $sym (sort keys %intrp) { |
8f872242 |
449 | print EM multon($sym,'I','PL_curinterp->'); |
760ac839 |
450 | } |
760ac839 |
451 | |
55497cff |
452 | print EM <<'END'; |
453 | |
5f05dabc |
454 | #else /* !MULTIPLICITY */ |
55497cff |
455 | |
456 | END |
760ac839 |
457 | |
d4cce5f1 |
458 | for $sym (sort keys %intrp) { |
459 | print EM multoff($sym,'I'); |
e50aee73 |
460 | } |
e50aee73 |
461 | |
56d28764 |
462 | print EM <<'END'; |
463 | |
d4cce5f1 |
464 | #ifndef USE_THREADS |
465 | |
466 | END |
467 | |
468 | for $sym (sort keys %thread) { |
469 | print EM multoff($sym,'T'); |
470 | } |
471 | |
472 | print EM <<'END'; |
473 | |
474 | #endif /* USE_THREADS */ |
475 | |
476 | /* Hide what would have been interpreter-specific symbols? */ |
5f05dabc |
477 | |
56d28764 |
478 | END |
e50aee73 |
479 | |
d4cce5f1 |
480 | for $sym (sort keys %intrp) { |
3280af22 |
481 | print EM embedvar($sym); |
d4cce5f1 |
482 | } |
483 | |
484 | print EM <<'END'; |
485 | |
486 | #ifndef USE_THREADS |
487 | |
488 | END |
489 | |
490 | for $sym (sort keys %thread) { |
3280af22 |
491 | print EM embedvar($sym); |
5f05dabc |
492 | } |
493 | |
494 | print EM <<'END'; |
495 | |
d4cce5f1 |
496 | #endif /* USE_THREADS */ |
e50aee73 |
497 | #endif /* MULTIPLICITY */ |
d4cce5f1 |
498 | |
499 | /* Now same trickey for per-thread variables */ |
500 | |
501 | #ifdef USE_THREADS |
502 | |
503 | END |
504 | |
505 | for $sym (sort keys %thread) { |
22239a37 |
506 | print EM multon($sym,'T','thr->'); |
d4cce5f1 |
507 | } |
508 | |
509 | print EM <<'END'; |
510 | |
511 | #endif /* USE_THREADS */ |
512 | |
22239a37 |
513 | #ifdef PERL_GLOBAL_STRUCT |
514 | |
515 | END |
516 | |
517 | for $sym (sort keys %globvar) { |
533c011a |
518 | print EM multon($sym,'G','PL_Vars.'); |
22239a37 |
519 | } |
520 | |
521 | print EM <<'END'; |
522 | |
523 | #else /* !PERL_GLOBAL_STRUCT */ |
524 | |
525 | END |
526 | |
527 | for $sym (sort keys %globvar) { |
528 | print EM multoff($sym,'G'); |
529 | } |
530 | |
531 | print EM <<'END'; |
532 | |
22239a37 |
533 | END |
534 | |
535 | for $sym (sort keys %globvar) { |
3280af22 |
536 | print EM embedvar($sym); |
22239a37 |
537 | } |
538 | |
539 | print EM <<'END'; |
540 | |
22239a37 |
541 | #endif /* PERL_GLOBAL_STRUCT */ |
542 | |
e50aee73 |
543 | END |
544 | |
84fee439 |
545 | print EM <<'END'; |
546 | |
db5cf5a9 |
547 | #ifdef PERL_POLLUTE /* disabled by default in 5.006 */ |
84fee439 |
548 | |
549 | END |
550 | |
551 | for $sym (sort @extvars) { |
552 | print EM hide($sym,"PL_$sym"); |
553 | } |
554 | |
555 | print EM <<'END'; |
556 | |
db5cf5a9 |
557 | #endif /* PERL_POLLUTE */ |
84fee439 |
558 | END |
559 | |
560 | |
3fe35a81 |
561 | close(EM); |
c6af7a1a |
562 | |
563 | unlink 'objXSUB.h'; |
564 | open(OBX, '> objXSUB.h') |
565 | or die "Can't create objXSUB.h: $!\n"; |
566 | |
567 | print OBX <<'EOT'; |
568 | /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!! |
569 | This file is built by embed.pl from global.sym, pp.sym, intrpvar.h, |
570 | perlvars.h and thrdvar.h. Any changes made here will be lost! |
571 | */ |
572 | |
573 | #ifndef __objXSUB_h__ |
574 | #define __objXSUB_h__ |
575 | |
576 | /* Variables */ |
577 | |
578 | EOT |
579 | |
580 | foreach my $sym (sort(keys(%intrp), |
581 | keys(%thread), |
582 | keys(%globvar), |
583 | keys(%objvar))) |
584 | { |
585 | print OBX objxsub_var($sym); |
586 | } |
587 | |
588 | print OBX <<'EOT'; |
589 | |
590 | /* Functions */ |
591 | |
592 | EOT |
593 | |
594 | |
595 | for $sym (sort(keys(%global),@staticfuncs)) { |
596 | print OBX objxsub_func($sym); |
597 | } |
598 | |
599 | |
600 | print OBX <<'EOT'; |
601 | |
602 | #endif /* __objXSUB_h__ */ |
603 | EOT |
604 | |
605 | close(OBX); |