Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8f165ee

Browse files
committed
Make PG_MODULE_MAGIC required in shared libraries that are loaded into
the server. Per discussion, there seems no point in a waiting periodbefore making this required.
1 parentc269f0f commit8f165ee

File tree

4 files changed

+54
-52
lines changed

4 files changed

+54
-52
lines changed

‎doc/src/sgml/xfunc.sgml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.114 2006/05/30 21:21:29 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.115 2006/05/31 20:58:09 tgl Exp $ -->
22

33
<sect1 id="xfunc">
44
<title>User-Defined Functions</title>
@@ -1910,6 +1910,41 @@ concat_text(PG_FUNCTION_ARGS)
19101910
</para>
19111911
</listitem>
19121912

1913+
<listitem>
1914+
<para>
1915+
To ensure your module is not loaded into an incompatible server,
1916+
it must include a <quote>magic block</>. This allows
1917+
the server to detect obvious incompatibilities, such as a module
1918+
compiled for a different major version of
1919+
<productname>PostgreSQL</productname>. A magic block is required
1920+
as of <productname>PostgreSQL</productname> 8.2. To include a magic
1921+
block, write this in one (and only one) of your module source files,
1922+
after having included the header <filename>fmgr.h</>:
1923+
</para>
1924+
1925+
<programlisting>
1926+
#ifdef PG_MODULE_MAGIC
1927+
PG_MODULE_MAGIC;
1928+
#endif
1929+
</programlisting>
1930+
1931+
<para>
1932+
The <literal>#ifdef</> test can be omitted if your code doesn't
1933+
need to compile against pre-8.2 <productname>PostgreSQL</productname>
1934+
releases.
1935+
</para>
1936+
</listitem>
1937+
1938+
<listitem>
1939+
<para>
1940+
Compiling and linking your code so that it can be dynamically
1941+
loaded into <productname>PostgreSQL</productname> always
1942+
requires special flags. See <xref linkend="dfunc"> for a
1943+
detailed explanation of how to do it for your particular
1944+
operating system.
1945+
</para>
1946+
</listitem>
1947+
19131948
<listitem>
19141949
<para>
19151950
When allocating memory, use the
@@ -1960,41 +1995,6 @@ concat_text(PG_FUNCTION_ARGS)
19601995
error messages to this effect.
19611996
</para>
19621997
</listitem>
1963-
1964-
<listitem>
1965-
<para>
1966-
To ensure your module is not loaded into an incompatible server, it
1967-
is recommended to include a <quote>magic block</>. This allows
1968-
the server to detect obvious incompatibilities, such as a module
1969-
compiled for a different major version of
1970-
<productname>PostgreSQL</productname>. It is likely that magic
1971-
blocks will be required in future releases. To include a magic
1972-
block, write this in one (and only one) of your module source files,
1973-
after having included the header <filename>fmgr.h</>:
1974-
</para>
1975-
1976-
<programlisting>
1977-
#ifdef PG_MODULE_MAGIC
1978-
PG_MODULE_MAGIC;
1979-
#endif
1980-
</programlisting>
1981-
1982-
<para>
1983-
The <literal>#ifdef</> test can be omitted if your code doesn't
1984-
need to compile against pre-8.2 <productname>PostgreSQL</productname>
1985-
releases.
1986-
</para>
1987-
</listitem>
1988-
1989-
<listitem>
1990-
<para>
1991-
Compiling and linking your code so that it can be dynamically
1992-
loaded into <productname>PostgreSQL</productname> always
1993-
requires special flags. See <xref linkend="dfunc"> for a
1994-
detailed explanation of how to do it for your particular
1995-
operating system.
1996-
</para>
1997-
</listitem>
19981998
</itemizedlist>
19991999
</para>
20002000
</sect2>

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.84 2006/05/30 21:21:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.85 2006/05/31 20:58:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -188,14 +188,14 @@ load_external_function(char *filename, char *funcname,
188188
}
189189
else
190190
{
191-
/*
192-
* Currently we do not reject modules for not having a
193-
* magic block, it would break every external module in
194-
* existence. At some point though, this will become an ERROR.
195-
*/
196-
ereport(LOG,
197-
(errmsg("library \"%s\" does not have a magic block",
198-
fullname)));
191+
/* try to unlink library */
192+
pg_dlclose(file_scanner->handle);
193+
free((char*)file_scanner);
194+
/* complain */
195+
ereport(ERROR,
196+
(errmsg("incompatible library \"%s\": missing magic block",
197+
fullname),
198+
errhint("Extension libraries are now required to use the PG_MODULE_MAGIC macro.")));
199199
}
200200

201201
/* OK to link it into list */

‎src/include/fmgr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/include/fmgr.h,v 1.44 2006/05/30 21:21:30 tgl Exp $
14+
* $PostgreSQL: pgsql/src/include/fmgr.h,v 1.45 2006/05/31 20:58:09 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -314,14 +314,14 @@ extern int no_such_variable
314314
/*-------------------------------------------------------------------------
315315
*Support for verifying backend compatibility of loaded modules
316316
*
317-
*If aloadedmodule includes the macro call
317+
*We require dynamically-loadedmodules to include the macro call
318318
*PG_MODULE_MAGIC;
319-
* (put this in only one source file), then we can check for obvious
320-
* incompatibility, such as being compiled for a different major PostgreSQL
321-
* version.
319+
* so that we can check for obvious incompatibility, such as being compiled
320+
* for a different major PostgreSQL version.
322321
*
323322
* To compile with versions of PostgreSQL that do not support this,
324-
* you may put an #ifdef/#endif test around it.
323+
* you may put an #ifdef/#endif test around it. Note that in a multiple-
324+
* source-file module, the macro call should only appear once.
325325
*
326326
* The specific items included in the magic block are intended to be ones that
327327
* are custom-configurable and especially likely to break dynamically loaded

‎src/tutorial/funcs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.14 2006/03/11 04:38:42 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.15 2006/05/31 20:58:09 tgl Exp $ */
22

33
/******************************************************************************
44
These are user-defined functions that can be bound to a Postgres backend
@@ -16,6 +16,8 @@
1616
#include"executor/executor.h"/* for GetAttributeByName() */
1717
#include"utils/geo_decls.h"/* for point type */
1818

19+
PG_MODULE_MAGIC;
20+
1921

2022
/* These prototypes just prevent possible warnings from gcc. */
2123

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp