+#ifdef HAVE_SHLIB
+/*
+ * If we are not in a pure undumped Emacs, we need to make a duplicate of
+ * the subr. This is because the only time this function will be called
+ * in a running Emacs is when a dynamically loaded module is adding a
+ * subr, and we need to make sure that the subr is in allocated, Lisp-
+ * accessible memory. The address assigned to the static subr struct
+ * in the shared object will be a trampoline address, so we need to create
+ * a copy here to ensure that a real address is used.
+ *
+ * Once we have copied everything across, we re-use the original static
+ * structure to store a pointer to the newly allocated one. This will be
+ * used in emodules.c by emodules_doc_subr() to find a pointer to the
+ * allocated object so that we can set its doc string propperly.
+ *
+ * NOTE: We dont actually use the DOC pointer here any more, but we did
+ * in an earlier implementation of module support. There is no harm in
+ * setting it here in case we ever need it in future implementations.
+ * subr->doc will point to the new subr structure that was allocated.
+ * Code can then get this value from the statis subr structure and use
+ * it if required.
+ *
+ * FIXME: Should newsubr be staticpro()'ed? I dont think so but I need
+ * a guru to check.
+ */
+#define check_module_subr() \
+do { \
+ if (initialized) { \
+ struct Lisp_Subr *newsubr; \
+ newsubr = (Lisp_Subr *)xmalloc(sizeof(struct Lisp_Subr)); \
+ memcpy (newsubr, subr, sizeof(struct Lisp_Subr)); \
+ subr->doc = (CONST char *)newsubr; \
+ subr = newsubr; \
+ } \
+} while (0)
+#else /* ! HAVE_SHLIB */
+#define check_module_subr()
+#endif
+
+void
+defsubr (Lisp_Subr *subr)
+{
+ Lisp_Object sym = intern (subr_name (subr));
+ Lisp_Object fun;
+
+ check_sane_subr (subr, sym);
+ check_module_subr ();
+
+ XSETSUBR (fun, subr);
+ XSYMBOL (sym)->function = fun;
+}
+
+/* Define a lisp macro using a Lisp_Subr. */
+void
+defsubr_macro (Lisp_Subr *subr)
+{
+ Lisp_Object sym = intern (subr_name (subr));
+ Lisp_Object fun;
+
+ check_sane_subr (subr, sym);
+ check_module_subr();
+
+ XSETSUBR (fun, subr);
+ XSYMBOL (sym)->function = Fcons (Qmacro, fun);