Skip to content

Commit ed0ba1c

Browse files
sergey-miryanovlkollar
authored andcommitted
pythongh-133158: Adjust c-analyzer max_sizes for typeobject.c (pythonGH-133159)
This also improves the error message for when a file is too large.
1 parent 650d0e0 commit ed0ba1c

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

Tools/c-analyzer/c_parser/parser/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
* alt impl using a state machine (& tokenizer or split on delimiters)
117117
"""
118118

119+
import textwrap
120+
119121
from ..info import ParsedItem
120122
from ._info import SourceInfo
121123

@@ -208,7 +210,27 @@ def _iter_source(lines, *, maxtext=11_000, maxlines=200, showtext=False):
208210
return
209211
# At this point either the file ended prematurely
210212
# or there's "too much" text.
211-
filename, lno, text = srcinfo.filename, srcinfo._start, srcinfo.text
213+
filename, lno_from, lno_to = srcinfo.filename, srcinfo.start, srcinfo.end
214+
text = srcinfo.text
212215
if len(text) > 500:
213216
text = text[:500] + '...'
214-
raise Exception(f'unmatched text ({filename} starting at line {lno}):\n{text}')
217+
218+
if srcinfo.too_much_text(maxtext):
219+
msg = f'''
220+
too much text, try to increase MAX_SIZES[MAXTEXT] in cpython/_parser.py
221+
{filename} starting at line {lno_from} to {lno_to}
222+
has code with length {len(text)} greater than {maxtext}:
223+
{text}
224+
'''
225+
raise RuntimeError(textwrap.dedent(msg))
226+
227+
if srcinfo.too_many_lines(maxlines):
228+
msg = f'''
229+
too many lines, try to increase MAX_SIZES[MAXLINES] in cpython/_parser.py
230+
{filename} starting at line {lno_from} to {lno_to}
231+
has code with number of lines {lno_to - lno_from} greater than {maxlines}:
232+
{text}
233+
'''
234+
raise RuntimeError(textwrap.dedent(msg))
235+
236+
raise RuntimeError(f'unmatched text ({filename} starting at line {lno_from}):\n{text}')

Tools/c-analyzer/c_parser/parser/_info.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,16 @@ def resolve(self, kind, data, name, parent=None):
123123
def done(self):
124124
self._set_ready()
125125

126+
def too_much_text(self, maxtext):
127+
return maxtext and len(self.text) > maxtext
128+
129+
def too_many_lines(self, maxlines):
130+
return maxlines and self.end - self.start > maxlines
131+
126132
def too_much(self, maxtext, maxlines):
127-
if maxtext and len(self.text) > maxtext:
133+
if self.too_much_text(maxtext):
128134
pass
129-
elif maxlines and self.end - self.start > maxlines:
135+
elif self.too_many_lines(maxlines):
130136
pass
131137
else:
132138
return False

Tools/c-analyzer/cpython/_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def clean_lines(text):
326326
_abs('Modules/_testcapimodule.c'): (20_000, 400),
327327
_abs('Modules/expat/expat.h'): (10_000, 400),
328328
_abs('Objects/stringlib/unicode_format.h'): (10_000, 400),
329-
_abs('Objects/typeobject.c'): (35_000, 200),
329+
_abs('Objects/typeobject.c'): (380_000, 13_000),
330330
_abs('Python/compile.c'): (20_000, 500),
331331
_abs('Python/optimizer.c'): (100_000, 5_000),
332332
_abs('Python/parking_lot.c'): (40_000, 1000),

0 commit comments

Comments
 (0)