8000 It was incorrect to call `PyType_Ready` on a type returned by `PyType… · pythonnet/pythonnet@c1e5622 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1e5622

Browse files
committed
It was incorrect to call PyType_Ready on a type returned by PyType.tp_new. It should have not been allowed in the first place, but we accidentally cleared Ready from tp_flags. Instead, we will extend tp_flags and call PyType_Modified at the end of CLR MetaType.tp_new
1 parent ea61b03 commit c1e5622

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/runtime/metatype.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
145145
return IntPtr.Zero;
146146
}
147147

148-
var flags = TypeFlags.Default;
148+
var flags = (TypeFlags)Util.ReadCLong(type, TypeOffset.tp_flags);
149+
if (!flags.HasFlag(TypeFlags.Ready))
150+
throw new NotSupportedException("PyType.tp_new returned an incomplete type");
149151
flags |= TypeFlags.HasClrInstance;
150152
flags |= TypeFlags.HeapType;
151153
flags |= TypeFlags.BaseType;
@@ -170,8 +172,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
170172
IntPtr gc = Marshal.ReadIntPtr(base_type, Offsets.tp_clr_inst);
171173
Marshal.WriteIntPtr(type, Offsets.tp_clr_inst, gc);
172174

173-
if (Runtime.PyType_Ready(type) != 0)
174-
throw PythonException.ThrowLastAsClrException();
175+
Runtime.PyType_Modified(new BorrowedReference(type));
175176

176177
return type;
177178
}

0 commit comments

Comments
 (0)
0