From d605ead4bc5dc96022a3f13bdbf05d2b63da3fd4 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 14:41:43 +0100 Subject: Add missing va_end --- src/buffer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/buffer.c b/src/buffer.c index b508310..15a6d05 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -175,6 +175,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; -- cgit v1.2.3 From 0e38a3706039607fb276228648f726ca9e15f6f0 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:24:14 +0100 Subject: Feature test for va_copy MSVC doesn't support va_copy. --- src/CMakeLists.txt | 2 ++ src/buffer.c | 1 + src/config.h.in | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 87651bc..bb0c7c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,6 +117,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 +126,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 index 15a6d05..87d817b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5,6 +5,7 @@ #include #include +#include "config.h" #include "cmark_ctype.h" #include "buffer.h" diff --git a/src/config.h.in b/src/config.h.in index 5294bc9..c1e9597 100644 --- 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 -- cgit v1.2.3 From 7787301eda4cbe4476a73241579c1838f6153279 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 15:30:26 +0100 Subject: Include guards and C linkage for cmark_ctype.h --- src/cmark_ctype.c | 2 ++ src/cmark_ctype.h | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/cmark_ctype.c b/src/cmark_ctype.c index 8805b9a..a3871a8 100644 --- a/src/cmark_ctype.c +++ b/src/cmark_ctype.c @@ -1,5 +1,7 @@ #include +#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 index 7423f80..f803946 100644 --- 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 -- cgit v1.2.3 From f20c3ed92efdb09c75f5ecfa14e00291825e65a0 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:12:48 +0100 Subject: Remove useless void* cast --- src/html.c | 5 ++--- src/man.c | 4 ++-- src/xml.c | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/html.c b/src/html.c index 67c93e9..bb04458 100644 --- 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/man.c b/src/man.c index 1b45f8b..176081f 100644 --- 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 index c0f9d4e..b012886 100644 --- 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; -- cgit v1.2.3 From 7081a8ec915762b71b9007ab6246e9914f34552f Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:14:26 +0100 Subject: Rename test builddir to 'build/testdir' The directory 'build/test' clashed with the 'test' Makefile target. Since nmake doesn't support phony targets, the tests wouldn't be run on Windows. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1863e09..6bf4cd6 100644 --- 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 -- cgit v1.2.3 From 858d7982fba21ff087c8fb75f310670e3723f2ae Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:22:35 +0100 Subject: Fix API test on Windows set_tests_properties must not be called before adding the test. --- test/CMakeLists.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f08b325..3d90b38 100644 --- 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 +) -- cgit v1.2.3 From 1b4d53f301e31fb5e4fbe687741367b938377009 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:10:50 +0100 Subject: Fix C++ API test --- api_test/cplusplus.cpp | 4 ++-- api_test/cplusplus.h | 17 +++++++++++++++++ api_test/main.c | 4 +--- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 api_test/cplusplus.h diff --git a/api_test/cplusplus.cpp b/api_test/cplusplus.cpp index ea64b06..b6228a3 100644 --- a/api_test/cplusplus.cpp +++ b/api_test/cplusplus.cpp @@ -1,10 +1,10 @@ #include #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 new file mode 100644 index 0000000..68edcb2 --- /dev/null +++ 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 index fae1d05..d2e41d3 100644 --- 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, -- cgit v1.2.3 From e9e8fa617a666b9ef36fb47dedb3d0fe96dfca48 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:24:55 +0100 Subject: Fix spec tests on Windows --- test/cmark.py | 2 +- test/spec_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cmark.py b/test/cmark.py index 21d0b3f..253e3a8 100644 --- 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 index b8b480e..cc676be 100755 --- 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): -- cgit v1.2.3 From fc9c8eed3d1b7f7608b8451c53b214e502f1b8f1 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 16:44:46 +0100 Subject: Write to stdout in binary mode on Windows This fixes the output of newlines. --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index b2027ee..e849b82 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,11 @@ #include "debug.h" #include "bench.h" +#if defined(_WIN32) && !defined(__CYGWIN__) + #include + #include +#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)); -- cgit v1.2.3 From e8a994cddc17eabaa415c73d970205aa489a756c Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 31 Dec 2014 17:01:13 +0100 Subject: Recreate scanners.c only on demand --- .travis.yml | 2 +- Makefile | 5 +++++ src/CMakeLists.txt | 18 ------------------ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67ad397..b96f79b 100644 --- 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/Makefile b/Makefile index e0679e5..e00107a 100644 --- 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/src/CMakeLists.txt b/src/CMakeLists.txt index bb0c7c1..b4a0fe8 100644 --- 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 -- cgit v1.2.3