summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2006-05-31 20:58:09 +0000
committerTom Lane2006-05-31 20:58:09 +0000
commit7b0390b2f793d6d00911046ffd0b44b976f793d4 (patch)
treedc546e905713716071fdaeae713442d63c349310
parent89a2a4d061ea7bb02d5cf9206ed5bad856d70dde (diff)
Make PG_MODULE_MAGIC required in shared libraries that are loaded into
the server. Per discussion, there seems no point in a waiting period before making this required.
-rw-r--r--doc/src/sgml/xfunc.sgml70
-rw-r--r--src/backend/utils/fmgr/dfmgr.c16
-rw-r--r--src/include/fmgr.h10
-rw-r--r--src/tutorial/funcs.c2
4 files changed, 50 insertions, 48 deletions
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index 5c523dda37..9b978aff43 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1912,6 +1912,41 @@ concat_text(PG_FUNCTION_ARGS)
<listitem>
<para>
+ To ensure your module is not loaded into an incompatible server,
+ it must include a <quote>magic block</>. This allows
+ the server to detect obvious incompatibilities, such as a module
+ compiled for a different major version of
+ <productname>PostgreSQL</productname>. A magic block is required
+ as of <productname>PostgreSQL</productname> 8.2. To include a magic
+ block, write this in one (and only one) of your module source files,
+ after having included the header <filename>fmgr.h</>:
+ </para>
+
+<programlisting>
+#ifdef PG_MODULE_MAGIC
+PG_MODULE_MAGIC;
+#endif
+</programlisting>
+
+ <para>
+ The <literal>#ifdef</> test can be omitted if your code doesn't
+ need to compile against pre-8.2 <productname>PostgreSQL</productname>
+ releases.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Compiling and linking your code so that it can be dynamically
+ loaded into <productname>PostgreSQL</productname> always
+ requires special flags. See <xref linkend="dfunc"> for a
+ detailed explanation of how to do it for your particular
+ operating system.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
When allocating memory, use the
<productname>PostgreSQL</productname> functions
<function>palloc</function><indexterm><primary>palloc</></> and <function>pfree</function><indexterm><primary>pfree</></>
@@ -1960,41 +1995,6 @@ concat_text(PG_FUNCTION_ARGS)
error messages to this effect.
</para>
</listitem>
-
- <listitem>
- <para>
- To ensure your module is not loaded into an incompatible server, it
- is recommended to include a <quote>magic block</>. This allows
- the server to detect obvious incompatibilities, such as a module
- compiled for a different major version of
- <productname>PostgreSQL</productname>. It is likely that magic
- blocks will be required in future releases. To include a magic
- block, write this in one (and only one) of your module source files,
- after having included the header <filename>fmgr.h</>:
- </para>
-
-<programlisting>
-#ifdef PG_MODULE_MAGIC
-PG_MODULE_MAGIC;
-#endif
-</programlisting>
-
- <para>
- The <literal>#ifdef</> test can be omitted if your code doesn't
- need to compile against pre-8.2 <productname>PostgreSQL</productname>
- releases.
- </para>
- </listitem>
-
- <listitem>
- <para>
- Compiling and linking your code so that it can be dynamically
- loaded into <productname>PostgreSQL</productname> always
- requires special flags. See <xref linkend="dfunc"> for a
- detailed explanation of how to do it for your particular
- operating system.
- </para>
- </listitem>
</itemizedlist>
</para>
</sect2>
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 2ad4c209fb..5e61a67ea3 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -188,14 +188,14 @@ load_external_function(char *filename, char *funcname,
}
else
{
- /*
- * Currently we do not reject modules for not having a
- * magic block, it would break every external module in
- * existence. At some point though, this will become an ERROR.
- */
- ereport(LOG,
- (errmsg("library \"%s\" does not have a magic block",
- fullname)));
+ /* try to unlink library */
+ pg_dlclose(file_scanner->handle);
+ free((char *) file_scanner);
+ /* complain */
+ ereport(ERROR,
+ (errmsg("incompatible library \"%s\": missing magic block",
+ fullname),
+ errhint("Extension libraries are now required to use the PG_MODULE_MAGIC macro.")));
}
/* OK to link it into list */
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 0acd1becee..e1fe4a9a76 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -314,14 +314,14 @@ extern int no_such_variable
/*-------------------------------------------------------------------------
* Support for verifying backend compatibility of loaded modules
*
- * If a loaded module includes the macro call
+ * We require dynamically-loaded modules to include the macro call
* PG_MODULE_MAGIC;
- * (put this in only one source file), then we can check for obvious
- * incompatibility, such as being compiled for a different major PostgreSQL
- * version.
+ * so that we can check for obvious incompatibility, such as being compiled
+ * for a different major PostgreSQL version.
*
* To compile with versions of PostgreSQL that do not support this,
- * you may put an #ifdef/#endif test around it.
+ * you may put an #ifdef/#endif test around it. Note that in a multiple-
+ * source-file module, the macro call should only appear once.
*
* The specific items included in the magic block are intended to be ones that
* are custom-configurable and especially likely to break dynamically loaded
diff --git a/src/tutorial/funcs.c b/src/tutorial/funcs.c
index fa9efd85f0..5bcecb5782 100644
--- a/src/tutorial/funcs.c
+++ b/src/tutorial/funcs.c
@@ -16,6 +16,8 @@
#include "executor/executor.h" /* for GetAttributeByName() */
#include "utils/geo_decls.h" /* for point type */
+PG_MODULE_MAGIC;
+
/* These prototypes just prevent possible warnings from gcc. */