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)
26 #define BGET_I32(arg) BGET_U32(arg)
27 #define BGET_IV(arg) BGET_UV(arg)
29 #define BGET_PV(arg) STMT_START { \
32 New(666, bstate->bs_pv.xpv_pv, arg, char); \
33 bl_read(bstate->bs_fdata, (void*)bstate->bs_pv.xpv_pv, arg, 1);\
34 bstate->bs_pv.xpv_len = arg; \
35 bstate->bs_pv.xpv_cur = arg - 1; \
37 bstate->bs_pv.xpv_pv = 0; \
38 bstate->bs_pv.xpv_len = 0; \
39 bstate->bs_pv.xpv_cur = 0; \
43 #ifdef BYTELOADER_LOG_COMMENTS
44 # define BGET_comment_t(arg) \
50 buf[i++] = (char)arg; \
51 } while (arg != '\n' && arg != EOF); \
53 PerlIO_printf(PerlIO_stderr(), "%s", buf); \
56 # define BGET_comment_t(arg) \
57 do { arg = BGET_FGETC(); } while (arg != '\n' && arg != EOF)
61 #define BGET_op_tr_array(arg) do { \
62 unsigned short *ary, len; \
64 New(666, ary, len, unsigned short); \
65 BGET_FREAD(ary, sizeof(unsigned short), len); \
69 #define BGET_pvcontents(arg) arg = bstate->bs_pv.xpv_pv
70 #define BGET_strconst(arg) STMT_START { \
71 for (arg = PL_tokenbuf; (*arg = BGET_FGETC()); arg++) /* nothing */; \
75 #define BGET_NV(arg) STMT_START { \
81 #define BGET_objindex(arg, type) STMT_START { \
83 arg = (type)bstate->bs_obj_list[ix]; \
85 #define BGET_svindex(arg) BGET_objindex(arg, svindex)
86 #define BGET_opindex(arg) BGET_objindex(arg, opindex)
87 #define BGET_pvindex(arg) STMT_START { \
88 BGET_objindex(arg, pvindex); \
89 arg = arg ? savepv(arg) : arg; \
92 #define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
93 #define BSET_ldspecsvx(sv, arg) STMT_START { \
94 BSET_ldspecsv(sv, arg); \
95 BSET_OBJ_STOREX(sv); \
98 #define BSET_stpv(pv, arg) STMT_START { \
99 BSET_OBJ_STORE(pv, arg); \
103 #define BSET_sv_refcnt_add(svrefcnt, arg) svrefcnt += arg
104 #define BSET_gp_refcnt_add(gprefcnt, arg) gprefcnt += arg
105 #define BSET_gp_share(sv, arg) STMT_START { \
107 GvGP(sv) = GvGP(arg); \
110 #define BSET_gv_fetchpv(sv, arg) sv = (SV*)gv_fetchpv(arg, TRUE, SVt_PV)
111 #define BSET_gv_fetchpvx(sv, arg) STMT_START { \
112 BSET_gv_fetchpv(sv, arg); \
113 BSET_OBJ_STOREX(sv); \
116 #define BSET_gv_stashpv(sv, arg) sv = (SV*)gv_stashpv(arg, TRUE)
117 #define BSET_gv_stashpvx(sv, arg) STMT_START { \
118 BSET_gv_stashpv(sv, arg); \
119 BSET_OBJ_STOREX(sv); \
122 #define BSET_sv_magic(sv, arg) sv_magic(sv, Nullsv, arg, 0, 0)
123 #define BSET_mg_name(mg, arg) mg->mg_ptr = arg; mg->mg_len = bstate->bs_pv.xpv_cur
124 #define BSET_mg_namex(mg, arg) \
125 (mg->mg_ptr = (char*)SvREFCNT_inc((SV*)arg), \
126 mg->mg_len = HEf_SVKEY)
127 #define BSET_sv_upgrade(sv, arg) (void)SvUPGRADE(sv, arg)
128 #define BSET_xpv(sv) do { \
129 SvPV_set(sv, bstate->bs_pv.xpv_pv); \
130 SvCUR_set(sv, bstate->bs_pv.xpv_cur); \
131 SvLEN_set(sv, bstate->bs_pv.xpv_len); \
133 #define BSET_av_extend(sv, arg) av_extend((AV*)sv, arg)
135 #define BSET_av_push(sv, arg) av_push((AV*)sv, arg)
136 #define BSET_av_pushx(sv, arg) (AvARRAY(sv)[++AvFILLp(sv)] = arg)
137 #define BSET_hv_store(sv, arg) \
138 hv_store((HV*)sv, bstate->bs_pv.xpv_pv, bstate->bs_pv.xpv_cur, arg, 0)
139 #define BSET_pv_free(pv) Safefree(pv.xpv_pv)
144 /* copied after the code in newPMOP() */
145 #define BSET_pregcomp(o, arg) \
149 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)) : \
151 if(av_len((AV*) PL_regex_pad[0]) > -1) { \
152 repointer = av_pop((AV*)PL_regex_pad[0]); \
153 cPMOPx(o)->op_pmoffset = SvIV(repointer); \
154 SvREPADTMP_off(repointer); \
155 sv_setiv(repointer,PTR2IV(rx)); \
157 repointer = newSViv(PTR2IV(rx)); \
158 av_push(PL_regex_padav,SvREFCNT_inc(repointer)); \
159 cPMOPx(o)->op_pmoffset = av_len(PL_regex_padav); \
160 PL_regex_pad = AvARRAY(PL_regex_padav); \
165 #define BSET_pregcomp(o, arg) \
167 PM_SETRE(((PMOP*)o), (arg ? \
168 CALLREGCOMP(aTHX_ arg, arg + bstate->bs_pv.xpv_cur, cPMOPx(o)): \
172 #endif /* USE_THREADS */
175 #define BSET_newsv(sv, arg) \
185 SvUPGRADE(sv, (arg)); \
187 #define BSET_newsvx(sv, arg) STMT_START { \
188 BSET_newsv(sv, arg & SVTYPEMASK); \
190 BSET_OBJ_STOREX(sv); \
192 #define BSET_newop(o, arg) \
193 ((o = (OP*)safemalloc(arg)), memzero((char*)o,arg))
194 #define BSET_newopx(o, arg) STMT_START { \
195 register int sz = arg & 0x7f; \
196 register OP* new = (OP*) safemalloc(sz);\
198 /* new->op_next = o; XXX */ \
201 BSET_op_type(o, arg); \
202 BSET_OBJ_STOREX(o); \
205 #define BSET_newopn(o, arg) STMT_START { \
207 BSET_newop(o, arg); \
208 oldop->op_next = o; \
211 #define BSET_ret(foo) STMT_START { \
212 Safefree(bstate->bs_obj_list); \
217 * stolen from toke.c: better if that was a function.
218 * in toke.c there are also #ifdefs for dosish systems and i/o layers
221 #if defined(HAS_FCNTL) && defined(F_SETFD)
222 #define set_clonex(fp) \
224 int fd = PerlIO_fileno(fp); \
225 fcntl(fd,F_SETFD,fd >= 3); \
228 #define set_clonex(fp)
231 #define BSET_data(dummy,arg) \
234 char *pname = "main"; \
236 pname = HvNAME(PL_curstash ? PL_curstash : PL_defstash); \
237 gv = gv_fetchpv(Perl_form(aTHX_ "%s::DATA", pname), TRUE, SVt_PVIO);\
240 GvIOp(gv) = newIO(); \
241 IoIFP(GvIOp(gv)) = PL_rsfp; \
242 set_clonex(PL_rsfp); \
243 /* Mark this internal pseudo-handle as clean */ \
244 IoFLAGS(GvIOp(gv)) |= IOf_UNTAINT; \
246 IoTYPE(GvIOp(gv)) = IoTYPE_PIPE; \
247 else if ((PerlIO*)PL_rsfp == PerlIO_stdin()) \
248 IoTYPE(GvIOp(gv)) = IoTYPE_STD; \
250 IoTYPE(GvIOp(gv)) = IoTYPE_RDONLY; \
251 Safefree(bstate->bs_obj_list); \
255 /* stolen from op.c */
256 #define BSET_load_glob(foo, gv) \
260 Perl_load_module(aTHX_ PERL_LOADMOD_NOIMPORT, \
261 newSVpvn("File::Glob", 10), Nullsv, Nullsv, Nullsv); \
262 glob_gv = gv_fetchpv("File::Glob::csh_glob", FALSE, SVt_PVCV); \
263 GvCV(gv) = GvCV(glob_gv); \
264 SvREFCNT_inc((SV*)GvCV(gv)); \
265 GvIMPORTED_CV_on(gv); \
270 * Kludge special-case workaround for OP_MAPSTART
271 * which needs the ppaddr for OP_GREPSTART. Blech.
273 #define BSET_op_type(o, arg) STMT_START { \
275 if (arg == OP_MAPSTART) \
276 arg = OP_GREPSTART; \
277 o->op_ppaddr = PL_ppaddr[arg]; \
279 #define BSET_op_ppaddr(o, arg) Perl_croak(aTHX_ "op_ppaddr not yet implemented")
280 #define BSET_curpad(pad, arg) STMT_START { \
281 PL_comppad = (AV *)arg; \
282 pad = AvARRAY(arg); \
286 #define BSET_cop_file(cop, arg) CopFILE_set(cop,arg)
287 #define BSET_cop_stashpv(cop, arg) CopSTASHPV_set(cop,arg)
289 /* this works now that Sarathy's changed the CopFILE_set macro to do the SvREFCNT_inc()
291 /* that really meant the actual CopFILEGV_set */
292 #define BSET_cop_filegv(cop, arg) CopFILEGV_set(cop,arg)
293 #define BSET_cop_stash(cop,arg) CopSTASH_set(cop,(HV*)arg)
296 /* this is simply stolen from the code in newATTRSUB() */
297 #define BSET_push_begin(ary,cv) \
299 I32 oldscope = PL_scopestack_ix; \
301 SAVECOPFILE(&PL_compiling); \
302 SAVECOPLINE(&PL_compiling); \
304 PL_beginav = newAV(); \
305 av_push(PL_beginav, (SV*)cv); \
306 GvCV(CvGV(cv)) = 0; /* cv has been hijacked */\
307 call_list(oldscope, PL_beginav); \
308 PL_curcop = &PL_compiling; \
309 PL_compiling.op_private = (U8)(PL_hints & HINT_PRIVATE_MASK);\
312 #define BSET_push_init(ary,cv) \
314 av_unshift((PL_initav ? PL_initav : \
315 (PL_initav = newAV(), PL_initav)), 1); \
316 av_store(PL_initav, 0, cv); \
318 #define BSET_push_end(ary,cv) \
320 av_unshift((PL_endav ? PL_endav : \
321 (PL_endav = newAV(), PL_endav)), 1); \
322 av_store(PL_endav, 0, cv); \
324 #define BSET_OBJ_STORE(obj, ix) \
325 ((I32)ix > bstate->bs_obj_list_fill ? \
326 bset_obj_store(aTHX_ bstate, obj, (I32)ix) : \
327 (bstate->bs_obj_list[ix] = obj), \
328 bstate->bs_ix = ix+1)
329 #define BSET_OBJ_STOREX(obj) \
330 (bstate->bs_ix > bstate->bs_obj_list_fill ? \
331 bset_obj_store(aTHX_ bstate, obj, bstate->bs_ix) : \
332 (bstate->bs_obj_list[bstate->bs_ix] = obj), \
335 #define BSET_signal(cv, name) \
336 mg_set(*hv_store(GvHV(gv_fetchpv("SIG", TRUE, SVt_PVHV)), \
337 name, strlen(name), cv, 0))
339 /* NOTE: the bytecode header only sanity-checks the bytecode. If a script cares about
340 * what version of Perl it's being called under, it should do a 'use 5.006_001' or
341 * equivalent. However, since the header includes checks requiring an exact match in
342 * ByteLoader versions (we can't guarantee forward compatibility), you don't
343 * need to specify one:
349 #define HEADER_FAIL(f) \
350 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f)
351 #define HEADER_FAIL1(f, arg1) \
352 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1)
353 #define HEADER_FAIL2(f, arg1, arg2) \
354 Perl_croak(aTHX_ "Invalid bytecode for this architecture: " f, arg1, arg2)
356 #define BYTECODE_HEADER_CHECK \
361 BGET_U32(sz); /* Magic: 'PLBC' */ \
362 if (sz != 0x43424c50) { \
363 HEADER_FAIL1("bad magic (want 0x43424c50, got %#x)", (int)sz); \
365 BGET_strconst(str); /* archname */ \
366 if (strNE(str, ARCHNAME)) { \
367 HEADER_FAIL2("wrong architecture (want %s, you have %s)",str,ARCHNAME); \
369 BGET_strconst(str); /* ByteLoader version */ \
370 if (strNE(str, VERSION)) { \
371 HEADER_FAIL2("mismatched ByteLoader versions (want %s, you have %s)", \
374 BGET_U32(sz); /* ivsize */ \
375 if (sz != IVSIZE) { \
376 HEADER_FAIL("different IVSIZE"); \
378 BGET_U32(sz); /* ptrsize */ \
379 if (sz != PTRSIZE) { \
380 HEADER_FAIL("different PTRSIZE"); \