Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for unkeyed decoding #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sirnacnud
Copy link
Contributor

This PR contains fixes to NSUnarchiver and NSCoder to properly decode the NIB from Apple's SimpleCocoaApp, which uses unkeyed coder.

Please review commit by commit/ I added a explanation for each of the fixes in the commit body.

When the call to decodeString failed, it returned immediately out of the
function without assigning the advanced type pointer to outType. Now it
breaks out of the switch and updates the pointer at the end of the
function.
The call to decodeString doesn't succeed in the case when charValue is
NewLabel, as it then calls decodeSharedString, which then tries to check
the next character for NullLabel/NewLabel/Default, fails as it is now on
the first character of the string.

I'm not for sure if decodeString is supposed to be called internally in
NSUarchiver. Inside NSUarchiver it is calling decodeSharedString every
place else. The difference between decodeString and decodeSharedString
is very minor.

I opted to just call decodeShareString in readType and it fixed the
described issue above.
Copy link
Contributor

@CuriousTommy CuriousTommy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit that this PR goes beyond my current knowledge of Darling, so there are some stuff I'm not really able to verify (such as the usage of decodeString vs decodeSharedString)

With that being said, the code and commits look good and the code compiles without issues. The type encoding (#) improvements matches what Apple says in their documentation.

I have one (optional) suggestion and a clarification on your comment.

src/NSUnarchiver.m Outdated Show resolved Hide resolved
…wrong retain count

Behavior:
- decodeObject should return an object that the caller has to explicitly retain
- decodeValueOfObjCType:at/decodeArrayOfObjCType:count:at:/decodeValuesOfObjCTypes:
  implicitly cause the outputted objects to be retained

See section titled When to Retain a Decoded Object from:
https://preterhuman.net/macstuff/techpubs/macosx/System/Library/Frameworks/Foundation.framework/Versions/C/Resources/English.lproj/Documentation/Reference/ObjC_classic/Classes/NSCoder.html
Copy link
Contributor

@CuriousTommy CuriousTommy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

I'll hold off merging this in-case if @bugaevc wants to also review this PR.

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.

2 participants