summaryrefslogtreecommitdiffstats
path: root/base/foundation_utils_mac.h
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-08 21:02:56 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-08 21:02:56 +0000
commit03d95ac0d42dd9eaa7333b068361e4205c28ca7d (patch)
tree8d433e8c73cf002cc1bea78d40f00dec51d6848c /base/foundation_utils_mac.h
parent89916bd485d5c6156030f9f4b62db0cadac87c85 (diff)
downloadchromium_src-03d95ac0d42dd9eaa7333b068361e4205c28ca7d.zip
chromium_src-03d95ac0d42dd9eaa7333b068361e4205c28ca7d.tar.gz
chromium_src-03d95ac0d42dd9eaa7333b068361e4205c28ca7d.tar.bz2
Provide converters to and from NSString* in sys_string_conversions
Review URL: http://codereview.chromium.org/6355 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/foundation_utils_mac.h')
-rw-r--r--base/foundation_utils_mac.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/base/foundation_utils_mac.h b/base/foundation_utils_mac.h
new file mode 100644
index 0000000..64ebeda
--- /dev/null
+++ b/base/foundation_utils_mac.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_FOUNDATION_UTILS_MAC_H_
+#define BASE_FOUNDATION_UTILS_MAC_H_
+
+#include <CoreFoundation/CoreFoundation.h>
+#import <Foundation/Foundation.h>
+
+// CFTypeRefToNSObjectAutorelease transfers ownership of a Core Foundation
+// object (one derived from CFTypeRef) to the Foundation memory management
+// system. In a traditional managed-memory environment, cf_object is
+// autoreleased and returned as an NSObject. In a garbage-collected
+// environment, cf_object is marked as eligible for garbage collection.
+//
+// This function should only be used to convert a concrete CFTypeRef type to
+// its equivalent "toll-free bridged" NSObject subclass, for example,
+// converting a CFStringRef to NSString.
+//
+// By calling this function, callers relinquish any ownership claim to
+// cf_object. In a managed-memory environment, the object's ownership will be
+// managed by the innermost NSAutoreleasePool, so after this function returns,
+// callers should not assume that cf_object is valid any longer than the
+// returned NSObject.
+static inline id CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object) {
+ // When GC is on, NSMakeCollectable marks cf_object for GC and autorelease
+ // is a no-op.
+ //
+ // In the traditional GC-less environment, NSMakeCollectable is a no-op,
+ // and cf_object is autoreleased, balancing out the caller's ownership claim.
+ //
+ // NSMakeCollectable returns nil when used on a NULL object.
+ return [NSMakeCollectable(cf_object) autorelease];
+}
+
+#endif // BASE_FOUNDATION_UTILS_MAC_H_