Commit 6eb900e
committed
fix(core): validate Host(is_numa_current=...) as a bool
`Host.__new__` validates `numa_id` carefully -- including an explicit bool
rejection whose comment spells out why:
# bool is an int subclass; reject explicitly so Host(True) doesn't
# alias Host(1) (and vice versa) in the singleton cache.
`is_numa_current` gets no validation at all, even though it lands in the
same process-wide singleton cache key and is stored verbatim as the
`is_numa_current` property. The same aliasing hazard applies from the other
side:
>>> Host(is_numa_current=1) # int, not True
>>> h = Host.numa_current()
>>> h.is_numa_current
1
>>> h.is_numa_current is True
False
`(None, 1)` and `(None, True)` are the same dict key, so whichever call runs
first wins for the lifetime of the process -- and `test_host.py` already
asserts `Host.numa_current().is_numa_current is True`, which that first call
turns into an order-dependent failure.
Non-int truthy values are worse: they mint a second singleton instead of
poisoning the first.
>>> dup = Host(is_numa_current="yes")
>>> repr(dup)
'Host.numa_current()'
>>> dup is Host.numa_current(), dup == Host.numa_current()
(False, False)
Both coerce to the same `_LocSpec(kind="host_numa_current")`, so they name
one physical location while breaking the documented "constructor calls with
the same arguments return the same instance" contract and the identity-based
set arithmetic in `ManagedBuffer.accessed_by`.
`is_numa_current=0` and `=None` are equally unhandled: they are falsy, so
they seed the *generic* `Host()` singleton with a non-bool
`is_numa_current`. And an unhashable value reaches the cache lookup and
raises `TypeError: unhashable type` out of the constructor.
Require a real bool, mirroring the numa_id check.1 parent 3bd069a commit 6eb900e
3 files changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
50 | 59 | | |
51 | 60 | | |
52 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
76 | 84 | | |
77 | 85 | | |
78 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
37 | 60 | | |
38 | 61 | | |
39 | 62 | | |
| |||
0 commit comments