8000 Merge pull request #1486 from losttech/bugs/PythonInheritsDotNet_Doub… · pythonnet/pythonnet@1391639 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1391639

Browse files
authored
Merge pull request #1486 from losttech/bugs/PythonInheritsDotNet_DoubleTypeReady
Fixed double call to `PyType_Ready` in CLR MetaType's `tp_new`
2 parents d300111 + c1e5622 commit 1391639

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