Skip to content

Commit d846b0b

Browse files
committed
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.
1 parent 3f9be70 commit d846b0b

File tree

94 files changed

+6921
-8029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+6921
-8029
lines changed

Makefile.am

+6-12
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,10 @@ objectivec_EXTRA_DIST= \
506506
objectivec/GPBDictionary.h \
507507
objectivec/GPBDictionary.m \
508508
objectivec/GPBDictionary_PackagePrivate.h \
509-
objectivec/GPBExtensionField.h \
510-
objectivec/GPBExtensionField.m \
511-
objectivec/GPBExtensionField_PackagePrivate.h \
509+
objectivec/GPBExtensionInternals.h \
510+
objectivec/GPBExtensionInternals.m \
512511
objectivec/GPBExtensionRegistry.h \
513512
objectivec/GPBExtensionRegistry.m \
514-
objectivec/GPBField.h \
515-
objectivec/GPBField.m \
516-
objectivec/GPBField_PackagePrivate.h \
517513
objectivec/GPBMessage.h \
518514
objectivec/GPBMessage.m \
519515
objectivec/GPBMessage_PackagePrivate.h \
@@ -523,7 +519,10 @@ objectivec_EXTRA_DIST= \
523519
objectivec/GPBRootObject.h \
524520
objectivec/GPBRootObject.m \
525521
objectivec/GPBRootObject_PackagePrivate.h \
526-
objectivec/GPBTypes.h \
522+
objectivec/GPBRuntimeTypes.h \
523+
objectivec/GPBUnknownField.h \
524+
objectivec/GPBUnknownField.m \
525+
objectivec/GPBUnknownField_PackagePrivate.h \
527526
objectivec/GPBUnknownFieldSet.h \
528527
objectivec/GPBUnknownFieldSet.m \
529528
objectivec/GPBUnknownFieldSet_PackagePrivate.h \
@@ -547,8 +546,6 @@ objectivec_EXTRA_DIST= \
547546
objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \
548547
objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \
549548
objectivec/README.md \
550-
objectivec/Tests/Filter1.txt \
551-
objectivec/Tests/Filter2.txt \
552549
objectivec/Tests/golden_message \
553550
objectivec/Tests/golden_packed_fields_message \
554551
objectivec/Tests/GPBARCUnittestProtos.m \
@@ -564,7 +561,6 @@ objectivec_EXTRA_DIST= \
564561
objectivec/Tests/GPBDictionaryTests+UInt32.m \
565562
objectivec/Tests/GPBDictionaryTests+UInt64.m \
566563
objectivec/Tests/GPBDictionaryTests.pddm \
567-
objectivec/Tests/GPBFilteredMessageTests.m \
568564
objectivec/Tests/GPBMessageTests+Merge.m \
569565
objectivec/Tests/GPBMessageTests+Runtime.m \
570566
objectivec/Tests/GPBMessageTests+Serialization.m \
@@ -596,8 +592,6 @@ objectivec_EXTRA_DIST= \
596592
objectivec/Tests/text_format_map_unittest_data.txt \
597593
objectivec/Tests/text_format_unittest_data.txt \
598594
objectivec/Tests/unittest_cycle.proto \
599-
objectivec/Tests/unittest_filter.proto \
600-
objectivec/Tests/unittest_name_mangling.proto \
601595
objectivec/Tests/unittest_objc.proto \
602596
objectivec/Tests/unittest_runtime_proto2.proto \
603597
objectivec/Tests/unittest_runtime_proto3.proto \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
# Invoked by the Xcode projects to build the protos needed for the unittests.
4+
5+
set -eu
6+
7+
readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
8+
9+
# Helper for bailing.
10+
die() {
11+
echo "Error: $1"
12+
exit 2
13+
}
14+
15+
# What to do.
16+
case "${ACTION}" in
17+
"")
18+
# Build, fall thru
19+
;;
20+
"clean")
21+
rm -rf "${OUTPUT_DIR}"
22+
exit 0
23+
;;
24+
*)
25+
die "Unknown action requested: ${ACTION}"
26+
;;
27+
esac
28+
29+
# Move to the top of the protobuf directories.
30+
cd "${SRCROOT}/.."
31+
32+
[[ -x src/protoc ]] || \
33+
die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
34+
35+
RUN_PROTOC=no
36+
if [[ ! -d "${OUTPUT_DIR}" ]] ; then
37+
RUN_PROTOC=yes
38+
else
39+
# Find the newest input file (protos, compiler, and this script).
40+
# (these patterns catch some extra stuff, but better to over sample than
41+
# under)
42+
readonly NewestInput=$(find \
43+
src/google/protobuf/*.proto \
44+
objectivec/Tests/*.proto \
45+
src/.libs src/*.la src/protoc \
46+
objectivec/DevTools/compile_testing_protos.sh \
47+
-type f -print0 \
48+
| xargs -0 stat -f "%m %N" \
49+
| sort -n | tail -n1 | cut -f2- -d" ")
50+
# Find the oldest output file.
51+
readonly OldestOutput=$(find \
52+
"${OUTPUT_DIR}" \
53+
-type f -print0 \
54+
| xargs -0 stat -f "%m %N" \
55+
| sort -n -r | tail -n1 | cut -f2- -d" ")
56+
# If the newest input is newer than the oldest output, regenerate.
57+
if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
58+
RUN_PROTOC=yes
59+
fi
60+
fi
61+
62+
if [[ "${RUN_PROTOC}" != "yes" ]] ; then
63+
# Up to date.
64+
exit 0
65+
fi
66+
67+
# Ensure the output dir exists
68+
mkdir -p "${OUTPUT_DIR}/google/protobuf"
69+
70+
CORE_PROTO_FILES=( \
71+
src/google/protobuf/unittest_custom_options.proto \
72+
src/google/protobuf/unittest_enormous_descriptor.proto \
73+
src/google/protobuf/unittest_embed_optimize_for.proto \
74+
src/google/protobuf/unittest_empty.proto \
75+
src/google/protobuf/unittest_import.proto \
76+
src/google/protobuf/unittest_import_lite.proto \
77+
src/google/protobuf/unittest_lite.proto \
78+
src/google/protobuf/unittest_mset.proto \
79+
src/google/protobuf/unittest_no_generic_services.proto \
80+
src/google/protobuf/unittest_optimize_for.proto \
81+
src/google/protobuf/unittest.proto \
82+
src/google/protobuf/unittest_import_public.proto \
83+
src/google/protobuf/unittest_import_public_lite.proto \
84+
src/google/protobuf/unittest_drop_unknown_fields.proto \
85+
src/google/protobuf/unittest_preserve_unknown_enum.proto \
86+
src/google/protobuf/map_lite_unittest.proto \
87+
src/google/protobuf/map_proto2_unittest.proto \
88+
src/google/protobuf/map_unittest.proto \
89+
)
90+
91+
compile_proto() {
92+
src/protoc \
93+
--objc_out="${OUTPUT_DIR}/google/protobuf" \
94+
--proto_path=src/google/protobuf/ \
95+
--proto_path=src \
96+
$*
97+
}
98+
99+
for a_proto in "${CORE_PROTO_FILES[@]}" ; do
100+
compile_proto "${a_proto}"
101+
done
102+
103+
OBJC_PROTO_FILES=( \
104+
objectivec/Tests/unittest_cycle.proto \
105+
objectivec/Tests/unittest_runtime_proto2.proto \
106+
objectivec/Tests/unittest_runtime_proto3.proto \
107+
objectivec/Tests/unittest_objc.proto \
108+
objectivec/Tests/unittest_objc_startup.proto \
109+
)
110+
111+
for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
112+
compile_proto --proto_path="objectivec/Tests" "${a_proto}"
113+
done

objectivec/DevTools/full_mac_build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ wrapped_make -j "${NUM_MAKE_JOBS}" all
162162
wrapped_make -j "${NUM_MAKE_JOBS}" check
163163

164164
header "Ensuring the ObjC descriptors are current."
165-
# Find the newest input file (protos, compiler, and this script).
165+
# Find the newest input file (protos, compiler, and the generator script).
166166
# (these patterns catch some extra stuff, but better to over sample than under)
167167
readonly NewestInput=$(find \
168168
src/google/protobuf/*.proto \

objectivec/GPBArray.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#import <Foundation/Foundation.h>
3232

33-
#import "GPBTypes.h"
33+
#import "GPBRuntimeTypes.h"
3434

3535
// These classes are used for repeated fields of basic data types. They are used because
3636
// they perform better than boxing into NSNumbers in NSArrays.

objectivec/GPBCodedInputStream.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
- (int64_t)readSInt64;
6161
- (BOOL)readBool;
6262
- (NSString *)readString;
63-
- (NSData *)readData;
63+
- (NSData *)readBytes;
6464

6565
// Read an embedded message field value from the stream.
6666
- (void)readMessage:(GPBMessage *)message

objectivec/GPBCodedInputStream.m

+13-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
static const NSUInteger kDefaultRecursionLimit = 64;
4040

41-
static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
41+
static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
4242
size_t newSize = state->bufferPos + size;
4343
if (newSize > state->bufferSize) {
4444
[NSException raise:NSParseErrorException format:@""];
@@ -50,26 +50,26 @@ static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
5050
}
5151
}
5252

53-
static inline int8_t ReadRawByte(GPBCodedInputStreamState *state) {
53+
static int8_t ReadRawByte(GPBCodedInputStreamState *state) {
5454
CheckSize(state, sizeof(int8_t));
5555
return ((int8_t *)state->bytes)[state->bufferPos++];
5656
}
5757

58-
static inline int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
58+
static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
5959
CheckSize(state, sizeof(int32_t));
6060
int32_t value = OSReadLittleInt32(state->bytes, state->bufferPos);
6161
state->bufferPos += sizeof(int32_t);
6262
return value;
6363
}
6464

65-
static inline int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
65+
static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
6666
CheckSize(state, sizeof(int64_t));
6767
int64_t value = OSReadLittleInt64(state->bytes, state->bufferPos);
6868
state->bufferPos += sizeof(int64_t);
6969
return value;
7070
}
7171

72-
static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
72+
static int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
7373
int8_t tmp = ReadRawByte(state);
7474
if (tmp >= 0) {
7575
return tmp;
@@ -104,7 +104,7 @@ static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
104104
return result;
105105
}
106106

107-
static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
107+
static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
108108
int32_t shift = 0;
109109
int64_t result = 0;
110110
while (shift < 64) {
@@ -119,7 +119,7 @@ static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
119119
return 0;
120120
}
121121

122-
static inline void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
122+
static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
123123
CheckSize(state, size);
124124
state->bufferPos += size;
125125
}
@@ -222,7 +222,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
222222
return result;
223223
}
224224

225-
NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state) {
225+
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
226226
int32_t size = ReadRawVarint32(state);
227227
if (size < 0) return nil;
228228
CheckSize(state, size);
@@ -232,7 +232,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
232232
return result;
233233
}
234234

235-
NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
235+
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
236236
GPBCodedInputStreamState *state) {
237237
int32_t size = ReadRawVarint32(state);
238238
if (size < 0) return nil;
@@ -453,8 +453,8 @@ - (void)readMapEntry:(id)mapDictionary
453453
GPBCodedInputStreamPopLimit(&state_, oldLimit);
454454
}
455455

456-
- (NSData *)readData {
457-
return [GPBCodedInputStreamReadRetainedData(&state_) autorelease];
456+
- (NSData *)readBytes {
457+
return [GPBCodedInputStreamReadRetainedBytes(&state_) autorelease];
458458
}
459459

460460
- (uint32_t)readUInt32 {
@@ -499,7 +499,7 @@ @implementation GPBString {
499499

500500
// Returns true if the passed in bytes are 7 bit ascii.
501501
// This routine needs to be fast.
502-
static inline bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
502+
static bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
503503
// In the loops below, it's more efficient to collect rather than do
504504
// conditional at every step.
505505
#if __LP64__
@@ -587,7 +587,7 @@ static inline bool AreBytesIn7BitASCII(const uint8_t *bytes, NSUInteger len) {
587587
return true;
588588
}
589589

590-
static inline void GPBStringInitStringValue(GPBString *string) {
590+
static void GPBStringInitStringValue(GPBString *string) {
591591
OSSpinLockLock(&string->lock_);
592592
GPBStringInitStringValueAlreadyLocked(string);
593593
OSSpinLockUnlock(&string->lock_);

objectivec/GPBCodedInputStream_PackagePrivate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
114114
BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
115115
NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
116116
__attribute((ns_returns_retained));
117-
NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state)
117+
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
118118
__attribute((ns_returns_retained));
119-
NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
119+
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
120120
GPBCodedInputStreamState *state) __attribute((ns_returns_retained));
121121

122122
size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,

0 commit comments

Comments
 (0)