From: Pierre Ossman Date: Wed, 4 Jan 2023 15:22:13 +0000 (+0100) Subject: Use __attribute__:s directly X-Git-Tag: v1.13.90~97^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1574%2Fhead;p=tigervnc.git Use __attribute__:s directly These are supported by gcc and clang, and I don't think MSVC works well with our code anyway, so let's keep things simple and use these directly. --- diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index e5bff80d..2c66ffca 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -21,18 +21,13 @@ #ifndef __RDR_EXCEPTION_H__ #define __RDR_EXCEPTION_H__ -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - namespace rdr { struct Exception { enum { len = 256 }; char str_[len]; - Exception(const char *format = 0, ...) __printf_attr(2, 3); + Exception(const char *format = 0, ...) + __attribute__((__format__ (__printf__, 2, 3))); virtual ~Exception() {} virtual const char* str() const { return str_; } }; diff --git a/common/rfb/LogWriter.h b/common/rfb/LogWriter.h index f718d60e..6eff6da1 100644 --- a/common/rfb/LogWriter.h +++ b/common/rfb/LogWriter.h @@ -25,22 +25,20 @@ #include #include -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - // Each log writer instance has a unique textual name, // and is attached to a particular Log instance and // is assigned a particular log level. #define DEF_LOGFUNCTION(name, level) \ - inline void v##name(const char* fmt, va_list ap) __printf_attr(2, 0) { \ + inline void v##name(const char* fmt, va_list ap) \ + __attribute__((__format__ (__printf__, 2, 0))) \ + { \ if (m_log && (level <= m_level)) \ m_log->write(level, m_name, fmt, ap); \ } \ - inline void name(const char* fmt, ...) __printf_attr(2, 3) { \ + inline void name(const char* fmt, ...) \ + __attribute__((__format__ (__printf__, 2, 3))) \ + { \ if (m_log && (level <= m_level)) { \ va_list ap; va_start(ap, fmt); \ m_log->write(level, m_name, fmt, ap);\ @@ -63,7 +61,9 @@ namespace rfb { void setLevel(int level); int getLevel(void) { return m_level; } - inline void write(int level, const char* format, ...) __printf_attr(3, 4) { + inline void write(int level, const char* format, ...) + __attribute__((__format__ (__printf__, 3, 4))) + { if (m_log && (level <= m_level)) { va_list ap; va_start(ap, format); diff --git a/common/rfb/Logger.h b/common/rfb/Logger.h index b75594c9..76f03535 100644 --- a/common/rfb/Logger.h +++ b/common/rfb/Logger.h @@ -28,12 +28,6 @@ // and is attached to a particular Logger instance and // is assigned a particular log level. -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - namespace rfb { class Logger { @@ -51,7 +45,8 @@ namespace rfb { // -=- Write data to a log virtual void write(int level, const char *logname, const char *text) = 0; - void write(int level, const char *logname, const char* format, va_list ap) __printf_attr(4, 0); + void write(int level, const char *logname, const char* format, va_list ap) + __attribute__((__format__ (__printf__, 4, 0))); // -=- Register a logger diff --git a/common/rfb/SConnection.h b/common/rfb/SConnection.h index 2c382513..b7e30c6a 100644 --- a/common/rfb/SConnection.h +++ b/common/rfb/SConnection.h @@ -222,7 +222,8 @@ namespace rfb { // throwConnFailedException() prints a message to the log, sends a conn // failed message to the client (if possible) and throws a // ConnFailedException. - void throwConnFailedException(const char* format, ...) __printf_attr(2, 3); + void throwConnFailedException(const char* format, ...) + __attribute__((__format__ (__printf__, 2, 3))); void setState(stateEnum s) { state_ = s; } diff --git a/common/rfb/util.h b/common/rfb/util.h index d0b32a61..99d350e3 100644 --- a/common/rfb/util.h +++ b/common/rfb/util.h @@ -29,12 +29,6 @@ struct timeval; -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - namespace rfb { // -=- Class to handle cleanup of arrays of characters @@ -49,7 +43,8 @@ namespace rfb { ~CharArray() { delete [] buf; } - void format(const char *fmt, ...) __printf_attr(2, 3); + void format(const char *fmt, ...) + __attribute__((__format__ (__printf__, 2, 3))); // Get the buffer pointer & clear it (i.e. caller takes ownership) char* takeBuf() {char* tmp = buf; buf = 0; return tmp;} void replaceBuf(char* b) {delete [] buf; buf = b;} diff --git a/unix/xserver/hw/vnc/RFBGlue.h b/unix/xserver/hw/vnc/RFBGlue.h index 695cea10..9dd91eab 100644 --- a/unix/xserver/hw/vnc/RFBGlue.h +++ b/unix/xserver/hw/vnc/RFBGlue.h @@ -26,16 +26,14 @@ extern "C" { void vncInitRFB(void); -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - -void vncLogError(const char *name, const char *format, ...) __printf_attr(2, 3); -void vncLogStatus(const char *name, const char *format, ...) __printf_attr(2, 3); -void vncLogInfo(const char *name, const char *format, ...) __printf_attr(2, 3); -void vncLogDebug(const char *name, const char *format, ...) __printf_attr(2, 3); +void vncLogError(const char *name, const char *format, ...) + __attribute__((__format__ (__printf__, 2, 3))); +void vncLogStatus(const char *name, const char *format, ...) + __attribute__((__format__ (__printf__, 2, 3))); +void vncLogInfo(const char *name, const char *format, ...) + __attribute__((__format__ (__printf__, 2, 3))); +void vncLogDebug(const char *name, const char *format, ...) + __attribute__((__format__ (__printf__, 2, 3))); int vncSetParam(const char *name, const char *value); int vncSetParamSimple(const char *nameAndValue); diff --git a/unix/xserver/hw/vnc/XorgGlue.h b/unix/xserver/hw/vnc/XorgGlue.h index 5d019493..40b3d343 100644 --- a/unix/xserver/hw/vnc/XorgGlue.h +++ b/unix/xserver/hw/vnc/XorgGlue.h @@ -24,18 +24,12 @@ extern "C" { #endif -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -# define __noreturn_attr __attribute__((noreturn)) -#else -# define __printf_attr(a, b) -# define __noreturn_attr -#endif // __GNUC__ - const char *vncGetDisplay(void); unsigned long vncGetServerGeneration(void); -void vncFatalError(const char *format, ...) __printf_attr(1, 2) __noreturn_attr; +void vncFatalError(const char *format, ...) + __attribute__((__format__ (__printf__, 1, 2))) + __attribute__((noreturn)); int vncGetScreenCount(void); diff --git a/vncviewer/DesktopWindow.h b/vncviewer/DesktopWindow.h index a654b126..f7721f2e 100644 --- a/vncviewer/DesktopWindow.h +++ b/vncviewer/DesktopWindow.h @@ -37,12 +37,6 @@ class Viewport; class Fl_Scrollbar; -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - class DesktopWindow : public Fl_Window { public: @@ -89,7 +83,8 @@ public: private: static void menuOverlay(void *data); - void setOverlay(const char *text, ...) __printf_attr(2, 3); + void setOverlay(const char *text, ...) + __attribute__((__format__ (__printf__, 2, 3))); static void updateOverlay(void *data); static int fltkDispatch(int event, Fl_Window *win); diff --git a/vncviewer/vncviewer.h b/vncviewer/vncviewer.h index 199e2e2c..f39a5776 100644 --- a/vncviewer/vncviewer.h +++ b/vncviewer/vncviewer.h @@ -21,18 +21,14 @@ #define VNCSERVERNAMELEN 256 -#ifdef __GNUC__ -# define __printf_attr(a, b) __attribute__((__format__ (__printf__, a, b))) -#else -# define __printf_attr(a, b) -#endif // __GNUC__ - namespace rdr { struct Exception; }; -void abort_vncviewer(const char *error, ...) __printf_attr(1, 2); -void abort_connection(const char *error, ...) __printf_attr(1, 2); +void abort_vncviewer(const char *error, ...) + __attribute__((__format__ (__printf__, 1, 2))); +void abort_connection(const char *error, ...) + __attribute__((__format__ (__printf__, 1, 2))); void abort_connection_with_unexpected_error(const rdr::Exception &); void disconnect();