Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens DFFI.addressof() / pointer dereferencing behavior (including C-like array-to-pointer decay) and introduces stricter typing across the codebase, backed by new tests and a mypy CI step.
Changes:
- Add tests that validate
addressof()type-info normalization, nested-field addressing, array decay, and safe deref. - Refine internal typing (Protocols/type aliases) and add mypy strict configuration + CI check.
- Harden a few runtime paths (symbol shifting, pointer deref / stride logic) to avoid crashes on unexpected
None/type shapes.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_addressof_enhancement.py |
Adds regression tests for addressof() normalization/decay and deref safety. |
src/dwarffi/dffi.py |
Normalizes addressof() target type info to dicts and applies array decay; improves typing in multiple APIs. |
src/dwarffi/instances.py |
Tightens typing for bound instances/pointers; adjusts deref/arithmetic logic and cache/field access typing. |
src/dwarffi/types.py |
Introduces typing helpers/aliases, narrows cache field types, and improves type flattening metadata. |
src/dwarffi/parser.py |
Small robustness improvements around symbol shifting and type-size computation typing. |
src/dwarffi/dtyping.py |
New Protocol/type-alias module to centralize shared typing without runtime circular imports. |
pyproject.toml |
Adds mypy to dev deps and configures strict mypy settings. |
.github/workflows/ci.yml |
Adds a mypy step to CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+67
to
+68
| # Clear the cache to ensure new types are recognized | ||
| self._parse_ctype_string.cache_clear() # type: ignore[attr-defined] |
| current_type: Union[TypeInfoDict, Vtype] = cdata._instance_type_def | ||
| for field_name in fields_or_indexes: | ||
| if not isinstance(current_type, VtypeUserType): | ||
| break # Should be caught by offsetof, but safety first |
Comment on lines
+992
to
+996
| # Build a multiplier format string, e.g., "<1000I" | ||
| fmt = f"{base_struct.format[0]}{count}{base_struct.format[1:]}" | ||
| buf = cdata._parent_instance._instance_buffer | ||
| offset = cdata._parent_instance._instance_offset + cdata._array_start_offset_in_parent | ||
| return list(struct.unpack_from(fmt, buf, offset)) # type: ignore[arg-type] |
| else: | ||
| subtype = self._subtype_info | ||
|
|
||
| # If the target is ALSO a pointer, we must read the raw pointer value from memory |
|
|
||
| def __ne__(self, other): | ||
| def __eq__(self, other: Any) -> bool: | ||
| return self.address == (other.address if isinstance(other, Ptr) else other) |
|
|
||
| # Pre-fetch the concrete type object | ||
| resolved_obj = None | ||
| # Explicity type this to prevent None union drift |
| import base64 | ||
| import struct | ||
| from typing import Any, Dict, List, Optional, Tuple, Union | ||
| from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Union, cast |
| @@ -0,0 +1,42 @@ | |||
| from typing import TYPE_CHECKING, Any, Dict, Optional, Protocol, Tuple, Union, runtime_checkable | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds static type checking to everything in our source directory.