aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-12-31 11:04:46 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-12-31 11:04:46 -0800
commit4cf38a5569d937142609441a27abf0edb9023da4 (patch)
treeeb3e9f177bd4f9bbcc15deabc9c764e421c59972
parent834266acfdb2aa63e07ae03b08ae11ca21e00dcf (diff)
parente8a994cddc17eabaa415c73d970205aa489a756c (diff)
Merge pull request #256 from nwellnhof/windows_fixes
Windows fixes
-rw-r--r--.travis.yml2
-rw-r--r--CMakeLists.txt2
-rw-r--r--Makefile5
-rw-r--r--api_test/cplusplus.cpp4
-rw-r--r--api_test/cplusplus.h17
-rw-r--r--api_test/main.c4
-rw-r--r--src/CMakeLists.txt20
-rw-r--r--src/buffer.c3
-rw-r--r--src/cmark_ctype.c2
-rw-r--r--src/cmark_ctype.h13
-rw-r--r--src/config.h.in6
-rw-r--r--src/html.c5
-rw-r--r--src/main.c9
-rw-r--r--src/man.c4
-rw-r--r--src/xml.c5
-rw-r--r--test/CMakeLists.txt16
-rw-r--r--test/cmark.py2
-rwxr-xr-xtest/spec_tests.py2
18 files changed, 78 insertions, 43 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/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
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/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 <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
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,
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 87651bc..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
@@ -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
index b508310..87d817b 100644
--- 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
index 8805b9a..a3871a8 100644
--- 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
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
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
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/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 <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
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;
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
+)
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):