Add the objects to the object graph and balance the retain count before
doing the parsing. This ensure if an error is hit (and a throw happens),
the object(s) won't be leaked.
Parsing will always mutate the graph, so yes this includes more mutations
in failure cases, but other fields could always be modified before the
bad data is encountered. But even then, that edge case *only* apples to api
users that are explicitly *merge* (-mergeFrom...), the majority of the calls
are to +parseFromData:error:, so the entire graph is released on failure.
PiperOrigin-RevId: 510417377
There was a twist code path (that some times showed up due to what happened to
be in memory in failure cases), that would cast a bogus wire type into the
enum, and then fall through switch statements.
Resolve this by validating all wire types when parsing tags and throwing the
error at that point so it can't enter the system.
As added safety, stick in a few asserts for apis that get passed tags to ensure
they also are only seeing valid data.
Bonus: Tweak the parsing loop to skip some work when we get the end marker
(zero tag) instead of still looping through all the fields.
Working on https://github.com/google/protobuf/issues/1599, specifically:
- Turn on more warnings that the Xcode UI calls out with individual controls.
- Manually add:
-Wundef
-Wswitch-enum
- Manually add and then diable in the unittests because of XCTest's headers:
-Wreserved-id-macro
-Wdocumentation-unknown-command
- Manually add -Wdirect-ivar-access, but disable it for the unittests and in
the library code (via #pragmas to suppress it). This is done so proto users
can enable the warning.
- Add more to the ObjC dir readme.
- Merge the ExtensionField and ExtensionDescriptor to reduce overhead.
- Fix an initialization race.
- Clean up the Xcode schemes.
- Remove the class/enum filter.
- Remove some forced inline that were bloating things without proof of performance wins.
- Rename some internal types to avoid conflicts with the well know types protos.
- Drop the use of ApplyFunctions to the compiler/optimizer can do what it wants.
- Better document some possible future improvements.
- Add missing support for parsing repeated primitive fields in packed or unpacked forms.
- Improve -hash.
- Add *Count for repeated and map<> fields to avoid auto create when checking for them being set.