rem: checked = (Scheme_Hash_Table *)SCHEME_CAR(future_checkeds);
add: next_checked = (Scheme_Hash_Table *)SCHEME_CAR(future_checkeds);
context: static Scheme_Object *namespace_attach_module(int argc, Scheme_Object *argv[]){  Scheme_Env *from_env, *to_env, *menv, *menv2;  Scheme_Object *todo, *next_phase_todo, *prev_phase_todo;  Scheme_Object *name, *notifies = scheme_null, *a[3], *resolver;  Scheme_Object *to_modchain, *from_modchain, *l;  Scheme_Hash_Table *checked, *next_checked, *prev_checked;  Scheme_Object *past_checkeds, *future_checkeds, *future_todos, *past_to_modchains;  Scheme_Module *m2;  int same_namespace, skip_notify = 0, with_tt;  if (!SCHEME_NAMESPACEP(argv[0]))    scheme_wrong_type("namespace-attach-module", "namespace", 0, argc, argv);  if (!SCHEME_SYMBOLP(argv[1]))    scheme_wrong_type("namespace-attach-module", "symbol", 1, argc, argv);  from_env = (Scheme_Env *)argv[0];  if (argc > 2) {    to_env = (Scheme_Env *)argv[2];    skip_notify = 1;  } else    to_env = scheme_get_env(NULL);  same_namespace = SAME_OBJ(from_env, to_env);  todo = scheme_make_pair(scheme_module_resolve(argv[1]), scheme_null);  next_phase_todo = scheme_null;  prev_phase_todo = scheme_null;  from_modchain = from_env->modchain;  to_modchain = to_env->modchain;  with_tt = 0;  checked = NULL;  next_checked = NULL;  prev_checked = NULL;  past_checkeds = scheme_null;  future_checkeds = scheme_null;  future_todos = scheme_null;  past_to_modchains = scheme_null;  /* Check whether todo, or anything it needs, is already declared     incompatibly. Successive iterations of the outer loop explore     successive phases (i.e, for-syntax levels). */  while (!SCHEME_NULLP(todo)) {    if (!checked)      checked = scheme_make_hash_table(SCHEME_hash_ptr);    /* This is just a shortcut: */    next_checked = scheme_make_hash_table(SCHEME_hash_ptr);    /* This loop iterates through require chains in the same phase */    while (!SCHEME_NULLP(todo)) {      name = SCHEME_CAR(todo);      todo = SCHEME_CDR(todo);      scheme_hash_set(checked, name, scheme_true);      if (!SAME_OBJ(name, kernel_symbol)) {	menv = (Scheme_Env *)scheme_hash_get(MODCHAIN_TABLE(from_modchain), name);	if (!menv) {	  /* Assert: name == argv[1] */	  /* Module at least declared? */	  if (scheme_hash_get(from_env->module_registry, name))	    scheme_arg_mismatch("namespace-attach-module",				"module not instantiated (in the source namespace): ",				name);	  else	    scheme_arg_mismatch("namespace-attach-module",				"unknown module (in the source namespace): ",				name);	}	/* If to_modchain goes to #f, then our source check has gone	   deeper in phases (for-syntax levels) than the target	   namespace has ever gone, so there's definitely no conflict	   at this level in that case. */	if (SCHEME_TRUEP(to_modchain)) {	  menv2 = (Scheme_Env *)scheme_hash_get(MODCHAIN_TABLE(to_modchain), name);	  if (menv2) {	    if (!SAME_OBJ(menv->toplevel, menv2->toplevel))	      m2 = menv2->module;	    else	      m2 = NULL;	  } else {	    m2 = (Scheme_Module *)scheme_hash_get(to_env->module_registry, name);	    if (m2 && SAME_OBJ(m2, menv->module))	      m2 = NULL;	  }	  	  if (m2) {	    char *phase, buf[32];	    if (!menv->phase)	      phase = "";	    else if (menv->phase == 1)	      phase = " for syntax";	    else {	      sprintf(buf, " at phase %ld", menv->phase);	      phase = buf;	    }	    scheme_raise_exn(MZEXN_FAIL_CONTRACT,			     "namespace-attach-module: "			     "a different module with the same name is already "			     "in the destination namespace%s, for name: %S",			     phase, name);	    return NULL;	  }	} else	  menv2 = NULL;	if (!menv2 || same_namespace) {	  /* Push requires onto the check list: */	  l = menv->require_names;	  while (!SCHEME_NULLP(l)) {	    name = scheme_module_resolve(SCHEME_CAR(l));	    if (!scheme_hash_get(checked, name)) {	      todo = scheme_make_pair(name, todo);	      scheme_hash_set(checked, name, scheme_true);	    }	    l = SCHEME_CDR(l);	  }	  /* Have to force laziness in source to ensure sharing: */	  if (menv->lazy_syntax)	    finish_expstart_module_in_namespace(menv, from_env);	  l = menv->et_require_names;	  while (!SCHEME_NULLP(l)) {	    name = scheme_module_resolve(SCHEME_CAR(l));	    if (!scheme_hash_get(next_checked, name)) {	      next_phase_todo = scheme_make_pair(name, next_phase_todo);	      scheme_hash_set(next_checked, name, scheme_true);	    }	    l = SCHEME_CDR(l);	  }	  if (with_tt) {	    l = menv->tt_require_names;	    if (l) {	      while (!SCHEME_NULLP(l)) {		if (!prev_checked)		  prev_checked = scheme_make_hash_table(SCHEME_hash_ptr);				name = scheme_module_resolve(SCHEME_CAR(l));		if (!scheme_hash_get(prev_checked, name)) {		  prev_phase_todo = scheme_make_pair(name, prev_phase_todo);		  scheme_hash_set(prev_checked, name, scheme_true);		}		l = SCHEME_CDR(l);	      }	    }	  }	}      }    }        do {      if (SCHEME_PAIRP(prev_phase_todo)) {	future_todos = cons(next_phase_todo, future_todos);	future_checkeds = cons((Scheme_Object *)next_checked, future_checkeds);	next_checked = checked;		next_phase_todo = scheme_null;	todo = prev_phase_todo;	prev_phase_todo = scheme_null;		checked = prev_checked;	prev_checked = (Scheme_Hash_Table *)SCHEME_CAR(past_checkeds);	past_checkeds = SCHEME_CDR(past_checkeds);	from_modchain = SCHEME_VEC_ELS(from_modchain)[2];	to_modchain = SCHEME_CAR(past_to_modchains);	past_to_modchains = SCHEME_CDR(past_to_modchains);      } else {	past_checkeds = cons((Scheme_Object *)prev_checked, past_checkeds);	prev_checked = checked;	todo = next_phase_todo;		if (SCHEME_NULLP(future_todos)) {	  next_phase_todo = scheme_null;	  checked = NULL;	} else {	  next_phase_todo = SCHEME_CAR(future_todos);	  future_todos = SCHEME_CDR(future_todos);	  checked = (Scheme_Hash_Table *)SCHEME_CAR(future_checkeds);	  future_checkeds = SCHEME_CDR(future_checkeds);	}		from_modchain = SCHEME_VEC_ELS(from_modchain)[1];	past_to_modchains = cons(to_modchain, past_to_modchains);	if (SCHEME_TRUEP(to_modchain))	  to_modchain = SCHEME_VEC_ELS(to_modchain)[1];	with_tt++;      }    } while (SCHEME_NULLP(todo) && (SCHEME_PAIRP(next_phase_todo)				    || SCHEME_PAIRP(future_todos)));  }  /* All of the modules that we saw are in the past_checkeds     hash tables, plus maybe prev_checked. */  if (prev_checked)    past_checkeds = cons((Scheme_Object *)prev_checked, past_checkeds);  /* Reverse the list */  while (!SCHEME_NULLP(past_checkeds)) {    if (SCHEME_CAR(past_checkeds))      future_checkeds = scheme_make_pair(SCHEME_CAR(past_checkeds),					 future_checkeds);    past_checkeds = SCHEME_CDR(past_checkeds);  }  /* Now all the modules to check are in the future_checkeds     list of hash tables. */  /* Go through that list, this time tranferring modules */  from_modchain = from_env->modchain;  to_modchain = to_env->modchain;  /* Again, outer loop iterates through phases. */  while (!SCHEME_NULLP(future_checkeds)) {    /* Inner loop iterates through requires within a phase. */    int i;    checked = (Scheme_Hash_Table *)SCHEME_CAR(future_checkeds);    for (i = checked->size; i--; ) {      if (checked->vals[i]) {	name = checked->keys[i];	if (!SAME_OBJ(name, kernel_symbol)) {	  menv = (Scheme_Env *)scheme_hash_get(MODCHAIN_TABLE(from_modchain), name);	  	  menv2 = (Scheme_Env *)scheme_hash_get(MODCHAIN_TABLE(to_modchain), name);	  if (!menv2) {	    /* Clone menv for the new namespace: */	    menv2 = scheme_clone_module_env(menv, to_env, to_modchain);	    if (menv->attached)	      menv2->attached = 1;	    	    scheme_hash_set(MODCHAIN_TABLE(to_modchain), name, (Scheme_Object *)menv2);	    scheme_hash_set(to_env->module_registry, name, (Scheme_Object *)menv2->module);	    	    /* Push name onto notify list: */	    if (!same_namespace)	      notifies = scheme_make_pair(name, notifies);	  }	}      }    }        future_checkeds = SCHEME_CDR(future_checkeds);    from_modchain = SCHEME_VEC_ELS(from_modchain)[1];    to_modchain = SCHEME_VEC_ELS(to_modchain)[1];    /* Preceding scheme_clone_module_env ensures that we don't get a       #f for to_modchain if there's more to do. */  }  if (!skip_notify) {    /* Notify module name resolver of attached modules: */    resolver = scheme_get_param(scheme_current_config(), MZCONFIG_CURRENT_MODULE_RESOLVER);    while (!SCHEME_NULLP(notifies)) {      a[0] = scheme_false;      a[1] = SCHEME_CAR(notifies);      a[2] = scheme_false;            name = scheme_apply(resolver, 3, a);            notifies = SCHEME_CDR(notifies);    }  }  return scheme_void;}