cmark

My personal build of CMark ✏️

Commit
4cf38a5569d937142609441a27abf0edb9023da4
Parent
834266acfdb2aa63e07ae03b08ae11ca21e00dcf
Author
John MacFarlane <jgm@berkeley.edu>
Date

Merge pull request #256 from nwellnhof/windows_fixes

Windows fixes

Diffstat

18 files changed, 78 insertions, 44 deletions

Status File Name N° Changes Insertions Deletions
Modified .travis.yml 2 1 1
Modified CMakeLists.txt 2 1 1
Modified Makefile 5 5 0
Modified api_test/cplusplus.cpp 4 2 2
Added api_test/cplusplus.h 17 17 0
Modified api_test/main.c 4 1 3
Modified src/CMakeLists.txt 20 2 18
Modified src/buffer.c 3 3 0
Modified src/cmark_ctype.c 2 2 0
Modified src/cmark_ctype.h 13 13 0
Modified src/config.h.in 6 6 0
Modified src/html.c 5 2 3
Modified src/main.c 9 9 0
Modified src/man.c 4 2 2
Modified src/xml.c 5 2 3
Modified test/CMakeLists.txt 17 8 9
Modified test/cmark.py 2 1 1
Modified test/spec_tests.py 2 1 1
diff --git a/.travis.yml b/.travis.yml
@@ -6,7 +6,7 @@ before_install:
  # we need a more recent cmake than travis provides (at least 2.8.9):
  - echo "yes" | sudo add-apt-repository ppa:kalakris/cmake
  - sudo apt-get update -qq
- - sudo apt-get install -qq cmake python3 pandoc re2c valgrind
+ - sudo apt-get install -qq cmake python3 pandoc valgrind
 script:
  - make testtarball
  - PROG=`ls cmark-*.*/build/src/cmark` make leakcheck
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -16,7 +16,7 @@ add_subdirectory(src)
 add_subdirectory(api_test)
 add_subdirectory(man)
 enable_testing()
-add_subdirectory(test)
+add_subdirectory(test testdir)
 
 if(NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING
diff --git a/Makefile b/Makefile
@@ -85,6 +85,11 @@ $(SRCDIR)/html_unescape.h: $(SRCDIR)/html_unescape.gperf
 $(SRCDIR)/case_fold_switch.inc: $(DATADIR)/CaseFolding-3.2.0.txt
 	perl mkcasefold.pl < $< > $@
 
+# We include scanners.c in the repository, so this shouldn't
+# normally need to be generated.
+$(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
+	re2c --case-insensitive -b -i --no-generation-date -o $@ $<
+
 test: $(SPEC) $(BUILDDIR)
 	make -C $(BUILDDIR) test ARGS="-V"
 
diff --git a/api_test/cplusplus.cpp b/api_test/cplusplus.cpp
@@ -1,10 +1,10 @@
 #include <cstdlib>
 
 #include "cmark.h"
-
+#include "cplusplus.h"
 #include "harness.h"
 
-extern "C" void
+void
 test_cplusplus(test_batch_runner *runner)
 {
     static const char md[] = "paragraph\n";
diff --git a/api_test/cplusplus.h b/api_test/cplusplus.h
@@ -0,0 +1,17 @@
+#ifndef CMARK_API_TEST_CPLUSPLUS_H
+#define CMARK_API_TEST_CPLUSPLUS_H
+
+#include "harness.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void
+test_cplusplus(test_batch_runner *runner);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/api_test/main.c b/api_test/main.c
@@ -7,12 +7,10 @@
 #include "node.h"
 
 #include "harness.h"
+#include "cplusplus.h"
 
 #define UTF8_REPL "\xEF\xBF\xBD"
 
-void
-test_cplusplus(test_batch_runner *runner);
-
 static const cmark_node_type node_types[] = {
 	CMARK_NODE_DOCUMENT,
 	CMARK_NODE_BLOCK_QUOTE,
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -47,24 +47,6 @@ set(PROGRAM_SOURCES
 
 include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
 
-set(RE2C re2c)
-if (MSVC)
-    file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} DOS_CURRENT_SOURCE_DIR)
-    add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
-                        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
-                        COMMAND ${RE2C} --case-insensitive -b -i
-                        --no-generation-date
-                        -o ${DOS_CURRENT_SOURCE_DIR}\\scanners.c
-                        ${DOS_CURRENT_SOURCE_DIR}\\scanners.re )
-else(MSVC)
-    add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
-                        DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re
-                        COMMAND ${RE2C} --case-insensitive -b -i
-                        --no-generation-date
-                        -o ${CMAKE_CURRENT_SOURCE_DIR}/scanners.c
-                        ${CMAKE_CURRENT_SOURCE_DIR}/scanners.re )
-endif(MSVC)
-
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libcmark.pc.in
   ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc @ONLY)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcmark.pc
@@ -117,6 +99,7 @@ install(FILES cmark.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
 # Feature tests
 include(CheckIncludeFile)
 include(CheckCSourceCompiles)
+include(CheckSymbolExists)
 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
 CHECK_C_SOURCE_COMPILES(
   "int main() { __builtin_expect(0,0); return 0; }"
@@ -125,6 +108,7 @@ CHECK_C_SOURCE_COMPILES("
   int f(void) __attribute__ (());
   int main() { return 0; }
 " HAVE___ATTRIBUTE__)
+CHECK_SYMBOL_EXISTS(va_copy stdarg.h HAVE_VA_COPY)
 
 CONFIGURE_FILE(
   ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
diff --git a/src/buffer.c b/src/buffer.c
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "config.h"
 #include "cmark_ctype.h"
 #include "buffer.h"
 
@@ -175,6 +176,8 @@ int cmark_strbuf_vprintf(cmark_strbuf *buf, const char *format, va_list ap)
 			format, args
 			);
 
+		va_end(args);
+
 		if (len < 0) {
 			free(buf->ptr);
 			buf->ptr = cmark_strbuf__oom;
diff --git a/src/cmark_ctype.c b/src/cmark_ctype.c
@@ -1,5 +1,7 @@
 #include <stdint.h>
 
+#include "cmark_ctype.h"
+
 /** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other
  */
 static const int8_t cmark_ctype_class[256] = {
diff --git a/src/cmark_ctype.h b/src/cmark_ctype.h
@@ -1,3 +1,10 @@
+#ifndef CMARK_CMARK_CTYPE_H
+#define CMARK_CMARK_CTYPE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /** Locale-independent versions of functions from ctype.h.
  * We want cmark to behave the same no matter what the system locale.
  */
@@ -9,3 +16,9 @@ int cmark_ispunct(char c);
 int cmark_isalnum(char c);
 
 int cmark_isdigit(char c);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/config.h.in b/src/config.h.in
@@ -15,3 +15,9 @@
 #else
   #define CMARK_ATTRIBUTE(list)
 #endif
+
+#cmakedefine HAVE_VA_COPY
+
+#ifndef HAVE_VA_COPY
+  #define va_copy(dest, src) ((dest) = (src))
+#endif
diff --git a/src/html.c b/src/html.c
@@ -50,10 +50,9 @@ S_render_sourcepos(cmark_node *node, cmark_strbuf *html, long options) {
 }
 
 static int
-S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate,
-	long options)
+S_render_node(cmark_node *node, cmark_event_type ev_type,
+	struct render_state *state, long options)
 {
-	struct render_state *state = vstate;
 	cmark_node *parent;
 	cmark_node *grandparent;
 	cmark_strbuf *html = state->html;
diff --git a/src/main.c b/src/main.c
@@ -7,6 +7,11 @@
 #include "debug.h"
 #include "bench.h"
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  #include <io.h>
+  #include <fcntl.h>
+#endif
+
 typedef enum {
 	FORMAT_NONE,
 	FORMAT_HTML,
@@ -58,6 +63,10 @@ int main(int argc, char *argv[])
 	writer_format writer = FORMAT_HTML;
 	long options = CMARK_OPT_DEFAULT;
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+	_setmode(_fileno(stdout), _O_BINARY);
+#endif
+
 	parser = cmark_parser_new();
 	files = (int *)malloc(argc * sizeof(*files));
 
diff --git a/src/man.c b/src/man.c
@@ -43,9 +43,9 @@ struct render_state {
 };
 
 static int
-S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate)
+S_render_node(cmark_node *node, cmark_event_type ev_type,
+	struct render_state *state)
 {
-	struct render_state *state = vstate;
 	cmark_node *tmp;
 	cmark_strbuf *man = state->man;
 	int list_number;
diff --git a/src/xml.c b/src/xml.c
@@ -35,10 +35,9 @@ static inline void indent(struct render_state *state)
 }
 
 static int
-S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate,
-	long options)
+S_render_node(cmark_node *node, cmark_event_type ev_type,
+	struct render_state *state, long options)
 {
-	struct render_state *state = vstate;
 	cmark_strbuf *xml = state->xml;
 	bool literal = false;
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
@@ -3,13 +3,6 @@
 find_package(PythonInterp 3 REQUIRED)
 set(PYTHON ${PYTHON_EXECUTABLE})
 
-if (WIN32)
-  file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR)
-  set_tests_properties(api_test PROPERTIES
-    ENVIRONMENT "PATH=${WIN_DLL_DIR};$ENV{PATH}"
-  )
-endif(WIN32)
-
 add_test(html_normalization
   ${PYTHON} "-m" "doctest"
   "${CMAKE_CURRENT_SOURCE_DIR}/normalize.py"
@@ -27,6 +20,13 @@ add_test(pathological_tests_library
 
 add_test(NAME api_test COMMAND api_test)
 
+if (WIN32)
+  file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR)
+  set_tests_properties(api_test PROPERTIES
+    ENVIRONMENT "PATH=${WIN_DLL_DIR};$ENV{PATH}"
+  )
+endif(WIN32)
+
 add_test(spectest_executable
    ${PYTHON} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" "${CMAKE_SOURCE_DIR}/spec.txt" "--program" "${CMAKE_BINARY_DIR}/src/cmark"
-)-
\ No newline at end of file
+)
diff --git a/test/cmark.py b/test/cmark.py
@@ -26,7 +26,7 @@ class CMark:
             if sysname == 'Darwin':
                 libname += ".dylib"
             elif sysname == 'Windows':
-                libname += ".dll"
+                libname = "cmark.dll"
             else:
                 libname += ".so"
             if library_dir:
diff --git a/test/spec_tests.py b/test/spec_tests.py
@@ -84,7 +84,7 @@ def get_tests(specfile):
 
     header_re = re.compile('#+ ')
 
-    with open(specfile, 'r') as specf:
+    with open(specfile, 'r', encoding='utf-8') as specf:
         for line in specf:
             line_number = line_number + 1
             if state == 0 and re.match(header_re, line):