Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve patching
ReferenceFix
to POINTER(POINTER(interface))
type. (
#631) * Refactor patching `ReferenceFix` to `POINTER(POINTER(interface))` type. In e6281cc, the approach of overriding the `__setitem__` method of `POINTER(p)` (i.e., `POINTER(POINTER(interface))`) was changed from directly overwriting it to using `partial.partial`. In f8e9855, `super` was introduced in the `__setitem__` method. In 3f99d4c, `partial.partial` was replaced with `patcher.Patch`. For a while, the code seemed to work, but a `NameError` started being raised due to `super(_, self)`, so in 32d21e3, it was changed to `super(POINTER(p), self)`. When passing a type `T` to `POINTER`, the caching mechanism ensures that the same `POINTER(T)` type is always returned. Passing `POINTER(T)` to `POINTER` and obtaining `POINTER(POINTER(T))` (which is `LP_POINTER(T)` in `repr`) can also be considered an equivalent relationship. Looking at the implementation of `ctypes.SetPointerType` (which is undocumented and has become deprecated), it doesn't seem intended to alter the relationship between `T` and `POINTER(T)`. Considering the historical background of these changes, the implementation of `ctypes`, and its use cases, it appears that `POINTER(p)` invoked within `__setitem__` was not intended to be evaluated later than the `POINTER(p)` passed to `patcher.Patch`. Even when assigning `pp = POINTER(p)` to a temporary variable and passing this `pp` to both `patcher.Patch` and `super` within `__setitem__`, the tests pass. Therefore, I determined that this change does not present an implementation problem. This also resolves the inconsistency where a `ptr_type` is actually being passed, despite the method name is `..._to_ptrptr_type`. * Add a `type: ignore` comment.
- Loading branch information