🌐 AI搜索 & 代理 主页
Skip to content

Commit 2533df1

Browse files
committed
Set ht_token to NULL in Python 3.14
1 parent dfe8fff commit 2533df1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/runtime/Native/TypeOffset.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static partial class TypeOffset
7777
internal static int tp_setattro { get; private set; }
7878
internal static int tp_str { get; private set; }
7979
internal static int tp_traverse { get; private set; }
80+
// Special case: Only available in Python 3.14 onwards, set to -1 by default
81+
internal static int ht_token { get; private set; } = -1;
8082

8183
internal static void Use(ITypeOffsets offsets, int extraHeadOffset)
8284
{
@@ -89,6 +91,19 @@ internal static void Use(ITypeOffsets offsets, int extraHeadOffset)
8991
slotNames.Add(offsetProperty.Name);
9092

9193
var sourceProperty = typeof(ITypeOffsets).GetProperty(offsetProperty.Name);
94+
if (sourceProperty == null)
95+
{
96+
if ((int)offsetProperty.GetValue(null) == -1)
97+
{
98+
// Skip, this is an optional offset value
99+
continue;
100+
}
101+
else
102+
{
103+
throw new Exception($"No offset defined for necessary slot {offsetProperty.Name}");
104+
}
105+
}
106+
92107
int value = (int)sourceProperty.GetValue(offsets, null);
93108
value += extraHeadOffset;
94109
offsetProperty.SetValue(obj: null, value: value, index: null);

src/runtime/TypeManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,11 @@ internal static PyType AllocateTypeObject(string name, PyType metatype)
618618
Util.WriteIntPtr(type, TypeOffset.tp_traverse, subtype_traverse);
619619
Util.WriteIntPtr(type, TypeOffset.tp_clear, subtype_clear);
620620

621+
// This is a new mechanism in Python 3.14. We should eventually use it to implement
622+
// a nicer type check, but for now we just need to ensure that it is set to NULL.
623+
if (TypeOffset.ht_token != -1)
624+
Util.WriteIntPtr(type, TypeOffset.ht_token, IntPtr.Zero);
625+
621626
InheritSubstructs(type.Reference.DangerousGetAddress());
622627

623628
return type;

0 commit comments

Comments
 (0)