localize %INC in a Safe compartment so that use/require work
Gurusamy Sarathy [Fri, 30 Jun 2000 02:05:28 +0000 (02:05 +0000)]
(many other magic globals probably need similar treatment)

p4raw-id: //depot/perl@6285

ext/Opcode/Opcode.xs

index 581cbc9..e191ec7 100644 (file)
@@ -250,7 +250,7 @@ PPCODE:
     save_aptr(&PL_endav);
     PL_endav = (AV*)sv_2mortal((SV*)newAV()); /* ignore END blocks for now     */
 
-    save_hptr(&PL_defstash);           /* save current default stack   */
+    save_hptr(&PL_defstash);           /* save current default stash   */
     /* the assignment to global defstash changes our sense of 'main'   */
     PL_defstash = gv_stashpv(Package, GV_ADDWARN); /* should exist already     */
     save_hptr(&PL_curstash);
@@ -263,6 +263,10 @@ PPCODE:
     sv_free((SV*)GvHV(gv));
     GvHV(gv) = (HV*)SvREFCNT_inc(PL_defstash);
 
+    /* %INC must be clean for use/require in compartment */
+    save_hash(PL_incgv);
+    GvHV(PL_incgv) = (HV*)SvREFCNT_inc(GvHV(gv_HVadd(gv_fetchpv("INC",TRUE,SVt_PVHV))));
+
     PUSHMARK(SP);
     perl_call_sv(codesv, GIMME|G_EVAL|G_KEEPERR); /* use callers context */
     SPAGAIN; /* for the PUTBACK added by xsubpp */