[ 
https://issues.apache.org/jira/browse/THRIFT-1340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13150936#comment-13150936
 ] 

HIRANO Satoshi commented on THRIFT-1340:
----------------------------------------

I'd like to give some explanation about the ARC patch for iOS and MacOS.

On 2011/11/14, at 14:36, HIRANO Satoshi wrote:
>- Works for iOS and MacOS.
>- The runtime and generated code are compatible with both ARC compilation 
>  mode and non-ARC compilation mode.

There is no compiler option for switching ARC and Non-ARC. It's fully automatic.

You must use retain_stub/release_stub instead of retain/release when you alter 
the runtime.
TObjective-C.h includes magic macros like this;

  #if __has_feature(objc_arc)
  #define retain_stub self
  #define release_stub self
  #else
  #define retain_stub retain
  #define release_stub release
  #endif

o = [obj retain_stub]     is replaced with 
o = [obj self]         in case of ARC compilation.

[obj release_stub] is replace with [obj self]. It takes a little bit time but 
not harmful.

> - Initialization of struct/exception/map/list/set with defalut values is
> implemented.

The Cocoa (Objective-C) generator ignored default values in 
struct/map/list/set. I found the generated code did not include default 
initializer. For example, "nobody" is not set when you create a Person object 
even if you write like this;

  struct Person {
       1: string name = "nobody",
       2: i32 age
  }

I added some code to generate the default initializer like this. It should 
handle any nested combination of struct/exception/map/list/set.

  - (id) init {
      self = [super init];
      [self setName:@"nobody"];
      return self;
  }

> - Now it generates much better code for initializing constants. The current 
> thrift compiler generates buggy code.

The current compiler can compile this example, because generated code has 
initWithName:age:.

   const Person stationMaster = {'name' : "John",  'age' : 49 }

But the following example fails, because generated code does not have 
initWithName:.

  const Person stationMaster = {'name' : "John"}

I ported the latest code for generating constant initializer from Java 
generator. The new compiler does not use initWithXXXX, but uses property 
setters repeatedly and recursively instead.


There are some more bug fixes.

I found memory leak in transport/TSocketClient.m. I fixed it by adding two 
CFRelease()s.

Objective-C compiler complains that transport/TSocketClient is not a compliant 
of NSStreamDelegate. I  fixed it with proper #ifdef. This problem is mentioned 
in the following JIRA page but not fixed.

   https://issues.apache.org/jira/browse/THRIFT-762


Have fun!

hirano


                
> Add support of ARC to Objective-C
> ---------------------------------
>
>                 Key: THRIFT-1340
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1340
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Cocoa - Compiler, Cocoa - Library
>    Affects Versions: 0.7
>         Environment: Mac OS X Lion, iOS 4.2, 4.3, 5.0..
>            Reporter: HIRANO Satoshi
>         Attachments: THRIFT-0.8.0-dev_cocoa_ARC.patch
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Objective-C in Xcode 4.2 supports ARC (Automatic Reference Counting, not GC 
> but similar) and now it is the default both on OS X Lion and iOS 5. (ARC 
> works on iOS 4.2 or higher.)
> The conventional Objective-C code includes many retain/release/autorelease 
> for maintaining  the life time of objects.
> Since the latest Objective-C compiler automatically generates stubs for 
> reference counting, code should not include any retain/release/autorelease.
> Many Mac OS/iOS projects are moving to ARC mode. Although we can specify a 
> compiler flag which tells ARC or no-ARC file by file in Xcode 4.2, there is 
> no means to tell the Xcode that files generated by the thrift compiler are 
> no-ARC. Xcode produces many error messages like "retain is not allowed in ARC 
> mode". 
> So, the thrift compiler should support ARC mode.
> What we need are:
> 1) add -objc-arc flag to the thrift compiler.
> 2) If -objc-arc flag exists, omit generating code for 
> retain/release/autorelease.
> Please look at "Programming with ARC reference notes" in iOS developer 
> library.
> http://andpdas.com/wp-content/uploads/2011/06/ARCProgrammingGuide.pdf

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to