--- Stash.xs	Mon Jan  7 11:40:15 2002
+++ Stash.xs	Tue Feb 12 15:20:01 2002
@@ -38,6 +38,7 @@
 extern "C" {
 #endif
 
+#define PERL_NO_GET_CONTEXT
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"
@@ -64,44 +65,44 @@
 
 typedef enum tt_ret { TT_RET_UNDEF, TT_RET_OK, TT_RET_CODEREF } TT_RET;
 
-static TT_RET	hash_op(SV*, char*, AV*, SV**);
-static TT_RET	list_op(SV*, char*, AV*, SV**);
-static TT_RET	scalar_op(SV*, char*, AV*, SV**);
-static TT_RET	tt_fetch_item(SV*, SV*, AV*, SV**);
-static SV*	dotop(SV*, SV*, AV*, int);
-static SV* 	call_coderef(SV*, AV*);
-static SV*	fold_results(I32);
-static SV*	find_perl_op(char*, char*);
-static AV*	mk_mortal_av(SV*, AV*, SV*);
-static SV*	do_getset(SV*, AV*, SV*, int);
-static AV*	convert_dotted_string(const char*, I32);
-static int	get_debug_flag(SV*);
+static TT_RET	hash_op(pTHX_ SV*, char*, AV*, SV**);
+static TT_RET	list_op(pTHX_ SV*, char*, AV*, SV**);
+static TT_RET	scalar_op(pTHX_ SV*, char*, AV*, SV**);
+static TT_RET	tt_fetch_item(pTHX_ SV*, SV*, AV*, SV**);
+static SV*	dotop(pTHX_ SV*, SV*, AV*, int);
+static SV* 	call_coderef(pTHX_ SV*, AV*);
+static SV*	fold_results(pTHX_ I32);
+static SV*	find_perl_op(pTHX_ char*, char*);
+static AV*	mk_mortal_av(pTHX_ SV*, AV*, SV*);
+static SV*	do_getset(pTHX_ SV*, AV*, SV*, int);
+static AV*	convert_dotted_string(pTHX_ const char*, I32);
+static int	get_debug_flag(pTHX_ SV*);
 static int	cmp_arg(const void *, const void *);
-static void   	die_object(SV *);
+static void   	die_object(pTHX_ SV *);
 static struct xs_arg *find_xs_op(char *);
-static SV*	list_dot_first(AV*, AV*);
-static SV*	list_dot_join(AV*, AV*);
-static SV*	list_dot_last(AV*, AV*);
-static SV*	list_dot_max(AV*, AV*);
-static SV*	list_dot_reverse(AV*, AV*);
-static SV*	list_dot_size(AV*, AV*);
-static SV*	hash_dot_each(HV*, AV*);
-static SV*	hash_dot_keys(HV*, AV*);
-static SV*	hash_dot_values(HV*, AV*);
-static SV*	scalar_dot_defined(SV*, AV*);
-static SV*	scalar_dot_length(SV*, AV*);
+static SV*	list_dot_first(pTHX_ AV*, AV*);
+static SV*	list_dot_join(pTHX_ AV*, AV*);
+static SV*	list_dot_last(pTHX_ AV*, AV*);
+static SV*	list_dot_max(pTHX_ AV*, AV*);
+static SV*	list_dot_reverse(pTHX_ AV*, AV*);
+static SV*	list_dot_size(pTHX_ AV*, AV*);
+static SV*	hash_dot_each(pTHX_ HV*, AV*);
+static SV*	hash_dot_keys(pTHX_ HV*, AV*);
+static SV*	hash_dot_values(pTHX_ HV*, AV*);
+static SV*	scalar_dot_defined(pTHX_ SV*, AV*);
+static SV*	scalar_dot_length(pTHX_ SV*, AV*);
 
 static char rcsid[] = 
 	"$Id: Stash.xs,v 1.5 2001/10/23 12:33:43 abw Exp $";
 
 /* dispatch table for XS versions of special "virtual methods",
  * names must be in alphabetical order 		
- */
+*/
 static const struct xs_arg {
 	const char *name;
-	SV* (*list_f)   (AV*, AV*);
-	SV* (*hash_f)   (HV*, AV*);
-	SV* (*scalar_f) (SV*, AV*);
+	SV* (*list_f)   (pTHX_ AV*, AV*);
+	SV* (*hash_f)   (pTHX_ HV*, AV*);
+	SV* (*scalar_f) (pTHX_ SV*, AV*);
 } xs_args[] = {
     /* name	 list (AV) ops.	   hash (HV) ops.   scalar (SV) ops.
        --------	 ----------------  ---------------  ------------------  */
@@ -302,7 +303,7 @@
 
 
 /*------------------------------------------------------------------------
- * tt_fetch_item(SV *root, SV *key_sv, AV *args, SV **result)
+ * tt_fetch_item(pTHX_ SV *root, SV *key_sv, AV *args, SV **result)
  *
  * Retrieves an item from the given hash or array ref.  If item is found
  * and a coderef then the coderef will be called and passed args.  Returns
@@ -310,7 +311,7 @@
  * TT_RET_UNDEF and result is undefined.
  *------------------------------------------------------------------------*/
 
-static TT_RET tt_fetch_item(SV *root, SV *key_sv, AV *args, SV **result) {
+static TT_RET tt_fetch_item(pTHX_ SV *root, SV *key_sv, AV *args, SV **result) {
     STRLEN key_len;
     char *key = SvPV(key_sv, key_len);
     SV **value = NULL;
@@ -338,7 +339,7 @@
 	if (SvROK(*value) 
 		&& (SvTYPE(SvRV(*value)) == SVt_PVCV) 
 		&& !sv_isobject(*value)) {
-	    *result = call_coderef(*value, args);
+	    *result = call_coderef(aTHX_ *value, args);
 	    return TT_RET_CODEREF;
 
 	} 
@@ -355,7 +356,7 @@
 
 
 /*------------------------------------------------------------------------
- * dotop(SV *root, SV *key_sv, AV *args, int flags)
+ * dotop(pTHX_ SV *root, SV *key_sv, AV *args, int flags)
  *
  * Resolves dot operations of the form root.key, where 'root' is a
  * reference to the root item, 'key_sv' is an SV containing the
@@ -366,7 +367,7 @@
  * debug flag.
  *------------------------------------------------------------------------*/
 
-static SV *dotop(SV *root, SV *key_sv, AV *args, int flags) {
+static SV *dotop(pTHX_ SV *root, SV *key_sv, AV *args, int flags) {
     dSP;
     STRLEN item_len;
     char *item = SvPV(key_sv, item_len);
@@ -384,7 +385,7 @@
 
         /* root is a HASH or Template::Stash */
 
-	switch(tt_fetch_item(root, key_sv, args, &result)) {
+	switch(tt_fetch_item(aTHX_ root, key_sv, args, &result)) {
 	case TT_RET_OK:
 	    /* return immediately */
 	    return result;
@@ -410,7 +411,7 @@
 	    }
 
 	    /* try hash pseudo-method */
-	    if (hash_op(root, item, args, &result) == TT_RET_UNDEF) {
+	    if (hash_op(aTHX_ root, item, args, &result) == TT_RET_UNDEF) {
 		/* try hash slice */ 
 		if (SvROK(key_sv) && SvTYPE(SvRV(key_sv)) == SVt_PVAV) {
 		    AV *a_av = newAV();
@@ -444,9 +445,9 @@
 
         /* try list pseudo-method, but not for lvalues */
 	if ((flags & TT_LVALUE_FLAG) ||
-		(list_op(root, item, args, &result) == TT_RET_UNDEF)) {
+		(list_op(aTHX_ root, item, args, &result) == TT_RET_UNDEF)) {
 
-	    switch (tt_fetch_item(root, key_sv, args, &result)) {
+	    switch (tt_fetch_item(aTHX_ root, key_sv, args, &result)) {
 	    case TT_RET_OK:
 		return result;
 		break;
@@ -515,26 +516,26 @@
 
 		if (SvROK(ERRSV) || !strstr(SvPV(ERRSV, PL_na), 
 			"Can't locate object method")) {
-		    die_object(ERRSV);
+		    die_object(aTHX_ ERRSV);
 		}
 	    } else {
-		result = fold_results(n);
+		result = fold_results(aTHX_ n);
 	    }
 	}
 
 	if (!result) {
 	    /* failed to call object method, so try some fallbacks */
 	    if ((SvTYPE(SvRV(root)) == SVt_PVHV)
-		&& ((n = tt_fetch_item(root, key_sv, args, &result)) != TT_RET_UNDEF)) {
+		&& ((n = tt_fetch_item(aTHX_ root, key_sv, args, &result)) != TT_RET_UNDEF)) {
 		if (n == TT_RET_OK) {
 		    return result;
 		}
 
 	    } 
 	    else if ((SvTYPE(SvRV(root)) == SVt_PVAV)
-		     && (list_op(root, item, args, &result) == TT_RET_UNDEF)) {
+		     && (list_op(aTHX_ root, item, args, &result) == TT_RET_UNDEF)) {
 		if (flags & TT_DEBUG_FLAG)
-		    result = (SV *) mk_mortal_av(&PL_sv_undef, NULL, ERRSV);
+		    result = (SV *) mk_mortal_av(aTHX_ &PL_sv_undef, NULL, ERRSV);
 	    }
 	}
     }
@@ -544,7 +545,7 @@
      */
 
     else if (!(flags & TT_LVALUE_FLAG) 
-	     && (scalar_op(root, item, args, &result) == TT_RET_UNDEF)) {
+	     && (scalar_op(aTHX_ root, item, args, &result) == TT_RET_UNDEF)) {
 	if (flags & TT_DEBUG_FLAG)
 	    croak("don't know how to access [ %s ].%s\n", 
 		SvPV(root, PL_na), item);
@@ -565,7 +566,7 @@
 		return result;
 	    } else if (len > 1 && (svp = av_fetch(array, 1, FALSE)) &&
 			(*svp != &PL_sv_undef)) {
-		die_object(*svp);
+		die_object(aTHX_ *svp);
 	    }
 	}
     } 
@@ -580,7 +581,7 @@
 
 
 /*------------------------------------------------------------------------
- * assign(SV *root, SV *key_sv, AV *args, SV *value, int flags)
+ * assign(pTHX_ SV *root, SV *key_sv, AV *args, SV *value, int flags)
  *
  * Resolves the final assignment element of a dotted compound variable
  * of the form "root.key(args) = value".  'root' is a reference to
@@ -592,7 +593,7 @@
  * if the item is currently undefined/false.
  *------------------------------------------------------------------------*/
 
-static SV *assign(SV *root, SV *key_sv, AV *args, SV *value, int flags) {
+static SV *assign(pTHX_ SV *root, SV *key_sv, AV *args, SV *value, int flags) {
     dSP;
     SV **svp, *newsv;
     HV *roothv;
@@ -631,7 +632,7 @@
 		count = perl_call_method(key, G_ARRAY);
 	        TT_PERF_END;
 		SPAGAIN;
-		return fold_results(count);		
+		return fold_results(aTHX_ count);		
 	    }
 	}
 
@@ -708,7 +709,7 @@
 /* dies and passes back a blessed object,  
  * or just a string if it's not blessed 
  */
-static void die_object (SV *err) {
+static void die_object (pTHX_ SV *err) {
 
     if (sv_isobject(err)) {
 	/* throw object via ERRSV ($@) */
@@ -725,7 +726,7 @@
 /* pushes any arguments in 'args' onto the stack then calls the code ref
  * in 'code'.  Calls fold_results() to return a listref or die.
  */
-static SV *call_coderef(SV *code, AV *args) {
+static SV *call_coderef(pTHX_ SV *code, AV *args) {
     dSP;
     SV **svp;
     I32 count = (args && args != Nullav) ? av_len(args) : -1;
@@ -739,7 +740,7 @@
     count = perl_call_sv(code, G_ARRAY);
     SPAGAIN;
 
-    return fold_results(count);
+    return fold_results(aTHX_ count);
 }
 
 
@@ -748,7 +749,7 @@
  * Returns undef if count == 0. 
  * Dies if first value of list is undef
  */
-static SV* fold_results(I32 count) {
+static SV* fold_results(pTHX_ I32 count) {
     dSP;
     SV *retval = &PL_sv_undef;
 
@@ -772,7 +773,7 @@
 
 	if (!SvOK(sv) || sv == &PL_sv_undef) {
 	    /* if first element was undef, die */
-	    die_object(last_sv);
+	    die_object(aTHX_ last_sv);
 	} 
 	return retval;
 
@@ -788,13 +789,11 @@
 /* Iterates through array calling dotop() to resolve all items
  * Skips the last if ''value'' is non-NULL.
  * If ''value'' is non-NULL, calls assign() to do the assignment.
- */
-static SV *do_getset(root, ident_av, value, flags)
-    SV *root; 
-    AV *ident_av; 
-    SV *value; 
-    int flags;
-{
+ *
+ * SV *root; AV *ident_av; SV *value; int flags;
+ *
+*/
+static SV* do_getset(pTHX_ SV *root, AV *ident_av, SV *value, int flags) {
     AV *key_args;
     SV *key;
     SV **svp;
@@ -823,7 +822,7 @@
 	else
 	    key_args = Nullav;
 		
-	root = dotop(root, key, key_args, flags);
+	root = dotop(aTHX_ root, key, key_args, flags);
 
 	if (!root || !SvOK(root))
 	    return root;
@@ -845,7 +844,7 @@
 	else
 	    key_args = Nullav;
 
-	return assign(root, key, key_args, value, flags);
+	return assign(aTHX_ root, key, key_args, value, flags);
     }
 
     return root;
@@ -854,7 +853,7 @@
 
 /* return [ map { s/\(.*$//; ($_, 0) } split(/\./, $str) ];
  */
-static AV *convert_dotted_string(const char *str, I32 len) {
+static AV *convert_dotted_string(pTHX_ const char *str, I32 len) {
     AV *av = newAV();
     char *buf, *b;
     int b_len = 0;
@@ -888,7 +887,7 @@
  * (e.g. keys, * values, each) on 'hash'.
  * returns TT_RET_CODEREF if successful, TT_RET_UNDEF otherwise.
  */
-static TT_RET hash_op(SV *root, char *key, AV *args, SV **result) {
+static TT_RET hash_op(pTHX_ SV *root, char *key, AV *args, SV **result) {
     struct xs_arg *a;
     SV *code;
     TT_PERF_INIT;
@@ -896,15 +895,15 @@
     /* look for XS version first */
     if ((a = find_xs_op(key)) && a->hash_f) {
 	TT_PERF_START(hv_op_cnt, hv_op_cnt_xs, key, perf_hv_hit_xs);
-	*result = a->hash_f((HV *) SvRV(root), args);
+	*result = a->hash_f(aTHX_ (HV *) SvRV(root), args);
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
 
     /* look for perl version in Template::Stash module */
-    if ((code = find_perl_op(key, TT_HASH_OPS))) {
+    if ((code = find_perl_op(aTHX_ key, TT_HASH_OPS))) {
 	TT_PERF_START(hv_op_cnt, hv_op_cnt_pl, key, perf_hv_hit_pl);
-	*result = call_coderef(code, mk_mortal_av(root, args, NULL)); 
+	*result = call_coderef(aTHX_ code, mk_mortal_av(aTHX_ root, args, NULL)); 
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
@@ -920,7 +919,7 @@
  * Additional arguments may be passed in 'args'. 
  * returns TT_RET_CODEREF if successful, TT_RET_UNDEF otherwise.
  */
-static TT_RET list_op(SV *root, char *key, AV *args, SV **result) {
+static TT_RET list_op(pTHX_ SV *root, char *key, AV *args, SV **result) {
     struct xs_arg *a;
     SV *code;
     TT_PERF_INIT;
@@ -928,15 +927,15 @@
     /* look for and execute XS version first */
     if ((a = find_xs_op(key)) && a->list_f) {
 	TT_PERF_START(av_op_cnt, av_op_cnt_xs, key, perf_av_hit_xs);
-	*result = a->list_f((AV *) SvRV(root), args);
+	*result = a->list_f(aTHX_ (AV *) SvRV(root), args);
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
 
     /* look for and execute perl version in Template::Stash module */
-    if ((code = find_perl_op(key, TT_LIST_OPS))) {
+    if ((code = find_perl_op(aTHX_ key, TT_LIST_OPS))) {
 	TT_PERF_START(av_op_cnt, av_op_cnt_pl, key, perf_av_hit_pl);
-	*result = call_coderef(code, mk_mortal_av(root, args, NULL));
+	*result = call_coderef(aTHX_ code, mk_mortal_av(aTHX_ root, args, NULL));
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
@@ -952,7 +951,7 @@
  * on 'sv'.  Additional arguments may be passed in 'args'. 
  * returns TT_RET_CODEREF if successful, TT_RET_UNDEF otherwise.
  */
-static TT_RET scalar_op(SV *sv, char *key, AV *args, SV **result) {
+static TT_RET scalar_op(pTHX_ SV *sv, char *key, AV *args, SV **result) {
     struct xs_arg *a;
     SV *code;
     TT_PERF_INIT;
@@ -960,15 +959,15 @@
     /* look for a XS version first */
     if ((a = find_xs_op(key)) && a->scalar_f) {
 	TT_PERF_START(sv_op_cnt, sv_op_cnt_xs, key, perf_sv_hit_xs);
-	*result = a->scalar_f(sv, args);
+	*result = a->scalar_f(aTHX_ sv, args);
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
 
     /* look for perl version in Template::Stash module */
-    if ((code = find_perl_op(key, TT_SCALAR_OPS))) {
+    if ((code = find_perl_op(aTHX_ key, TT_SCALAR_OPS))) {
 	TT_PERF_START(sv_op_cnt, sv_op_cnt_pl, key, perf_sv_hit_pl);
-	*result = call_coderef(code, mk_mortal_av(sv, args, NULL));
+	*result = call_coderef(aTHX_ code, mk_mortal_av(aTHX_ sv, args, NULL));
 	TT_PERF_END;
 	return TT_RET_CODEREF;
     }
@@ -1007,7 +1006,7 @@
 /* Searches the perl Template::Stash.pm module for ''key'' in the
  * hashref named ''perl_var''. Returns SV if found, NULL otherwise.
  */
-static SV *find_perl_op(char *key, char *perl_var) {
+static SV *find_perl_op(pTHX_ char *key, char *perl_var) {
     SV *tt_ops;
     SV **svp;
 
@@ -1023,7 +1022,7 @@
 
 
 /* Returns: @a = ($sv, @av, $more) */
-static AV *mk_mortal_av(SV *sv, AV *av, SV *more) {
+static AV *mk_mortal_av(pTHX_ SV *sv, AV *av, SV *more) {
     SV **svp;
     AV *a;
     I32 i = 0, size;
@@ -1048,7 +1047,7 @@
 
 
 /* Returns TT_DEBUG_FLAG if _DEBUG key is true in hashref ''sv''. */
-static int get_debug_flag (SV *sv) {
+static int get_debug_flag (pTHX_ SV *sv) {
     const char *key = "_DEBUG";
     const I32 len = 6;
     SV **debug;
@@ -1068,12 +1067,12 @@
  * ----------------------------------------- */
 
 /* list.first */
-static SV *list_dot_first(AV *list, AV *args) {
+static SV *list_dot_first(pTHX_ AV *list, AV *args) {
     SV **svp;
     if ((svp = av_fetch(list, 0, FALSE))) {
 	/* entry fetched from arry may be code ref */
 	if (SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVCV) {
-	    return call_coderef(*svp, args);
+	    return call_coderef(aTHX_ *svp, args);
 	} else {
 	    return *svp;
 	}
@@ -1083,7 +1082,7 @@
 
 
 /* list.join */
-static SV *list_dot_join(AV *list, AV *args) {
+static SV *list_dot_join(pTHX_ AV *list, AV *args) {
     SV **svp;
     SV *item, *retval;
     I32 size, i;
@@ -1103,7 +1102,7 @@
 	if ((svp = av_fetch(list, i, FALSE)) != NULL) {
 	    item = *svp;
 	    if (SvROK(item) && SvTYPE(SvRV(item)) == SVt_PVCV) {
-		item = call_coderef(*svp, args);
+		item = call_coderef(aTHX_ *svp, args);
 		sv_catsv(retval, item);
 	    } else {
 		sv_catsv(retval, item);
@@ -1117,13 +1116,13 @@
 
 
 /* list.last */
-static SV *list_dot_last(AV *list, AV *args) {
+static SV *list_dot_last(pTHX_ AV *list, AV *args) {
     SV **svp;
     if ((av_len(list) > -1)
 	&& (svp = av_fetch(list, av_len(list), FALSE))) {
 	/* entry fetched from arry may be code ref */
 	if (SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVCV) {
-	    return call_coderef(*svp, args);
+	    return call_coderef(aTHX_ *svp, args);
 	} else {
 	    return *svp;
 	}
@@ -1133,13 +1132,13 @@
  
 
 /* list.max */
-static SV *list_dot_max(AV *list, AV *args) {
+static SV *list_dot_max(pTHX_ AV *list, AV *args) {
     return sv_2mortal(newSViv((IV) av_len(list)));
 }
 
 
 /* list.reverse */
-static SV *list_dot_reverse(AV *list, AV *args) {
+static SV *list_dot_reverse(pTHX_ AV *list, AV *args) {
     SV **svp;
     AV *result = newAV();
     I32 size, i;
@@ -1157,13 +1156,13 @@
 
 
 /* list.size */
-static SV *list_dot_size(AV *list, AV *args) {
+static SV *list_dot_size(pTHX_ AV *list, AV *args) {
     return sv_2mortal(newSViv((IV) av_len(list) + 1));
 }
 
 
 /* hash.each */
-static SV *hash_dot_each(HV *hash, AV *args) {
+static SV *hash_dot_each(pTHX_ HV *hash, AV *args) {
     AV *result = newAV();
     HE *he;
     hv_iterinit(hash);
@@ -1176,7 +1175,7 @@
 
 
 /* hash.keys */
-static SV *hash_dot_keys(HV *hash, AV *args) {
+static SV *hash_dot_keys(pTHX_ HV *hash, AV *args) {
     AV *result = newAV();
     HE *he;
 
@@ -1189,7 +1188,7 @@
 
 
 /* hash.values */
-static SV *hash_dot_values(HV *hash, AV *args) {
+static SV *hash_dot_values(pTHX_ HV *hash, AV *args) {
     AV *result = newAV();
     HE *he;
 
@@ -1202,13 +1201,13 @@
 
 
 /* scalar.defined */
-static SV *scalar_dot_defined(SV *sv, AV *args) {
+static SV *scalar_dot_defined(pTHX_ SV *sv, AV *args) {
     return &PL_sv_yes;
 }
 
 
 /* scalar.length */
-static SV *scalar_dot_length(SV *sv, AV *args) {
+static SV *scalar_dot_length(pTHX_ SV *sv, AV *args) {
     STRLEN length;
     SvPV(sv, length);
 
@@ -1234,7 +1233,7 @@
     SV *ident
     CODE:
     AV *args;
-    int flags = get_debug_flag(root);
+    int flags = get_debug_flag(aTHX_ root);
     STRLEN len;
     char *str;
 
@@ -1244,20 +1243,20 @@
 	? (AV *) SvRV(ST(2)) : Nullav;
 
     if (SvROK(ident) && (SvTYPE(SvRV(ident)) == SVt_PVAV)) {
-	RETVAL = do_getset(root, (AV *) SvRV(ident), NULL, flags);
+	RETVAL = do_getset(aTHX_ root, (AV *) SvRV(ident), NULL, flags);
 
     } else if (SvROK(ident)) {
 	croak(TT_STASH_PKG ": get (arg 2) must be a scalar or listref");
 
     } else if ((str = SvPV(ident, len)) && memchr(str, '.', len)) {
 	/* convert dotted string into an array */
-	AV *av = convert_dotted_string(str, len);
-	RETVAL = do_getset(root, av, NULL, flags);
+	AV *av = convert_dotted_string(aTHX_ str, len);
+	RETVAL = do_getset(aTHX_ root, av, NULL, flags);
 	av_undef(av);
 
     } else {
 	/* otherwise ident is a scalar so we call dotop() just once */
-	RETVAL = dotop(root, ident, args, flags);
+	RETVAL = dotop(aTHX_ root, ident, args, flags);
     }
 
     if (!SvOK(RETVAL))
@@ -1279,7 +1278,7 @@
     SV *ident
     SV *value
     CODE:
-    int flags = get_debug_flag(root);
+    int flags = get_debug_flag(aTHX_ root);
     STRLEN len;
     char *str;
 
@@ -1287,20 +1286,20 @@
     flags |= ((items > 3) && SvTRUE(ST(3))) ? TT_DEFAULT_FLAG : 0;
 
     if (SvROK(ident) && (SvTYPE(SvRV(ident)) == SVt_PVAV)) {
-	RETVAL = do_getset(root, (AV *) SvRV(ident), value, flags);
+	RETVAL = do_getset(aTHX_ root, (AV *) SvRV(ident), value, flags);
 
     } else if (SvROK(ident)) {
 	croak(TT_STASH_PKG ": set (arg 2) must be a scalar or listref");
 
     } else if ((str = SvPV(ident, len)) && memchr(str, '.', len)) {
 	/* convert dotted string into a temporary array */
-	AV *av = convert_dotted_string(str, len);
-	RETVAL = do_getset(root, av, value, flags);
+	AV *av = convert_dotted_string(aTHX_ str, len);
+	RETVAL = do_getset(aTHX_ root, av, value, flags);
 	av_undef(av);
 
     } else {
 	/* otherwise a simple scalar so call assign() just once */
-	RETVAL = assign(root, ident, Nullav, value, flags);
+	RETVAL = assign(aTHX_ root, ident, Nullav, value, flags);
     }
 
     if (!SvOK(RETVAL))
