Python.Runtime.TypeManager.InitializeSlots C# (CSharp) Метод

InitializeSlots() статический приватный Метод

static private InitializeSlots ( IntPtr type, Type impl ) : void
type System.IntPtr
impl System.Type
Результат void
        internal static void InitializeSlots(IntPtr type, Type impl)
        {
            Hashtable seen = new Hashtable(8);
            Type offsetType = typeof(TypeOffset);

            while (impl != null)
            {
                MethodInfo[] methods = impl.GetMethods(tbFlags);
                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo method = methods[i];
                    string name = method.Name;
                    if (!(name.StartsWith("tp_") ||
                          name.StartsWith("nb_") ||
                          name.StartsWith("sq_") ||
                          name.StartsWith("mp_") ||
                          name.StartsWith("bf_")
                        ))
                    {
                        continue;
                    }

                    if (seen[name] != null)
                    {
                        continue;
                    }

                    FieldInfo fi = offsetType.GetField(name);
                    int offset = (int)fi.GetValue(offsetType);

                    IntPtr slot = Interop.GetThunk(method);
                    Marshal.WriteIntPtr(type, offset, slot);

                    seen[name] = 1;
                }

                impl = impl.BaseType;
            }
        }

Usage Example

Пример #1
0
        internal static IntPtr RestoreRuntimeData(RuntimeDataStorage storage)
        {
            PyCLRMetaType    = storage.PopValue <IntPtr>();
            _metaSlotsHodler = new SlotsHolder(PyCLRMetaType);
            TypeManager.InitializeSlots(PyCLRMetaType, typeof(MetaType), _metaSlotsHodler);

            IntPtr mdef = Marshal.ReadIntPtr(PyCLRMetaType, TypeOffset.tp_methods);

            foreach (var methodName in CustomMethods)
            {
                var       mi        = typeof(MetaType).GetMethod(methodName);
                ThunkInfo thunkInfo = Interop.GetThunk(mi, "BinaryFunc");
                _metaSlotsHodler.KeeapAlive(thunkInfo);
                mdef = TypeManager.WriteMethodDef(mdef, methodName, thunkInfo.Address);
            }
            return(PyCLRMetaType);
        }