Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc137bb

Browse files
committed
added a workaround for tp_clear implementations, that do not check, that they are not the first in tp_clear's MRO
https://bugs.python.org/issue45266
1 parent6b20409 commitbc137bb

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

‎src/runtime/classbase.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,33 @@ public static void tp_dealloc(IntPtr ob)
360360

361361
publicstaticinttp_clear(IntPtrob)
362362
{
363-
ManagedTypeself=GetManagedObject(ob);
363+
varself=(CLRObject)GetManagedObject(ob);
364364

365-
boolisTypeObject=Runtime.PyObject_TYPE(ob)==Runtime.PyCLRMetaType;
366-
if(!isTypeObject)
367-
{
368-
ClearObjectDict(ob);
365+
if(self.clearReentryGuard)return0;
369366

370-
intbaseClearResult=BaseUnmanagedClear(ob);
371-
if(baseClearResult!=0)
367+
// workaround for https://bugs.python.org/issue45266
368+
self.clearReentryGuard=true;
369+
370+
try
371+
{
372+
boolisTypeObject=Runtime.PyObject_TYPE(ob)==Runtime.PyCLRMetaType;
373+
if(!isTypeObject)
372374
{
373-
returnbaseClearResult;
375+
intbaseClearResult=BaseUnmanagedClear(ob);
376+
if(baseClearResult!=0)
377+
{
378+
returnbaseClearResult;
379+
}
380+
381+
ClearObjectDict(ob);
374382
}
383+
if(selfis notnull)self.tpHandle=IntPtr.Zero;
384+
return0;
385+
}
386+
finally
387+
{
388+
self.clearReentryGuard=false;
375389
}
376-
if(selfis notnull)self.tpHandle=IntPtr.Zero;
377-
return0;
378390
}
379391

380392
staticunsafeintBaseUnmanagedClear(IntPtrob)

‎src/runtime/clrobject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ namespace Python.Runtime
99
internalclassCLRObject:ManagedType
1010
{
1111
internalobjectinst;
12+
internalboolclearReentryGuard;
1213

1314
internalCLRObject(objectob,IntPtrtp)
1415
{
15-
System.Diagnostics.Debug.Assert(tp!=IntPtr.Zero);
16+
Debug.Assert(tp!=IntPtr.Zero);
1617
IntPtrpy=Runtime.PyType_GenericAlloc(tp,0);
1718

1819
tpHandle=tp;

‎src/runtime/managedtype.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal static bool IsInstanceOfManagedType(IntPtr ob)
145145

146146
internalstaticboolIsManagedType(BorrowedReferencetype)
147147
{
148-
varflags=(TypeFlags)Util.ReadCLong(type.DangerousGetAddress(),TypeOffset.tp_flags);
148+
varflags=PyType.GetFlags(type);
149149
return(flags&TypeFlags.HasClrInstance)!=0;
150150
}
151151

‎src/runtime/pytype.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ internal IntPtr GetSlot(TypeSlotID slot)
103103
returnExceptions.ErrorCheckIfNull(result);
104104
}
105105

106+
internalstaticTypeFlagsGetFlags(BorrowedReferencetype)
107+
{
108+
Debug.Assert(TypeOffset.tp_flags>0);
109+
return(TypeFlags)Util.ReadCLong(type.DangerousGetAddress(),TypeOffset.tp_flags);
110+
}
111+
106112
internalstaticBorrowedReferenceGetBase(BorrowedReferencetype)
107113
{
108114
Debug.Assert(IsType(type));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp