Skip to content

Fixes and tests#14

Merged
lacraig2 merged 8 commits intomainfrom
fixes
Mar 11, 2026
Merged

Fixes and tests#14
lacraig2 merged 8 commits intomainfrom
fixes

Conversation

@lacraig2
Copy link
Contributor

This pull request introduces comprehensive support for tracking and propagating absolute base memory addresses (_base_address) when creating and manipulating instances from memory buffers. This enhancement enables accurate pointer arithmetic and address calculations, especially when working with memory snapshots or overlays with known absolute addresses. The changes also include improved buffer handling, more robust type checking, and new tests to ensure correctness of address calculations across complex nested types and arrays.

Absolute Address Handling and Propagation:

  • Added an optional base_address parameter to instance creation methods (such as from_buffer and internal _create_instance), ensuring that the absolute address is associated with instances created from memory snapshots or overlays. (src/dwarffi/dffi.py [1] [2] [3] [4] [5]
  • Modified the BoundTypeInstance class to store and propagate _base_address and to use it in pointer arithmetic and address calculations, including when extracting nested fields or creating array views. (src/dwarffi/instances.py [1] [2] [3]
  • Updated the addressof method to use _base_address (if present) instead of _address, ensuring correct calculation of absolute addresses for both root and nested fields. (src/dwarffi/dffi.py src/dwarffi/dffi.pyL512-R513)

Buffer and Type Handling Improvements:

  • Improved buffer handling in BoundTypeInstance to support both native Python buffers and proxy objects, and to ensure efficient zero-copy operations by wrapping buffers in memoryview when appropriate. (src/dwarffi/instances.py src/dwarffi/instances.pyL246-R283)
  • Refined equality and assignment logic to work directly with the underlying buffer, reducing unnecessary conversions and improving performance. (src/dwarffi/instances.py [1] [2] [3]

Testing and Coverage:

  • Added extensive new tests to verify correct propagation of base addresses, pointer arithmetic, nested field extraction, and array pointer decay, including edge cases and comprehensive scenarios. (tests/test_ffi.py tests/test_ffi.pyR336-R441)
  • Introduced a new deep coverage test file to exercise error paths, introspection utilities, dictionary export, pretty-printing, deep initialization, symbol shifting, and complex struct unpacking. (tests/test_coverage_deep.py tests/test_coverage_deep.pyR1-R219)

Other Improvements:

@lacraig2 lacraig2 merged commit 6c5f434 into main Mar 11, 2026
3 checks passed
@lacraig2 lacraig2 deleted the fixes branch March 11, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant