Skip to content

Commit

Permalink
Adding JXArcCompatibilityMacros.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanX2 committed Feb 25, 2013
1 parent 0e699c7 commit dbe7768
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DiffMatchPatch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
3DA642BC128DEF4900B33CE9 /* MinMaxMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MinMaxMacros.h; sourceTree = "<group>"; };
3DC87023129FF4B6001F602B /* NSString+JavaSubstring.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JavaSubstring.h"; sourceTree = "<group>"; };
3DC87024129FF4B6001F602B /* NSString+JavaSubstring.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+JavaSubstring.m"; sourceTree = "<group>"; };
3DEB56D916DBA4C300D11FA5 /* JXArcCompatibilityMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JXArcCompatibilityMacros.h; sourceTree = "<group>"; };
3DEE4C70129D484D00885485 /* NSMutableDictionary+DMPExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+DMPExtensions.h"; sourceTree = "<group>"; };
3DEE4C71129D484D00885485 /* NSMutableDictionary+DMPExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+DMPExtensions.m"; sourceTree = "<group>"; };
3DFF2F3613C2105300DC564A /* TestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestUtilities.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -213,6 +214,7 @@
3DA642BC128DEF4900B33CE9 /* MinMaxMacros.h */,
3DA6416F128DDA3400B33CE9 /* DiffMatchPatchCFUtilities.h */,
3DA64170128DDA3400B33CE9 /* DiffMatchPatchCFUtilities.c */,
3DEB56D916DBA4C300D11FA5 /* JXArcCompatibilityMacros.h */,
);
indentWidth = 2;
name = "Other Sources";
Expand Down
72 changes: 72 additions & 0 deletions JXArcCompatibilityMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* JXArcCompatibilityMacros.h
*
* Created by Jan on 29.09.12.
* Copyright 2012-2013 Jan Weiß
*
* Based on “DDMathParser.h” by Dave DeLong.
*
* Released under the BSD software licence and 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.
*
* Author: jan@geheimwerk.de (Jan Weiß)
*/


#ifndef JXArcCompatibilityMacros_h
#define JXArcCompatibilityMacros_h

#ifdef __clang__
#define JX_STRONG strong
#else
#define JX_STRONG retain
#endif

/*
Porting help (pretty crude, could use improvement):
\[(.+) retain\] JX_RETAIN(\1)
\[(.+) release\] JX_RELEASE(\1)
\[(.+) autorelease\] JX_AUTORELEASE(\1)
\(id\)([\w\d.]+|\[.+\]) JX_BRIDGED_CAST(id, \1)
\(__bridge ((CF|NS)\w+(\ \*)?)\)(\w+) JX_BRIDGED_CAST(\1, \4)
The above have usual problems with nesting. Don’t use them with “Replace all”!
*/

#if __has_feature(objc_arc)

#define JX_HAS_ARC 1
#define JX_RETAIN(_o) (_o)
#define JX_RELEASE(_o)
#define JX_AUTORELEASE(_o) (_o)

#define JX_BRIDGED_CAST(_type, _o) (__bridge _type)(_o)
#define JX_TRANSFER_OBJC_TO_CF(_type, _o) (__bridge_retained _type)(_o)
#define JX_TRANSFER_CF_TO_OBJC(_type, _o) (__bridge_transfer _type)(_o)

#else

#define JX_HAS_ARC 0
#define JX_RETAIN(_o) [(_o) retain]
#define JX_RELEASE(_o) [(_o) release]
#define JX_AUTORELEASE(_o) [(_o) autorelease]

#define JX_BRIDGED_CAST(_type, _o) (_type)(_o)
#define JX_TRANSFER_OBJC_TO_CF(_type, _o) (_type)((_o) ? CFRetain((CFTypeRef)(_o)) : NULL)
#define JX_TRANSFER_CF_TO_OBJC(_type, _o) [(_type)CFMakeCollectable(_o) autorelease]

#endif


#endif

0 comments on commit dbe7768

Please sign in to comment.