Skip to content

Commit 970f3c8

Browse files
author
Christopher Rowley
committed
simplify implementation of ft macro
1 parent 321f92e commit 970f3c8

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/C/extras.jl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ const _FT_TYPE_REPLACEMENTS = Dict{Symbol,Symbol}(
1212
:PyJuliaValueObject => :PyJuliaValueObjectFT,
1313
)
1414

15-
_ft_replace(sym::Symbol) = get(_FT_TYPE_REPLACEMENTS, sym, sym)
16-
1715
function _ft_transform(ex)
1816
if ex isa Symbol
19-
return _ft_replace(ex)
17+
return get(_FT_TYPE_REPLACEMENTS, ex, ex)
2018
elseif ex isa QuoteNode
21-
v = ex.value
22-
return v isa Symbol ? QuoteNode(_ft_replace(v)) : ex
19+
return QuoteNode(_ft_transform(ex.value))
2320
elseif ex isa Expr
24-
# Handle dotted refs like `C.PyObject` (Expr(:., ...)).
25-
if ex.head === :. && length(ex.args) == 2 && ex.args[2] isa QuoteNode && ex.args[2].value isa Symbol
26-
return Expr(:., _ft_transform(ex.args[1]), QuoteNode(_ft_replace(ex.args[2].value)))
27-
end
2821
return Expr(ex.head, map(_ft_transform, ex.args)...)
2922
else
3023
return ex
@@ -43,12 +36,8 @@ CTX.is_free_threaded` throughout the code.
4336
"""
4437
macro ft(ex)
4538
ex_ft = _ft_transform(ex)
46-
ctx = GlobalRef(@__MODULE__, :CTX)
47-
return esc(:(if $ctx.is_free_threaded
48-
$ex_ft
49-
else
50-
$ex
51-
end))
39+
m = @__MODULE__
40+
return esc(:($m.CTX.is_free_threaded ? $ex_ft : $ex))
5241
end
5342

5443
Py_Type(x) = Base.GC.@preserve x @ft PyPtr(UnsafePtr{PyObject}(asptr(x)).type[!])

0 commit comments

Comments
 (0)