Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: automarkup.py: Use new C roles in Sphinx 3

While Sphinx 2 used a single c:type role for struct, union, enum and
typedef, Sphinx 3 uses a specific role for each one.
To keep backward compatibility, detect the Sphinx version and use the
correct roles for that version.

Signed-off-by: Nícolas F. R. A. Prado <nfraprado@protonmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Nícolas F. R. A. Prado and committed by
Mauro Carvalho Chehab
06dc65b0 2791f47d

+49 -6
+49 -6
Documentation/sphinx/automarkup.py
··· 23 23 # bit tries to restrict matches to things that won't create trouble. 24 24 # 25 25 RE_function = re.compile(r'(([\w_][\w\d_]+)\(\))') 26 - RE_type = re.compile(r'(struct|union|enum|typedef)\s+([\w_][\w\d_]+)') 26 + 27 + # 28 + # Sphinx 2 uses the same :c:type role for struct, union, enum and typedef 29 + # 30 + RE_generic_type = re.compile(r'(struct|union|enum|typedef)\s+([\w_][\w\d_]+)') 31 + 32 + # 33 + # Sphinx 3 uses a different C role for each one of struct, union, enum and 34 + # typedef 35 + # 36 + RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=re.ASCII) 37 + RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=re.ASCII) 38 + RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=re.ASCII) 39 + RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=re.ASCII) 40 + 27 41 # 28 42 # Detects a reference to a documentation page of the form Documentation/... with 29 43 # an optional extension ··· 62 48 # 63 49 # Associate each regex with the function that will markup its matches 64 50 # 65 - markup_func = {RE_type: markup_c_ref, 66 - RE_function: markup_c_ref, 67 - RE_doc: markup_doc_ref} 51 + markup_func_sphinx2 = {RE_doc: markup_doc_ref, 52 + RE_function: markup_c_ref, 53 + RE_generic_type: markup_c_ref} 54 + 55 + markup_func_sphinx3 = {RE_doc: markup_doc_ref, 56 + RE_function: markup_c_ref, 57 + RE_struct: markup_c_ref, 58 + RE_union: markup_c_ref, 59 + RE_enum: markup_c_ref, 60 + RE_typedef: markup_c_ref} 61 + 62 + if sphinx.version_info[0] >= 3: 63 + markup_func = markup_func_sphinx3 64 + else: 65 + markup_func = markup_func_sphinx2 66 + 68 67 match_iterators = [regex.finditer(t) for regex in markup_func] 69 68 # 70 69 # Sort all references by the starting position in text ··· 106 79 # type_name) with an appropriate cross reference. 107 80 # 108 81 def markup_c_ref(docname, app, match): 109 - class_str = {RE_function: 'c-func', RE_type: 'c-type'} 110 - reftype_str = {RE_function: 'function', RE_type: 'type'} 82 + class_str = {RE_function: 'c-func', 83 + # Sphinx 2 only 84 + RE_generic_type: 'c-type', 85 + # Sphinx 3+ only 86 + RE_struct: 'c-struct', 87 + RE_union: 'c-union', 88 + RE_enum: 'c-enum', 89 + RE_typedef: 'c-type', 90 + } 91 + reftype_str = {RE_function: 'function', 92 + # Sphinx 2 only 93 + RE_generic_type: 'type', 94 + # Sphinx 3+ only 95 + RE_struct: 'struct', 96 + RE_union: 'union', 97 + RE_enum: 'enum', 98 + RE_typedef: 'type', 99 + } 111 100 112 101 cdom = app.env.domains['c'] 113 102 #