Skip to content

Commit 8a19633

Browse files
gh-133160: fix in Tools/build/deepfreeze.py nsmallposints were still 256
1 parent 5c942f1 commit 8a19633

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

Tools/build/consts_getter.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
SCRIPT_NAME = 'Tools/build/consts_getter.py'
4+
__file__ = os.path.abspath(__file__)
5+
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
6+
INTERNAL = os.path.join(ROOT, 'Include', 'internal')
7+
8+
def get_nsmallnegints_and_nsmallposints():
9+
nsmallposints = None
10+
nsmallnegints = None
11+
with open(os.path.join(INTERNAL, 'pycore_runtime_structs.h')) as infile:
12+
for line in infile:
13+
if line.startswith('#define _PY_NSMALLPOSINTS'):
14+
nsmallposints = int(line.split()[-1])
15+
elif line.startswith('#define _PY_NSMALLNEGINTS'):
16+
nsmallnegints = int(line.split()[-1])
17+
break
18+
else:
19+
raise NotImplementedError
20+
assert nsmallposints
21+
assert nsmallnegints
22+
return nsmallnegints, nsmallposints

Tools/build/deepfreeze.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818
import types
1919

20+
import consts_getter
2021
import umarshal
2122

2223
TYPE_CHECKING = False
@@ -362,7 +363,9 @@ def _generate_int_for_bits(self, name: str, i: int, digit: int) -> None:
362363
self.write(f".ob_digit = {{ {ds} }},")
363364

364365
def generate_int(self, name: str, i: int) -> str:
365-
if -5 <= i <= 256:
366+
nsmallnegints, nsmallposints = consts_getter.get_nsmallnegints_and_nsmallposints()
367+
368+
if -nsmallnegints <= i <= nsmallposints:
366369
return f"(PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + {i}]"
367370
if i >= 0:
368371
name = f"const_int_{i}"

Tools/build/generate_global_objects.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os.path
44
import re
55

6+
import consts_getter
7+
68
SCRIPT_NAME = 'Tools/build/generate_global_objects.py'
79
__file__ = os.path.abspath(__file__)
810
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@@ -274,20 +276,7 @@ def generate_global_strings(identifiers, strings):
274276

275277

276278
def generate_runtime_init(identifiers, strings):
277-
# First get some info from the declarations.
278-
nsmallposints = None
279-
nsmallnegints = None
280-
with open(os.path.join(INTERNAL, 'pycore_runtime_structs.h')) as infile:
281-
for line in infile:
282-
if line.startswith('#define _PY_NSMALLPOSINTS'):
283-
nsmallposints = int(line.split()[-1])
284-
elif line.startswith('#define _PY_NSMALLNEGINTS'):
285-
nsmallnegints = int(line.split()[-1])
286-
break
287-
else:
288-
raise NotImplementedError
289-
assert nsmallposints
290-
assert nsmallnegints
279+
nsmallnegints, nsmallposints = consts_getter.get_nsmallnegints_and_nsmallposints()
291280

292281
# Then target the runtime initializer.
293282
filename = os.path.join(INTERNAL, 'pycore_runtime_init_generated.h')

0 commit comments

Comments
 (0)