Merging latest minor Cocoa changes
Summary: BinaryProtocol handling of null strings, destructor, and contributors email fix. Submitted by Andrew McGeachie
Reviewed By: mcslee
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665278 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 0557374..e6c9682 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -5,7 +5,7 @@
Dave Engberg <engberg@gmail.com>
-JavaBean/JavaDoc enhancements
-Andrew McGeachie <geech@evernote.com>
+Andrew McGeachie <geechorama@gmail.com>
-Cocoa/Objective-C support
Ben Maurer <bmaurer@andrew.cmu.edu>
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index c44d061..fe28a7a 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -928,15 +928,24 @@
const vector<t_field*>& fields = arg_struct->get_members();
vector<t_field*>::const_iterator fld_iter;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
+ string fieldName = (*fld_iter)->get_name();
+ if (type_can_be_null((*fld_iter)->get_type())) {
+ out << indent() << "if (" << fieldName << " != nil)";
+ scope_up(out);
+ }
out <<
- indent() << "[outProtocol writeFieldBeginWithName: @\"" << (*fld_iter)->get_name() << "\""
+ indent() << "[outProtocol writeFieldBeginWithName: @\"" << fieldName << "\""
" type: " << type_to_enum((*fld_iter)->get_type()) <<
" fieldID: " << (*fld_iter)->get_key() << "];" << endl;
- generate_serialize_field(out, *fld_iter, (*fld_iter)->get_name());
+ generate_serialize_field(out, *fld_iter, fieldName);
out <<
indent() << "[outProtocol writeFieldEnd];" << endl;
+
+ if (type_can_be_null((*fld_iter)->get_type())) {
+ scope_down(out);
+ }
}
out <<
diff --git a/lib/cocoa/TBinaryProtocol.m b/lib/cocoa/TBinaryProtocol.m
index 2d2ca8e..ba7808c 100644
--- a/lib/cocoa/TBinaryProtocol.m
+++ b/lib/cocoa/TBinaryProtocol.m
@@ -24,6 +24,13 @@
}
+- (void) dealloc
+{
+ [mTransport release];
+ [super dealloc];
+}
+
+
- (id <TTransport>) transport
{
return mTransport;
@@ -332,12 +339,18 @@
[self writeI64: *((int64_t *) &value)];
}
+
- (void) writeString: (NSString *) value
{
- const char * utf8Bytes = [value UTF8String];
- size_t length = strlen(utf8Bytes);
- [self writeI32: length];
- [mTransport write: (uint8_t *) utf8Bytes offset: 0 length: length];
+ if (value != nil) {
+ const char * utf8Bytes = [value UTF8String];
+ size_t length = strlen(utf8Bytes);
+ [self writeI32: length];
+ [mTransport write: (uint8_t *) utf8Bytes offset: 0 length: length];
+ } else {
+ // instead of crashing when we get null, let's write out a zero length string
+ [self writeI32: 0];
+ }
}