Fix KeyError(b'd') in make_type for unregistered struct types on Python 3#149
Open
ElliotGarbus wants to merge 2 commits into
Open
Fix KeyError(b'd') in make_type for unregistered struct types on Python 3#149ElliotGarbus wants to merge 2 commits into
ElliotGarbus wants to merge 2 commits into
Conversation
…on 3 The types dict uses str keys but signature_types_to_list returns bytes on Python 3 (b'd' != 'd'), causing a KeyError for any unregistered struct with primitive fields (e.g. UIEdgeInsets). Pre-registered structs such as CGRect never hit this path, masking the bug. Decode _type from bytes before the dict lookup and collapse the duplicated field_list.append call into a single statement. Closes kivy#148
connection_didFailWithError_ calls CFRunLoopStop after each failure, so a single CFRunLoopRunInMode call exits after the first delegate fires and the second connection's event is never delivered. Run the loop in short bursts, restarting after each CFRunLoopStop, until both delegates have been called.
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.
Summary
Fixes #148.
On Python 3,
signature_types_to_listreturns bytes items (e.g.b'd'), but thetypesdict inobjc_py_types.pyhas str keys ('d'). Pre-registered structs (CGRect, NSRange, CGPoint, CGSize) are returned from the registry beforemake_typeis ever called, which masked this bug. Any unregistered struct with primitive fields — includingUIEdgeInsets— falls through tomake_typeand raisesKeyError: b'd'.Changes
pyobjus/objc_py_types.py— decode_typefrom bytes before thetypesdict lookup inmake_type. Also collapsed the duplicatedfield_list.appendthat existed in both branches ofif not field_nameinto a single statement.tests/test_make_type_bytes.py— new regression test file with 6 tests (+ 14 subtests) covering: 4-double struct (the UIEdgeInsets shape), float, mixed int/float, every primitive type in the dict via subtests, and both code paths (auto-generated field names and explicit member names).Also fixed a pre-existing failure in
test_multiple_delegates: eachconnection_didFailWithError_callback callsCFRunLoopStop, so a singleCFRunLoopRunInModecall exits after the first delegate fires and the second connection's event is never delivered. The fix restarts the run loop in short bursts until both delegates have been called (or a 10-second timeout is reached).