Skip to content

Commit

Permalink
Beta quality drop of Objective C Support.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
thomasvl committed Jun 8, 2015
1 parent 3f9be70 commit d846b0b
Show file tree
Hide file tree
Showing 94 changed files with 6,921 additions and 8,029 deletions.
18 changes: 6 additions & 12 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,10 @@ objectivec_EXTRA_DIST= \
objectivec/GPBDictionary.h \
objectivec/GPBDictionary.m \
objectivec/GPBDictionary_PackagePrivate.h \
objectivec/GPBExtensionField.h \
objectivec/GPBExtensionField.m \
objectivec/GPBExtensionField_PackagePrivate.h \
objectivec/GPBExtensionInternals.h \
objectivec/GPBExtensionInternals.m \
objectivec/GPBExtensionRegistry.h \
objectivec/GPBExtensionRegistry.m \
objectivec/GPBField.h \
objectivec/GPBField.m \
objectivec/GPBField_PackagePrivate.h \
objectivec/GPBMessage.h \
objectivec/GPBMessage.m \
objectivec/GPBMessage_PackagePrivate.h \
Expand All @@ -523,7 +519,10 @@ objectivec_EXTRA_DIST= \
objectivec/GPBRootObject.h \
objectivec/GPBRootObject.m \
objectivec/GPBRootObject_PackagePrivate.h \
objectivec/GPBTypes.h \
objectivec/GPBRuntimeTypes.h \
objectivec/GPBUnknownField.h \
objectivec/GPBUnknownField.m \
objectivec/GPBUnknownField_PackagePrivate.h \
objectivec/GPBUnknownFieldSet.h \
objectivec/GPBUnknownFieldSet.m \
objectivec/GPBUnknownFieldSet_PackagePrivate.h \
Expand All @@ -547,8 +546,6 @@ objectivec_EXTRA_DIST= \
objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \
objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \
objectivec/README.md \
objectivec/Tests/Filter1.txt \
objectivec/Tests/Filter2.txt \
objectivec/Tests/golden_message \
objectivec/Tests/golden_packed_fields_message \
objectivec/Tests/GPBARCUnittestProtos.m \
Expand All @@ -564,7 +561,6 @@ objectivec_EXTRA_DIST= \
objectivec/Tests/GPBDictionaryTests+UInt32.m \
objectivec/Tests/GPBDictionaryTests+UInt64.m \
objectivec/Tests/GPBDictionaryTests.pddm \
objectivec/Tests/GPBFilteredMessageTests.m \
objectivec/Tests/GPBMessageTests+Merge.m \
objectivec/Tests/GPBMessageTests+Runtime.m \
objectivec/Tests/GPBMessageTests+Serialization.m \
Expand Down Expand Up @@ -596,8 +592,6 @@ objectivec_EXTRA_DIST= \
objectivec/Tests/text_format_map_unittest_data.txt \
objectivec/Tests/text_format_unittest_data.txt \
objectivec/Tests/unittest_cycle.proto \
objectivec/Tests/unittest_filter.proto \
objectivec/Tests/unittest_name_mangling.proto \
objectivec/Tests/unittest_objc.proto \
objectivec/Tests/unittest_runtime_proto2.proto \
objectivec/Tests/unittest_runtime_proto3.proto \
Expand Down
113 changes: 113 additions & 0 deletions objectivec/DevTools/compile_testing_protos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

# Invoked by the Xcode projects to build the protos needed for the unittests.

set -eu

readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"

# Helper for bailing.
die() {
echo "Error: $1"
exit 2
}

# What to do.
case "${ACTION}" in
"")
# Build, fall thru
;;
"clean")
rm -rf "${OUTPUT_DIR}"
exit 0
;;
*)
die "Unknown action requested: ${ACTION}"
;;
esac

# Move to the top of the protobuf directories.
cd "${SRCROOT}/.."

[[ -x src/protoc ]] || \
die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."

RUN_PROTOC=no
if [[ ! -d "${OUTPUT_DIR}" ]] ; then
RUN_PROTOC=yes
else
# Find the newest input file (protos, compiler, and this script).
# (these patterns catch some extra stuff, but better to over sample than
# under)
readonly NewestInput=$(find \
src/google/protobuf/*.proto \
objectivec/Tests/*.proto \
src/.libs src/*.la src/protoc \
objectivec/DevTools/compile_testing_protos.sh \
-type f -print0 \
| xargs -0 stat -f "%m %N" \
| sort -n | tail -n1 | cut -f2- -d" ")
# Find the oldest output file.
readonly OldestOutput=$(find \
"${OUTPUT_DIR}" \
-type f -print0 \
| xargs -0 stat -f "%m %N" \
| sort -n -r | tail -n1 | cut -f2- -d" ")
# If the newest input is newer than the oldest output, regenerate.
if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
RUN_PROTOC=yes
fi
fi

if [[ "${RUN_PROTOC}" != "yes" ]] ; then
# Up to date.
exit 0
fi

# Ensure the output dir exists
mkdir -p "${OUTPUT_DIR}/google/protobuf"

CORE_PROTO_FILES=( \
src/google/protobuf/unittest_custom_options.proto \
src/google/protobuf/unittest_enormous_descriptor.proto \
src/google/protobuf/unittest_embed_optimize_for.proto \
src/google/protobuf/unittest_empty.proto \
src/google/protobuf/unittest_import.proto \
src/google/protobuf/unittest_import_lite.proto \
src/google/protobuf/unittest_lite.proto \
src/google/protobuf/unittest_mset.proto \
src/google/protobuf/unittest_no_generic_services.proto \
src/google/protobuf/unittest_optimize_for.proto \
src/google/protobuf/unittest.proto \
src/google/protobuf/unittest_import_public.proto \
src/google/protobuf/unittest_import_public_lite.proto \
src/google/protobuf/unittest_drop_unknown_fields.proto \
src/google/protobuf/unittest_preserve_unknown_enum.proto \
src/google/protobuf/map_lite_unittest.proto \
src/google/protobuf/map_proto2_unittest.proto \
src/google/protobuf/map_unittest.proto \
)

compile_proto() {
src/protoc \
--objc_out="${OUTPUT_DIR}/google/protobuf" \
--proto_path=src/google/protobuf/ \
--proto_path=src \
$*
}

for a_proto in "${CORE_PROTO_FILES[@]}" ; do
compile_proto "${a_proto}"
done

OBJC_PROTO_FILES=( \
objectivec/Tests/unittest_cycle.proto \
objectivec/Tests/unittest_runtime_proto2.proto \
objectivec/Tests/unittest_runtime_proto3.proto \
objectivec/Tests/unittest_objc.proto \
objectivec/Tests/unittest_objc_startup.proto \
)

for a_proto in "${OBJC_PROTO_FILES[@]}" ; do
compile_proto --proto_path="objectivec/Tests" "${a_proto}"
done
2 changes: 1 addition & 1 deletion objectivec/DevTools/full_mac_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ wrapped_make -j "${NUM_MAKE_JOBS}" all
wrapped_make -j "${NUM_MAKE_JOBS}" check

header "Ensuring the ObjC descriptors are current."
# Find the newest input file (protos, compiler, and this script).
# Find the newest input file (protos, compiler, and the generator script).
# (these patterns catch some extra stuff, but better to over sample than under)
readonly NewestInput=$(find \
src/google/protobuf/*.proto \
Expand Down
2 changes: 1 addition & 1 deletion objectivec/GPBArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#import <Foundation/Foundation.h>

#import "GPBTypes.h"
#import "GPBRuntimeTypes.h"

// These classes are used for repeated fields of basic data types. They are used because
// they perform better than boxing into NSNumbers in NSArrays.
Expand Down
2 changes: 1 addition & 1 deletion objectivec/GPBCodedInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
- (int64_t)readSInt64;
- (BOOL)readBool;
- (NSString *)readString;
- (NSData *)readData;
- (NSData *)readBytes;

// Read an embedded message field value from the stream.
- (void)readMessage:(GPBMessage *)message
Expand Down
26 changes: 13 additions & 13 deletions objectivec/GPBCodedInputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

static const NSUInteger kDefaultRecursionLimit = 64;

static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
size_t newSize = state->bufferPos + size;
if (newSize > state->bufferSize) {
[NSException raise:NSParseErrorException format:@""];
Expand All @@ -50,26 +50,26 @@ static inline void CheckSize(GPBCodedInputStreamState *state, size_t size) {
}
}

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

static inline int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int32_t));
int32_t value = OSReadLittleInt32(state->bytes, state->bufferPos);
state->bufferPos += sizeof(int32_t);
return value;
}

static inline int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int64_t));
int64_t value = OSReadLittleInt64(state->bytes, state->bufferPos);
state->bufferPos += sizeof(int64_t);
return value;
}

static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
static int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
int8_t tmp = ReadRawByte(state);
if (tmp >= 0) {
return tmp;
Expand Down Expand Up @@ -104,7 +104,7 @@ static inline int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
return result;
}

static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
int32_t shift = 0;
int64_t result = 0;
while (shift < 64) {
Expand All @@ -119,7 +119,7 @@ static inline int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
return 0;
}

static inline void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
CheckSize(state, size);
state->bufferPos += size;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
return result;
}

NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
CheckSize(state, size);
Expand All @@ -232,7 +232,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
return result;
}

NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
Expand Down Expand Up @@ -453,8 +453,8 @@ - (void)readMapEntry:(id)mapDictionary
GPBCodedInputStreamPopLimit(&state_, oldLimit);
}

- (NSData *)readData {
return [GPBCodedInputStreamReadRetainedData(&state_) autorelease];
- (NSData *)readBytes {
return [GPBCodedInputStreamReadRetainedBytes(&state_) autorelease];
}

- (uint32_t)readUInt32 {
Expand Down Expand Up @@ -499,7 +499,7 @@ @implementation GPBString {

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

static inline void GPBStringInitStringValue(GPBString *string) {
static void GPBStringInitStringValue(GPBString *string) {
OSSpinLockLock(&string->lock_);
GPBStringInitStringValueAlreadyLocked(string);
OSSpinLockUnlock(&string->lock_);
Expand Down
4 changes: 2 additions & 2 deletions objectivec/GPBCodedInputStream_PackagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
__attribute((ns_returns_retained));
NSData *GPBCodedInputStreamReadRetainedData(GPBCodedInputStreamState *state)
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
__attribute((ns_returns_retained));
NSData *GPBCodedInputStreamReadRetainedDataNoCopy(
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
GPBCodedInputStreamState *state) __attribute((ns_returns_retained));

size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
Expand Down
Loading

0 comments on commit d846b0b

Please sign in to comment.