mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
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
This commit is contained in:
@@ -398,7 +398,16 @@ hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
|
||||
if (flags & HASH_KEYCOPY)
|
||||
hashp->keycopy = info->keycopy;
|
||||
else if (hashp->hash == string_hash)
|
||||
hashp->keycopy = (HashCopyFunc) strlcpy;
|
||||
{
|
||||
/*
|
||||
* The signature of keycopy is meant for memcpy(), which returns
|
||||
* void*, but strlcpy() returns size_t. Since we never use the return
|
||||
* value of keycopy, and size_t is pretty much always the same size as
|
||||
* void *, this should be safe. The extra cast in the middle is to
|
||||
* avoid warnings from -Wcast-function-type.
|
||||
*/
|
||||
hashp->keycopy = (HashCopyFunc) (pg_funcptr_t) strlcpy;
|
||||
}
|
||||
else
|
||||
hashp->keycopy = memcpy;
|
||||
|
||||
|
Reference in New Issue
Block a user