public bool IsSubtypeOf(PyTypeObject type) { if (this == type) { return(true); } PyTypeObject tp_base = this.tp_base.TryRead(); if (tp_base != null && tp_base.IsSubtypeOf(type)) { return(true); } PyTupleObject tp_bases = this.tp_bases.TryRead(); if (tp_bases != null) { var bases = tp_bases.ReadElements().OfType <PyTypeObject>(); if (bases.Any(t => t.IsSubtypeOf(type))) { return(true); } } return(false); }
CreateTuple(int size) { PyTupleObject tuple = new PyTupleObject(); tuple.ob_refcnt = 1; tuple.ob_type = this.PyTuple_Type; tuple.ob_size = size; int baseSize = Marshal.SizeOf(typeof(PyTupleObject)); int extraSize = (CPyMarshal.PtrSize * (size - 1)); IntPtr tuplePtr = this.allocator.Alloc((uint)(baseSize + extraSize)); Marshal.StructureToPtr(tuple, tuplePtr, false); IntPtr itemsPtr = CPyMarshal.Offset( tuplePtr, Marshal.OffsetOf(typeof(PyTupleObject), "ob_item")); CPyMarshal.Zero(itemsPtr, CPyMarshal.PtrSize * size); return(tuplePtr); }
private static ProxyInfo?FindProxyInfoForPyType(DkmProcess process, ulong typePtr) { if (typePtr == 0) { return(null); } var map = process.GetOrCreateDataItem(() => new ProxyTypes(process)).ProxyInfoFromPyTypePtr; if (map.TryGetValue(typePtr, out ProxyInfo proxyInfo)) { return(proxyInfo); } // If we didn't get a direct match, look at tp_base and tp_bases. PyTypeObject typeObject = new PyTypeObject(process, typePtr); var tp_base = typeObject.tp_base.Raw.Read(); var baseProxyInfo = FindProxyInfoForPyType(process, tp_base); if (baseProxyInfo != null) { return(baseProxyInfo); } PyTupleObject tp_bases = typeObject.tp_bases.TryRead(); if (tp_bases != null) { foreach (var bas in tp_bases.ReadElements()) { baseProxyInfo = FindProxyInfoForPyType(process, bas.Raw.Read()); if (baseProxyInfo != null) { return(baseProxyInfo); } } } return(null); }
CreateTuple(int size) { PyTupleObject tuple = new PyTupleObject(); tuple.ob_refcnt = 1; tuple.ob_type = this.PyTuple_Type; tuple.ob_size = size; int baseSize = Marshal.SizeOf(typeof(PyTupleObject)); int extraSize = (CPyMarshal.PtrSize * (size - 1)); IntPtr tuplePtr = this.allocator.Alloc((uint)(baseSize + extraSize)); Marshal.StructureToPtr(tuple, tuplePtr, false); IntPtr itemsPtr = CPyMarshal.Offset( tuplePtr, Marshal.OffsetOf(typeof(PyTupleObject), "ob_item")); CPyMarshal.Zero(itemsPtr, CPyMarshal.PtrSize * size); return tuplePtr; }
/// <summary> /// Unwraps from <see cref="IPyObject"/> wrapper. /// </summary> /// <param name="pyTuple"></param> /// <returns></returns> public static IReadOnlyList <object> UnPy(this PyTupleObject pyTuple) => pyTuple.Value.Select(x => x.Value).ToList();