mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Map pg_attribute_counted_by() to _Field_size_() under MSVC
MSVC has no counted_by attribute, but its source annotation language (SAL) has _Field_size_(), which states the same property: the field is a buffer whose writable size in elements is given by the named expression. MSVC's static analyzer (/analyze) will make use of the information. Author: Tristan Partin <tristan@partin.io> Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io
This commit is contained in:
@@ -76,6 +76,9 @@
|
||||
#if defined(WIN32) || defined(__CYGWIN__)
|
||||
#include <fcntl.h> /* ensure O_BINARY is available */
|
||||
#endif
|
||||
#ifdef _MSC_VER
|
||||
#include <sal.h>
|
||||
#endif
|
||||
#include <locale.h>
|
||||
#ifdef HAVE_XLOCALE_H
|
||||
#include <xlocale.h>
|
||||
@@ -310,10 +313,17 @@ extern "C++"
|
||||
* including after either member is updated.
|
||||
*
|
||||
* The attribute is ignored in C++ due to lack of compiler support.
|
||||
*
|
||||
* MSVC has no counted_by attribute, but the equivalent SAL annotation
|
||||
* _Field_size_() is understood by its static analyzer (/analyze); in ordinary
|
||||
* builds it expands to nothing. (C++ would be supported here, but we leave
|
||||
* it off for consistency with the other compilers.)
|
||||
*/
|
||||
#ifndef __cplusplus
|
||||
#if __has_attribute (counted_by)
|
||||
#define pg_attribute_counted_by(count) __attribute__((counted_by(count)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define pg_attribute_counted_by(count) _Field_size_(count)
|
||||
#else
|
||||
#define pg_attribute_counted_by(count)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user