From aa3c5a882c747a7686fc3dac8f7a5572cc55cdfd Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Wed, 19 Sep 2007 21:12:52 +0000 Subject: [PATCH] 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 --- CONTRIBUTORS | 2 +- .../cpp/src/generate/t_cocoa_generator.cc | 13 ++++++++++-- lib/cocoa/TBinaryProtocol.m | 21 +++++++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 05573749..e6c96820 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -5,7 +5,7 @@ Release 20070917 Dave Engberg -JavaBean/JavaDoc enhancements -Andrew McGeachie +Andrew McGeachie -Cocoa/Objective-C support Ben Maurer diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc index c44d0614..fe28a7a3 100644 --- a/compiler/cpp/src/generate/t_cocoa_generator.cc +++ b/compiler/cpp/src/generate/t_cocoa_generator.cc @@ -928,15 +928,24 @@ void t_cocoa_generator::generate_cocoa_service_client_implementation(ofstream& o const vector& fields = arg_struct->get_members(); vector::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 2d2ca8ea..ba7808c2 100644 --- a/lib/cocoa/TBinaryProtocol.m +++ b/lib/cocoa/TBinaryProtocol.m @@ -24,6 +24,13 @@ int32_t VERSION_MASK = 0xffff0000; } +- (void) dealloc +{ + [mTransport release]; + [super dealloc]; +} + + - (id ) transport { return mTransport; @@ -332,12 +339,18 @@ int32_t VERSION_MASK = 0xffff0000; [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]; + } } -- 2.17.1