Browse code

remove mailman2

Hanno Böck authored on27/09/2020 11:09:51
Showing1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,250 +0,0 @@
1
-From 19ff1036043ae40ff3d8a2e1a6a793219e1ec378 Mon Sep 17 00:00:00 2001
2
-From: Armin Rigo <arigo@tunes.org>
3
-Date: Tue, 26 May 2020 15:51:56 +0200
4
-Subject: [PATCH] Issue #454
5
-
6
-Try harder to avoid #line directives confuse the rest of pre-parsing
7
- cffi/cparser.py               | 37 ++++++++++++++++++++++++---
8
- testing/cffi0/test_parsing.py | 48 ++++++++++++++++++++++++++++++++++-
9
- 2 files changed, 81 insertions(+), 4 deletions(-)
10
-
11
-diff --git a/cffi/cparser.py b/cffi/cparser.py
12
-index d7069a73..d9784655 100644
13
-+++ b/cffi/cparser.py
14
-@@ -29,6 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
15
- _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
16
-                         r"\b((?:[^\n\\]|\\.)*?)$",
17
-                         re.DOTALL | re.MULTILINE)
18
-+_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
19
- _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
20
- _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
21
- _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
22
-@@ -163,10 +164,37 @@ def _warn_for_non_extern_non_static_global_variable(decl):
23
-                       "with C it should have a storage class specifier "
24
-                       "(usually 'extern')" % (decl.name,))
25
- 
26
-+def _remove_line_directives(csource):
27
-+    # _r_line_directive matches whole lines, without the final \n, if they
28
-+    # start with '#line' with some spacing allowed.  This function stores
29
-+    # them away and replaces them with exactly the string '#line@N', where
30
-+    # N is the index in the list 'line_directives'.
31
-+    line_directives = []
32
-+    def replace(m):
33
-+        i = len(line_directives)
34
-+        line_directives.append(m.group())
35
-+        return '#line@%d' % i
36
-+    csource = _r_line_directive.sub(replace, csource)
37
-+    return csource, line_directives
38
-+
39
-+def _put_back_line_directives(csource, line_directives):
40
-+    def replace(m):
41
-+        s = m.group()
42
-+        if not s.startswith('#line@'):
43
-+            raise AssertionError("unexpected #line directive "
44
-+                                 "(should have been processed and removed")
45
-+        return line_directives[int(s[6:])]
46
-+    return _r_line_directive.sub(replace, csource)
47
-+
48
- def _preprocess(csource):
49
-+    # First, remove the lines of the form '#line N "filename"' because
50
-+    # the "filename" part could confuse the rest
51
-+    csource, line_directives = _remove_line_directives(csource)
52
-     # Remove comments.  NOTE: this only work because the cdef() section
53
--    # should not contain any string literal!
54
--    csource = _r_comment.sub(' ', csource)
55
-+    # should not contain any string literals (except in line directives)!
56
-+    def replace_keeping_newlines(m):
57
-+        return ' ' + m.group().count('\n') * '\n'
58
-+    csource = _r_comment.sub(replace_keeping_newlines, csource)
59
-     # Remove the "#define FOO x" lines
60
-     macros = {}
61
-     for match in _r_define.finditer(csource):
62
-@@ -219,7 +247,10 @@ def _preprocess(csource):
63
-     csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource)
64
-     # Replace all remaining "..." with the same name, "__dotdotdot__",
65
-     # which is declared with a typedef for the purpose of C parsing.
66
--    return csource.replace('...', ' __dotdotdot__ '), macros
67
-+    csource = csource.replace('...', ' __dotdotdot__ ')
68
-+    # Finally, put back the line directives
69
-+    csource = _put_back_line_directives(csource, line_directives)
70
-+    return csource, macros
71
- 
72
- def _common_type_names(csource):
73
-     # Look in the source for what looks like usages of types from the
74
-diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
75
-index 3fc3783a..5f2d7ec4 100644
76
-+++ b/testing/cffi0/test_parsing.py
77
-@@ -174,7 +174,7 @@ def test_remove_line_continuation_comments():
78
-         double // blah \\
79
-                   more comments
80
-         x(void);
81
--        double // blah\\\\
82
-+        double // blah // blah\\\\
83
-         y(void);
84
-         double // blah\\ \
85
-                   etc
86
-@@ -185,6 +185,52 @@ def test_remove_line_continuation_comments():
87
-     m.y
88
-     m.z
89
- 
90
-+def test_dont_remove_comment_in_line_directives():
91
-+    ffi = FFI(backend=FakeBackend())
92
-+    e = py.test.raises(CDefError, ffi.cdef, """
93
-+        \t # \t line \t 8 \t "baz.c" \t
94
-+
95
-+        some syntax error here
96
-+    """)
97
-+    assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
98
-+    #
99
-+    e = py.test.raises(CDefError, ffi.cdef, """
100
-+        #line 7 "foo//bar.c"
101
-+
102
-+        some syntax error here
103
-+    """)
104
-+    assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
105
-+
106
-+def test_multiple_line_directives():
107
-+    ffi = FFI(backend=FakeBackend())
108
-+    e = py.test.raises(CDefError, ffi.cdef,
109
-+    """ #line 5 "foo.c"
110
-+        extern int xx;
111
-+        #line 6 "bar.c"
112
-+        extern int yy;
113
-+        #line 7 "baz.c"
114
-+        some syntax error here
115
-+        #line 8 "yadda.c"
116
-+        extern int zz;
117
-+    """)
118
-+    assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
119
-+
120
-+def test_commented_line_directive():
121
-+    ffi = FFI(backend=FakeBackend())
122
-+    e = py.test.raises(CDefError, ffi.cdef, """
123
-+        /*
124
-+        #line 5 "foo.c"
125
-+        */
126
-+        void xx(void);
127
-+
128
-+        #line 6 "bar.c"
129
-+        /*
130
-+        #line 35 "foo.c"
131
-+        */
132
-+        some syntax error
133
-+    """)
134
-+    assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
135
-+
136
- def test_line_continuation_in_defines():
137
-     ffi = FFI(backend=FakeBackend())
138
-     ffi.cdef("""
139
-2.26.2
140
-
141
-From 31249d786c833d4960bbbf4e0d7f7bcaecf92d1f Mon Sep 17 00:00:00 2001
142
-From: Armin Rigo <arigo@tunes.org>
143
-Date: Fri, 29 May 2020 10:27:40 +0200
144
-Subject: [PATCH] #454
145
-
146
-Second try with '# NUMBER' instead of '#line NUMBER', as gcc seems to output
147
- cffi/cparser.py               |  8 +++----
148
- testing/cffi0/test_parsing.py | 41 +++++++++++++++++++++++++++++++++++
149
- 2 files changed, 45 insertions(+), 4 deletions(-)
150
-
151
-diff --git a/cffi/cparser.py b/cffi/cparser.py
152
-index d9784655..74830e91 100644
153
-+++ b/cffi/cparser.py
154
-@@ -29,7 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
155
- _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
156
-                         r"\b((?:[^\n\\]|\\.)*?)$",
157
-                         re.DOTALL | re.MULTILINE)
158
--_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
159
-+_r_line_directive = re.compile(r"^[ \t]*#[ \t]*(?:line|\d+)\b.*$", re.MULTILINE)
160
- _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
161
- _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
162
- _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
163
-@@ -166,9 +166,9 @@ def _warn_for_non_extern_non_static_global_variable(decl):
164
- 
165
- def _remove_line_directives(csource):
166
-     # _r_line_directive matches whole lines, without the final \n, if they
167
--    # start with '#line' with some spacing allowed.  This function stores
168
--    # them away and replaces them with exactly the string '#line@N', where
169
--    # N is the index in the list 'line_directives'.
170
-+    # start with '#line' with some spacing allowed, or '#NUMBER'.  This
171
-+    # function stores them away and replaces them with exactly the string
172
-+    # '#line@N', where N is the index in the list 'line_directives'.
173
-     line_directives = []
174
-     def replace(m):
175
-         i = len(line_directives)
176
-diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
177
-index 5f2d7ec4..a5e45874 100644
178
-+++ b/testing/cffi0/test_parsing.py
179
-@@ -199,6 +199,21 @@ def test_dont_remove_comment_in_line_directives():
180
- 
181
-         some syntax error here
182
-     """)
183
-+    #
184
-+    assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
185
-+    ffi = FFI(backend=FakeBackend())
186
-+    e = py.test.raises(CDefError, ffi.cdef, """
187
-+        \t # \t 8 \t "baz.c" \t
188
-+
189
-+        some syntax error here
190
-+    """)
191
-+    assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
192
-+    #
193
-+    e = py.test.raises(CDefError, ffi.cdef, """
194
-+        # 7 "foo//bar.c"
195
-+
196
-+        some syntax error here
197
-+    """)
198
-     assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
199
- 
200
- def test_multiple_line_directives():
201
-@@ -214,6 +229,18 @@ def test_multiple_line_directives():
202
-         extern int zz;
203
-     """)
204
-     assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
205
-+    #
206
-+    e = py.test.raises(CDefError, ffi.cdef,
207
-+    """ # 5 "foo.c"
208
-+        extern int xx;
209
-+        # 6 "bar.c"
210
-+        extern int yy;
211
-+        # 7 "baz.c"
212
-+        some syntax error here
213
-+        # 8 "yadda.c"
214
-+        extern int zz;
215
-+    """)
216
-+    assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
217
- 
218
- def test_commented_line_directive():
219
-     ffi = FFI(backend=FakeBackend())
220
-@@ -229,6 +256,20 @@ def test_commented_line_directive():
221
-         */
222
-         some syntax error
223
-     """)
224
-+    #
225
-+    assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
226
-+    e = py.test.raises(CDefError, ffi.cdef, """
227
-+        /*
228
-+        # 5 "foo.c"
229
-+        */
230
-+        void xx(void);
231
-+
232
-+        # 6 "bar.c"
233
-+        /*
234
-+        # 35 "foo.c"
235
-+        */
236
-+        some syntax error
237
-+    """)
238
-     assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
239
- 
240
- def test_line_continuation_in_defines():
241
-2.26.2
242
-
Browse code

fix python2 stuff

Hanno Böck authored on24/09/2020 13:26:09
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,250 @@
1
+From 19ff1036043ae40ff3d8a2e1a6a793219e1ec378 Mon Sep 17 00:00:00 2001
2
+From: Armin Rigo <arigo@tunes.org>
3
+Date: Tue, 26 May 2020 15:51:56 +0200
4
+Subject: [PATCH] Issue #454
5
+
6
+Try harder to avoid #line directives confuse the rest of pre-parsing
7
+---
8
+ cffi/cparser.py               | 37 ++++++++++++++++++++++++---
9
+ testing/cffi0/test_parsing.py | 48 ++++++++++++++++++++++++++++++++++-
10
+ 2 files changed, 81 insertions(+), 4 deletions(-)
11
+
12
+diff --git a/cffi/cparser.py b/cffi/cparser.py
13
+index d7069a73..d9784655 100644
14
+--- a/cffi/cparser.py
15
+@@ -29,6 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
16
+ _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
17
+                         r"\b((?:[^\n\\]|\\.)*?)$",
18
+                         re.DOTALL | re.MULTILINE)
19
++_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
20
+ _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
21
+ _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
22
+ _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
23
+@@ -163,10 +164,37 @@ def _warn_for_non_extern_non_static_global_variable(decl):
24
+                       "with C it should have a storage class specifier "
25
+                       "(usually 'extern')" % (decl.name,))
26
+ 
27
++def _remove_line_directives(csource):
28
++    # _r_line_directive matches whole lines, without the final \n, if they
29
++    # start with '#line' with some spacing allowed.  This function stores
30
++    # them away and replaces them with exactly the string '#line@N', where
31
++    # N is the index in the list 'line_directives'.
32
++    line_directives = []
33
++    def replace(m):
34
++        i = len(line_directives)
35
++        line_directives.append(m.group())
36
++        return '#line@%d' % i
37
++    csource = _r_line_directive.sub(replace, csource)
38
++    return csource, line_directives
39
++
40
++def _put_back_line_directives(csource, line_directives):
41
++    def replace(m):
42
++        s = m.group()
43
++        if not s.startswith('#line@'):
44
++            raise AssertionError("unexpected #line directive "
45
++                                 "(should have been processed and removed")
46
++        return line_directives[int(s[6:])]
47
++    return _r_line_directive.sub(replace, csource)
48
++
49
+ def _preprocess(csource):
50
++    # First, remove the lines of the form '#line N "filename"' because
51
++    # the "filename" part could confuse the rest
52
++    csource, line_directives = _remove_line_directives(csource)
53
+     # Remove comments.  NOTE: this only work because the cdef() section
54
+-    # should not contain any string literal!
55
+-    csource = _r_comment.sub(' ', csource)
56
++    # should not contain any string literals (except in line directives)!
57
++    def replace_keeping_newlines(m):
58
++        return ' ' + m.group().count('\n') * '\n'
59
++    csource = _r_comment.sub(replace_keeping_newlines, csource)
60
+     # Remove the "#define FOO x" lines
61
+     macros = {}
62
+     for match in _r_define.finditer(csource):
63
+@@ -219,7 +247,10 @@ def _preprocess(csource):
64
+     csource = _r_float_dotdotdot.sub(' __dotdotdotfloat__ ', csource)
65
+     # Replace all remaining "..." with the same name, "__dotdotdot__",
66
+     # which is declared with a typedef for the purpose of C parsing.
67
+-    return csource.replace('...', ' __dotdotdot__ '), macros
68
++    csource = csource.replace('...', ' __dotdotdot__ ')
69
++    # Finally, put back the line directives
70
++    csource = _put_back_line_directives(csource, line_directives)
71
++    return csource, macros
72
+ 
73
+ def _common_type_names(csource):
74
+     # Look in the source for what looks like usages of types from the
75
+diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
76
+index 3fc3783a..5f2d7ec4 100644
77
+--- a/testing/cffi0/test_parsing.py
78
+@@ -174,7 +174,7 @@ def test_remove_line_continuation_comments():
79
+         double // blah \\
80
+                   more comments
81
+         x(void);
82
+-        double // blah\\\\
83
++        double // blah // blah\\\\
84
+         y(void);
85
+         double // blah\\ \
86
+                   etc
87
+@@ -185,6 +185,52 @@ def test_remove_line_continuation_comments():
88
+     m.y
89
+     m.z
90
+ 
91
++def test_dont_remove_comment_in_line_directives():
92
++    ffi = FFI(backend=FakeBackend())
93
++    e = py.test.raises(CDefError, ffi.cdef, """
94
++        \t # \t line \t 8 \t "baz.c" \t
95
++
96
++        some syntax error here
97
++    """)
98
++    assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
99
++    #
100
++    e = py.test.raises(CDefError, ffi.cdef, """
101
++        #line 7 "foo//bar.c"
102
++
103
++        some syntax error here
104
++    """)
105
++    assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
106
++
107
++def test_multiple_line_directives():
108
++    ffi = FFI(backend=FakeBackend())
109
++    e = py.test.raises(CDefError, ffi.cdef,
110
++    """ #line 5 "foo.c"
111
++        extern int xx;
112
++        #line 6 "bar.c"
113
++        extern int yy;
114
++        #line 7 "baz.c"
115
++        some syntax error here
116
++        #line 8 "yadda.c"
117
++        extern int zz;
118
++    """)
119
++    assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
120
++
121
++def test_commented_line_directive():
122
++    ffi = FFI(backend=FakeBackend())
123
++    e = py.test.raises(CDefError, ffi.cdef, """
124
++        /*
125
++        #line 5 "foo.c"
126
++        */
127
++        void xx(void);
128
++
129
++        #line 6 "bar.c"
130
++        /*
131
++        #line 35 "foo.c"
132
++        */
133
++        some syntax error
134
++    """)
135
++    assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
136
++
137
+ def test_line_continuation_in_defines():
138
+     ffi = FFI(backend=FakeBackend())
139
+     ffi.cdef("""
140
+-- 
141
+2.26.2
142
+
143
+From 31249d786c833d4960bbbf4e0d7f7bcaecf92d1f Mon Sep 17 00:00:00 2001
144
+From: Armin Rigo <arigo@tunes.org>
145
+Date: Fri, 29 May 2020 10:27:40 +0200
146
+Subject: [PATCH] #454
147
+
148
+Second try with '# NUMBER' instead of '#line NUMBER', as gcc seems to output
149
+---
150
+ cffi/cparser.py               |  8 +++----
151
+ testing/cffi0/test_parsing.py | 41 +++++++++++++++++++++++++++++++++++
152
+ 2 files changed, 45 insertions(+), 4 deletions(-)
153
+
154
+diff --git a/cffi/cparser.py b/cffi/cparser.py
155
+index d9784655..74830e91 100644
156
+--- a/cffi/cparser.py
157
+@@ -29,7 +29,7 @@ _r_comment = re.compile(r"/\*.*?\*/|//([^\n\\]|\\.)*?$",
158
+ _r_define  = re.compile(r"^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)"
159
+                         r"\b((?:[^\n\\]|\\.)*?)$",
160
+                         re.DOTALL | re.MULTILINE)
161
+-_r_line_directive = re.compile(r"^[ \t]*#[ \t]*line\b.*$", re.MULTILINE)
162
++_r_line_directive = re.compile(r"^[ \t]*#[ \t]*(?:line|\d+)\b.*$", re.MULTILINE)
163
+ _r_partial_enum = re.compile(r"=\s*\.\.\.\s*[,}]|\.\.\.\s*\}")
164
+ _r_enum_dotdotdot = re.compile(r"__dotdotdot\d+__$")
165
+ _r_partial_array = re.compile(r"\[\s*\.\.\.\s*\]")
166
+@@ -166,9 +166,9 @@ def _warn_for_non_extern_non_static_global_variable(decl):
167
+ 
168
+ def _remove_line_directives(csource):
169
+     # _r_line_directive matches whole lines, without the final \n, if they
170
+-    # start with '#line' with some spacing allowed.  This function stores
171
+-    # them away and replaces them with exactly the string '#line@N', where
172
+-    # N is the index in the list 'line_directives'.
173
++    # start with '#line' with some spacing allowed, or '#NUMBER'.  This
174
++    # function stores them away and replaces them with exactly the string
175
++    # '#line@N', where N is the index in the list 'line_directives'.
176
+     line_directives = []
177
+     def replace(m):
178
+         i = len(line_directives)
179
+diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
180
+index 5f2d7ec4..a5e45874 100644
181
+--- a/testing/cffi0/test_parsing.py
182
+@@ -199,6 +199,21 @@ def test_dont_remove_comment_in_line_directives():
183
+ 
184
+         some syntax error here
185
+     """)
186
++    #
187
++    assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
188
++    ffi = FFI(backend=FakeBackend())
189
++    e = py.test.raises(CDefError, ffi.cdef, """
190
++        \t # \t 8 \t "baz.c" \t
191
++
192
++        some syntax error here
193
++    """)
194
++    assert str(e.value) == "parse error\nbaz.c:9:14: before: syntax"
195
++    #
196
++    e = py.test.raises(CDefError, ffi.cdef, """
197
++        # 7 "foo//bar.c"
198
++
199
++        some syntax error here
200
++    """)
201
+     assert str(e.value) == "parse error\nfoo//bar.c:8:14: before: syntax"
202
+ 
203
+ def test_multiple_line_directives():
204
+@@ -214,6 +229,18 @@ def test_multiple_line_directives():
205
+         extern int zz;
206
+     """)
207
+     assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
208
++    #
209
++    e = py.test.raises(CDefError, ffi.cdef,
210
++    """ # 5 "foo.c"
211
++        extern int xx;
212
++        # 6 "bar.c"
213
++        extern int yy;
214
++        # 7 "baz.c"
215
++        some syntax error here
216
++        # 8 "yadda.c"
217
++        extern int zz;
218
++    """)
219
++    assert str(e.value) == "parse error\nbaz.c:7:14: before: syntax"
220
+ 
221
+ def test_commented_line_directive():
222
+     ffi = FFI(backend=FakeBackend())
223
+@@ -229,6 +256,20 @@ def test_commented_line_directive():
224
+         */
225
+         some syntax error
226
+     """)
227
++    #
228
++    assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
229
++    e = py.test.raises(CDefError, ffi.cdef, """
230
++        /*
231
++        # 5 "foo.c"
232
++        */
233
++        void xx(void);
234
++
235
++        # 6 "bar.c"
236
++        /*
237
++        # 35 "foo.c"
238
++        */
239
++        some syntax error
240
++    """)
241
+     assert str(e.value) == "parse error\nbar.c:9:14: before: syntax"
242
+ 
243
+ def test_line_continuation_in_defines():
244
+-- 
245
+2.26.2
246
+