public bool IsSubtypeOf(PyTypeObject type) { if (this == type) { return(true); } var tp_base = this.tp_base.TryRead(); if (tp_base != null && tp_base.IsSubtypeOf(type)) { return(true); } var 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); }
public bool IsInstanceOf(PyTypeObject type) { if (this == type) { return(true); } return(ob_type.Read().IsSubtypeOf(type)); }
public ProxyTypes(DkmProcess process) { var langVer = process.GetPythonRuntimeInfo().LanguageVersion; var proxyTypes = typeof(PyObject).Assembly.GetTypes().Where(t => typeof(PyObject).IsAssignableFrom(t) && !t.IsAbstract); foreach (var proxyType in proxyTypes) { string typeVarName = null; var pyTypeAttrs = (PyTypeAttribute[])Attribute.GetCustomAttributes(proxyType, typeof(PyTypeAttribute), inherit: false); if (pyTypeAttrs.Length == 0) { typeVarName = ComputeVariableName(proxyType); } else { foreach (var pyTypeAttr in pyTypeAttrs) { if (pyTypeAttr.MinVersion != PythonLanguageVersion.None && langVer < pyTypeAttr.MinVersion) { continue; } if (pyTypeAttr.MaxVersion != PythonLanguageVersion.None && langVer > pyTypeAttr.MaxVersion) { continue; } typeVarName = pyTypeAttr.VariableName ?? ComputeVariableName(proxyType); break; } if (typeVarName == null) { continue; } } var pyType = PyTypeObject.FromNativeGlobalVariable(process, typeVarName); var proxyInfo = new ProxyInfo(proxyType); ProxyInfoFromPyTypePtr.Add(pyType.Address, proxyInfo); PyTypeFromType.Add(proxyType, pyType); } }
private static ProxyInfo?FindProxyInfoForPyType(DkmProcess process, ulong typePtr) { if (typePtr == 0) { return(null); } ProxyInfo proxyInfo; var map = process.GetOrCreateDataItem(() => new ProxyTypes(process)).ProxyInfoFromPyTypePtr; if (map.TryGetValue(typePtr, out proxyInfo)) { return(proxyInfo); } // If we didn't get a direct match, look at tp_base and tp_bases. var typeObject = new PyTypeObject(process, typePtr); var tp_base = typeObject.tp_base.Raw.Read(); var baseProxyInfo = FindProxyInfoForPyType(process, tp_base); if (baseProxyInfo != null) { return(baseProxyInfo); } var 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); }
public bool IsSubtypeOf(PyTypeObject type) { if (this == type) { return true; } var tp_base = this.tp_base.TryRead(); if (tp_base != null && tp_base.IsSubtypeOf(type)) { return true; } var 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; }