Merge branch 'master' into boehm-demers-weiser-gc
[bpt/guile.git] / libguile / modules.c
index e4a2df0..04527a5 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998,2000,2001,2002,2003,2004,2006,2007 Free Software Foundation, Inc.
+/* Copyright (C) 1998,2000,2001,2002,2003,2004,2006,2007,2008 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,6 +17,9 @@
 
 
 \f
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <stdarg.h>
 
@@ -40,12 +43,25 @@ scm_t_bits scm_module_tag;
 
 static SCM the_module;
 
+static SCM the_root_module_var;
+
+static SCM
+the_root_module ()
+{
+  if (scm_module_system_booted_p)
+    return SCM_VARIABLE_REF (the_root_module_var);
+  else
+    return SCM_BOOL_F;
+}
+
 SCM_DEFINE (scm_current_module, "current-module", 0, 0, 0,
            (),
            "Return the current module.")
 #define FUNC_NAME s_scm_current_module
 {
-  return scm_fluid_ref (the_module);
+  SCM curr = scm_fluid_ref (the_module);
+
+  return scm_is_true (curr) ? curr : the_root_module ();
 }
 #undef FUNC_NAME
 
@@ -230,17 +246,6 @@ scm_env_top_level (SCM env)
 
 SCM_SYMBOL (sym_module, "module");
 
-static SCM the_root_module_var;
-
-static SCM
-the_root_module ()
-{
-  if (scm_module_system_booted_p)
-    return SCM_VARIABLE_REF (the_root_module_var);
-  else
-    return SCM_BOOL_F;
-}
-
 SCM
 scm_lookup_closure_module (SCM proc)
 {
@@ -250,7 +255,13 @@ scm_lookup_closure_module (SCM proc)
     return SCM_PACK (SCM_SMOB_DATA (proc));
   else
     {
-      SCM mod = scm_procedure_property (proc, sym_module);
+      SCM mod;
+
+      /* FIXME: The `module' property is no longer set.  See
+        `set-module-eval-closure!' in `boot-9.scm'.  */
+      abort ();
+
+      mod = scm_procedure_property (proc, sym_module);
       if (scm_is_false (mod))
        mod = the_root_module ();
       return mod;