Skip to content

Commit 6061b90

Browse files
authored
[compiler-rt] [test] refine target_page_size() in lit.common.cfg.py (NFC) (#170475)
Use mmap.PAGESIZE and fallback to os.sysconf if it is not available. This allows to query the page size on Windows too, which has mmap but not sysconf. This is a pedantic change because Windows has a fixed page size of 4KiB. I found this solution independently of #168857, and thought it might be worth committing, since this is technically more correct. [mmap.PAGESIZE implementation in CPython](https://github.com/python/cpython/blob/88cd5d9850d2dc51abe43eb84198904d9870c26e/Modules/mmapmodule.c#L47)
1 parent 60bb450 commit 6061b90

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

compiler-rt/test/lit.common.cfg.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,17 @@ def target_page_size():
968968
stdin=subprocess.PIPE,
969969
stdout=subprocess.PIPE,
970970
)
971+
# UNIX (except WASI) and Windows can use mmap.PAGESIZE,
972+
# attempt to use os.sysconf for other targets.
971973
out, err = proc.communicate(
972-
b'import os; print(os.sysconf("SC_PAGESIZE") if hasattr(os, "sysconf") else "")'
974+
b"""
975+
try:
976+
from mmap import PAGESIZE
977+
print(PAGESIZE)
978+
except ImportError:
979+
from os import sysconf
980+
print(sysconf("SC_PAGESIZE"))
981+
"""
973982
)
974983
return int(out)
975984
except:

0 commit comments

Comments
 (0)