diff --git a/src/module_support.c b/src/module_support.c
index 498084ab2d5ae02394b33d24ce05e6884029b62f..d3f753067ebfc735dd379371495a1bc1144bd580 100644
--- a/src/module_support.c
+++ b/src/module_support.c
@@ -5,8 +5,10 @@
 #include "stralloc.h"
 #include "pike_types.h"
 #include "pike_error.h"
+#include "mapping.h"
+#include "object.h"
 
-RCSID("$Id: module_support.c,v 1.38 2000/12/01 08:09:50 hubbe Exp $");
+RCSID("$Id: module_support.c,v 1.39 2000/12/13 21:35:05 hubbe Exp $");
 
 /* Checks that args_to_check arguments are OK.
  * Returns 1 if everything worked ok, zero otherwise.
@@ -363,3 +365,61 @@ PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format,  ... )
     }
   }
 }
+
+/* NOTA BENE:
+ * The code below assumes that dynamic modules are not
+ * unloaded from memory...
+ */
+   
+static struct mapping *exported_symbols;
+static struct program *function_encapsulation_program;
+
+PMOD_EXPORT void pike_module_export_symbol(char *name,
+					   int len,
+					   void *ptr)
+{
+  struct pike_string *str=make_shared_binary_string(name,len);
+  struct svalue s;
+  if(!exported_symbols) exported_symbols=allocate_mapping(10);
+  s.u.refs=(INT32 *)ptr;
+  s.type=T_INT;
+  s.subtype=4711;
+  mapping_string_insert(exported_symbols, str, &s);
+}
+
+PMOD_EXPORT void *pike_module_import_symbol(char *name,
+					    int len,
+					    char *module,
+					    int module_len)
+{
+  struct svalue *s;
+  struct pike_string *str=make_shared_binary_string(name,len);
+  if(exported_symbols)
+  {
+    s=low_mapping_string_lookup(exported_symbols, str);
+    if(s && s->type == T_INT && s->subtype == 4711)
+    {
+      free_string(str);
+      return s->u.refs;
+    }
+  }
+
+  /* Load the module */
+  push_string(make_shared_binary_string(module,module_len));
+  SAFE_APPLY_MASTER("resolv",1);
+  pop_stack();
+
+  if(exported_symbols)
+  {
+    s=low_mapping_string_lookup(exported_symbols, str);
+
+    if(s && s->type == T_INT && s->subtype == 4711)
+    {
+      free_string(str);
+      return s->u.refs;
+    }
+  }
+
+  free_string(str);
+  return 0;
+}
diff --git a/src/module_support.h b/src/module_support.h
index db7ca4126e2417fff3bd17c23d67441859e618e1..459a4863abb2da0ce5aeb010c5a8431508e9c11c 100644
--- a/src/module_support.h
+++ b/src/module_support.h
@@ -5,7 +5,7 @@
 \*/
 
 /*
- * $Id: module_support.h,v 1.7 2000/07/28 17:16:55 hubbe Exp $
+ * $Id: module_support.h,v 1.8 2000/12/13 21:35:05 hubbe Exp $
  */
 #ifndef MODULE_SUPPORT_H
 #include <stdarg.h>
@@ -24,6 +24,13 @@ struct expect_result {
   TYPE_T got;               /* What type did we actually receive */
 };
 
+/* This should be used in module_init */
+#define PIKE_MODULE_EXPORT(MOD, SYM) \
+  pike_module_export_symbol(#MOD "." #SYM, CONSTANT_STRLEN(#MOD "." #SYM), SYM)
+
+#define PIKE_MODULE_IMPORT(MOD, SYM) \
+  pike_module_import_symbol(#MOD "." #SYM, CONSTANT_STRLEN(#MOD "." #SYM), #MOD, CONSTANT_STRLEN(#MOD))
+
 
 /* Prototypes begin here */
 PMOD_EXPORT int check_args(int args, ...);
@@ -36,6 +43,13 @@ PMOD_EXPORT int get_args(struct svalue *s,
 	     INT32 num_args,
 	     char *fmt, ...);
 PMOD_EXPORT void get_all_args(char *fname, INT32 args, char *format,  ... );
+PMOD_EXPORT void pike_module_export_symbol(char *str,
+					   int len,
+					   void *ptr);
+PMOD_EXPORT void *pike_module_import_symbol(char *str,
+					    int len,
+					    char *module,
+					    int module_len);
 /* Prototypes end here */
 
 #endif