From 7daaeb074ff778c9a3ba2cf3f44f357bf2d9b35a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 29 Dec 2023 12:26:59 -0800 Subject: [PATCH] remove some compiler compatibility checks (#498) `stdbool.h` is part of C99 however was not provided by Visual Studio 2013 until RTM [1]. Remove the check for the header and inline the include at the usage sites rather than relying on `config.h`. VS2013 was EOL'ed Apr 9, 2019, with extended support ending Apr 9, 2024. `HAVE___ATTRIBUTE__` was unused in the codebase and served no purpose. Remove shims for `snprintf` and `vsnprintf` which were unavailable prior to VS2015. As VS2013 is no longer serviced, this reduces complexity in the project. [1] https://devblogs.microsoft.com/cppblog/c99-library-support-in-visual-studio-2013/ --- src/CMakeLists.txt | 6 ------ src/blocks.c | 5 +++-- src/buffer.c | 10 ++++----- src/commonmark.c | 7 +++--- src/config.h.in | 54 ---------------------------------------------- src/html.c | 6 ++++-- src/inlines.c | 3 ++- src/iterator.c | 1 + src/latex.c | 5 +++-- src/man.c | 5 +++-- src/node.c | 1 + src/node.h | 3 ++- src/render.h | 2 ++ src/xml.c | 5 +++-- 14 files changed, 33 insertions(+), 80 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50dc442b0..a234d6b98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -174,16 +174,10 @@ if(CMARK_SHARED OR CMARK_STATIC) endif() # Feature tests -include(CheckIncludeFile) include(CheckCSourceCompiles) -CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H) CHECK_C_SOURCE_COMPILES( "int main() { __builtin_expect(0,0); return 0; }" HAVE___BUILTIN_EXPECT) -CHECK_C_SOURCE_COMPILES(" - int f(void) __attribute__ (()); - int main() { return 0; } -" HAVE___ATTRIBUTE__) CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in diff --git a/src/blocks.c b/src/blocks.c index 3f262cb11..83f3785d3 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -5,10 +5,11 @@ * see http://spec.commonmark.org/0.24/#phase-1-block-structure */ -#include #include -#include #include +#include +#include +#include #include "cmark_ctype.h" #include "config.h" diff --git a/src/buffer.c b/src/buffer.c index d94649310..d2ac2eeb0 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,11 +1,11 @@ -#include -#include #include -#include +#include +#include +#include +#include #include #include -#include -#include +#include #include "config.h" #include "cmark_ctype.h" diff --git a/src/commonmark.c b/src/commonmark.c index b45906dd3..f5536f92c 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -1,8 +1,9 @@ -#include +#include +#include +#include #include +#include #include -#include -#include #include "config.h" #include "cmark.h" diff --git a/src/config.h.in b/src/config.h.in index de1a4dd49..b4de81f13 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -5,24 +5,8 @@ extern "C" { #endif -#cmakedefine HAVE_STDBOOL_H - -#ifdef HAVE_STDBOOL_H - #include -#elif !defined(__cplusplus) - typedef char bool; -#endif - #cmakedefine HAVE___BUILTIN_EXPECT -#cmakedefine HAVE___ATTRIBUTE__ - -#ifdef HAVE___ATTRIBUTE__ - #define CMARK_ATTRIBUTE(list) __attribute__ (list) -#else - #define CMARK_ATTRIBUTE(list) -#endif - #ifndef CMARK_INLINE #if defined(_MSC_VER) && !defined(__cplusplus) #define CMARK_INLINE __inline @@ -31,44 +15,6 @@ extern "C" { #endif #endif -/* snprintf and vsnprintf fallbacks for MSVC before 2015, - due to Valentin Milea http://stackoverflow.com/questions/2915672/ -*/ - -#if defined(_MSC_VER) && _MSC_VER < 1900 - -#include -#include - -#define snprintf c99_snprintf -#define vsnprintf c99_vsnprintf - -CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) -{ - int count = -1; - - if (size != 0) - count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); - if (count == -1) - count = _vscprintf(format, ap); - - return count; -} - -CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...) -{ - int count; - va_list ap; - - va_start(ap, format); - count = c99_vsnprintf(outBuf, size, format, ap); - va_end(ap); - - return count; -} - -#endif - #ifdef __cplusplus } #endif diff --git a/src/html.c b/src/html.c index 962d7952b..37870b223 100644 --- a/src/html.c +++ b/src/html.c @@ -1,7 +1,9 @@ -#include +#include +#include #include +#include #include -#include + #include "cmark_ctype.h" #include "config.h" #include "cmark.h" diff --git a/src/inlines.c b/src/inlines.c index 1313428d5..79cd150cb 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -1,6 +1,7 @@ +#include +#include #include #include -#include #include "cmark_ctype.h" #include "config.h" diff --git a/src/iterator.c b/src/iterator.c index 63cbf9ebc..d41b90d69 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -1,4 +1,5 @@ #include +#include #include #include "config.h" diff --git a/src/latex.c b/src/latex.c index 2051ed31d..55d204505 100644 --- a/src/latex.c +++ b/src/latex.c @@ -1,7 +1,8 @@ -#include +#include +#include #include +#include #include -#include #include "config.h" #include "cmark.h" diff --git a/src/man.c b/src/man.c index 65e5c7950..c793a05fa 100644 --- a/src/man.c +++ b/src/man.c @@ -1,7 +1,8 @@ -#include +#include +#include #include +#include #include -#include #include "config.h" #include "cmark.h" diff --git a/src/node.c b/src/node.c index 3b0cf1361..a07b8c0ad 100644 --- a/src/node.c +++ b/src/node.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/src/node.h b/src/node.h index 1cae5d745..430ee5671 100644 --- a/src/node.h +++ b/src/node.h @@ -5,8 +5,9 @@ extern "C" { #endif -#include +#include #include +#include #include "config.h" #include "cmark.h" diff --git a/src/render.h b/src/render.h index db60a5d54..6f71acbd4 100644 --- a/src/render.h +++ b/src/render.h @@ -5,7 +5,9 @@ extern "C" { #endif +#include #include + #include "buffer.h" typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping; diff --git a/src/xml.c b/src/xml.c index 45589b9d4..86c74117e 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1,7 +1,8 @@ -#include +#include +#include #include +#include #include -#include #include "config.h" #include "cmark.h"