Skip to content

Commit 24aee96

Browse files
author
Christopher Doris
committed
revert most of this...
1 parent e7057cd commit 24aee96

File tree

9 files changed

+130
-129
lines changed

9 files changed

+130
-129
lines changed

src/C/extras.jl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
asptr(x) = Base.unsafe_convert(PyPtr, x)
1+
Py_Type(x::PyPtr) = PyPtr(UnsafePtr(x).type[!])
22

3-
Py_Type(x) = Base.GC.@preserve x PyPtr(UnsafePtr(asptr(x)).type[!])
3+
PyObject_Type(x::PyPtr) = (t = Py_Type(x); Py_IncRef(t); t)
44

5-
PyObject_Type(x) = Base.GC.@preserve x (t = Py_Type(asptr(x)); Py_IncRef(t); t)
5+
Py_TypeCheck(o::PyPtr, t::PyPtr) = PyType_IsSubtype(Py_Type(o), t)
6+
Py_TypeCheckFast(o::PyPtr, f::Integer) = PyType_IsSubtypeFast(Py_Type(o), f)
67

7-
Py_TypeCheck(o, t) = Base.GC.@preserve o t PyType_IsSubtype(Py_Type(asptr(o)), asptr(t))
8-
Py_TypeCheckFast(o, f::Integer) = Base.GC.@preserve o PyType_IsSubtypeFast(Py_Type(asptr(o)), f)
8+
PyType_IsSubtypeFast(t::PyPtr, f::Integer) =
9+
Cint(!iszero(UnsafePtr{PyTypeObject}(t).flags[] & f))
910

10-
PyType_IsSubtypeFast(t, f::Integer) =
11-
Base.GC.@preserve t Cint(!iszero(UnsafePtr{PyTypeObject}(asptr(t)).flags[] & f))
11+
PyMemoryView_GET_BUFFER(m::PyPtr) = Ptr{Py_buffer}(UnsafePtr{PyMemoryViewObject}(m).view)
1212

13-
PyMemoryView_GET_BUFFER(m) = Base.GC.@preserve m Ptr{Py_buffer}(UnsafePtr{PyMemoryViewObject}(asptr(m)).view)
14-
15-
PyType_CheckBuffer(t) = Base.GC.@preserve t begin
16-
p = UnsafePtr{PyTypeObject}(asptr(t)).as_buffer[]
13+
PyType_CheckBuffer(t::PyPtr) = begin
14+
p = UnsafePtr{PyTypeObject}(t).as_buffer[]
1715
return p != C_NULL && p.get[!] != C_NULL
1816
end
1917

20-
PyObject_CheckBuffer(o) = Base.GC.@preserve o PyType_CheckBuffer(Py_Type(asptr(o)))
18+
PyObject_CheckBuffer(o::PyPtr) = PyType_CheckBuffer(Py_Type(o))
2119

22-
PyObject_GetBuffer(_o, b, flags) = Base.GC.@preserve _o begin
23-
o = asptr(_o)
20+
PyObject_GetBuffer(o::PyPtr, b, flags) = begin
2421
p = UnsafePtr{PyTypeObject}(Py_Type(o)).as_buffer[]
2522
if p == C_NULL || p.get[!] == C_NULL
2623
PyErr_SetString(
@@ -64,8 +61,8 @@ function PyOS_RunInputHook()
6461
end
6562
end
6663

67-
function PySimpleObject_GetValue(::Type{T}, o) where {T}
68-
Base.GC.@preserve o UnsafePtr{PySimpleObject{T}}(asptr(o)).value[!]
64+
function PySimpleObject_GetValue(::Type{T}, o::PyPtr) where {T}
65+
UnsafePtr{PySimpleObject{T}}(o).value[!]
6966
end
7067

7168
# FAST REFCOUNTING

src/Compat/pycall.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ function init_pycall(PyCall::Module)
1616
end
1717
@eval function PyCall.PyObject(x::Py)
1818
C.CTX.matches_pycall::Bool || error($errmsg)
19-
return $PyCall.PyObject($PyCall.PyPtr(getptr(incref(x))))
19+
return $PyCall.PyObject($PyCall.PyPtr(incref(getptr(x))))
2020
end
2121
end

src/Convert/ctypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct pyconvert_rule_ctypessimplevalue{R,S} <: Function end
22

33
function (::pyconvert_rule_ctypessimplevalue{R,SAFE})(::Type{T}, x::Py) where {R,SAFE,T}
4-
ptr = C.PySimpleObject_GetValue(Ptr{R}, x)
4+
ptr = Base.GC.@preserve x C.PySimpleObject_GetValue(Ptr{R}, getptr(x))
55
ans = unsafe_load(ptr)
66
if SAFE
77
pyconvert_return(convert(T, ans))

src/Convert/numpy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct pyconvert_rule_numpysimplevalue{R,S} <: Function end
22

33
function (::pyconvert_rule_numpysimplevalue{R,SAFE})(::Type{T}, x::Py) where {R,SAFE,T}
4-
ans = C.PySimpleObject_GetValue(R, x)
4+
ans = Base.GC.@preserve x C.PySimpleObject_GetValue(R, getptr(x))
55
if SAFE
66
pyconvert_return(convert(T, ans))
77
else

src/Convert/pyconvert.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function _pyconvert_get_rules(pytype::Py)
238238
end
239239
end
240240
for (t, x) in reverse(collect(zip(mro, xmro)))
241-
if C.PyType_CheckBuffer(t)
241+
if C.PyType_CheckBuffer(getptr(t))
242242
push!(x, "<buffer>")
243243
break
244244
end
@@ -350,7 +350,7 @@ function pytryconvert(::Type{T}, x_) where {T}
350350

351351
# get rules from the cache
352352
# TODO: we should hold weak references and clear the cache if types get deleted
353-
tptr = C.Py_Type(x)
353+
tptr = C.Py_Type(getptr(x))
354354
trules = pyconvert_rules_cache(T)
355355
rules = get!(trules, tptr) do
356356
t = pynew(incref(tptr))

src/Convert/rules.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pyconvert_rule_bytes(::Type{Base.CodeUnits{UInt8,String}}, x::Py) =
6161
pyconvert_rule_int(::Type{T}, x::Py) where {T<:Number} = begin
6262
# first try to convert to Clonglong (or Culonglong if unsigned)
6363
v =
64-
T <: Unsigned ? C.PyLong_AsUnsignedLongLong(x) :
65-
C.PyLong_AsLongLong(x)
64+
T <: Unsigned ? C.PyLong_AsUnsignedLongLong(getptr(x)) :
65+
C.PyLong_AsLongLong(getptr(x))
6666
if !iserrset_ambig(v)
6767
# success
6868
return pyconvert_tryconvert(T, v)

0 commit comments

Comments
 (0)