[ https://issues.apache.org/jira/browse/THRIFT-1340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13161374#comment-13161374 ]
HIRANO Satoshi commented on THRIFT-1340: ---------------------------------------- Mike, Thanks for testing and your warm comment. My small magic for the issue of ARC/nonARC compatibility is applicable to any Cocoa project. I'm happy that you found the value of it. I pin it here so that many people can find. Everyone, use it in your project. TObjective-C.h is for supporting coexistence of both the ARC (Automatic Reference Counting) mode and the Non-ARC mode of Objective-C in the same source code. hirano /* TObjective-C.h * * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * TObjective-C.h is for supporting coexistence of both the ARC (Automatic * Reference Counting) mode and the Non-ARC mode of Objective-C * in the same source code. * * 2011/11/14 HIRANO Satoshi (AIST, Japan) * * Before: * * var = [aObject retain]; * [aObject release]; * [aObject autorelease]; * [super dealloc]; * CFFunction(obj); * * ARC and Non-ARC compatible: * * #import "TObjective-C.h" * var = [aObject retain_stub]; * [aObject release_stub]; * [aObject autorelease_stub]; * [super dealloc_stub]; * CFFunction(bridge_stub obj); * * Don't use retain_stub for @property(retain). * Use NSAutoreleasePool like this: * #if __has_feature(objc_arc) * @autoreleasepool { * // code * } * #else * NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init... * // code * [pool release]; * #endif */ #if !defined(retain_stub) #if __has_feature(objc_arc) #define retain_stub self #define autorelease_stub self #define release_stub self #define dealloc_stub self #define bridge_stub __bridge #else #define retain_stub retain #define autorelease_stub autorelease #define release_stub release #define dealloc_stub dealloc #define bridge_stub #endif #endif > 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