Commit Graph

328 Commits

Author SHA1 Message Date
Thomas Van Lenten
e1e5b8af79 [ObjC] Update some library internals to not pass syntax versions.
- With the new flags, the syntax isn't needed, so don't pass it.
- To keep library binary compatibility, rename the helpers since one
  "Internal" method was called from generated code. Keep a shim with
  the old signature to support those generated sources.
2020-04-24 16:36:15 -04:00
Thomas Van Lenten
8d224b4c48 [ObjC] Runtime support for proto3 optional.
- Add a Descriptor flag to capture if the field should clear on being zeroed.
- Update the runtime to use the new clear on zero flag.
- Add a flag on message initialization to indicate the sources were generated
  with/without this support so the runtime can backfill the flag for older
  generated sources.
2020-04-24 16:36:15 -04:00
Thomas Van Lenten
e9b0c92659 [ObjC] Update oneof generation for proto3 optional.
- Don't make an OneofGenerator for synthetic oneofs.
- Update the field calculations that determine if hasbits are needed to
  know about synthetic oneofs and ignore them.
2020-04-24 16:36:15 -04:00
Joshua Haberman
bb30225f06 Sync from Piper @307316823
PROTOBUF_SYNC_PIPER
2020-04-19 18:01:44 -07:00
Thomas Van Lenten
7b8a241b57 [ObjC] Improve validation on public apis. 2020-04-15 13:22:05 -04:00
Thomas Van Lenten
95282469eb [ObjC] Remove helper to avoid extra lookups.
Skip the helper that fetches the desc again since these methods already
collected it.
2020-04-15 13:22:05 -04:00
Joshua Haberman
74ad62759e Sync from Piper @306496510
PROTOBUF_SYNC_PIPER
2020-04-14 12:55:41 -07:00
Thomas Van Lenten
6f3bda22f4 [ObjC] Fix some tests checking the wrong Message class. 2020-04-14 12:15:23 -04:00
Thomas Van Lenten
24dda9e233 Update the build/test script for newer Xcode 11 versions
Apple stopped really supporting the 32bit simulators, so don't try
running those any more.
2020-04-14 12:15:23 -04:00
Thomas Van Lenten
56c48ae592 Revisit how the WKTs are bundled with ObjC.
There are have been a few issues around people using case sensitive file systems
what Xcode/clang does when looking at the paths. In attempts to solve one set of
warnings, new warnings/errors happened in different setup. So, to hopefully put
these problem away for got, move the WKTs to be at the same level as the other
headers.

- Revert "Override CocoaPods module to lowercase (#6464)"
  This reverts commit 479ba8226b.
- Move WKTs to the objectivec directory and make the old headers shim back to
  the new locations.
- Update objectivec/generate_well_known_types.sh to check them one at a time
  and to deal with the new locations for them.

Fixes #6803
2020-02-10 12:20:05 -05:00
Dave MacLachlan
302f3ea1e5 Update GOOGLE_PROTOBUF_OBJC_VERSION to 30003 2020-01-30 13:08:32 -05:00
Dave MacLachlan
f4a6b99339 Block subclassing
Add GPB_FINAL macro to block subclassing of generated ObjC classes.
2020-01-24 11:51:37 -05:00
dmaclach
6f9d488149 Move min Xcode version to 10.3
Xcode 10.1 has a compiler bug that breaks on generated code.
Xcode 10.3+ appear to be fine.
2020-01-23 16:43:00 -05:00
Thomas Van Lenten
edf69e5858 Make the unittest proto file generation handle additions better.
Didn't really handle when a file was missing, but all the other were up to date,
this handles that case also.
2020-01-23 08:30:51 -05: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
Dave MacLachlan
aa1d7e7c48 Change Objective C class references to using macros.
Allows easy replacing of class names in generated code using #define to redefine class names at compile time.
2020-01-21 12:12:11 -05:00
Dave MacLachlan
74956e1c15 Use references to Objective C classes instead of looking classes up by name.
This should reduce binary size slightly, small performance improvement, and improve linkage by forcing references to all used classes.

Note that this maintains backwards compatibility for sources generated by older protoc for the time being. If you want the benefits
you will need to recompile your protos with the newer protoc.
2020-01-15 15:01:53 -05:00
Brian Wignall
a104dffcb6 Fix typos (#7050)
Uses https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines to find likely typos, with https://github.com/bwignall/typochecker to help automate the checking.
2020-01-08 10:18:20 -08:00
Thomas Van Lenten
065fa2f395 Remove use of VLA.
VLAs complicate static analysis and bloat stack size. Replace VLA allocation
with calls to malloc and free.  This will alos the code to build with -Wvla.
2019-12-10 17:31:25 -05:00
Rafi Kamal
58d4420e2d Down Integrate Internal Changes 2019-11-12 13:38:58 -08:00
Thomas Van Lenten
668eb3b4e6 Fix decoding of overencoded booleans.
if the value was >32bit with the low bits all being zero, it was decoded as
false instead of as true.

Fixes #6863
2019-11-08 17:56:45 -05:00
Thomas Van Lenten
f6eeb435bf General Xcode 11 support for picking iOS simulators to test against. 2019-11-04 11:20:35 -05:00
dmaclach
4702ba9043 Remove OSReadLittle* due to alignment requirements (#6678)
The OSReadLittleInt64 function as defined by Apple reduces down to:

`return *(volatile uint64_t *)((uintptr_t)base + byteOffset);`

which means we are type-punning using a cast. On ARMv7 and other aligned architectures this can cause crashes. 
Minimal example: https://gist.github.com/dmaclach/b10b0a71ae614d304c067cb9bd264336

Fixes #6679
2019-09-20 11:19:45 -04:00
Thomas Van Lenten
5846439713
[ObjC] Don't use unions and instead use memcpy for the type swaps. (#6672)
The code in question hasn't change in a long time so the cause of
https://github.com/firebase/firebase-ios-sdk/issues/3851 still appears to be
an Xcode 11 clang change/bug; but this does appear to be slightly better
code for the work being done.

Cleanup along the way for #6679
2019-09-20 10:52:34 -04:00
Thomas Van Lenten
030a38b954 Fix typo that snuck in with last commit. 2019-08-30 11:43:08 -04:00
Thomas Van Lenten
6ec27f0d08 Add an explicit test using secure coding for added safety. 2019-08-30 09:46:30 -04: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
Paul Beusterien
479ba8226b Override CocoaPods module to lowercase (#6464)
Fix #3218
2019-08-06 15:05:24 -04:00
Paul Yang
7bff8393ca
Down Integrate to GitHub (#6414)
* Down integrate to GitHub

* Fix broken tests
2019-07-19 14:49:01 -07:00
Thomas Van Lenten
a8b8c037fc Add Xcode 11 support to the script. 2019-06-06 15:29:59 -04:00
Thomas Van Lenten
1c8a7a10f8 Update some tests for newer clang error messages. 2019-06-06 15:29:59 -04:00
Julien Poumailloux
1c95097dd3 ObjC: avoid assign for object properties (part 2)
Follow up on https://github.com/protocolbuffers/protobuf/pull/6221
2019-06-06 13:42:44 -04:00
Andrzej Hunt
4e740a724f ObjC: avoid assign for object properties
This avoids hitting the following warning when including GPBDescriptor.h in ARC
projects with stricter warning settings:
error: 'assign' property of object type may become a dangling reference; consider using 'unsafe_unretained' [-Werror,-Wobjc-property-assign-on-object-type

We first hit this in XCode 11, it's unclear whether it simply got stricter about
enforcing this warning or whether the flags enabled with -Wall or -Weverything
have been expanded.
2019-06-06 10:17:42 -04:00
Hao Nguyen
ef1e8e7172 Add module for JavaLite and fix builds 2019-04-09 06:48:01 -07:00
Benjamin Peterson
5939bc3619 Fix "the the". 2019-03-25 13:38:06 -07:00
Thomas Van Lenten
70dc39ed3d Stop enabling more warnings for CXX compiles.
For reasons I don't follow, when passing CXXFLAGS to configure, the build
ends up breaking because something along the way fails to detect C++11
support within the third_party/googletest part of the build.
2019-03-11 16:20:05 -04:00
Xiang Dai
e479410564 delete all duplicate empty blanks (#5758)
Signed-off-by: Xiang Dai <764524258@qq.com>
2019-02-20 19:28:50 -08:00
Thomas Van Lenten
bd00671b92 ObjC: Add a Xcode project for tvOS.
The CocoaPod (and source) have always support tvOS, but adding the project
makes it easier to run the tests and debug if there ever were an issue.

(not adding a watchOS project at the moment because Apple doesn't provide
 XCTest, so all it could do is build the library. We still support that,
 just can't "test" it.)
2019-01-08 08:22:12 -05:00
Thomas Van Lenten
f56adaeb57 Remove stale target reference. 2019-01-08 08:22:12 -05:00
Thomas Van Lenten
d529720e2f If enum aliases overlap in ObjC names skip generating the extras.
Some protos have enum values of "FOO" and "Foo", which the ObjC generation
then makes into the same thing. Just skip generating the enum element for
the duplicate as it would be a compile error because of the name collision.

The descriptors are still generated to support reflection and TextFormat
more completely.
2018-12-18 08:11:58 -05:00
Thomas Van Lenten
4c559316e0 Small fix to -[GPBEnumDescriptor getValue:forEnumTextFormatName:]
Don't look up the TextFormat for the value as aliases can trip that
up, instead check the TextFormat names directly and then fetch the
value.
2018-12-18 08:11:58 -05:00
Dave MacLachlan
b6311767e6 Minimize amount of filepaths being copied into protos.
By putting the NSAssert behind a DEBUG flag we aren't copying filepaths
into release builds.
2018-12-13 08:53:50 -05:00
Thomas Van Lenten
1484b58056 [ObjC] Properly annotate extensions for ARC.
Just like fields, some extension fieldnames can be named such that they appear
to have meaning to ARC. Add the annotation to the compiler will get things
correct.

Add a bunch of extensions to allow inspection on generation to ensure things
are correct.
2018-12-05 13:15:30 -05:00
Thomas Van Lenten
c486130482 Annotate the GPBDictionary enumerate* apis with NS_NOESCAPE.
This should help the Swift compiler if these apis are used because it
changes the codegen to not need copies/retains.
2018-12-05 11:08:18 -05:00
Thomas Van Lenten
2af9c68591 Annotate the GPBArray enumerate* apis with NS_NOESCAPE.
This should help the Swift compiler if these apis are used because it
changes the codegen to not need copies/retains.
2018-12-05 11:08:18 -05:00
Stephane Moore
74fa874537 [protos/objc] Include more context in deprecation messages ⚠️
For deprecated fields, identify the deprecated field and source file in the deprecation message. For deprecated files, identify the deprecated file in deprecation messages of generated interfaces. This additional context in deprecation messages will help provide developers with more context which could help them seek recommended alternatives to deprecated interfaces.
2018-12-03 10:20:24 -05:00
Dave MacLachlan
ef3a725002 Make sure Objective C Proto compiler doesn't "duplicate" prefixes unnecessarily.
In some cases proto files that want/need to use the objc_class_prefix option have
types that already have the prefix on a subset of their names. In this case we don't
want to duplicate the prefix.

Added tests for this (and prefixes in general).
2018-11-27 08:06:36 -05:00
Stephane Moore
b323b13679 [protobuf/objc] Introduce a protobuf-specific deprecation annotation ⚠️
Instead of using DEPRECATED_ATTRIBUTE from AvailabilityMacros.h, we should introduce a Google-specific Objective-C protobuf deprecation annotation. This helps address IWYU issues with using DEPRECATED_ATTRIBUTE and also enables allows clients to redefine the macro to treat protobuf warnings differently than other types of warnings (e.g., treating protobuf deprecation warnings as errors or ignoring them).
2018-11-19 13:33:41 -05:00
Thomas Van Lenten
ffa6bfc01a
ObjC: small improvement to extension serialization.
For messages that have multiple extension ranges, this will improve things
by avoiding repeated work.  For messages with a single range, it should
be a wash.

- Sort the list of set extensions once during serialization and reuse the list.
- Break out of the serialization loop as soon as the loop has moved pasted at
  accepted range for field ids.
2018-11-19 11:42:47 -05:00
Thomas Van Lenten
92a879b2eb Add a unittest for ObjC TextFormat extension support. 2018-11-14 17:06:51 -05:00
Thomas Van Lenten
af2d4134e0 TextFormat extension printing fix.
If a proto has multiple extension ranges back to back, don't double
print the first items as they also are the ending range of the
previous.
2018-11-14 17:06:51 -05:00
Thomas Van Lenten
3eb2889e9e Add the missing newlines between repeated extension files. 2018-11-14 17:06:51 -05:00
Thomas Van Lenten
8dadfda1e3 Improve comment about warning being incomplete. 2018-11-14 14:22:25 -05:00
Thomas Van Lenten
7fa7fbaf16 In debug builds output a warning about NSCoding and extensions.
Using NSCoding with a Message that has extensions is risky because
when reloaded, there is no way to provide a registry through the
NSCoding plumbing, so output a warnings to atleast give developers
a hint about the potential issues.
2018-11-14 13:57:04 -05:00
Thomas Van Lenten
c0bc265b67 Fix up the Xcode project.
The builds were failing under Xcode 10 because of the new build system.
Even when reverted to the old build system, the build was failing
on the analyzer and swift bridging header, so it seems the general
logic for searching for things was changed in a way the setting does
not always cover.

- Disable HeaderMaps.
- Set user header search paths instead of system search paths.
- Turn off always search user paths (now recommended).

Tested in Xcode 10.1 and 9.4.1; both are able to build/pass with this.
2018-11-14 12:32:02 -05:00
Adam Cozzette
86d4fe47df Updated checked-in generated code 2018-11-09 11:35:34 -08:00
Dave MacLachlan
be83b29bdd Fix bugs in our keyword conversion support for objectivec
We have code for converting C/C++/Objc keywords that appear in protos
to convert them so that they can be compiled.
One of the things we need to be careful of is accidentally overriding methods
that Apple declares in NSObject. It turns out that we have run into issues
where we conflict with "hidden" methods in NSObject or methods added by
categories. method_dump.sh collects all of the methods we care about for
macOS and iOS and dumps them into objectivec_nsobject_methods.h which
is then included in objectivec_helpers.cc as part of the build.

Added a pile of tests to verify that conversions are happening as expected.
2018-11-08 10:29:03 -05:00
Parveen Bhatia
29f27bfd0b Added safety checks when malloc returns nil in GPBDescriptor 2018-11-04 17:39:50 -05:00
Thomas Van Lenten
eecccdc802 Let the 9.4 migrator migrate the Swift source.
No changes were needed, but since the Xcode projects pick up the updated
setting, the tests require a newer Xcode that supports Swift 4.

This is being done because Xcode 10 starting warning about Swift 3 support
going away in the future, so we might as well do the updates since most
folks shouldn't be on those really old Xcode versions any more.
2018-11-02 13:28:33 -04:00
Thomas Van Lenten
d52f2bb9e4 Add more Xcode versions to the objc build script. 2018-11-01 14:59:33 -04:00
Thomas Van Lenten
8c1748f1cd Add tests to confirm strings/bytes are copied. 2018-10-02 13:45:18 -04:00
Thomas Van Lenten
09c001e999 Copy the value when setting message/data fields.
Follow ObjC conventions and how the generated header labels things by
copying NSStrings/NSData fields when setting them.
2018-10-02 13:45:18 -04:00
Thomas Van Lenten
97d03abb85 Turn off ALWAYS_SEARCH_USER_PATHS.
Causes a warning in newer Xcodes.
2018-10-02 13:45:18 -04:00
Thomas Van Lenten
561413523f Remove stray 'return'. 2018-10-02 13:45:18 -04:00
Michael Shields
10360e342f Regenerate C# and Objective-C. 2018-09-19 12:54:57 -07:00
Josh Haberman
f14064184c Regenerated Objective C protos. 2018-09-07 11:32:06 -07:00
Feng Xiao
afe98de32a Replace repo links. 2018-08-22 11:55:30 -07:00
Feng Xiao
a4862e790e Update generated descriptors. 2018-08-08 17:21:04 -07:00
dmaclach
3389bd965b Add header need for module maps.
If you make up a module map for Objective C protocol buffers, the compiler will complain about missing a declaration for GPBUnknownFieldSet which is used in this file.
2018-08-06 18:41:22 -04:00
Feng Xiao
2dcd6ae409
Remove/replace travis references (#4953)
* Remove/replace travis references.
2018-07-22 17:14:24 -07:00
Benjamin Barenblat
048f5c26a7 objectivec: Quash -Wself-assign and -Wvla (#4897)
* objectivec: Quash -Wself-assign

* objectivec: Set -Wno-vla when building

Objective-C protobuf uses VLAs for performance reasons. Ensure Clang
doesn’t complain about them.
2018-07-11 13:20:01 -04:00
Sergio Campamá
6933e2f499 Update code to work for Xcode 10b1 (#4729)
* Update code to work for Xcode 10b

* Update README and test scripts to mention that Xcode 7 is no longer supported
2018-06-05 15:14:19 -04:00
leovitch
2804902446 [ObjC] Add ability to introspect list of enum values (#4678)
Added new API to GPBEnumDescriptor to enable introspection of enum values.

Refactored implementation so that this contains a minimum of added code.

Clarified comments regarding behavior in the presence of the alias_allowed option.

Added unit tests for new functionality and for the alias case.
2018-05-29 08:08:00 -04:00
Hiroshi Ichikawa
7d978084ca [objectivec] Fix memory leak of exceptions raised by RaiseException() (#4556)
* Fix memory leak of exceptions raised by RaiseException()

Currently exceptions raised by RaiseException() is never deallocated because:

* ARC is disabled for this library: https://github.com/google/protobuf/blob/master/BUILD#L913
* It is constructed with `+alloc` but is never `-release`d.

This change fixes the issue by using `-[NSException exceptionWithName:...]` instead, which returns an autoreleased instance, so it is deallocated properly.

* Fix format.
2018-04-30 11:44:41 -04:00
Thomas Van Lenten
8417871a71 Move to Xcode 9.3 which also means a High Sierra image. 2018-04-21 12:04:03 -04:00
Thomas Van Lenten
b59da6d099 Remove the iOS Test App.
The tests can run as what Apple calls a Logic Test (under xctest), which means
it doesn't have to load an full UI App under the simulator, which speeds things
up a fair amount.
2018-04-20 17:26:38 -04:00
Sergio Campama
ce24b8a224 Update Xcode settings 2018-04-06 10:37:14 -04:00
Thomas Van Lenten
e998b8ff66 Add compile test sources for to test include order.
To ensure all headers aren't dependent on other things being imported
before/after them, make a source that just imports each header and add
it to the unittesting target, that way we ensure it can be included on
its own with ordering issues.

Also do this testing with a few generated headers that aren't part of
the library to help ensure the different generated imports needed are
complete.
2018-04-02 09:54:29 -04:00
Thomas Van Lenten
bca797dac9 Trim imports for bundled generated protos.
To avoid a cycle between headers, have the WKTs use minimal imports instead
of using the helper to get everything from the library.

Fixes https://github.com/google/protobuf/issues/4301
Fixes https://github.com/google/protobuf/issues/4403
2018-04-02 09:54:29 -04:00
Adam Cozzette
ed4321d1cb
Merge pull request #4387 from acozzette/down-integrate
Integrated internal changes from Google
2018-03-20 16:14:32 -07:00
Adam Cozzette
b1216d95db Updated checked-in generated code 2018-03-14 11:17:06 -07:00
Felix Jendrusch
1da9ffe394 Check return value on write of raw pointer 2018-03-08 16:20:37 +01:00
Felix Jendrusch
38508e9bbb Add test for failing write of raw pointer to output stream 2018-03-08 16:20:05 +01:00
Thomas Van Lenten
07f023188e Fix up the docs to mention the WKTs generated files also.
Fixes #4277
2018-02-07 10:41:21 -05:00
Thomas Van Lenten
cf016a42e6 Work around strange error with atomic and swift under Xcode 8.3.3.
Haven't been able to make a repo case, but this should "fix" the problem
by avoid it completely.

- Move readOnlySemaphore_ into the .m file so it isn't exposed in any
  header.
- Move GPBGetObjectIvarWithField() also to go with the new limited
  visibility on the readOnlySemaphore_.
2018-01-31 16:57:53 -05:00
Thomas Van Lenten
d570d48648 Don't assume c-strings are 4 byte aligned.
The Undefined Behavior sanitizer flags one part of the unittests for this.
For default values for `bytes` we write a length on the front of a c-string
in the static data, apparently the compiler/linker doesn't always make this
4 byte aligned, so it get flagged for undefined/degraded performance. Avoid
this by using memcpy instead.
2018-01-31 15:40:22 -05:00
Thomas Van Lenten
d83837ded5 Fix to use "nil" instead of "NULL" for objc objects. 2018-01-31 14:24:51 -05:00
Thomas Van Lenten
81aeed082e Work around the static analyzer false report. 2018-01-31 14:24:51 -05:00
Thomas Van Lenten
953adb16ff Add casts to removed undefined behaviors around shifts.
Fixes #4246
Fixes #4247
2018-01-31 12:36:54 -05:00
Thomas Van Lenten
3e1587fd4b Add an explicit import of stdatomic.h.
The generated code for enums needs atomics support, so generate the
import instead of relying on it via transitive imports. This will
make future changes to this likely likely to break generated code
and runtime support are mixed.

Followup to https://github.com/google/protobuf/pull/4184.
2018-01-25 12:18:39 -05:00
Thomas Van Lenten
6fd2ae7e45 Bring back import of OSAtomic.
Followup to https://github.com/google/protobuf/pull/4184, keep the
import to not break any existing generated code that isn't regenerated
when they update to the newer protobuf code.
2018-01-25 12:18:39 -05:00
Jonathan Dierksen
a721bf6d29 Migrate away from deprecated OSAtomic APIs. (#4184)
* Migrate away from deprecated OSAtomic APIs.
2018-01-22 16:26:39 -05:00
Thomas Van Lenten
4588e6e2b9 Force a copy when saving the NSData that came from another. 2018-01-03 13:12:29 -05:00
Thomas Van Lenten
156161dfcd Properly copy maps with string keys but pod values.
Add tests to cover all the common special casing in the runtime code to
ensure things come out correctly.
2018-01-03 11:46:03 -05:00
kvukic
8529f2aee3 Resolved issue #3510. Malformed errorr messages replaced with meaningful description 2017-12-29 11:33:47 -05:00
Thomas Van Lenten
860d693cf7 Add Xcode 9.2 to the testing support
Fixes #4060
2017-12-18 10:36:40 -05:00
Feng Xiao
75eceb8424 Update generated code. 2017-12-12 14:57:34 -08:00
Adam Cozzette
0ba8eea655 Merge branch 'master' into down-integrate 2017-12-01 10:05:19 -08:00
Adam Cozzette
92a7e778e7 Integrated internal changes from Google 2017-12-01 10:05:10 -08: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