Einspect

Latest version: v0.5.16

Safety actively analyzes 638437 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 4 of 7

0.5.0a1

New
- `einspect.view` now supports subtypes. The additional instance dictionary is supported to be moved during `View.move_from` or `View.move_to`
python
from einspect import view

class Num(int):
pass

print(view(10))
IntView(<PyLongObject at 0x101786a60>)

print(view(Num(10)))
IntView[Num](<PyLongObject at 0x1006e7440>)

- Memory moves now no longer require an unsafe context if it can be performed safely.
- If safe moving is not possible (target size exceeds allocated memory for the object) an UnsafeError is raised.
python
from einspect import view

x = 900
view(x) << 50

ls = [1, 2]
view(ls) << [3, 4, 5]

tup = (1, 2)
view(tup) << (1, 2)


Changes
- `einspect.view` DeprecationWarning for non-concrete types is removed.
- `View.move_from` no longer makes a deep-copy of `other`, this was originally added to prevent member references from being dropped but hindered features like connected instance dictionary pointers from working.
- Such, the target of a move will receive most heap-allocated pointers of the source. For example, moved lists will share the original `ob_item` array
python
from einspect import view, unsafe

ls = []
x = [3, 4]

with unsafe():
view(ls) << x

print(ls) [3, 4]
Updating x will now affect ls as well
x[0] = "hi"
print(ls) ['hi', 4]

- However, this only applies to pointers referring to allocations off the object struct, other attributes are still statically moved. For example, calling `x.clear()` will deallocate the `ob_item` array of `x` and set it as a `NULL` pointer. But `ls` still has an `ob_size` of 2, and will try to access its `ob_item` pointer to get elements.
python
from einspect import view, unsafe

ls = []
x = [3, 4]

with unsafe():
view(ls) << x

x.clear()
print(ls) Segmentation fault (likely)


- To revert to original behavior, `deepcopy` can be called explicitly

python
from copy import deepcopy
from einspect import view, unsafe

ls = []
x = [3, 4]

with unsafe():
view(ls) << deepcopy(x)

x.clear()
print(ls) [3, 4]


What's Changed
* Implement formatting for `MappingProxyView.info` by ionite34 in https://github.com/ionite34/einspect/pull/30
* Add tests for MappingProxyView info formatting by ionite34 in https://github.com/ionite34/einspect/pull/32
* Add subclass support for Views, safe memory moves no longer requires unsafe context by ionite34 in https://github.com/ionite34/einspect/pull/33


**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.10...v0.5.0a1

0.4.10

Adds
- PyObject `instance_dict` method
- View `instance_dict` property

Fixes
- Formatting for `StrView.info` will now resolve additional values fields like `wstr`

Improvements
- Test coverage

**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.9...v0.4.10

0.4.9

Implement dynamic string structs to reflect CPython implementation:
- PyASCIIObject
- PyCompactUnicodeObject
- PyUnicodeObject

Added some macros to py_unicode
> These should exactly match their C equivalents when possible
- PyUnicode_DATA
- PyUnicode_IS_COMPACT_ASCII
- PyUnicode_UTF8_LENGTH
- PyUnicode_WSTR_LENGTH
- _PyUnicode_COMPACT_DATA
- _PyUnicode_HAS_UTF8_MEMORY
- _PyUnicode_HAS_WSTR_MEMORY
- _PyUnicode_NONCOMPACT_DATA
- _PyUnicode_UTF8
- _PyUnicode_UTF8_LENGTH

Added `MutableSequence` methods for StrView:
- `__delitem__` (index / slice)
- `__setitem__` (index / slice)
- append
- clear
- extend
- insert
- pop
- remove
- reverse

> These new methods will not require an unsafe context normally as they check the allocated memory bounds before any resize operation. If resizing will be beyond allocated memory, an `UnsafeError` is raised.

> An unsafe context can be entered to bypass this allocated memory check.

Fixes:
- ViewStr will now dynamically use one of `PyASCIIObject`, `PyCompactUnicodeObject`, or `PyUnicodeObject` structs. Previously the single usage of `PyUnicodeObject` could cause out of bounds memory access.
- PyASCIIObject and subtypes now use a `mem_size` that is logically equivalent to the C implementation of `str.__sizeof__`, and should match in all cases.

**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.8...v0.4.9

0.4.8

Added
- Py.Mem api methods (Malloc, Calloc, Realloc)
- Add try_from and with_ref methods to PyObject

Fixes and Enhancements
- Simplify PyUnicode field access
- ListView and TupleView ob_item setters now will cast from PyObject and objects to the required ptr[PyObject] types

**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.7...v0.4.8

0.4.7

Enhancements
- Expand `PyTupleObject.ob_digit` setter compatibility for casts

Docs
- Improve documentation coverage

**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.6...v0.4.7

0.4.6

Added `MutableSequence` protocols for TupleView:
- `__getitem__` (index / slice)
- `__setitem__` (index / slice)
- `__delitem__` (index / slice)
- `__iadd__`
- `append`
- `clear`
- `extend`
- `insert`
- `pop`
- `remove`
- `reverse`

> These new methods will not require an unsafe context normally as they check the allocated memory bounds before any resize operation. If resizing will be beyond allocated memory for the tuple, an `UnsafeError` is raised.

> An unsafe context can be entered to bypass this allocated memory check.

Fixes
- Fixed `DictView.__getitem__` missing PyObject cast
- TupleView `mem_size` uses base implementation from `PyTupleObject` for increased accuracy

**Full Changelog**: https://github.com/ionite34/einspect/compare/v0.4.5...v0.4.6

Page 4 of 7

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.