Skip to content

Commit 3e3761a

Browse files
Yuki IzumiYuki Izumi
authored andcommitted
Strip extensions API down and separate from core
1 parent c8960d7 commit 3e3761a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+835
-1722
lines changed

Makefile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
SRCDIR=src
2-
EXTDIR=extensions
32
DATADIR=data
43
BUILDDIR?=build
54
GENERATOR?=Unix Makefiles
@@ -127,19 +126,6 @@ $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
127126
--encoding-policy substitute -o $@ $<
128127
$(CLANG_FORMAT) $@
129128

130-
# We include scanners.c in the repository, so this shouldn't
131-
# normally need to be generated.
132-
$(EXTDIR)/ext_scanners.c: $(EXTDIR)/ext_scanners.re
133-
@case "$$(re2c -v)" in \
134-
*\ 0.13.*|*\ 0.14|*\ 0.14.1) \
135-
echo "re2c >= 0.14.2 is required"; \
136-
false; \
137-
;; \
138-
esac
139-
re2c --case-insensitive -b -i --no-generation-date -8 \
140-
--encoding-policy substitute -o $@ $<
141-
clang-format -style llvm -i $@
142-
143129
# We include entities.inc in the repository, so normally this
144130
# doesn't need to be regenerated:
145131
$(SRCDIR)/entities.inc: tools/make_entities_inc.py
@@ -203,6 +189,9 @@ newbench:
203189
format:
204190
$(CLANG_FORMAT) src/*.c src/*.h api_test/*.c api_test/*.h
205191

192+
format-extensions:
193+
clang-format -style llvm -i extensions/*.c extensions/*.h
194+
206195
operf: $(CMARK)
207196
operf $< < $(BENCHFILE) > /dev/null
208197

api_test/main.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void test_md_to_html(test_batch_runner *runner, const char *markdown,
2424
const char *expected_html, const char *msg);
2525

2626
static void test_content(test_batch_runner *runner, cmark_node_type type,
27-
int allowed_content);
27+
unsigned int *allowed_content);
2828

2929
static void test_char(test_batch_runner *runner, int valid, const char *utf8,
3030
const char *msg);
@@ -177,7 +177,7 @@ static void accessors(test_batch_runner *runner) {
177177
OK(runner, cmark_node_set_literal(string, literal + sizeof("prefix")),
178178
"set_literal suffix");
179179

180-
char *rendered_html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
180+
char *rendered_html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
181181
static const char expected_html[] =
182182
"<h3>Header</h3>\n"
183183
"<ol start=\"3\">\n"
@@ -299,7 +299,7 @@ static void iterator_delete(test_batch_runner *runner) {
299299
}
300300
}
301301

302-
char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
302+
char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
303303
static const char expected[] = "<p>a c</p>\n"
304304
"<p>a c</p>\n";
305305
STR_EQ(runner, html, expected, "iterate and delete nodes");
@@ -339,7 +339,7 @@ static void create_tree(test_batch_runner *runner) {
339339
OK(runner, cmark_node_append_child(emph, str2), "append3");
340340
INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append3 consistent");
341341

342-
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
342+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
343343
STR_EQ(runner, html, "<p>Hello, <em>world</em>!</p>\n", "render_html");
344344
free(html);
345345

@@ -375,7 +375,7 @@ static void create_tree(test_batch_runner *runner) {
375375

376376
cmark_node_unlink(emph);
377377

378-
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
378+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
379379
STR_EQ(runner, html, "<p>brzz!</p>\n", "render_html after shuffling");
380380
free(html);
381381

@@ -407,7 +407,7 @@ static void custom_nodes(test_batch_runner *runner) {
407407
STR_EQ(runner, cmark_node_get_on_exit(cb), "", "get_on_exit (empty)");
408408
cmark_node_append_child(doc, cb);
409409

410-
html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
410+
html = cmark_render_html(doc, CMARK_OPT_DEFAULT, NULL);
411411
STR_EQ(runner, html, "<p><ON ENTER|Hello|ON EXIT></p>\n<on enter|\n",
412412
"render_html");
413413
free(html);
@@ -434,22 +434,18 @@ void hierarchy(test_batch_runner *runner) {
434434

435435
cmark_node_free(bquote1);
436436

437-
int max_node_type = CMARK_NODE_LAST_BLOCK > CMARK_NODE_LAST_INLINE
438-
? CMARK_NODE_LAST_BLOCK
439-
: CMARK_NODE_LAST_INLINE;
440-
OK(runner, max_node_type < 32, "all node types < 32");
441-
442-
int list_item_flag = 1 << CMARK_NODE_ITEM;
443-
int top_level_blocks =
444-
(1 << CMARK_NODE_BLOCK_QUOTE) | (1 << CMARK_NODE_LIST) |
445-
(1 << CMARK_NODE_CODE_BLOCK) | (1 << CMARK_NODE_HTML_BLOCK) |
446-
(1 << CMARK_NODE_PARAGRAPH) | (1 << CMARK_NODE_HEADING) |
447-
(1 << CMARK_NODE_THEMATIC_BREAK);
448-
int all_inlines = (1 << CMARK_NODE_TEXT) | (1 << CMARK_NODE_SOFTBREAK) |
449-
(1 << CMARK_NODE_LINEBREAK) | (1 << CMARK_NODE_CODE) |
450-
(1 << CMARK_NODE_HTML_INLINE) | (1 << CMARK_NODE_EMPH) |
451-
(1 << CMARK_NODE_STRONG) | (1 << CMARK_NODE_LINK) |
452-
(1 << CMARK_NODE_IMAGE);
437+
unsigned int list_item_flag[] = {CMARK_NODE_ITEM, 0};
438+
unsigned int top_level_blocks[] = {
439+
CMARK_NODE_BLOCK_QUOTE, CMARK_NODE_LIST,
440+
CMARK_NODE_CODE_BLOCK, CMARK_NODE_HTML_BLOCK,
441+
CMARK_NODE_PARAGRAPH, CMARK_NODE_HEADING,
442+
CMARK_NODE_THEMATIC_BREAK, 0};
443+
unsigned int all_inlines[] = {
444+
CMARK_NODE_TEXT, CMARK_NODE_SOFTBREAK,
445+
CMARK_NODE_LINEBREAK, CMARK_NODE_CODE,
446+
CMARK_NODE_HTML_INLINE, CMARK_NODE_EMPH,
447+
CMARK_NODE_STRONG, CMARK_NODE_LINK,
448+
CMARK_NODE_IMAGE, 0};
453449

454450
test_content(runner, CMARK_NODE_DOCUMENT, top_level_blocks);
455451
test_content(runner, CMARK_NODE_BLOCK_QUOTE, top_level_blocks);
@@ -472,15 +468,18 @@ void hierarchy(test_batch_runner *runner) {
472468
}
473469

474470
static void test_content(test_batch_runner *runner, cmark_node_type type,
475-
int allowed_content) {
471+
unsigned int *allowed_content) {
476472
cmark_node *node = cmark_node_new(type);
477473

478474
for (int i = 0; i < num_node_types; ++i) {
479475
cmark_node_type child_type = node_types[i];
480476
cmark_node *child = cmark_node_new(child_type);
481477

482478
int got = cmark_node_append_child(node, child);
483-
int expected = (allowed_content >> child_type) & 1;
479+
int expected = 0;
480+
if (allowed_content)
481+
for (unsigned int *p = allowed_content; *p; ++p)
482+
expected |= *p == child_type;
484483

485484
INT_EQ(runner, got, expected, "add %d as child of %d", child_type, type);
486485

@@ -505,17 +504,17 @@ static void render_html(test_batch_runner *runner) {
505504
cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
506505

507506
cmark_node *paragraph = cmark_node_first_child(doc);
508-
html = cmark_render_html(paragraph, CMARK_OPT_DEFAULT);
507+
html = cmark_render_html(paragraph, CMARK_OPT_DEFAULT, NULL);
509508
STR_EQ(runner, html, "<p>foo <em>bar</em></p>\n", "render single paragraph");
510509
free(html);
511510

512511
cmark_node *string = cmark_node_first_child(paragraph);
513-
html = cmark_render_html(string, CMARK_OPT_DEFAULT);
512+
html = cmark_render_html(string, CMARK_OPT_DEFAULT, NULL);
514513
STR_EQ(runner, html, "foo ", "render single inline");
515514
free(html);
516515

517516
cmark_node *emph = cmark_node_next(string);
518-
html = cmark_render_html(emph, CMARK_OPT_DEFAULT);
517+
html = cmark_render_html(emph, CMARK_OPT_DEFAULT, NULL);
519518
STR_EQ(runner, html, "<em>bar</em>", "render inline with children");
520519
free(html);
521520

extensions/CMakeLists.txt

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
cmake_minimum_required(VERSION 2.8)
2-
set(LIBRARY "cmarkextensions")
2+
set(STATICLIBRARY "libcmarkextensions_static")
33
set(LIBRARY_SOURCES
4-
${PROJECT_SOURCE_DIR}/src/buffer.c
5-
${PROJECT_SOURCE_DIR}/src/cmark_ctype.c
64
core-extensions.c
7-
ext_scanners.c
8-
ext_scanners.h
95
)
106

117
include_directories(
@@ -27,6 +23,54 @@ include_directories(. ${CMAKE_CURRENT_BINARY_DIR})
2723
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg")
2824
set(CMAKE_LINKER_PROFILE "${CMAKE_LINKER_FLAGS_RELEASE} -pg")
2925

30-
add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})
26+
add_library(${STATICLIBRARY} STATIC ${LIBRARY_SOURCES})
3127

32-
target_link_libraries(cmarkextensions libcmark)
28+
set_target_properties(${STATICLIBRARY} PROPERTIES
29+
COMPILE_FLAGS -DCMARK_STATIC_DEFINE
30+
POSITION_INDEPENDENT_CODE ON)
31+
32+
if (MSVC)
33+
set_target_properties(${STATICLIBRARY} PROPERTIES
34+
OUTPUT_NAME "cmarkextensions_static"
35+
VERSION ${PROJECT_VERSION})
36+
else()
37+
set_target_properties(${STATICLIBRARY} PROPERTIES
38+
OUTPUT_NAME "cmarkextensions"
39+
VERSION ${PROJECT_VERSION})
40+
endif(MSVC)
41+
42+
# Feature tests
43+
include(CheckIncludeFile)
44+
include(CheckCSourceCompiles)
45+
include(CheckCSourceRuns)
46+
include(CheckSymbolExists)
47+
CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
48+
CHECK_C_SOURCE_COMPILES(
49+
"int main() { __builtin_expect(0,0); return 0; }"
50+
HAVE___BUILTIN_EXPECT)
51+
CHECK_C_SOURCE_COMPILES("
52+
int f(void) __attribute__ (());
53+
int main() { return 0; }
54+
" HAVE___ATTRIBUTE__)
55+
56+
# Always compile with warnings
57+
if(MSVC)
58+
# Force to always compile with W4
59+
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
60+
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
61+
else()
62+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
63+
endif()
64+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4706 /D_CRT_SECURE_NO_WARNINGS")
65+
elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
66+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c99 -pedantic")
67+
endif()
68+
69+
# Compile as C++ under MSVC older than 12.0
70+
if(MSVC AND MSVC_VERSION LESS 1800)
71+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
72+
endif()
73+
74+
if(CMAKE_BUILD_TYPE STREQUAL "Ubsan")
75+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
76+
endif()

0 commit comments

Comments
 (0)