Commit 50a765ba authored by Bo Yang's avatar Bo Yang

Fix bugs in objective-c.

parent ad0a5cab
......@@ -87,9 +87,12 @@ vsprojects/Release
# Directories created by opening the Objective C Xcode projects.
objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcuserdata/
objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/ProtocolBuffers_OSX.xccheckout
objectivec/ProtocolBuffers_OSX.xcodeproj/xcuserdata/
objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcuserdata/
objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/ProtocolBuffers_iOS.xccheckout
objectivec/ProtocolBuffers_iOS.xcodeproj/xcuserdata/
objectivec/**/.DS_Store
# Comformance test output
conformance/.libs/
......
......@@ -213,15 +213,31 @@ javanano_EXTRA_DIST=
objectivec_EXTRA_DIST= \
objectivec/DevTools/check_version_stamps.sh \
objectivec/DevTools/full_mac_build.sh \
objectivec/DevTools/pddm.py \
objectivec/DevTools/pddm_tests.py \
objectivec/generate_descriptors_proto.sh \
objectivec/google/protobuf/Descriptor.pbobjc.h \
objectivec/google/protobuf/Descriptor.pbobjc.m \
objectivec/google/protobuf/Duration.pbobjc.h \
objectivec/google/protobuf/Duration.pbobjc.m \
objectivec/google/protobuf/Timestamp.pbobjc.h \
objectivec/google/protobuf/Timestamp.pbobjc.m \
objectivec//google/protobuf/Any.pbobjc.h \
objectivec//google/protobuf/Any.pbobjc.m \
objectivec//google/protobuf/Api.pbobjc.h \
objectivec//google/protobuf/Api.pbobjc.m \
objectivec//google/protobuf/Descriptor.pbobjc.h \
objectivec//google/protobuf/Descriptor.pbobjc.m \
objectivec//google/protobuf/Duration.pbobjc.h \
objectivec//google/protobuf/Duration.pbobjc.m \
objectivec//google/protobuf/Empty.pbobjc.h \
objectivec//google/protobuf/Empty.pbobjc.m \
objectivec//google/protobuf/FieldMask.pbobjc.h \
objectivec//google/protobuf/FieldMask.pbobjc.m \
objectivec//google/protobuf/SourceContext.pbobjc.h \
objectivec//google/protobuf/SourceContext.pbobjc.m \
objectivec//google/protobuf/Struct.pbobjc.h \
objectivec//google/protobuf/Struct.pbobjc.m \
objectivec//google/protobuf/Timestamp.pbobjc.h \
objectivec//google/protobuf/Timestamp.pbobjc.m \
objectivec//google/protobuf/Type.pbobjc.h \
objectivec//google/protobuf/Type.pbobjc.m \
objectivec//google/protobuf/Wrappers.pbobjc.h \
objectivec//google/protobuf/Wrappers.pbobjc.m \
objectivec/GPBArray.h \
objectivec/GPBArray.m \
objectivec/GPBArray_PackagePrivate.h \
......@@ -277,6 +293,7 @@ objectivec_EXTRA_DIST= \
objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \
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 \
......@@ -311,15 +328,15 @@ objectivec_EXTRA_DIST= \
objectivec/Tests/GPBWireFormatTests.m \
objectivec/Tests/iOSTestHarness/AppDelegate.m \
objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7@3x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7@2x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7@3x.png \
objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json \
objectivec/Tests/iOSTestHarness/Info.plist \
objectivec/Tests/iOSTestHarness/LaunchScreen.xib \
......
......@@ -725,7 +725,7 @@
INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = UnitTests;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
......@@ -742,7 +742,7 @@
INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_NAME = UnitTests;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
};
name = Release;
};
......
......@@ -875,7 +875,7 @@
"\"$(DEVELOPER_DIR)/usr/lib\"",
);
PRODUCT_NAME = UnitTests;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
......@@ -903,7 +903,7 @@
"\"$(DEVELOPER_DIR)/usr/lib\"",
);
PRODUCT_NAME = UnitTests;
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/Tests/UnitTests-Bridging-Header.h";
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
};
......
......@@ -177,6 +177,13 @@ static NSData *DataFromCStr(const char *str) {
XCTAssertEqual([field.varintList valueAtIndex:0],
(uint64_t)Message3_Enum_Extra3);
// TODO(teboring): This test could fail without explicitly marking the repeated_enum in Message3
// to be unpacked. This is becaucse proto3 repeated primitive field is packed by default. However,
// the proto2 primitive repeated field is still unpacked by default. Previously, parsing of the
// repeated_enum field would fail. To fix it:
// 1) Objective-C implementation of parsing should be able to parse packed field for unpacked
// field and vice versa.
// 2) repeated_packed_enum in Message3 should be removed, because it's unnecessary now.
field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray];
XCTAssertEqual(field.varintList.count, 1U);
XCTAssertEqual([field.varintList valueAtIndex:0],
......
......@@ -75,7 +75,10 @@ message Message3 {
repeated bytes repeated_bytes = 45;
// No 'group' in proto3.
repeated Message3 repeated_message = 48;
repeated Enum repeated_enum = 49;
// TODO(teboring): In proto3, repeated primitive field is packed by default.
// testProto2UnknownEnumToUnknownField needs repeated_enum to be unpacked.
// Remove this option when testProto2UnknownEnumToUnknownField.
repeated Enum repeated_enum = 49 [packed=false];
repeated Enum repeated_packed_enum = 50 [packed=true];
oneof o {
......
......@@ -111,6 +111,23 @@ GPBEnumDescriptor *GPBFieldOptions_CType_EnumDescriptor(void);
BOOL GPBFieldOptions_CType_IsValidValue(int32_t value);
#pragma mark - Enum GPBFieldOptions_JSType
typedef GPB_ENUM(GPBFieldOptions_JSType) {
// Use the default type.
GPBFieldOptions_JSType_JsNormal = 0,
// Use JavaScript strings.
GPBFieldOptions_JSType_JsString = 1,
// Use JavaScript numbers.
GPBFieldOptions_JSType_JsNumber = 2,
};
GPBEnumDescriptor *GPBFieldOptions_JSType_EnumDescriptor(void);
BOOL GPBFieldOptions_JSType_IsValidValue(int32_t value);
#pragma mark - GPBDescriptorRoot
......@@ -218,6 +235,8 @@ typedef GPB_ENUM(GPBDescriptorProto_FieldNumber) {
GPBDescriptorProto_FieldNumber_ExtensionArray = 6,
GPBDescriptorProto_FieldNumber_Options = 7,
GPBDescriptorProto_FieldNumber_OneofDeclArray = 8,
GPBDescriptorProto_FieldNumber_ReservedRangeArray = 9,
GPBDescriptorProto_FieldNumber_ReservedNameArray = 10,
};
// Describes a message type.
......@@ -247,6 +266,14 @@ typedef GPB_ENUM(GPBDescriptorProto_FieldNumber) {
@property(nonatomic, readwrite) BOOL hasOptions;
@property(nonatomic, readwrite, strong) GPBMessageOptions *options;
// |reservedRangeArray| contains |GPBDescriptorProto_ReservedRange|
@property(nonatomic, readwrite, strong) NSMutableArray *reservedRangeArray;
// Reserved field names, which may not be used by fields in the same message.
// A given name may only be reserved once.
// |reservedNameArray| contains |NSString|
@property(nonatomic, readwrite, strong) NSMutableArray *reservedNameArray;
@end
#pragma mark - GPBDescriptorProto_ExtensionRange
......@@ -266,6 +293,28 @@ typedef GPB_ENUM(GPBDescriptorProto_ExtensionRange_FieldNumber) {
@end
#pragma mark - GPBDescriptorProto_ReservedRange
typedef GPB_ENUM(GPBDescriptorProto_ReservedRange_FieldNumber) {
GPBDescriptorProto_ReservedRange_FieldNumber_Start = 1,
GPBDescriptorProto_ReservedRange_FieldNumber_End = 2,
};
// Range of reserved tag numbers. Reserved tag numbers may not be used by
// fields or extension ranges in the same message. Reserved ranges may
// not overlap.
@interface GPBDescriptorProto_ReservedRange : GPBMessage
// Inclusive.
@property(nonatomic, readwrite) BOOL hasStart;
@property(nonatomic, readwrite) int32_t start;
// Exclusive.
@property(nonatomic, readwrite) BOOL hasEnd;
@property(nonatomic, readwrite) int32_t end;
@end
#pragma mark - GPBFieldDescriptorProto
typedef GPB_ENUM(GPBFieldDescriptorProto_FieldNumber) {
......@@ -654,6 +703,7 @@ typedef GPB_ENUM(GPBFieldOptions_FieldNumber) {
GPBFieldOptions_FieldNumber_Packed = 2,
GPBFieldOptions_FieldNumber_Deprecated = 3,
GPBFieldOptions_FieldNumber_Lazy = 5,
GPBFieldOptions_FieldNumber_Jstype = 6,
GPBFieldOptions_FieldNumber_Weak = 10,
GPBFieldOptions_FieldNumber_UninterpretedOptionArray = 999,
};
......@@ -670,10 +720,23 @@ typedef GPB_ENUM(GPBFieldOptions_FieldNumber) {
// The packed option can be enabled for repeated primitive fields to enable
// a more efficient representation on the wire. Rather than repeatedly
// writing the tag and type for each element, the entire array is encoded as
// a single length-delimited blob.
// a single length-delimited blob. In proto3, only explicit setting it to
// false will avoid using packed encoding.
@property(nonatomic, readwrite) BOOL hasPacked;
@property(nonatomic, readwrite) BOOL packed;
// The jstype option determines the JavaScript type used for values of the
// field. The option is permitted only for 64 bit integral and fixed types
// (int64, uint64, sint64, fixed64, sfixed64). By default these types are
// represented as JavaScript strings. This avoids loss of precision that can
// happen when a large value is converted to a floating point JavaScript
// numbers. Specifying JS_NUMBER for the jstype causes the generated
// JavaScript code to use the JavaScript "number" type instead of strings.
// This option is an enum to permit additional types to be added,
// e.g. goog.math.Integer.
@property(nonatomic, readwrite) BOOL hasJstype;
@property(nonatomic, readwrite) GPBFieldOptions_JSType jstype;
// Should this field be parsed lazily? Lazy applies only to message-type
// fields. It means that when the outer message is initially parsed, the
// inner message's contents will not be parsed but instead stored in encoded
......
......@@ -273,6 +273,8 @@ typedef struct GPBFileDescriptorProto_Storage {
@dynamic extensionRangeArray;
@dynamic oneofDeclArray;
@dynamic hasOptions, options;
@dynamic reservedRangeArray;
@dynamic reservedNameArray;
typedef struct GPBDescriptorProto_Storage {
uint32_t _has_storage_[1];
......@@ -284,6 +286,8 @@ typedef struct GPBDescriptorProto_Storage {
NSMutableArray *extensionArray;
GPBMessageOptions *options;
NSMutableArray *oneofDeclArray;
NSMutableArray *reservedRangeArray;
NSMutableArray *reservedNameArray;
} GPBDescriptorProto_Storage;
// This method is threadsafe because it is initially called
......@@ -380,6 +384,28 @@ typedef struct GPBDescriptorProto_Storage {
.typeSpecific.className = GPBStringifySymbol(GPBOneofDescriptorProto),
.fieldOptions = NULL,
},
{
.name = "reservedRangeArray",
.number = GPBDescriptorProto_FieldNumber_ReservedRangeArray,
.hasIndex = GPBNoHasBit,
.flags = GPBFieldRepeated,
.type = GPBTypeMessage,
.offset = offsetof(GPBDescriptorProto_Storage, reservedRangeArray),
.defaultValue.valueMessage = nil,
.typeSpecific.className = GPBStringifySymbol(GPBDescriptorProto_ReservedRange),
.fieldOptions = NULL,
},
{
.name = "reservedNameArray",
.number = GPBDescriptorProto_FieldNumber_ReservedNameArray,
.hasIndex = GPBNoHasBit,
.flags = GPBFieldRepeated,
.type = GPBTypeString,
.offset = offsetof(GPBDescriptorProto_Storage, reservedNameArray),
.defaultValue.valueMessage = nil,
.typeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
descriptor = [GPBDescriptor allocDescriptorForClass:[GPBDescriptorProto class]
rootClass:[GPBDescriptorRoot class]
......@@ -461,6 +487,67 @@ typedef struct GPBDescriptorProto_ExtensionRange_Storage {
@end
#pragma mark - GPBDescriptorProto_ReservedRange
@implementation GPBDescriptorProto_ReservedRange
@dynamic hasStart, start;
@dynamic hasEnd, end;
typedef struct GPBDescriptorProto_ReservedRange_Storage {
uint32_t _has_storage_[1];
int32_t start;
int32_t end;
} GPBDescriptorProto_ReservedRange_Storage;
// This method is threadsafe because it is initially called
// in +initialize for each subclass.
+ (GPBDescriptor *)descriptor {
static GPBDescriptor *descriptor = NULL;
if (!descriptor) {
static GPBMessageFieldDescription fields[] = {
{
.name = "start",
.number = GPBDescriptorProto_ReservedRange_FieldNumber_Start,
.hasIndex = 0,
.flags = GPBFieldOptional,
.type = GPBTypeInt32,
.offset = offsetof(GPBDescriptorProto_ReservedRange_Storage, start),
.defaultValue.valueInt32 = 0,
.typeSpecific.className = NULL,
.fieldOptions = NULL,
},
{
.name = "end",
.number = GPBDescriptorProto_ReservedRange_FieldNumber_End,
.hasIndex = 1,
.flags = GPBFieldOptional,
.type = GPBTypeInt32,
.offset = offsetof(GPBDescriptorProto_ReservedRange_Storage, end),
.defaultValue.valueInt32 = 0,
.typeSpecific.className = NULL,
.fieldOptions = NULL,
},
};
descriptor = [GPBDescriptor allocDescriptorForClass:[GPBDescriptorProto_ReservedRange class]
rootClass:[GPBDescriptorRoot class]
file:GPBDescriptorRoot_FileDescriptor()
fields:fields
fieldCount:sizeof(fields) / sizeof(GPBMessageFieldDescription)
oneofs:NULL
oneofCount:0
enums:NULL
enumCount:0
ranges:NULL
rangeCount:0
storageSize:sizeof(GPBDescriptorProto_ReservedRange_Storage)
wireFormat:NO];
}
return descriptor;
}
@end
#pragma mark - GPBFieldDescriptorProto
@implementation GPBFieldDescriptorProto
......@@ -1462,6 +1549,7 @@ typedef struct GPBMessageOptions_Storage {
@dynamic hasCtype, ctype;
@dynamic hasPacked, packed;
@dynamic hasJstype, jstype;
@dynamic hasLazy, lazy;
@dynamic hasDeprecated, deprecated;
@dynamic hasWeak, weak;
......@@ -1474,6 +1562,7 @@ typedef struct GPBFieldOptions_Storage {
BOOL lazy;
BOOL weak;
GPBFieldOptions_CType ctype;
GPBFieldOptions_JSType jstype;
NSMutableArray *uninterpretedOptionArray;
} GPBFieldOptions_Storage;
......@@ -1508,7 +1597,7 @@ typedef struct GPBFieldOptions_Storage {
{
.name = "deprecated",
.number = GPBFieldOptions_FieldNumber_Deprecated,
.hasIndex = 3,
.hasIndex = 4,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, deprecated),
......@@ -1519,7 +1608,7 @@ typedef struct GPBFieldOptions_Storage {
{
.name = "lazy",
.number = GPBFieldOptions_FieldNumber_Lazy,
.hasIndex = 2,
.hasIndex = 3,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, lazy),
......@@ -1527,10 +1616,21 @@ typedef struct GPBFieldOptions_Storage {
.typeSpecific.className = NULL,
.fieldOptions = NULL,
},
{
.name = "jstype",
.number = GPBFieldOptions_FieldNumber_Jstype,
.hasIndex = 2,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue | GPBFieldHasEnumDescriptor,
.type = GPBTypeEnum,
.offset = offsetof(GPBFieldOptions_Storage, jstype),
.defaultValue.valueEnum = GPBFieldOptions_JSType_JsNormal,
.typeSpecific.enumDescFunc = GPBFieldOptions_JSType_EnumDescriptor,
.fieldOptions = NULL,
},
{
.name = "weak",
.number = GPBFieldOptions_FieldNumber_Weak,
.hasIndex = 4,
.hasIndex = 5,
.flags = GPBFieldOptional | GPBFieldHasDefaultValue,
.type = GPBTypeBool,
.offset = offsetof(GPBFieldOptions_Storage, weak),
......@@ -1552,6 +1652,7 @@ typedef struct GPBFieldOptions_Storage {
};
static GPBMessageEnumDescription enums[] = {
{ .enumDescriptorFunc = GPBFieldOptions_CType_EnumDescriptor },
{ .enumDescriptorFunc = GPBFieldOptions_JSType_EnumDescriptor },
};
static GPBExtensionRange ranges[] = {
{ .start = 1000, .end = 536870912 },
......@@ -1604,6 +1705,35 @@ BOOL GPBFieldOptions_CType_IsValidValue(int32_t value__) {
}
}
#pragma mark - Enum GPBFieldOptions_JSType
GPBEnumDescriptor *GPBFieldOptions_JSType_EnumDescriptor(void) {
static GPBEnumDescriptor *descriptor = NULL;
if (!descriptor) {
static GPBMessageEnumValueDescription values[] = {
{ .name = "JsNormal", .number = GPBFieldOptions_JSType_JsNormal },
{ .name = "JsString", .number = GPBFieldOptions_JSType_JsString },
{ .name = "JsNumber", .number = GPBFieldOptions_JSType_JsNumber },
};
descriptor = [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBFieldOptions_JSType)
values:values
valueCount:sizeof(values) / sizeof(GPBMessageEnumValueDescription)
enumVerifier:GPBFieldOptions_JSType_IsValidValue];
}
return descriptor;
}
BOOL GPBFieldOptions_JSType_IsValidValue(int32_t value__) {
switch (value__) {
case GPBFieldOptions_JSType_JsNormal:
case GPBFieldOptions_JSType_JsString:
case GPBFieldOptions_JSType_JsNumber:
return YES;
default:
return NO;
}
}
#pragma mark - GPBEnumOptions
@implementation GPBEnumOptions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment