+/* --- Module setup/teardown ----------------------------------------------- */
+
+static void xsh_user_global_setup(pTHX) {
+ xsh_ck_replace(OP_CONST, indirect_ck_const, &indirect_old_ck_const);
+ xsh_ck_replace(OP_RV2SV, indirect_ck_rv2sv, &indirect_old_ck_rv2sv);
+ xsh_ck_replace(OP_PADANY, indirect_ck_padany, &indirect_old_ck_padany);
+ xsh_ck_replace(OP_SCOPE, indirect_ck_scope, &indirect_old_ck_scope);
+ xsh_ck_replace(OP_LINESEQ, indirect_ck_scope, &indirect_old_ck_lineseq);
+
+ xsh_ck_replace(OP_METHOD, indirect_ck_method,
+ &indirect_old_ck_method);
+ xsh_ck_replace(OP_METHOD_NAMED, indirect_ck_method_named,
+ &indirect_old_ck_method_named);
+ xsh_ck_replace(OP_ENTERSUB, indirect_ck_entersub,
+ &indirect_old_ck_entersub);
+
+ return;
+}
+
+static void xsh_user_local_setup(pTHX_ xsh_user_cxt_t *cxt) {
+ HV *stash;
+
+ stash = gv_stashpvn(XSH_PACKAGE, XSH_PACKAGE_LEN, 1);
+ newCONSTSUB(stash, "I_THREADSAFE", newSVuv(XSH_THREADSAFE));
+ newCONSTSUB(stash, "I_FORKSAFE", newSVuv(XSH_FORKSAFE));
+
+ cxt->map = ptable_new(32);
+ cxt->global_code = NULL;
+
+ return;
+}
+
+static void xsh_user_local_teardown(pTHX_ xsh_user_cxt_t *cxt) {
+ SvREFCNT_dec(cxt->global_code);
+ cxt->global_code = NULL;
+
+ ptable_free(cxt->map);
+ cxt->map = NULL;
+
+ return;
+}
+
+static void xsh_user_global_teardown(pTHX) {
+ xsh_ck_restore(OP_CONST, &indirect_old_ck_const);
+ xsh_ck_restore(OP_RV2SV, &indirect_old_ck_rv2sv);
+ xsh_ck_restore(OP_PADANY, &indirect_old_ck_padany);
+ xsh_ck_restore(OP_SCOPE, &indirect_old_ck_scope);
+ xsh_ck_restore(OP_LINESEQ, &indirect_old_ck_lineseq);
+
+ xsh_ck_restore(OP_METHOD, &indirect_old_ck_method);
+ xsh_ck_restore(OP_METHOD_NAMED, &indirect_old_ck_method_named);
+ xsh_ck_restore(OP_ENTERSUB, &indirect_old_ck_entersub);
+
+ return;
+}