Skip to content

Commit 1080a67

Browse files
committed
remove PyTypeObject
1 parent 7c844e2 commit 1080a67

File tree

3 files changed

+16
-76
lines changed

3 files changed

+16
-76
lines changed

src/C/consts.jl

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -249,81 +249,6 @@ end
249249
weakreflist::PyPtr = PyNULL
250250
end
251251

252-
@kwdef struct PyTypeObject
253-
ob_base::PyVarObject = PyVarObject()
254-
name::Cstring = C_NULL
255-
256-
basicsize::Py_ssize_t = 0
257-
itemsize::Py_ssize_t = 0
258-
259-
dealloc::Ptr{Cvoid} = C_NULL
260-
vectorcall_offset::Py_ssize_t = 0
261-
getattr::Ptr{Cvoid} = C_NULL
262-
setattr::Ptr{Cvoid} = C_NULL
263-
as_async::Ptr{Cvoid} = C_NULL
264-
repr::Ptr{Cvoid} = C_NULL
265-
266-
as_number::Ptr{PyNumberMethods} = C_NULL
267-
as_sequence::Ptr{PySequenceMethods} = C_NULL
268-
as_mapping::Ptr{PyMappingMethods} = C_NULL
269-
270-
hash::Ptr{Cvoid} = C_NULL
271-
call::Ptr{Cvoid} = C_NULL
272-
str::Ptr{Cvoid} = C_NULL
273-
getattro::Ptr{Cvoid} = C_NULL
274-
setattro::Ptr{Cvoid} = C_NULL
275-
276-
as_buffer::Ptr{PyBufferProcs} = C_NULL
277-
278-
flags::Culong = 0
279-
280-
doc::Cstring = C_NULL
281-
282-
traverse::Ptr{Cvoid} = C_NULL
283-
284-
clear::Ptr{Cvoid} = C_NULL
285-
286-
richcompare::Ptr{Cvoid} = C_NULL
287-
288-
weaklistoffset::Py_ssize_t = 0
289-
290-
iter::Ptr{Cvoid} = C_NULL
291-
iternext::Ptr{Cvoid} = C_NULL
292-
293-
methods::Ptr{PyMethodDef} = C_NULL
294-
members::Ptr{PyMemberDef} = C_NULL
295-
getset::Ptr{PyGetSetDef} = C_NULL
296-
base::PyPtr = C_NULL
297-
dict::PyPtr = C_NULL
298-
descr_get::Ptr{Cvoid} = C_NULL
299-
descr_set::Ptr{Cvoid} = C_NULL
300-
dictoffset::Py_ssize_t = 0
301-
init::Ptr{Cvoid} = C_NULL
302-
alloc::Ptr{Cvoid} = C_NULL
303-
new::Ptr{Cvoid} = C_NULL
304-
free::Ptr{Cvoid} = C_NULL
305-
is_gc::Ptr{Cvoid} = C_NULL
306-
bases::PyPtr = C_NULL
307-
mro::PyPtr = C_NULL
308-
cache::PyPtr = C_NULL
309-
subclasses::PyPtr = C_NULL
310-
weaklist::PyPtr = C_NULL
311-
del::Ptr{Cvoid} = C_NULL
312-
313-
version_tag::Cuint = 0
314-
315-
finalize::Ptr{Cvoid} = C_NULL
316-
vectorcall::Ptr{Cvoid} = C_NULL
317-
318-
# Python 3.12+ fields
319-
tp_watched::Cchar = 0
320-
321-
# Python 3.13+ fields
322-
tp_versions_used::Cushort = 0
323-
end
324-
325-
const PyTypePtr = Ptr{PyTypeObject}
326-
327252
@kwdef struct PyType_Slot
328253
slot::Cint = 0
329254
pfunc::Ptr{Cvoid} = C_NULL

src/C/extras.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Py_TypeCheckFast(o, f::Integer) = Base.GC.@preserve o PyType_IsSubtypeFast(Py_Ty
1010
PyType_IsSubtypeFast(t, f::Integer) =
1111
Base.GC.@preserve t Cint(!iszero(PyType_GetFlags(asptr(t)) & f))
1212

13+
function pytypename(t::PyPtr)
14+
name_obj = PyObject_GetAttrString(t, "__name__")
15+
name_obj == C_NULL && return "(unknown type)"
16+
cstr = PyUnicode_AsUTF8(name_obj)
17+
if cstr == C_NULL
18+
Py_DecRef(name_obj)
19+
return "(unknown type)"
20+
else
21+
str = unsafe_string(cstr)
22+
Py_DecRef(name_obj)
23+
return str
24+
end
25+
end
26+
1327
PyMemoryView_GET_BUFFER(m) = Base.GC.@preserve m Ptr{Py_buffer}(UnsafePtr{PyMemoryViewObject}(asptr(m)).view)
1428

1529
PyType_CheckBuffer(t) = Base.GC.@preserve t begin
@@ -25,7 +39,7 @@ PyObject_GetBuffer(_o, b, flags) = Base.GC.@preserve _o begin
2539
if getbuf == C_NULL
2640
PyErr_SetString(
2741
POINTERS.PyExc_TypeError,
28-
"a bytes-like object is required, not '$(String(UnsafePtr{PyTypeObject}(Py_Type(o)).name[]))'",
42+
"a bytes-like object is required, not '$(pytypename(Py_Type(o)))'",
2943
)
3044
return Cint(-1)
3145
end

src/C/pointers.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const CAPI_FUNC_SIGS = Dict{Symbol,Pair{Tuple,Type}}(
144144
:PyComplex_AsCComplex => (PyPtr,) => Py_complex,
145145
# STR
146146
:PyUnicode_DecodeUTF8 => (Ptr{Cchar}, Py_ssize_t, Ptr{Cchar}) => PyPtr,
147+
:PyUnicode_AsUTF8 => (PyPtr,) => Ptr{Cchar},
147148
:PyUnicode_AsUTF8String => (PyPtr,) => PyPtr,
148149
:PyUnicode_InternInPlace => (Ptr{PyPtr},) => Cvoid,
149150
# BYTES

0 commit comments

Comments
 (0)