Commit 8f165ee1 authored by Tom Lane's avatar Tom Lane

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.
parent c269f0f1
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.114 2006/05/30 21:21:29 tgl Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.115 2006/05/31 20:58:09 tgl Exp $ -->
<sect1 id="xfunc"> <sect1 id="xfunc">
<title>User-Defined Functions</title> <title>User-Defined Functions</title>
...@@ -1910,6 +1910,41 @@ concat_text(PG_FUNCTION_ARGS) ...@@ -1910,6 +1910,41 @@ concat_text(PG_FUNCTION_ARGS)
</para> </para>
</listitem> </listitem>
<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> <listitem>
<para> <para>
When allocating memory, use the When allocating memory, use the
...@@ -1960,41 +1995,6 @@ concat_text(PG_FUNCTION_ARGS) ...@@ -1960,41 +1995,6 @@ concat_text(PG_FUNCTION_ARGS)
error messages to this effect. error messages to this effect.
</para> </para>
</listitem> </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> </itemizedlist>
</para> </para>
</sect2> </sect2>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.84 2006/05/30 21:21:30 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.85 2006/05/31 20:58:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -188,14 +188,14 @@ load_external_function(char *filename, char *funcname, ...@@ -188,14 +188,14 @@ load_external_function(char *filename, char *funcname,
} }
else else
{ {
/* /* try to unlink library */
* Currently we do not reject modules for not having a pg_dlclose(file_scanner->handle);
* magic block, it would break every external module in free((char *) file_scanner);
* existence. At some point though, this will become an ERROR. /* complain */
*/ ereport(ERROR,
ereport(LOG, (errmsg("incompatible library \"%s\": missing magic block",
(errmsg("library \"%s\" does not have a magic block", fullname),
fullname))); errhint("Extension libraries are now required to use the PG_MODULE_MAGIC macro.")));
} }
/* OK to link it into list */ /* OK to link it into list */
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/fmgr.h,v 1.44 2006/05/30 21:21:30 tgl Exp $ * $PostgreSQL: pgsql/src/include/fmgr.h,v 1.45 2006/05/31 20:58:09 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -314,14 +314,14 @@ extern int no_such_variable ...@@ -314,14 +314,14 @@ extern int no_such_variable
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Support for verifying backend compatibility of loaded modules * 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; * PG_MODULE_MAGIC;
* (put this in only one source file), then we can check for obvious * so that we can check for obvious incompatibility, such as being compiled
* incompatibility, such as being compiled for a different major PostgreSQL * for a different major PostgreSQL version.
* version.
* *
* To compile with versions of PostgreSQL that do not support this, * 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 * The specific items included in the magic block are intended to be ones that
* are custom-configurable and especially likely to break dynamically loaded * are custom-configurable and especially likely to break dynamically loaded
......
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.14 2006/03/11 04:38:42 momjian Exp $ */ /* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.15 2006/05/31 20:58:09 tgl Exp $ */
/****************************************************************************** /******************************************************************************
These are user-defined functions that can be bound to a Postgres backend These are user-defined functions that can be bound to a Postgres backend
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "executor/executor.h" /* for GetAttributeByName() */ #include "executor/executor.h" /* for GetAttributeByName() */
#include "utils/geo_decls.h" /* for point type */ #include "utils/geo_decls.h" /* for point type */
PG_MODULE_MAGIC;
/* These prototypes just prevent possible warnings from gcc. */ /* These prototypes just prevent possible warnings from gcc. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment