Commit graph

31 commits

Author SHA1 Message Date
Thomas Van Lenten
1bf47797fb [ObjC] Adapt the varint size calculation from C++
The C++ has a version that is mostly branchless and also very short, so just use
that.

However, don't bother with also doing the Intel version as that won't likely
matter for Apple platforms for much longer.

We've seen cases where folks use clang flags to aggressively inline things and
so this could actual shrink things depending on how many times it gets inlined
within CodedOutputStream.

PiperOrigin-RevId: 831826052
2025-11-13 06:07:00 -08:00
Nicholas Levin
bd56046a2f Automated rollback of commit 0437d645a8.
PiperOrigin-RevId: 830503499
2025-11-10 10:30:09 -08:00
Thomas Van Lenten
0437d645a8 [ObjC] Adapt the varint size calculation from C++
The C++ has a version that is branchless and also very short, so just use that.

However, don't bother with also doing the Intel version as that won't likely
matter for Apple platforms for much longer.

We've seen cases where folks use clang flags to aggressively inline things and
so this could actual shrink things depending on how many times it gets inlined
within CodedOutputStream.

PiperOrigin-RevId: 830479425
2025-11-10 09:44:04 -08:00
Thomas Van Lenten
d4bef77490 [ObjC] Fix some tests to not violate GPBCodedOutputStream invariants.
If the class is writing to an NSOutputStream, the buffer must always
be used to batch things up. The tests were accidentally making a zero
length buffer which isn't valid.

Fix the tests to not do this.

Make the core code assert in debug to ensure the invariant can't be
broken.

PiperOrigin-RevId: 817153199
2025-10-09 06:17:35 -07:00
Thomas Van Lenten
0772e19244 [ObjC] fix the pddm source check.
PiperOrigin-RevId: 781117217
2025-07-09 10:46:13 -07:00
Thomas Van Lenten
2b93422f7e [ObjC] Breaking Change: Remove GPBUnknownFieldSet.
GPBUnknownFieldSet and the related apis have been replaced by
GPBUnknownFields. The new api allows the Objective-C Protobuf
implementation to be fully conformant around requirements for
parsing/re-serialization of unknown fields.

PiperOrigin-RevId: 684140581
2024-10-09 16:14:56 -07:00
Thomas Van Lenten
5710bfcbb9 [ObjC] Use more complete imports
Import both the public and private header into impls when the
private is needed.

Also update the tests to use more complete imports.

PiperOrigin-RevId: 671388271
2024-09-05 08:52:31 -07:00
Thomas Van Lenten
d794139f09 [ObjC] Deprecate GPBUnknownFieldSet and related apis.
GPBUnknownFields will be going away in the next major release of the ObjC
Protobuf runtime. Code should be updated to make use of GPBUnknownFields
instead.

PiperOrigin-RevId: 659963056
2024-08-06 08:26:33 -07:00
Protobuf Team Bot
a2815fa13f [ObjC] Ensure -[GPBCodedOutputStream dealloc] cannot throw exceptions
If `-[GPBCodedOutputStream flush]` failed (e.g., because the filesystem
was out of space), then `-[GPBCodedOutputStream dealloc]` would throw
an exception.

`-dealloc` cannot fail, so the only thing to do in this case is to silently
swallow the exception.

PiperOrigin-RevId: 579916429
2023-11-06 12:04:29 -08:00
Sandy Zhang
81068e8e8c Internal change
PiperOrigin-RevId: 566426899
2023-09-18 15:17:56 -07:00
Joshua Haberman
44bd65b2d3 Shorten our license headers into an abbreviated form that references LICENSE instead of including it in full.
PiperOrigin-RevId: 563894040
2023-09-08 18:47:26 -07:00
Thomas Van Lenten
f6409bd2c4 [ObjC] Mark NSOutputStream helper as not inlinable.
With some optimizer flags, GPBCodedOutputStream results in a lot of
code bloat, for now just prevent the new helper related to
NSOutputStream from being inlined to keep that in check.

PiperOrigin-RevId: 554525631
2023-08-07 10:50:10 -07:00
Thomas Van Lenten
f607b66d9f Fix typos.
They got noticed after the previous change was being submitted.

PiperOrigin-RevId: 553560211
2023-08-03 12:45:35 -07:00
Thomas Van Lenten
94a9261a28 [ObjC] Handle interruptions when writing to NSOutputStreams.
A write succeed but only write out a subset of the requested amount
of data, handle that via a helper that will loop and advance as need
to completely write out the data.

PiperOrigin-RevId: 553516360
2023-08-03 10:23:15 -07:00
Mike Kruskal
3688ddb5b3 Internal changes
PiperOrigin-RevId: 544976965
2023-07-03 05:59:06 -07:00
Protobuf Team Bot
e6d01b2edc [ObjC] Enforce the max message size when serializing to binary form.
The validation is done at the highest point so if a sub message is what
goes over the limit it is caught at the outer message, thus reducing the
impact on the serialization code.

PiperOrigin-RevId: 511473008
2023-02-22 05:55:46 -08:00
Thomas Van Lenten
2fb33b8c54 [ObjC] Move from #pragma unused() to _unused 2022-09-26 11:01:59 -04:00
Thomas Van Lenten
189f6325d4 Format the runtime sources. 2022-09-23 14:09:00 -04:00
Thomas Van Lenten
9e069b2e51 [ObjC] Tweak some things to be better shape for clang-format.
- Minor formatting changes to make thing happy.
- Block clang-format from the PDDM macro definitions to avoid it wrapping
  things.
- Don't add clang-format directives to the expansion, easier to handling
  it outside of there.
2022-09-23 14:09:00 -04:00
Dave MacLachlan
ab48ecf140 Update pddm to work with clang-format
Add clang-format off/on directives around pddm expansions to simplify formatting other code.
2020-01-21 13:14:01 -05:00
Thomas Van Lenten
b273cba192 Fix enum writing.
Enums use varint, so if the value is negative it should end up being longer.

This was caught my new conformance test cases.
2019-08-26 17:17:32 -04:00
Felix Jendrusch
1da9ffe394 Check return value on write of raw pointer 2018-03-08 16:20:37 +01:00
Thomas Van Lenten
baed06e694 Small code reorder to maybe make #3893 happy.
Use the ivar for the -open, so hopefully it lines up with the -close
in dealloc and isn't seen as an unbalanced "open".
2017-11-17 12:32:22 -05:00
Thomas Van Lenten
5fd71ce631 ObjC: Document the exceptions on some of the writing apis. 2017-06-19 10:33:45 -04:00
Sergio Campamá
14e74f6a21 Support the -Wassign-enum compiler flag. (#2085)
Support the -Wassign-enum compiler flag.
2016-09-08 15:15:12 -04:00
Thomas Van Lenten
1a6c1d092d Never use strlen on utf8 runs so null characters work.
Fixes https://github.com/google/protobuf/issues/1933

Add a new test that forces strings into two different implementations from the
NSString class cluster to help confirm we're exercising both paths by which
CodedOutputStream will extract data from an NSString.

Move the old +load test (that was flawed because the behavior really depends on
the type of string from the NSString class cluster); into a unittest that
targets the specific case we're adding a behavior confirmation on.

As a bonus, improve the TextFormat generation of string characters < 0x20.
2016-08-09 10:37:16 -04:00
Thomas Van Lenten
c8a440dfb6 Add more warnings to for the ObjC runtime build
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.
2016-05-25 16:42:31 -04:00
Thomas Van Lenten
36650a07cf HeaderDoc support in the library and generated sources
- Convert most of the core library headers over to HeaderDoc format.
- Switch the generated comments over to HeaderDoc.
- Create GPBCodedOutputStream_PackagePrivate and move some things into there
  that should be more internal.
2016-03-07 12:07:03 -05:00
Thomas Van Lenten
8c88957ef3 Add nonnil markup to ObjC library.
Add the clang annotations to the objc library and generated code to help with Swift bridging and compiler checks.
2015-06-16 17:04:50 -04:00
Thomas Van Lenten
d846b0b059 Beta quality drop of Objective C Support.
- 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.
2015-06-08 17:17:22 -04:00
Thomas Van Lenten
30650d81d9 Alpha 1 drop of Google's Objective C plugin and runtime support for protobufs. 2015-05-06 13:19:14 -04:00