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

Fix obj_c types to not overwrite jsonDict with nil #201

Merged
merged 2 commits into from
Nov 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stone/backends/obj_c_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ def emit_serializer():
if is_user_defined_type(data_type):
if is_struct_type(data_type) and \
not data_type.has_enumerated_subtypes():
self.emit('jsonDict = [{} mutableCopy];'.
Copy link

Choose a reason for hiding this comment

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

The only thing i'd be worried about here is that in the old version, we are relying on the fact that we either get a brand new dictionary or nil. I the new code, we are adding the serialized dictionary to whatever jsonDict already contains. Are we 100% certain that every instance where this is used does not have an instance of jsonDict with some values already in it??

Something safer (if your unsure about my question above) would be to do something like:

jsonDict = [{} mutableCopy] ?: [[NSMutableDictionary alloc] init];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the deleted code, I think your saying that I should do

let additionDict = [{} mutableCopy] ?: [[NSMutableDictionary alloc] init]; // to guarantee non-nilness
[jsonDict addEntriesFromDictionary: additionDict]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we are adding nil entries like [jsonDict addEntriesFromDictionary:nil], the json will still be non-nil. so we don't need a additionDict to be non-nil

self.emit('[jsonDict addEntriesFromDictionary:{}];'.
format(serialize_call))
else:
self.emit(
Expand Down