Skip to content

Commit

Permalink
remove some compiler compatibility checks (#498)
Browse files Browse the repository at this point in the history
`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/
  • Loading branch information
compnerd authored Dec 29, 2023
1 parent 02ca61e commit 7daaeb0
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 80 deletions.
6 changes: 0 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* see http://spec.commonmark.org/0.24/#phase-1-block-structure
*/

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#include "cmark_ctype.h"
#include "config.h"
Expand Down
10 changes: 5 additions & 5 deletions src/buffer.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <string.h>

#include "config.h"
#include "cmark_ctype.h"
Expand Down
7 changes: 4 additions & 3 deletions src/commonmark.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>

#include "config.h"
#include "cmark.h"
Expand Down
54 changes: 0 additions & 54 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,8 @@
extern "C" {
#endif

#cmakedefine HAVE_STDBOOL_H

#ifdef HAVE_STDBOOL_H
#include <stdbool.h>
#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
Expand All @@ -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 <stdio.h>
#include <stdarg.h>

#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
Expand Down
6 changes: 4 additions & 2 deletions src/html.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "cmark_ctype.h"
#include "config.h"
#include "cmark.h"
Expand Down
3 changes: 2 additions & 1 deletion src/inlines.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "cmark_ctype.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions src/iterator.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>

#include "config.h"
Expand Down
5 changes: 3 additions & 2 deletions src/latex.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "config.h"
#include "cmark.h"
Expand Down
5 changes: 3 additions & 2 deletions src/man.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "config.h"
#include "cmark.h"
Expand Down
1 change: 1 addition & 0 deletions src/node.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

Expand Down
3 changes: 2 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
extern "C" {
#endif

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "config.h"
#include "cmark.h"
Expand Down
2 changes: 2 additions & 0 deletions src/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
extern "C" {
#endif

#include <stdbool.h>
#include <stdlib.h>

#include "buffer.h"

typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping;
Expand Down
5 changes: 3 additions & 2 deletions src/xml.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "config.h"
#include "cmark.h"
Expand Down

0 comments on commit 7daaeb0

Please sign in to comment.