]> git.saurik.com Git - apple/security.git/blobdiff - OSX/libsecurity_utilities/lib/seccfobject.h
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_utilities / lib / seccfobject.h
index dd59388388fea4b66f148f352215d0567d7f2e64..6ea5445eee4bfdd99abc229a926a6466519457c9 100644 (file)
@@ -29,6 +29,7 @@
 #include <CoreFoundation/CFRuntime.h>
 #include <new>
 #include "threading.h"
 #include <CoreFoundation/CFRuntime.h>
 #include <new>
 #include "threading.h"
+#include <os/lock.h>
 
 #if( __cplusplus <= 201103L)
 #include <stdatomic.h>
 
 #if( __cplusplus <= 201103L)
 #include <stdatomic.h>
@@ -45,13 +46,15 @@ operator APIPTR() const \
 \
 OBJTYPE *retain() \
 { SecCFObject::handle(true); return this; } \
 \
 OBJTYPE *retain() \
 { SecCFObject::handle(true); return this; } \
-APIPTR handle(bool retain = true) \
+APIPTR CF_RETURNS_RETAINED handle() \
+{ return (APIPTR)SecCFObject::handle(true); } \
+APIPTR handle(bool retain) \
 { return (APIPTR)SecCFObject::handle(retain); }
 
 #define SECCFFUNCTIONS_CREATABLE(OBJTYPE, APIPTR, CFCLASS) \
 SECCFFUNCTIONS_BASE(OBJTYPE, APIPTR)\
 \
 { return (APIPTR)SecCFObject::handle(retain); }
 
 #define SECCFFUNCTIONS_CREATABLE(OBJTYPE, APIPTR, CFCLASS) \
 SECCFFUNCTIONS_BASE(OBJTYPE, APIPTR)\
 \
-void *operator new(size_t size) throw(std::bad_alloc) \
+void *operator new(size_t size)\
 { return SecCFObject::allocate(size, CFCLASS); }
 
 #define SECCFFUNCTIONS(OBJTYPE, APIPTR, ERRCODE, CFCLASS) \
 { return SecCFObject::allocate(size, CFCLASS); }
 
 #define SECCFFUNCTIONS(OBJTYPE, APIPTR, ERRCODE, CFCLASS) \
@@ -76,13 +79,13 @@ struct SecRuntimeBase: CFRuntimeBase
 class SecCFObject
 {
 private:
 class SecCFObject
 {
 private:
-       void *operator new(size_t) throw(std::bad_alloc);
+       void *operator new(size_t);
 
        // Align up to a multiple of 16 bytes
        static const size_t kAlignedRuntimeSize = SECALIGNUP(sizeof(SecRuntimeBase), 4);
 
     uint32_t mRetainCount;
 
        // Align up to a multiple of 16 bytes
        static const size_t kAlignedRuntimeSize = SECALIGNUP(sizeof(SecRuntimeBase), 4);
 
     uint32_t mRetainCount;
-    OSSpinLock mRetainSpinLock;
+    os_unfair_lock mRetainLock;
 
 public:
        // For use by SecPointer only. Returns true once the first time it's called after the object has been created.
 
 public:
        // For use by SecPointer only. Returns true once the first time it's called after the object has been created.
@@ -94,23 +97,23 @@ public:
         return !atomic_flag_test_and_set(&(base->isOld));
        }
 
         return !atomic_flag_test_and_set(&(base->isOld));
        }
 
-       static SecCFObject *optional(CFTypeRef) throw();
+       static SecCFObject *optional(CFTypeRef) _NOEXCEPT;
        static SecCFObject *required(CFTypeRef, OSStatus error);
        static SecCFObject *required(CFTypeRef, OSStatus error);
-       static void *allocate(size_t size, const CFClass &cfclass) throw(std::bad_alloc);
+       static void *allocate(size_t size, const CFClass &cfclass);
 
     SecCFObject();
        virtual ~SecCFObject();
     uint32_t updateRetainCount(intptr_t direction, uint32_t *oldCount);
     uint32_t getRetainCount() {return updateRetainCount(0, NULL);}
 
 
     SecCFObject();
        virtual ~SecCFObject();
     uint32_t updateRetainCount(intptr_t direction, uint32_t *oldCount);
     uint32_t getRetainCount() {return updateRetainCount(0, NULL);}
 
-       static void operator delete(void *object) throw();
-       virtual operator CFTypeRef() const throw()
+       static void operator delete(void *object) _NOEXCEPT;
+       virtual operator CFTypeRef() const _NOEXCEPT
        {
                return reinterpret_cast<CFTypeRef>(reinterpret_cast<const uint8_t *>(this) - kAlignedRuntimeSize);
        }
 
        // This bumps up the retainCount by 1, by calling CFRetain(), iff retain is true
        {
                return reinterpret_cast<CFTypeRef>(reinterpret_cast<const uint8_t *>(this) - kAlignedRuntimeSize);
        }
 
        // This bumps up the retainCount by 1, by calling CFRetain(), iff retain is true
-       CFTypeRef handle(bool retain = true) throw();
+       CFTypeRef handle(bool retain = true) _NOEXCEPT;
 
     virtual bool equal(SecCFObject &other);
     virtual CFHashCode hash();
 
     virtual bool equal(SecCFObject &other);
     virtual CFHashCode hash();
@@ -153,10 +156,12 @@ public:
        T *yield() { T *result = static_cast<T *>(ptr); ptr = NULL; return result; }
        
        // dereference operations
        T *yield() { T *result = static_cast<T *>(ptr); ptr = NULL; return result; }
        
        // dereference operations
-    T* get () const                            { return static_cast<T*>(ptr); }        // mimic auto_ptr
+    T* get () const                            { return static_cast<T*>(ptr); }        // mimic unique_ptr
        operator T * () const           { return static_cast<T*>(ptr); }
        T * operator -> () const        { return static_cast<T*>(ptr); }
        T & operator * () const         { return *static_cast<T*>(ptr); }
        operator T * () const           { return static_cast<T*>(ptr); }
        T * operator -> () const        { return static_cast<T*>(ptr); }
        T & operator * () const         { return *static_cast<T*>(ptr); }
+
+    SecPointer& operator=(const SecPointer& other) { SecPointerBase::operator=(other); return *this; }
 };
 
 template <class T>
 };
 
 template <class T>