Skip to content

Commit 60cdf2e

Browse files
authored
Merge pull request #56 from ionite34/dev
2 parents a3fbd67 + caa5fda commit 60cdf2e

38 files changed

+693
-305
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
project = "einspect"
1616
copyright = "2023, Ionite"
1717
author = "Ionite"
18-
release = "v0.5.10"
18+
release = "v0.5.11"
1919

2020

2121
# -- General configuration ---------------------------------------------------

poetry.lock

Lines changed: 42 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "einspect"
3-
version = "0.5.10"
3+
version = "0.5.11"
44
packages = [{ include = "einspect", from = "src" }]
55
description = "Extended Inspect - view and modify memory structs of runtime objects."
66
authors = ["ionite34 <dev@ionite.io>"]

src/einspect/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
__all__ = ("view", "unsafe", "impl", "orig", "ptr", "NULL")
1414

15-
__version__ = "0.5.10"
15+
__version__ = "0.5.11"
1616

1717
unsafe = global_unsafe

src/einspect/_compat/py_function_3_10.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
from types import FunctionType
44

5-
from einspect.structs.deco import struct
65
from einspect.structs.include.object_h import vectorcallfunc
76
from einspect.structs.py_object import PyObject
87
from einspect.types import ptr
98

109

11-
@struct
1210
class PyFunctionObject(PyObject[FunctionType, None, None]):
1311
globals: ptr[PyObject]
1412
builtins: ptr[PyObject]

src/einspect/_compat/py_function_3_9.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
from types import FunctionType
44

5-
from einspect.structs.deco import struct
65
from einspect.structs.include.object_h import vectorcallfunc
76
from einspect.structs.py_object import PyObject
87
from einspect.types import ptr
98

109

11-
@struct
1210
class PyFunctionObject(PyObject[FunctionType, None, None]):
1311
code: ptr[PyObject] # A code object, the __code__ attribute
1412
globals: ptr[PyObject]

src/einspect/_compat/py_unicode_3_12.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from ctypes import (
4-
Union,
54
addressof,
65
c_char,
76
c_char_p,
@@ -22,7 +21,7 @@
2221

2322
from einspect.api import Py_hash_t
2423
from einspect.protocols import bind_api
25-
from einspect.structs.deco import struct
24+
from einspect.structs.deco import Union
2625
from einspect.structs.py_object import Fields, PyObject
2726
from einspect.structs.traits import IsGC
2827
from einspect.types import Array, char_p, ptr, void_p
@@ -103,15 +102,13 @@ def type_info(self) -> Type[c_wchar | c_uint8 | c_uint16 | c_uint32]:
103102
return types_map[int(self)]
104103

105104

106-
@struct
107105
class LegacyUnion(Union):
108106
any: void_p
109107
latin1: ptr[c_uint8] # Py_UCS1
110108
ucs2: ptr[c_uint16] # Py_UCS2
111109
ucs4: ptr[c_uint32] # Py_UCS4
112110

113111

114-
@struct
115112
class PyASCIIObject(PyObject[str, None, None], IsGC):
116113
"""
117114
Defines a PyUnicodeObject Structure
@@ -205,7 +202,6 @@ def GetLength(self) -> int:
205202
"""Return the length of the string in code points."""
206203

207204

208-
@struct
209205
class PyCompactUnicodeObject(PyASCIIObject):
210206
"""
211207
Defines a PyCompactUnicodeObject Structure
@@ -226,7 +222,6 @@ def _format_fields_(self) -> Fields:
226222
}
227223

228224

229-
@struct
230225
class PyUnicodeObject(PyCompactUnicodeObject):
231226
"""Defines a PyUnicodeObject Structure."""
232227

src/einspect/_patch.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66

77
from einspect import types
88
from einspect.structs.py_object import PyObject
9+
from einspect.types import Pointer, PyCFuncPtrType
910

1011

1112
class _Null_LP_PyObject(POINTER(PyObject)):
1213
_type_ = PyObject
1314

1415
def __repr__(self) -> str:
1516
"""Returns the string representation of the pointer."""
16-
return f"<NULL ptr[PyObject] at {addressof(self):#04x}>"
17+
return f"<Null LP_PyObject at {addressof(self):#04x}>"
1718

1819
def __eq__(self, other) -> bool:
1920
"""Returns equal to other null pointers."""
20-
# noinspection PyUnresolvedReferences
21-
if not isinstance(other, ctypes._Pointer):
22-
return NotImplemented
23-
return not other
21+
if isinstance(other, Pointer):
22+
return not other
23+
24+
if isinstance(type(other), PyCFuncPtrType):
25+
return not ctypes.cast(other, c_void_p)
26+
27+
return NotImplemented
2428

2529

2630
def run() -> None:

src/einspect/protocols/type_parse.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from typing_extensions import Self
1212

13+
from einspect.types import _SelfPtr
14+
1315
log = logging.getLogger(__name__)
1416

1517
Py_ssize_t = ctypes.c_ssize_t
@@ -27,6 +29,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any:
2729

2830

2931
aliases = {
32+
bool: ctypes.c_bool,
3033
# ctypes will cast c_ssize_t to (int)
3134
int: Py_ssize_t,
3235
# ctypes will cast py_object to (object)
@@ -101,6 +104,12 @@ def convert_type_hints(source: type, owner_cls: type) -> type | None:
101104
if isinstance(source, typing._GenericAlias):
102105
source = get_origin(source)
103106

107+
# For special SelfPtr object
108+
if source is _SelfPtr:
109+
res = POINTER(owner_cls) # type: ignore
110+
res.__module__ = owner_cls.__module__
111+
return res
112+
104113
if source in aliases:
105114
return aliases[source]
106115

0 commit comments

Comments
 (0)