mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Replace pg_restrict by standard restrict
MSVC in C11 mode supports the standard restrict qualifier, so we don't need the workaround naming pg_restrict anymore. Even though restrict is in C99 and should be supported by all supported compilers, we keep the configure test and the hardcoded redirection to __restrict, because that will also work in C++ in all supported compilers. (restrict is not part of the C++ standard.) For backward compatibility for extensions, we keep a #define of pg_restrict around, but our own code doesn't use it anymore. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/0e3d8644-c01d-4374-86ea-9f0a987981f0%40eisentraut.org
This commit is contained in:
18
configure
vendored
18
configure
vendored
@@ -14999,10 +14999,10 @@ _ACEOF
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# MSVC doesn't cope well with defining restrict to __restrict, the
|
# Even though restrict is in C99 and should be supported by all
|
||||||
# spelling it understands, because it conflicts with
|
# supported compilers, but this macro is useful because it will prefer
|
||||||
# __declspec(restrict). Therefore we define pg_restrict to the
|
# a spelling that also works in C++ (often __restrict). (restrict is
|
||||||
# appropriate definition, which presumably won't conflict.
|
# not part of the C++ standard.)
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C/C++ restrict keyword" >&5
|
||||||
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
|
$as_echo_n "checking for C/C++ restrict keyword... " >&6; }
|
||||||
if ${ac_cv_c_restrict+:} false; then :
|
if ${ac_cv_c_restrict+:} false; then :
|
||||||
@@ -15049,16 +15049,6 @@ _ACEOF
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if test "$ac_cv_c_restrict" = "no"; then
|
|
||||||
pg_restrict=""
|
|
||||||
else
|
|
||||||
pg_restrict="$ac_cv_c_restrict"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cat >>confdefs.h <<_ACEOF
|
|
||||||
#define pg_restrict $pg_restrict
|
|
||||||
_ACEOF
|
|
||||||
|
|
||||||
|
|
||||||
ac_fn_c_check_type "$LINENO" "struct option" "ac_cv_type_struct_option" "#ifdef HAVE_GETOPT_H
|
ac_fn_c_check_type "$LINENO" "struct option" "ac_cv_type_struct_option" "#ifdef HAVE_GETOPT_H
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|||||||
16
configure.ac
16
configure.ac
@@ -1685,19 +1685,11 @@ PGAC_UNION_SEMUN
|
|||||||
AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
|
AC_CHECK_TYPES(socklen_t, [], [], [#include <sys/socket.h>])
|
||||||
PGAC_STRUCT_SOCKADDR_SA_LEN
|
PGAC_STRUCT_SOCKADDR_SA_LEN
|
||||||
|
|
||||||
# MSVC doesn't cope well with defining restrict to __restrict, the
|
# Even though restrict is in C99 and should be supported by all
|
||||||
# spelling it understands, because it conflicts with
|
# supported compilers, this test is useful because it will prefer a
|
||||||
# __declspec(restrict). Therefore we define pg_restrict to the
|
# spelling that also works in C++ (often __restrict). (restrict is
|
||||||
# appropriate definition, which presumably won't conflict.
|
# not part of the C++ standard.)
|
||||||
AC_C_RESTRICT
|
AC_C_RESTRICT
|
||||||
if test "$ac_cv_c_restrict" = "no"; then
|
|
||||||
pg_restrict=""
|
|
||||||
else
|
|
||||||
pg_restrict="$ac_cv_c_restrict"
|
|
||||||
fi
|
|
||||||
AC_DEFINE_UNQUOTED([pg_restrict], [$pg_restrict],
|
|
||||||
[Define to keyword to use for C99 restrict support, or to nothing if not
|
|
||||||
supported])
|
|
||||||
|
|
||||||
AC_CHECK_TYPES([struct option], [], [],
|
AC_CHECK_TYPES([struct option], [], [],
|
||||||
[#ifdef HAVE_GETOPT_H
|
[#ifdef HAVE_GETOPT_H
|
||||||
|
|||||||
13
meson.build
13
meson.build
@@ -2803,13 +2803,12 @@ int main(void)
|
|||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
|
||||||
# MSVC doesn't cope well with defining restrict to __restrict, the spelling it
|
# Even though restrict is in C99 and should be supported by all
|
||||||
# understands, because it conflicts with __declspec(restrict). Therefore we
|
# supported compilers, this indirection is useful because __restrict
|
||||||
# define pg_restrict to the appropriate definition, which presumably won't
|
# also works in C++ in all supported compilers. (If not, then we
|
||||||
# conflict.
|
# might have to write a real test.) (restrict is not part of the C++
|
||||||
#
|
# standard.)
|
||||||
# We assume C99 support, so we don't need to make this conditional.
|
cdata.set('restrict', '__restrict')
|
||||||
cdata.set('pg_restrict', '__restrict')
|
|
||||||
|
|
||||||
|
|
||||||
# Most libraries are included only if they demonstrably provide a function we
|
# Most libraries are included only if they demonstrably provide a function we
|
||||||
|
|||||||
@@ -1228,7 +1228,7 @@ parse_required_wal(verifier_context *context, char *pg_waldump_path,
|
|||||||
* context says we should.
|
* context says we should.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
|
report_backup_error(verifier_context *context, const char *restrict fmt,...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@@ -1245,7 +1245,7 @@ report_backup_error(verifier_context *context, const char *pg_restrict fmt,...)
|
|||||||
* Report a fatal error and exit
|
* Report a fatal error and exit
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
report_fatal_error(const char *pg_restrict fmt,...)
|
report_fatal_error(const char *restrict fmt,...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
|||||||
@@ -96,9 +96,9 @@ typedef struct verifier_context
|
|||||||
} verifier_context;
|
} verifier_context;
|
||||||
|
|
||||||
extern void report_backup_error(verifier_context *context,
|
extern void report_backup_error(verifier_context *context,
|
||||||
const char *pg_restrict fmt,...)
|
const char *restrict fmt,...)
|
||||||
pg_attribute_printf(2, 3);
|
pg_attribute_printf(2, 3);
|
||||||
pg_noreturn extern void report_fatal_error(const char *pg_restrict fmt,...)
|
pg_noreturn extern void report_fatal_error(const char *restrict fmt,...)
|
||||||
pg_attribute_printf(1, 2);
|
pg_attribute_printf(1, 2);
|
||||||
extern bool should_ignore_relpath(verifier_context *context,
|
extern bool should_ignore_relpath(verifier_context *context,
|
||||||
const char *relpath);
|
const char *relpath);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno)
|
|||||||
|
|
||||||
void
|
void
|
||||||
pg_log_generic(enum pg_log_level level, enum pg_log_part part,
|
pg_log_generic(enum pg_log_level level, enum pg_log_part part,
|
||||||
const char *pg_restrict fmt,...)
|
const char *restrict fmt,...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ pg_log_generic(enum pg_log_level level, enum pg_log_part part,
|
|||||||
|
|
||||||
void
|
void
|
||||||
pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
|
pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
|
||||||
const char *pg_restrict fmt, va_list ap)
|
const char *restrict fmt, va_list ap)
|
||||||
{
|
{
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
const char *filename = NULL;
|
const char *filename = NULL;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ pg_str_endswith(const char *str, const char *end)
|
|||||||
* strtoint --- just like strtol, but returns int not long
|
* strtoint --- just like strtol, but returns int not long
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
|
strtoint(const char *restrict str, char **restrict endptr, int base)
|
||||||
{
|
{
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,12 @@
|
|||||||
#define inline
|
#define inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Previously used PostgreSQL-specific spelling, for backward compatibility
|
||||||
|
* for extensions.
|
||||||
|
*/
|
||||||
|
#define pg_restrict restrict
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attribute macros
|
* Attribute macros
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ void pg_logging_set_pre_callback(void (*cb) (void));
|
|||||||
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
|
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
|
||||||
|
|
||||||
void pg_log_generic(enum pg_log_level level, enum pg_log_part part,
|
void pg_log_generic(enum pg_log_level level, enum pg_log_part part,
|
||||||
const char *pg_restrict fmt,...)
|
const char *restrict fmt,...)
|
||||||
pg_attribute_printf(3, 4);
|
pg_attribute_printf(3, 4);
|
||||||
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
|
void pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
|
||||||
const char *pg_restrict fmt, va_list ap)
|
const char *restrict fmt, va_list ap)
|
||||||
pg_attribute_printf(3, 0);
|
pg_attribute_printf(3, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ typedef struct PromptInterruptContext
|
|||||||
|
|
||||||
/* functions in src/common/string.c */
|
/* functions in src/common/string.c */
|
||||||
extern bool pg_str_endswith(const char *str, const char *end);
|
extern bool pg_str_endswith(const char *str, const char *end);
|
||||||
extern int strtoint(const char *pg_restrict str, char **pg_restrict endptr,
|
extern int strtoint(const char *restrict str, char **restrict endptr,
|
||||||
int base);
|
int base);
|
||||||
extern char *pg_clean_ascii(const char *str, int alloc_flags);
|
extern char *pg_clean_ascii(const char *str, int alloc_flags);
|
||||||
extern int pg_strip_crlf(char *str);
|
extern int pg_strip_crlf(char *str);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
|
|||||||
* Append a [u]int8 to a StringInfo buffer, which already has enough space
|
* Append a [u]int8 to a StringInfo buffer, which already has enough space
|
||||||
* preallocated.
|
* preallocated.
|
||||||
*
|
*
|
||||||
* The use of pg_restrict allows the compiler to optimize the code based on
|
* The use of restrict allows the compiler to optimize the code based on
|
||||||
* the assumption that buf, buf->len, buf->data and *buf->data don't
|
* the assumption that buf, buf->len, buf->data and *buf->data don't
|
||||||
* overlap. Without the annotation buf->len etc cannot be kept in a register
|
* overlap. Without the annotation buf->len etc cannot be kept in a register
|
||||||
* over subsequent pq_writeintN calls.
|
* over subsequent pq_writeintN calls.
|
||||||
@@ -43,7 +43,7 @@ extern void pq_sendfloat8(StringInfo buf, float8 f);
|
|||||||
* overly picky and demanding a * before a restrict.
|
* overly picky and demanding a * before a restrict.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pq_writeint8(StringInfoData *pg_restrict buf, uint8 i)
|
pq_writeint8(StringInfoData *restrict buf, uint8 i)
|
||||||
{
|
{
|
||||||
uint8 ni = i;
|
uint8 ni = i;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ pq_writeint8(StringInfoData *pg_restrict buf, uint8 i)
|
|||||||
* preallocated.
|
* preallocated.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pq_writeint16(StringInfoData *pg_restrict buf, uint16 i)
|
pq_writeint16(StringInfoData *restrict buf, uint16 i)
|
||||||
{
|
{
|
||||||
uint16 ni = pg_hton16(i);
|
uint16 ni = pg_hton16(i);
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ pq_writeint16(StringInfoData *pg_restrict buf, uint16 i)
|
|||||||
* preallocated.
|
* preallocated.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pq_writeint32(StringInfoData *pg_restrict buf, uint32 i)
|
pq_writeint32(StringInfoData *restrict buf, uint32 i)
|
||||||
{
|
{
|
||||||
uint32 ni = pg_hton32(i);
|
uint32 ni = pg_hton32(i);
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ pq_writeint32(StringInfoData *pg_restrict buf, uint32 i)
|
|||||||
* preallocated.
|
* preallocated.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pq_writeint64(StringInfoData *pg_restrict buf, uint64 i)
|
pq_writeint64(StringInfoData *restrict buf, uint64 i)
|
||||||
{
|
{
|
||||||
uint64 ni = pg_hton64(i);
|
uint64 ni = pg_hton64(i);
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ pq_writeint64(StringInfoData *pg_restrict buf, uint64 i)
|
|||||||
* sent to the frontend.
|
* sent to the frontend.
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str)
|
pq_writestring(StringInfoData *restrict buf, const char *restrict str)
|
||||||
{
|
{
|
||||||
int slen = strlen(str);
|
int slen = strlen(str);
|
||||||
char *p;
|
char *p;
|
||||||
|
|||||||
@@ -796,10 +796,6 @@
|
|||||||
#undef inline
|
#undef inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Define to keyword to use for C99 restrict support, or to nothing if not
|
|
||||||
supported */
|
|
||||||
#undef pg_restrict
|
|
||||||
|
|
||||||
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
||||||
nothing if this is not supported. Do not define if restrict is
|
nothing if this is not supported. Do not define if restrict is
|
||||||
supported directly. */
|
supported directly. */
|
||||||
|
|||||||
Reference in New Issue
Block a user