Skip to content

Commit 0f871ea

Browse files
Merge remote-tracking branch 'github/master' into QuietMisdreavus/sync-upstream-gfm.7
2 parents 5b3d12b + eb32891 commit 0f871ea

File tree

10 files changed

+34
-48
lines changed

10 files changed

+34
-48
lines changed

api_test/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,6 @@ int main() {
15751575
int retval;
15761576
test_batch_runner *runner = test_batch_runner_new();
15771577

1578-
cmark_init_standard_node_flags();
15791578
version(runner);
15801579
constructor(runner);
15811580
accessors(runner);

bin/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ int main(int argc, char *argv[]) {
143143
}
144144
#endif
145145

146-
cmark_init_standard_node_flags();
147146
cmark_gfm_core_extensions_ensure_registered();
148147

149148
#ifdef USE_PLEDGE

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[0.29.0.gfm.8]
2+
3+
* We restored backwards compatibility by deprecating the `cmark_init_standard_node_flags()` requirement, which is now a noop (#305)
4+
* We added a quadratic complexity fuzzing target (#304)
5+
16
[0.29.0.gfm.7]
27

38
* Fixed a polynomial time complexity issue per

extensions/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
cmake_minimum_required(VERSION 2.8)
21
set(LIBRARY "libcmark-gfm-extensions")
32
set(STATICLIBRARY "libcmark-gfm-extensions_static")
43
set(LIBRARY_SOURCES
@@ -24,7 +23,6 @@ include_directories(include ${CMAKE_CURRENT_BINARY_DIR})
2423

2524
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg")
2625
set(CMAKE_LINKER_PROFILE "${CMAKE_LINKER_FLAGS_RELEASE} -pg")
27-
add_compiler_export_flags()
2826

2927
if (CMARK_SHARED)
3028
add_library(${LIBRARY} SHARED ${LIBRARY_SOURCES})

extensions/core-extensions.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ static void register_plugins(void) {
2727

2828
void cmark_gfm_core_extensions_ensure_registered(void) {
2929
CMARK_RUN_ONCE(registered, register_plugins);
30-
31-
// Also initialize the standard node flags if they haven't been already, in case an existing
32-
// caller has not updated their code but is already registering the core extensions.
33-
cmark_init_standard_node_flags();
3430
}

extensions/table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "cmark-gfm-core-extensions.h"
1313

1414
// Custom node flag, initialized in `create_table_extension`.
15-
static cmark_node__internal_flags CMARK_NODE__TABLE_VISITED;
15+
static cmark_node_internal_flags CMARK_NODE__TABLE_VISITED;
1616

1717
cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW,
1818
CMARK_NODE_TABLE_CELL;

fuzz/fuzz_quadratic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const char *extension_names[] = {
1717
};
1818

1919
int LLVMFuzzerInitialize(int *argc, char ***argv) {
20-
cmark_init_standard_node_flags();
2120
cmark_gfm_core_extensions_ensure_registered();
2221
return 0;
2322
}

src/include/node.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ typedef struct {
5252
cmark_chunk on_exit;
5353
} cmark_custom;
5454

55-
typedef uint16_t cmark_node__internal_flags;
55+
enum cmark_node__internal_flags {
56+
CMARK_NODE__OPEN = (1 << 0),
57+
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
58+
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
59+
60+
// Extensions can register custom flags by calling `cmark_register_node_flag`.
61+
// This is the starting value for the custom flags.
62+
CMARK_NODE__REGISTER_FIRST = (1 << 3),
63+
};
64+
65+
typedef uint16_t cmark_node_internal_flags;
5666

5767
struct cmark_node {
5868
cmark_strbuf content;
@@ -72,7 +82,7 @@ struct cmark_node {
7282
int end_column;
7383
int internal_offset;
7484
uint16_t type;
75-
cmark_node__internal_flags flags;
85+
cmark_node_internal_flags flags;
7686
int backtick_count;
7787

7888
cmark_syntax_extension *extension;
@@ -104,19 +114,15 @@ struct cmark_node {
104114
* which will store the flag value.
105115
*/
106116
CMARK_GFM_EXPORT
107-
void cmark_register_node_flag(cmark_node__internal_flags *flags);
108-
109-
/**
110-
* Standard node flags. (Initialized using `cmark_init_standard_node_flags`.)
111-
*/
112-
extern cmark_node__internal_flags CMARK_NODE__OPEN;
113-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
114-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
117+
void cmark_register_node_flag(cmark_node_internal_flags *flags);
115118

116119
/**
117-
* Uses `cmark_register_node_flag` to initialize the standard node flags.
118-
* This function should be called at program startup time. Calling it
119-
* multiple times has no additional effect.
120+
* DEPRECATED.
121+
*
122+
* This function was added in cmark-gfm version 0.29.0.gfm.7, and was
123+
* required to be called at program start time, which caused
124+
* backwards-compatibility issues in applications that use cmark-gfm as a
125+
* library. It is now a no-op.
120126
*/
121127
CMARK_GFM_EXPORT
122128
void cmark_init_standard_node_flags();

src/node.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@
66
#include "node.h"
77
#include "syntax_extension.h"
88

9-
CMARK_DEFINE_LOCK(shift)
9+
CMARK_DEFINE_LOCK(nextflag)
1010

1111
static void S_node_unlink(cmark_node *node);
1212

1313
#define NODE_MEM(node) cmark_node_mem(node)
1414

15-
cmark_node__internal_flags CMARK_NODE__OPEN;
16-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
17-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
15+
void cmark_register_node_flag(cmark_node_internal_flags *flags) {
16+
CMARK_INITIALIZE_AND_LOCK(nextflag);
1817

19-
void cmark_register_node_flag(cmark_node__internal_flags *flags) {
20-
CMARK_INITIALIZE_AND_LOCK(shift);
21-
22-
static uint8_t shift = 0;
18+
static cmark_node_internal_flags nextflag = CMARK_NODE__REGISTER_FIRST;
2319

2420
// flags should be a pointer to a global variable and this function
2521
// should only be called once to initialize its value.
@@ -29,28 +25,18 @@ void cmark_register_node_flag(cmark_node__internal_flags *flags) {
2925
}
3026

3127
// Check that we haven't run out of bits.
32-
if (shift >= 8 * sizeof(cmark_node__internal_flags)) {
28+
if (nextflag == 0) {
3329
fprintf(stderr, "too many flags in cmark_register_node_flag\n");
3430
abort();
3531
}
3632

37-
*flags = (cmark_node__internal_flags)1 << shift;
38-
shift++;
33+
*flags = nextflag;
34+
nextflag <<= 1;
3935

40-
CMARK_UNLOCK(shift);
36+
CMARK_UNLOCK(nextflag);
4137
}
4238

43-
CMARK_DEFINE_ONCE(initialized);
44-
45-
static void initialize_standard_flags(void) {
46-
cmark_register_node_flag(&CMARK_NODE__OPEN);
47-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_BLANK);
48-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_CHECKED);
49-
}
50-
51-
void cmark_init_standard_node_flags() {
52-
CMARK_RUN_ONCE(initialized, initialize_standard_flags);
53-
}
39+
void cmark_init_standard_node_flags() {}
5440

5541
bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) {
5642
if (child_type == CMARK_NODE_DOCUMENT) {

test/cmark.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def pipe_through_prog(prog, text):
1313

1414
def parse(lib, extlib, text, extensions):
1515
cmark_gfm_core_extensions_ensure_registered = extlib.cmark_gfm_core_extensions_ensure_registered
16-
cmark_init_standard_node_flags = lib.cmark_init_standard_node_flags
1716

1817
find_syntax_extension = lib.cmark_find_syntax_extension
1918
find_syntax_extension.restype = c_void_p
@@ -33,7 +32,6 @@ def parse(lib, extlib, text, extensions):
3332
parser_finish.restype = c_void_p
3433
parser_finish.argtypes = [c_void_p]
3534

36-
cmark_init_standard_node_flags()
3735
cmark_gfm_core_extensions_ensure_registered()
3836

3937
parser = parser_new(0)

0 commit comments

Comments
 (0)