2 #define PERL_NO_GET_CONTEXT
9 #include "hook_op_check_entersubforcv.h"
11 /* lifted from op.c */
13 #define LINKLIST(o) ((o)->op_next ? (o)->op_next : linklist((OP*)o))
15 STATIC OP *lift_cb(pTHX_ OP *o, CV *cv, void *user_data) {
19 OP *curop, *kid, *saved_next;
20 I32 type = o->op_type;
22 /* shamelessly lifted from fold_constants in op.c */
28 if (0) { /* call as macro */
31 /* this means the argument pushing ops are not executed, only the GV to
32 * resolve the call is, and B::OP objects will be made of all the opcodes
34 PUSHMARK(SP); /* push a mark for the arguments */
36 /* push an arg for every sibling op */
37 for ( arg = curop->op_sibling; arg->op_sibling; arg = arg->op_sibling ) {
38 XPUSHs(sv_bless(newRV_inc(newSViv(PTR2IV(arg))), gv_stashpv("B::LISTOP", 0)));
41 /* find the last non null before the lifted entersub */
42 for ( kid = curop; kid->op_next != o; kid = kid->op_next ) {
43 if ( kid->op_type == OP_GV )
47 PL_op = gv; /* make the call to our sub without evaluating the arg ops */
52 /* stop right after the call */
53 saved_next = o->op_next;
61 if (SP > stack_save) { /* sub returned something */
63 if (o->op_targ && sv == PAD_SV(o->op_targ)) /* grab pad temp? */
64 pad_swipe(o->op_targ, FALSE);
65 else if (SvTEMP(sv)) { /* grab mortal temp? */
66 (void)SvREFCNT_inc(sv);
70 if (SvROK(sv) && sv_derived_from(sv, "B::OP")) {
71 OP *new = INT2PTR(OP *,SvIV((SV *)SvRV(sv)));
72 new->op_sibling = NULL;
74 /* FIXME this is bullshit */
75 if ( (PL_opargs[new->op_type] & OA_CLASS_MASK) != OA_SVOP ) {
76 new->op_next = saved_next;
85 return newGVOP(OP_GV, 0, (GV*)sv);
87 if (SvTYPE(sv) == SVt_NULL) {
89 return newOP(OP_NULL, 0);
92 return newSVOP(OP_CONST, 0, sv);
94 /* this bit not lifted, handles the 'sub doesn't return stuff' case
95 which fold_constants can ignore */
97 return newOP(OP_NULL, 0);
101 MODULE = Devel::BeginLift PACKAGE = Devel::BeginLift
106 setup_for_cv (class, CV *cv)
108 RETVAL = (UV)hook_op_check_entersubforcv (cv, lift_cb, NULL);
113 teardown_for_cv (class, UV id)
115 hook_op_check_entersubforcv_remove ((hook_op_check_id)id);