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)
24 #define BGET_I32(arg) BGET_U32(arg)
25 #define BGET_IV(arg) BGET_UV(arg)
27 #define BGET_PV(arg) STMT_START { \
30 New(666, bstate->bs_pv.xpv_pv, arg, char); \
31 bl_read(bstate->bs_fdata, (void*)bstate->bs_pv.xpv_pv, arg, 1);\
32 bstate->bs_pv.xpv_len = arg; \
33 bstate->bs_pv.xpv_cur = arg - 1; \
35 bstate->bs_pv.xpv_pv = 0; \
36 bstate->bs_pv.xpv_len = 0; \
37 bstate->bs_pv.xpv_cur = 0; \
41 #ifdef BYTELOADER_LOG_COMMENTS
42 # define BGET_comment_t(arg) \
48 buf[i++] = (char)arg; \
49 } while (arg != '\n' && arg != EOF); \
51 PerlIO_printf(PerlIO_stderr(), "%s", buf); \
54 # define BGET_comment_t(arg) \
55 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
59 #define BGET_op_tr_array(arg) do { \
60 unsigned short *ary, len; \
62 New(666, ary, len, unsigned short); \
63 BGET_FREAD(ary, sizeof(unsigned short), len); \
67 #define BGET_pvcontents(arg) arg = bstate->bs_pv.xpv_pv
68 #define BGET_strconst(arg) STMT_START { \
69 for (arg = PL_tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
73 #define BGET_NV(arg) STMT_START { \
79 #define BGET_objindex(arg, type) STMT_START { \
81 arg = (type)bstate->bs_obj_list[ix]; \
83 #define BGET_svindex(arg) BGET_objindex(arg, svindex)
84 #define BGET_opindex(arg) BGET_objindex(arg, opindex)
85 #define BGET_pvindex(arg) STMT_START { \
86 BGET_objindex(arg, pvindex); \
87 arg = arg ? savepv(arg) : arg; \
90 #define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
91 #define BSET_ldspecsvx(sv, arg) STMT_START { \
92 BSET_ldspecsv(sv, arg); \
93 BSET_OBJ_STOREX(sv); \
96 #define BSET_stpv(pv, arg) STMT_START { \
97 BSET_OBJ_STORE(pv, arg); \
101 #define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
102 #define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
103 #define BSET_gp_share(sv, arg) STMT_START { \
105 GvGP(sv) = GvGP(arg); \
108 #define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
109 #define BSET_gv_fetchpvx(sv, arg) STMT_START { \
110 BSET_gv_fetchpv(sv, arg); \
111 BSET_OBJ_STOREX(sv); \
114 #define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
115 #define BSET_gv_stashpvx(sv, arg) STMT_START { \
116 BSET_gv_stashpv(sv, arg); \
117 BSET_OBJ_STOREX(sv); \
120 #define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
121 #define BSET_mg_name(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.xpv_cur
122 #define BSET_mg_namex(mg, arg) \
123 (mg->mg_ptr = (char*)SvREFCNT_inc((SV*)arg), \
124 mg->mg_len = HEf_SVKEY)
125 #define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
126 #define BSET_xpv(sv) do { \
127 SvPV_set(sv, bstate->bs_pv.xpv_pv); \
128 SvCUR_set(sv, bstate->bs_pv.xpv_cur); \
129 SvLEN_set(sv, bstate->bs_pv.xpv_len); \
131 #define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
133 #define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
134 #define BSET_av_pushx(sv, arg) (AvARRAY(sv)[++AvFILLp(sv)] = arg)
135 #define BSET_hv_store(sv, arg) \
136 hv_store((HV*)sv, bstate->bs_pv.xpv_pv, bstate->bs_pv.xpv_cur, arg, 0)
137 #define BSET_pv_free(pv) Safefree(pv.xpv_pv)
142 /* copied after the code in newPMOP() */
143 #define BSET_pregcomp(o, arg) \
147 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)) : \
149 if(av_len((AV*) PL_regex_pad[0]) > -1) { \
150 repointer = av_pop((AV*)PL_regex_pad[0]); \
151 cPMOPx(o)->op_pmoffset = SvIV(repointer); \
152 SvREPADTMP_off(repointer); \
153 sv_setiv(repointer,PTR2IV(rx)); \
155 repointer = newSViv(PTR2IV(rx)); \
156 av_push(PL_regex_padav,SvREFCNT_inc(repointer)); \
157 cPMOPx(o)->op_pmoffset = av_len(PL_regex_padav); \
158 PL_regex_pad = AvARRAY(PL_regex_padav); \
163 #define BSET_pregcomp(o, arg) \
165 PM_SETRE(((PMOP*)o), (arg ? \
166 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)): \
170 #endif /* USE_THREADS */
173 #define BSET_newsv(sv, arg) \
175 sv = (arg == SVt_PVAV ? (SV*)newAV() : \
176 arg == SVt_PVHV ? (SV*)newHV() : \
178 SvUPGRADE(sv, arg); \
180 #define BSET_newsvx(sv, arg) STMT_START { \
181 BSET_newsv(sv, arg & SVTYPEMASK); \
183 BSET_OBJ_STOREX(sv); \
185 #define BSET_newop(o, arg) \
186 ((o = (OP*)safemalloc(arg)), memzero((char*)o,arg))
187 #define BSET_newopx(o, arg) STMT_START { \
188 register int sz = arg & 0x7f; \
189 register OP* new = (OP*) safemalloc(sz);\
191 /* new->op_next = o; XXX */ \
194 BSET_op_type(o, arg); \
195 BSET_OBJ_STOREX(o); \
198 #define BSET_newopn(o, arg) STMT_START { \
200 BSET_newop(o, arg); \
201 oldop->op_next = o; \
204 #define BSET_ret(foo) STMT_START { \
205 Safefree(bstate->bs_obj_list); \
210 * stolen from toke.c: better if that was a function.
211 * in toke.c there are also #ifdefs for dosish systems and i/o layers
214 #if defined(HAS_FCNTL) && defined(F_SETFD)
215 #define set_clonex(fp) \
217 int fd = PerlIO_fileno(fp); \
218 fcntl(fd,F_SETFD,fd >= 3); \
221 #define set_clonex(fp)
224 #define BSET_data(dummy,arg) \
227 char *pname = "main"; \
229 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); \
230 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);\
233 GvIOp(gv) = newIO(); \
234 IoIFP(GvIOp(gv)) = PL_rsfp; \
235 set_clonex(PL_rsfp); \
236 /* Mark this internal pseudo-handle as clean */ \
237 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; \
239 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; \
240 else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) \
241 IoTYPE(GvIOp(gv)) = IoTYPE_STD; \
243 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; \
244 Safefree(bstate->bs_obj_list); \
248 /* stolen from op.c */
249 #define BSET_load_glob(foo, gv) \
253 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, \
254 newSVpvn("File::Glob", 10), Nullsv, Nullsv, Nullsv); \
255 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV); \
256 GvCV(gv) = GvCV(glob_gv); \
257 SvREFCNT_inc((SV*)GvCV(gv)); \
258 GvIMPORTED_CV_on(gv); \
263 * Kludge special-case workaround for OP_MAPSTART
264 * which needs the ppaddr for OP_GREPSTART. Blech.
266 #define BSET_op_type(o, arg) STMT_START { \
268 if (arg == OP_MAPSTART) \
269 arg = OP_GREPSTART; \
270 o->op_ppaddr = PL_ppaddr[arg]; \
272 #define BSET_op_ppaddr(o, arg) Perl_croak(aTHX_ "op_ppaddr not yet implemented")
273 #define BSET_curpad(pad, arg) STMT_START { \
274 PL_comppad = (AV *)arg; \
275 pad = AvARRAY(arg); \
279 #define BSET_cop_file(cop, arg) CopFILE_set(cop,arg)
280 #define BSET_cop_stashpv(cop, arg) CopSTASHPV_set(cop,arg)
282 /* this works now that Sarathy's changed the CopFILE_set macro to do the SvREFCNT_inc()
284 /* that really meant the actual CopFILEGV_set */
285 #define BSET_cop_filegv(cop, arg) CopFILEGV_set(cop,arg)
286 #define BSET_cop_stash(cop,arg) CopSTASH_set(cop,(HV*)arg)
289 /* this is simply stolen from the code in newATTRSUB() */
290 #define BSET_push_begin(ary,cv) \
292 I32 oldscope = PL_scopestack_ix; \
294 SAVECOPFILE(&PL_compiling); \
295 SAVECOPLINE(&PL_compiling); \
297 PL_beginav = newAV(); \
298 av_push(PL_beginav, (SV*)cv); \
299 GvCV(CvGV(cv)) = 0; /* cv has been hijacked */\
300 call_list(oldscope, PL_beginav); \
301 PL_curcop = &PL_compiling; \
302 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);\
305 #define BSET_push_init(ary,cv) \
307 av_unshift((PL_initav ? PL_initav : \
308 (PL_initav = newAV(), PL_initav)), 1); \
309 av_store(PL_initav, 0, cv); \
311 #define BSET_push_end(ary,cv) \
313 av_unshift((PL_endav ? PL_endav : \
314 (PL_endav = newAV(), PL_endav)), 1); \
315 av_store(PL_endav, 0, cv); \
317 #define BSET_OBJ_STORE(obj, ix) \
318 ((I32)ix > bstate->bs_obj_list_fill ? \
319 bset_obj_store(aTHX_ bstate, obj, (I32)ix) : \
320 (bstate->bs_obj_list[ix] = obj), \
321 bstate->bs_ix = ix+1)
322 #define BSET_OBJ_STOREX(obj) \
323 (bstate->bs_ix > bstate->bs_obj_list_fill ? \
324 bset_obj_store(aTHX_ bstate, obj, bstate->bs_ix) : \
325 (bstate->bs_obj_list[bstate->bs_ix] = obj), \
328 #define BSET_signal(cv, name) \
329 mg_set(*hv_store(GvHV(gv_fetchpv("SIG", TRUE, SVt_PVHV)), \
330 name, strlen(name), cv, 0))
332 /* NOTE: the bytecode header only sanity-checks the bytecode. If a script cares about
333 * what version of Perl it's being called under, it should do a 'use 5.006_001' or
334 * equivalent. However, since the header includes checks requiring an exact match in
335 * ByteLoader versions (we can't guarantee forward compatibility), you don't
336 * need to specify one:
342 #define HEADER_FAIL(f) \
343 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f)
344 #define HEADER_FAIL1(f, arg1) \
345 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1)
346 #define HEADER_FAIL2(f, arg1, arg2) \
347 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1, arg2)
349 #define BYTECODE_HEADER_CHECK \
354 BGET_U32(sz); /* Magic: 'PLBC' */ \
355 if (sz != 0x43424c50) { \
356 HEADER_FAIL1("bad magic (want 0x43424c50, got %#x)", (int)sz); \
358 BGET_strconst(str); /* archname */ \
359 if (strNE(str, ARCHNAME)) { \
360 HEADER_FAIL2("wrong architecture (want %s, you have %s)",str,ARCHNAME); \
362 BGET_strconst(str); /* ByteLoader version */ \
363 if (strNE(str, VERSION)) { \
364 HEADER_FAIL2("mismatched ByteLoader versions (want %s, you have %s)", \
367 BGET_U32(sz); /* ivsize */ \
368 if (sz != IVSIZE) { \
369 HEADER_FAIL("different IVSIZE"); \
371 BGET_U32(sz); /* ptrsize */ \
372 if (sz != PTRSIZE) { \
373 HEADER_FAIL("different PTRSIZE"); \
375 BGET_strconst(str); /* byteorder */ \
376 if (strNE(str, STRINGIFY(BYTEORDER))) { \
377 HEADER_FAIL("different byteorder"); \