mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Code review for magic-block patch. Remove separate header file pgmagic.h,
as this seems only likely to create headaches for module developers. Put the macro in the pre-existing fmgr.h file instead. Avoid being too cute about how many fields we can cram into a word, and avoid trying to fetch from a library we've already unlinked. Along the way, it occurred to me that the magic block really ought to be 'const' so it can be stored in the program text area. Do the same for the existing data blocks for PG_FUNCTION_INFO_V1 functions.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/fmgr.h,v 1.43 2006/04/04 19:35:37 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/fmgr.h,v 1.44 2006/05/30 21:21:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -293,7 +293,7 @@ typedef struct
|
||||
} Pg_finfo_record;
|
||||
|
||||
/* Expected signature of an info function */
|
||||
typedef Pg_finfo_record *(*PGFInfoFunction) (void);
|
||||
typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
|
||||
|
||||
/*
|
||||
* Macro to build an info function associated with the given function name.
|
||||
@@ -301,16 +301,75 @@ typedef Pg_finfo_record *(*PGFInfoFunction) (void);
|
||||
* doesn't hurt to add DLLIMPORT in case they don't.
|
||||
*/
|
||||
#define PG_FUNCTION_INFO_V1(funcname) \
|
||||
extern DLLIMPORT Pg_finfo_record * CppConcat(pg_finfo_,funcname) (void); \
|
||||
Pg_finfo_record * \
|
||||
extern DLLIMPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
|
||||
const Pg_finfo_record * \
|
||||
CppConcat(pg_finfo_,funcname) (void) \
|
||||
{ \
|
||||
static Pg_finfo_record my_finfo = { 1 }; \
|
||||
static const Pg_finfo_record my_finfo = { 1 }; \
|
||||
return &my_finfo; \
|
||||
} \
|
||||
extern int no_such_variable
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Support for verifying backend compatibility of loaded modules
|
||||
*
|
||||
* If a loaded module includes 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.
|
||||
*
|
||||
* To compile with versions of PostgreSQL that do not support this,
|
||||
* you may put an #ifdef/#endif test around it.
|
||||
*
|
||||
* The specific items included in the magic block are intended to be ones that
|
||||
* are custom-configurable and especially likely to break dynamically loaded
|
||||
* modules if they were compiled with other values. Also, the length field
|
||||
* can be used to detect definition changes.
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* Definition of the magic block structure */
|
||||
typedef struct
|
||||
{
|
||||
int len; /* sizeof(this struct) */
|
||||
int version; /* PostgreSQL major version */
|
||||
int funcmaxargs; /* FUNC_MAX_ARGS */
|
||||
int indexmaxkeys; /* INDEX_MAX_KEYS */
|
||||
int namedatalen; /* NAMEDATALEN */
|
||||
} Pg_magic_struct;
|
||||
|
||||
/* The actual data block contents */
|
||||
#define PG_MODULE_MAGIC_DATA \
|
||||
{ \
|
||||
sizeof(Pg_magic_struct), \
|
||||
PG_VERSION_NUM / 100, \
|
||||
FUNC_MAX_ARGS, \
|
||||
INDEX_MAX_KEYS, \
|
||||
NAMEDATALEN \
|
||||
}
|
||||
|
||||
/*
|
||||
* Declare the module magic function. It needs to be a function as the dlsym
|
||||
* in the backend is only guaranteed to work on functions, not data
|
||||
*/
|
||||
typedef const Pg_magic_struct *(*PGModuleMagicFunction) (void);
|
||||
|
||||
#define PG_MAGIC_FUNCTION_NAME Pg_magic_func
|
||||
#define PG_MAGIC_FUNCTION_NAME_STRING "Pg_magic_func"
|
||||
|
||||
#define PG_MODULE_MAGIC \
|
||||
extern DLLIMPORT const Pg_magic_struct *PG_MAGIC_FUNCTION_NAME(void); \
|
||||
const Pg_magic_struct * \
|
||||
PG_MAGIC_FUNCTION_NAME(void) \
|
||||
{ \
|
||||
static const Pg_magic_struct Pg_magic_data = PG_MODULE_MAGIC_DATA; \
|
||||
return &Pg_magic_data; \
|
||||
} \
|
||||
extern int no_such_variable
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Support routines and macros for callers of fmgr-compatible functions
|
||||
*-------------------------------------------------------------------------
|
||||
@@ -414,7 +473,7 @@ extern bytea *OidSendFunctionCall(Oid functionId, Datum val);
|
||||
/*
|
||||
* Routines in fmgr.c
|
||||
*/
|
||||
extern Pg_finfo_record *fetch_finfo_record(void *filehandle, char *funcname);
|
||||
extern const Pg_finfo_record *fetch_finfo_record(void *filehandle, char *funcname);
|
||||
extern void clear_external_function_hash(void *filehandle);
|
||||
extern Oid fmgr_internal_function(const char *proname);
|
||||
extern Oid get_fn_expr_rettype(FmgrInfo *flinfo);
|
||||
|
Reference in New Issue
Block a user