diff options
| author | Peter Eisentraut | 2020-07-14 17:36:30 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2020-07-14 17:55:25 +0000 |
| commit | de8feb1f3a23465b5737e8a8c160e8ca62f61339 (patch) | |
| tree | 9d53a080b5fc83459e69cc374d021e97b2af8192 /src/include | |
| parent | 101f903e51f52bf595cd8177d2e0bc6fe9000762 (diff) | |
Fix -Wcast-function-type warnings
Three groups of issues needed to be addressed:
load_external_function() and related functions returned PGFunction,
even though not necessarily all callers are looking for a function of
type PGFunction. Since these functions are really just wrappers
around dlsym(), change to return void * just like dlsym().
In dynahash.c, we are using strlcpy() where a function with a
signature like memcpy() is expected. This should be safe, as the new
comment there explains, but the cast needs to be augmented to avoid
the warning.
In PL/Python, methods all need to be cast to PyCFunction, per Python
API, but this now runs afoul of these warnings. (This issue also
exists in core CPython.)
To fix the second and third case, we add a new type pg_funcptr_t that
is defined specifically so that gcc accepts it as a special function
pointer that can be cast to any other function pointer without the
warning.
Also add -Wcast-function-type to the standard warning flags, subject
to configure check.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/1e97628e-6447-b4fd-e230-d109cec2d584%402ndquadrant.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/c.h | 7 | ||||
| -rw-r--r-- | src/include/fmgr.h | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/include/c.h b/src/include/c.h index a904b49a37f..f242e32edbe 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -266,6 +266,13 @@ #endif /* + * Generic function pointer. This can be used in the rare cases where it's + * necessary to cast a function pointer to a seemingly incompatible function + * pointer type while avoiding gcc's -Wcast-function-type warnings. + */ +typedef void (*pg_funcptr_t) (void); + +/* * We require C99, hence the compiler should understand flexible array * members. However, for documentation purposes we still consider it to be * project style to write "field[FLEXIBLE_ARRAY_MEMBER]" not just "field[]". diff --git a/src/include/fmgr.h b/src/include/fmgr.h index d349510b7c7..f25068fae20 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -716,9 +716,9 @@ extern bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid); */ extern char *Dynamic_library_path; -extern PGFunction load_external_function(const char *filename, const char *funcname, - bool signalNotFound, void **filehandle); -extern PGFunction lookup_external_function(void *filehandle, const char *funcname); +extern void *load_external_function(const char *filename, const char *funcname, + bool signalNotFound, void **filehandle); +extern void *lookup_external_function(void *filehandle, const char *funcname); extern void load_file(const char *filename, bool restricted); extern void **find_rendezvous_variable(const char *varName); extern Size EstimateLibraryStateSpace(void); |
