diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2018-10-02 10:42:55 -0400 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2018-10-02 13:45:18 -0400 |
commit | 09c001e999660401162b592ef16c59b2036339f1 (patch) | |
tree | b98b83e01a01a8892e33a1b938e42d3623d3aa0c /objectivec/GPBMessage.m | |
parent | 97d03abb851dfb0f3df4a706987e06c74fed2d70 (diff) | |
download | protobuf-09c001e999660401162b592ef16c59b2036339f1.tar.gz protobuf-09c001e999660401162b592ef16c59b2036339f1.tar.bz2 protobuf-09c001e999660401162b592ef16c59b2036339f1.zip |
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.
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r-- | objectivec/GPBMessage.m | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m index c51dfb25..c8664117 100644 --- a/objectivec/GPBMessage.m +++ b/objectivec/GPBMessage.m @@ -3084,6 +3084,14 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, result->encodingSelector = @selector(set##NAME:); \ break; \ } +#define CASE_SET_COPY(NAME) \ + case GPBDataType##NAME: { \ + result->impToAdd = imp_implementationWithBlock(^(id obj, id value) { \ + return GPBSetRetainedObjectIvarWithFieldInternal(obj, field, [value copy], syntax); \ + }); \ + result->encodingSelector = @selector(set##NAME:); \ + break; \ + } CASE_SET(Bool, BOOL, Bool) CASE_SET(Fixed32, uint32_t, UInt32) CASE_SET(SFixed32, int32_t, Int32) @@ -3097,8 +3105,8 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, CASE_SET(SInt64, int64_t, Int64) CASE_SET(UInt32, uint32_t, UInt32) CASE_SET(UInt64, uint64_t, UInt64) - CASE_SET(Bytes, id, Object) - CASE_SET(String, id, Object) + CASE_SET_COPY(Bytes) + CASE_SET_COPY(String) CASE_SET(Message, id, Object) CASE_SET(Group, id, Object) CASE_SET(Enum, int32_t, Enum) |