1 typedef char *pvcontents;
2 typedef char *strconst;
4 typedef char *op_tr_array;
10 #define BGET_FREAD(argp, len, nelem) \
11 bl_read(bstate->bs_fdata,(char*)(argp),(len),(nelem))
12 #define BGET_FGETC() bl_getc(bstate->bs_fdata)
14 /* all this should be made endianness-agnostic */
16 #define BGET_U8(arg) arg = BGET_FGETC()
17 #define BGET_U16(arg) \
18 BGET_FREAD(&arg, sizeof(U16), 1)
19 #define BGET_U32(arg) \
20 BGET_FREAD(&arg, sizeof(U32), 1)
21 #define BGET_UV(arg) \
22 BGET_FREAD(&arg, sizeof(UV), 1)
23 #define BGET_PADOFFSET(arg) \
24 BGET_FREAD(&arg, sizeof(PADOFFSET), 1)
25 #define BGET_long(arg) \
26 BGET_FREAD(&arg, sizeof(long), 1)
28 #define BGET_I32(arg) BGET_U32(arg)
29 #define BGET_IV(arg) BGET_UV(arg)
31 #define BGET_PV(arg) STMT_START { \
34 Newx(bstate->bs_pv.pvx, arg, char); \
35 bl_read(bstate->bs_fdata, bstate->bs_pv.pvx, arg, 1); \
36 bstate->bs_pv.xpv.xpv_len = arg; \
37 bstate->bs_pv.xpv.xpv_cur = arg - 1; \
39 bstate->bs_pv.pvx = 0; \
40 bstate->bs_pv.xpv.xpv_len = 0; \
41 bstate->bs_pv.xpv.xpv_cur = 0; \
45 #ifdef BYTELOADER_LOG_COMMENTS
46 # define BGET_comment_t(arg) \
52 buf[i++] = (char)arg; \
53 } while (arg != '\n' && arg != EOF); \
55 PerlIO_printf(PerlIO_stderr(), "%s", buf); \
58 # define BGET_comment_t(arg) \
59 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
63 #define BGET_op_tr_array(arg) do { \
64 unsigned short *ary, len; \
66 Newx(ary, len, unsigned short); \
67 BGET_FREAD(ary, sizeof(unsigned short), len); \
71 #define BGET_pvcontents(arg) arg = bstate->bs_pv.pvx
72 #define BGET_strconst(arg) STMT_START { \
73 for (arg = PL_tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
77 #define BGET_NV(arg) STMT_START { \
83 #define BGET_objindex(arg, type) STMT_START { \
85 arg = (type)bstate->bs_obj_list[ix]; \
87 #define BGET_svindex(arg) BGET_objindex(arg, svindex)
88 #define BGET_opindex(arg) BGET_objindex(arg, opindex)
89 #define BGET_pvindex(arg) STMT_START { \
90 BGET_objindex(arg, pvindex); \
91 arg = arg ? savepv(arg) : arg; \
94 #define BSET_ldspecsv(sv, arg) STMT_START { \
95 assert(arg < sizeof(specialsv_list) / sizeof(specialsv_list[0])); \
96 sv = specialsv_list[arg]; \
99 #define BSET_ldspecsvx(sv, arg) STMT_START { \
100 BSET_ldspecsv(sv, arg); \
101 BSET_OBJ_STOREX(sv); \
104 #define BSET_stpv(pv, arg) STMT_START { \
105 BSET_OBJ_STORE(pv, arg); \
109 #define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
110 #define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
111 #define BSET_gp_share(sv, arg) STMT_START { \
113 GvGP(sv) = GvGP(arg); \
116 #define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
117 #define BSET_gv_fetchpvx(sv, arg) STMT_START { \
118 BSET_gv_fetchpv(sv, arg); \
119 BSET_OBJ_STOREX(sv); \
122 #define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
123 #define BSET_gv_stashpvx(sv, arg) STMT_START { \
124 BSET_gv_stashpv(sv, arg); \
125 BSET_OBJ_STOREX(sv); \
128 #define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
129 #define BSET_mg_name(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.xpv.xpv_cur
130 #define BSET_mg_namex(mg, arg) \
131 (mg->mg_ptr = (char*)SvREFCNT_inc((SV*)arg), \
132 mg->mg_len = HEf_SVKEY)
133 #define BSET_xmg_stash(sv, arg) *(SV**)&(((XPVMG*)SvANY(sv))->xmg_stash) = (arg)
134 #define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
135 #define BSET_xrv(sv, arg) SvRV_set(sv, arg)
136 #define BSET_xpv(sv) do { \
137 SvPV_set(sv, bstate->bs_pv.pvx); \
138 SvCUR_set(sv, bstate->bs_pv.xpv.xpv_cur); \
139 SvLEN_set(sv, bstate->bs_pv.xpv.xpv_len); \
141 #define BSET_xpv_cur(sv, arg) SvCUR_set(sv, arg)
142 #define BSET_xpv_len(sv, arg) SvLEN_set(sv, arg)
143 #define BSET_xiv(sv, arg) SvIV_set(sv, arg)
144 #define BSET_xnv(sv, arg) SvNV_set(sv, arg)
146 #define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
148 #define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
149 #define BSET_av_pushx(sv, arg) (AvARRAY(sv)[++AvFILLp(sv)] = arg)
150 #define BSET_hv_store(sv, arg) \
151 hv_store((HV*)sv, bstate->bs_pv.pvx, bstate->bs_pv.xpv.xpv_cur, arg, 0)
152 #define BSET_pv_free(p) Safefree(p)
157 /* copied after the code in newPMOP() */
158 #define BSET_pregcomp(o, arg) \
162 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv.xpv_cur, cPMOPx(o)) : \
164 if(av_len((AV*) PL_regex_pad[0]) > -1) { \
165 repointer = av_pop((AV*)PL_regex_pad[0]); \
166 cPMOPx(o)->op_pmoffset = SvIV(repointer); \
167 SvREPADTMP_off(repointer); \
168 sv_setiv(repointer,PTR2IV(rx)); \
170 repointer = newSViv(PTR2IV(rx)); \
171 av_push(PL_regex_padav,SvREFCNT_inc(repointer)); \
172 cPMOPx(o)->op_pmoffset = av_len(PL_regex_padav); \
173 PL_regex_pad = AvARRAY(PL_regex_padav); \
178 #define BSET_pregcomp(o, arg) \
180 PM_SETRE(((PMOP*)o), (arg ? \
181 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv.xpv_cur, cPMOPx(o)): \
185 #endif /* USE_THREADS */
188 #define BSET_newsv(sv, arg) \
198 SvUPGRADE(sv, (arg)); \
200 #define BSET_newsvx(sv, arg) STMT_START { \
201 BSET_newsv(sv, arg & SVTYPEMASK); \
203 BSET_OBJ_STOREX(sv); \
206 #define BSET_newop(o, arg) NewOpSz(666, o, arg)
207 #define BSET_newopx(o, arg) STMT_START { \
208 register int sz = arg & 0x7f; \
209 register OP* newop; \
210 BSET_newop(newop, sz); \
211 /* newop->op_next = o; XXX */ \
214 BSET_op_type(o, arg); \
215 BSET_OBJ_STOREX(o); \
218 #define BSET_newopn(o, arg) STMT_START { \
220 BSET_newop(o, arg); \
221 oldop->op_next = o; \
224 #define BSET_ret(foo) STMT_START { \
225 Safefree(bstate->bs_obj_list); \
229 #define BSET_op_pmstashpv(op, arg) PmopSTASHPV_set(op, arg)
232 * stolen from toke.c: better if that was a function.
233 * in toke.c there are also #ifdefs for dosish systems and i/o layers
236 #if defined(HAS_FCNTL) && defined(F_SETFD)
237 #define set_clonex(fp) \
239 int fd = PerlIO_fileno(fp); \
240 fcntl(fd,F_SETFD,fd >= 3); \
243 #define set_clonex(fp)
246 #define BSET_data(dummy,arg) \
249 char *pname = "main"; \
251 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); \
252 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);\
255 GvIOp(gv) = newIO(); \
256 IoIFP(GvIOp(gv)) = PL_rsfp; \
257 set_clonex(PL_rsfp); \
258 /* Mark this internal pseudo-handle as clean */ \
259 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; \
261 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; \
262 else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) \
263 IoTYPE(GvIOp(gv)) = IoTYPE_STD; \
265 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; \
266 Safefree(bstate->bs_obj_list); \
270 /* stolen from op.c */
271 #define BSET_load_glob(foo, gv) \
275 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, \
276 newSVpvn("File::Glob", 10), Nullsv, Nullsv, Nullsv); \
277 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV); \
278 GvCV(gv) = GvCV(glob_gv); \
279 SvREFCNT_inc((SV*)GvCV(gv)); \
280 GvIMPORTED_CV_on(gv); \
285 * Kludge special-case workaround for OP_MAPSTART
286 * which needs the ppaddr for OP_GREPSTART. Blech.
288 #define BSET_op_type(o, arg) STMT_START { \
290 if (arg == OP_MAPSTART) \
291 arg = OP_GREPSTART; \
292 o->op_ppaddr = PL_ppaddr[arg]; \
294 #define BSET_op_ppaddr(o, arg) Perl_croak(aTHX_ "op_ppaddr not yet implemented")
295 #define BSET_curpad(pad, arg) STMT_START { \
296 PL_comppad = (AV *)arg; \
297 pad = AvARRAY(arg); \
301 #define BSET_cop_file(cop, arg) CopFILE_set(cop,arg)
302 #define BSET_cop_stashpv(cop, arg) CopSTASHPV_set(cop,arg)
304 /* this works now that Sarathy's changed the CopFILE_set macro to do the SvREFCNT_inc()
306 /* that really meant the actual CopFILEGV_set */
307 #define BSET_cop_filegv(cop, arg) CopFILEGV_set(cop,arg)
308 #define BSET_cop_stash(cop,arg) CopSTASH_set(cop,(HV*)arg)
311 /* this is simply stolen from the code in newATTRSUB() */
312 #define BSET_push_begin(ary,cv) \
314 I32 oldscope = PL_scopestack_ix; \
316 SAVECOPFILE(&PL_compiling); \
317 SAVECOPLINE(&PL_compiling); \
319 PL_beginav = newAV(); \
320 av_push(PL_beginav, (SV*)cv); \
321 GvCV(CvGV(cv)) = 0; /* cv has been hijacked */\
322 call_list(oldscope, PL_beginav); \
323 PL_curcop = &PL_compiling; \
324 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);\
327 #define BSET_push_init(ary,cv) \
329 av_unshift((PL_initav ? PL_initav : \
330 (PL_initav = newAV(), PL_initav)), 1); \
331 av_store(PL_initav, 0, cv); \
333 #define BSET_push_end(ary,cv) \
335 av_unshift((PL_endav ? PL_endav : \
336 (PL_endav = newAV(), PL_endav)), 1); \
337 av_store(PL_endav, 0, cv); \
339 #define BSET_OBJ_STORE(obj, ix) \
340 ((I32)ix > bstate->bs_obj_list_fill ? \
341 bset_obj_store(aTHX_ bstate, obj, (I32)ix) : \
342 (bstate->bs_obj_list[ix] = obj), \
343 bstate->bs_ix = ix+1)
344 #define BSET_OBJ_STOREX(obj) \
345 (bstate->bs_ix > bstate->bs_obj_list_fill ? \
346 bset_obj_store(aTHX_ bstate, obj, bstate->bs_ix) : \
347 (bstate->bs_obj_list[bstate->bs_ix] = obj), \
350 #define BSET_signal(cv, name) \
351 mg_set(*hv_store(GvHV(gv_fetchpv("SIG", TRUE, SVt_PVHV)), \
352 name, strlen(name), cv, 0))
354 #define BSET_xhv_name(hv, name) hv_name_set((HV*)hv, name, strlen(name), 0)
355 #define BSET_cop_arybase(c, b) CopARYBASE_set(c, b)
356 #define BSET_cop_warnings(c, w) \
358 if (specialWARN((STRLEN *)w)) { \
359 c->cop_warnings = (STRLEN *)w; \
362 const char *const p = SvPV_const(w, len); \
364 Perl_new_warnings_bitfield(aTHX_ NULL, p, len); \
369 /* NOTE: the bytecode header only sanity-checks the bytecode. If a script cares about
370 * what version of Perl it's being called under, it should do a 'use 5.006_001' or
371 * equivalent. However, since the header includes checks requiring an exact match in
372 * ByteLoader versions (we can't guarantee forward compatibility), you don't
373 * need to specify one:
379 #define HEADER_FAIL(f) \
380 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f)
381 #define HEADER_FAIL1(f, arg1) \
382 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1)
383 #define HEADER_FAIL2(f, arg1, arg2) \
384 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1, arg2)
386 #define BYTECODE_HEADER_CHECK \
391 BGET_U32(sz); /* Magic: 'PLBC' */ \
392 if (sz != 0x43424c50) { \
393 HEADER_FAIL1("bad magic (want 0x43424c50, got %#x)", (int)sz); \
395 BGET_strconst(str); /* archname */ \
396 if (strNE(str, ARCHNAME)) { \
397 HEADER_FAIL2("wrong architecture (want %s, you have %s)",str,ARCHNAME); \
399 BGET_strconst(str); /* ByteLoader version */ \
400 if (strNE(str, VERSION)) { \
401 HEADER_FAIL2("mismatched ByteLoader versions (want %s, you have %s)", \
404 BGET_U32(sz); /* ivsize */ \
405 if (sz != IVSIZE) { \
406 HEADER_FAIL("different IVSIZE"); \
408 BGET_U32(sz); /* ptrsize */ \
409 if (sz != PTRSIZE) { \
410 HEADER_FAIL("different PTRSIZE"); \