Skip to content

Commit 459b8d0

Browse files
Merge pull request commonmark#305 from kevinbackhouse/deprecate-cmark_init_standard_node_flags
Deprecate cmark_init_standard_node_flags
2 parents 2a86e65 + 0685ab0 commit 459b8d0

File tree

7 files changed

+26
-37
lines changed

7 files changed

+26
-37
lines changed

api_test/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,6 @@ int main() {
11331133
int retval;
11341134
test_batch_runner *runner = test_batch_runner_new();
11351135

1136-
cmark_init_standard_node_flags();
11371136
version(runner);
11381137
constructor(runner);
11391138
accessors(runner);

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/main.c

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

142-
cmark_init_standard_node_flags();
143142
cmark_gfm_core_extensions_ensure_registered();
144143

145144
#ifdef USE_PLEDGE

src/node.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ static void S_node_unlink(cmark_node *node);
99

1010
#define NODE_MEM(node) cmark_node_mem(node)
1111

12-
cmark_node__internal_flags CMARK_NODE__OPEN;
13-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
14-
cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
15-
16-
void cmark_register_node_flag(cmark_node__internal_flags *flags) {
17-
static uint8_t shift = 0;
12+
void cmark_register_node_flag(cmark_node_internal_flags *flags) {
13+
static cmark_node_internal_flags nextflag = CMARK_NODE__REGISTER_FIRST;
1814

1915
// flags should be a pointer to a global variable and this function
2016
// should only be called once to initialize its value.
@@ -24,24 +20,16 @@ void cmark_register_node_flag(cmark_node__internal_flags *flags) {
2420
}
2521

2622
// Check that we haven't run out of bits.
27-
if (shift >= 8 * sizeof(cmark_node__internal_flags)) {
23+
if (nextflag == 0) {
2824
fprintf(stderr, "too many flags in cmark_register_node_flag\n");
2925
abort();
3026
}
3127

32-
*flags = (cmark_node__internal_flags)1 << shift;
33-
shift++;
28+
*flags = nextflag;
29+
nextflag <<= 1;
3430
}
3531

36-
void cmark_init_standard_node_flags() {
37-
static int initialized = 0;
38-
if (!initialized) {
39-
initialized = 1;
40-
cmark_register_node_flag(&CMARK_NODE__OPEN);
41-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_BLANK);
42-
cmark_register_node_flag(&CMARK_NODE__LAST_LINE_CHECKED);
43-
}
44-
}
32+
void cmark_init_standard_node_flags() {}
4533

4634
bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) {
4735
if (child_type == CMARK_NODE_DOCUMENT) {

src/node.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,17 @@ typedef struct {
4848
cmark_chunk on_exit;
4949
} cmark_custom;
5050

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

5363
struct cmark_node {
5464
cmark_strbuf content;
@@ -68,7 +78,7 @@ struct cmark_node {
6878
int end_column;
6979
int internal_offset;
7080
uint16_t type;
71-
cmark_node__internal_flags flags;
81+
cmark_node_internal_flags flags;
7282

7383
cmark_syntax_extension *extension;
7484

@@ -98,19 +108,15 @@ struct cmark_node {
98108
* which will store the flag value.
99109
*/
100110
CMARK_GFM_EXPORT
101-
void cmark_register_node_flag(cmark_node__internal_flags *flags);
102-
103-
/**
104-
* Standard node flags. (Initialized using `cmark_init_standard_node_flags`.)
105-
*/
106-
extern cmark_node__internal_flags CMARK_NODE__OPEN;
107-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_BLANK;
108-
extern cmark_node__internal_flags CMARK_NODE__LAST_LINE_CHECKED;
111+
void cmark_register_node_flag(cmark_node_internal_flags *flags);
109112

110113
/**
111-
* Uses `cmark_register_node_flag` to initialize the standard node flags.
112-
* This function should be called at program startup time. Calling it
113-
* multiple times has no additional effect.
114+
* DEPRECATED.
115+
*
116+
* This function was added in cmark-gfm version 0.29.0.gfm.7, and was
117+
* required to be called at program start time, which caused
118+
* backwards-compatibility issues in applications that use cmark-gfm as a
119+
* library. It is now a no-op.
114120
*/
115121
CMARK_GFM_EXPORT
116122
void cmark_init_standard_node_flags();

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)