Skip to content

Commit d535f84

Browse files
committed
feat: new primitive for weakref.__call__
1 parent 81eadfb commit d535f84

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

mypyc/primitives/weakref_ops.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from mypyc.ir.ops import ERR_MAGIC
22
from mypyc.ir.rtypes import object_rprimitive
3-
from mypyc.primitives.registry import function_op
3+
from mypyc.primitives.registry import ERR_NEG_INT, function_op
44

55
# Weakref operations
66

@@ -11,3 +11,11 @@
1111
c_function_name="PyWeakref_NewRef",
1212
error_kind=ERR_MAGIC,
1313
)
14+
15+
deref_op = function_op(
16+
name="weakref.ReferenceType.__call__",
17+
arg_types=[object_rprimitive],
18+
return_type=object_rprimitive,
19+
c_function_name="PyWeakref_GetRef",
20+
error_kind=ERR_NEG_INT,
21+
)

mypyc/test-data/irbuild-weakref.test

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ L0:
1515
from typing import Any, Callable
1616
from weakref import ref
1717
def f(x: object, cb: Callable[[object], Any]) -> object:
18-
return ref(x, cb)
18+
return ref(x, cb)()
1919

2020
[out]
2121
def f(x, cb):
22-
x, cb, r0 :: object
22+
x, cb, r0, r1 :: object
2323
L0:
2424
r0 = PyWeakref_NewRef(x, cb)
25-
return r0
25+
r1 = PyWeakref_GetRef(r0)
26+
return r1

0 commit comments

Comments
 (0)