Skip to content

TypeOffset class no longer depends on target Python version #1292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed missing ITypeOffset members np_inplace_*
  • Loading branch information
lostmsu committed Nov 29, 2020
commit e36a027944ba632b8d70388555791e18f24f0538
2 changes: 2 additions & 0 deletions src/runtime/native/ITypeOffsets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface ITypeOffsets
int mp_subscript { get; }
int name { get; }
int nb_add { get; }
int nb_inplace_add { get; }
int nb_inplace_subtract { get; }
int ob_size { get; }
int ob_type { get; }
int qualname { get; }
Expand Down
46 changes: 46 additions & 0 deletions src/runtime/native/TypeOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static partial class TypeOffset
internal static int mp_subscript { get; private set; }
internal static int name { get; private set; }
internal static int nb_add { get; private set; }
internal static int nb_inplace_add { get; private set; }
internal static int nb_inplace_subtract { get; private set; }
internal static int ob_size { get; private set; }
internal static int ob_type { get; private set; }
internal static int qualname { get; private set; }
Expand Down Expand Up @@ -73,6 +75,7 @@ internal static void Use(ITypeOffsets offsets)
}

ValidateUnusedTypeOffsetProperties(offsetProperties);
ValidateRequiredOffsetsPresent(offsetProperties);
}

static readonly BindingFlags FieldFlags = BindingFlags.NonPublic | BindingFlags.Static;
Expand Down Expand Up @@ -102,5 +105,48 @@ static void ValidateUnusedTypeOffsetProperties(PropertyInfo[] offsetProperties)
extras.Sort();
Debug.Assert(extras.Count == 0, message: string.Join(", ", extras));
}

[Conditional("DEBUG")]
static void ValidateRequiredOffsetsPresent(PropertyInfo[] offsetProperties)
{
var present = new HashSet<string>(offsetProperties.Select(p => p.Name));
var missing = new HashSet<string>();

var thisAssembly = Assembly.GetExecutingAssembly();
var managedTypes = thisAssembly.GetTypes()
.Where(typeof(ManagedType).IsAssignableFrom)
.ToList();
foreach (var managedType in managedTypes)
{
var slots = managedType.GetMethods(BindingFlags.Public | BindingFlags.Static);
foreach(var slot in slots)
if (!present.Contains(slot.Name))
missing.Add(slot.Name);
}
foreach (string notSlot in new[]
{
"__instancecheck__",
"__subclasscheck__",
"_AtExit",
"AddReference",
"FinalizeObject",
"FindAssembly",
"get_SuppressDocs",
"get_SuppressOverloads",
"GetClrType",
"getPreload",
"Initialize",
"ListAssemblies",
"Release",
"Reset",
"set_SuppressDocs",
"set_SuppressOverloads",
"setPreload",
})
missing.Remove(notSlot);

Debug.Assert(missing.Count == 0,
"Missing slots: " + string.Join(", ", missing));
}
}
}