Loading...
libkern/c++/OSSet.cpp xnu-12377.101.15 xnu-6153.121.1
--- xnu/xnu-12377.101.15/libkern/c++/OSSet.cpp
+++ xnu/xnu-6153.121.1/libkern/c++/OSSet.cpp
@@ -27,20 +27,14 @@
  */
 /* IOSet.m created by rsulack on Thu 11-Jun-1998 */
 
-#define IOKIT_ENABLE_SHARED_PTR
-
+#include <libkern/c++/OSDictionary.h>
 #include <libkern/c++/OSArray.h>
-#include <libkern/c++/OSDictionary.h>
 #include <libkern/c++/OSSerialize.h>
 #include <libkern/c++/OSSet.h>
-#include <libkern/c++/OSSharedPtr.h>
-#include <os/cpp_util.h>
-#include <kern/zalloc.h>
 
 #define super OSCollection
 
-OSDefineMetaClassAndStructorsWithZone(OSSet, OSCollection,
-    ZC_ZFREE_CLEARMEM)
+OSDefineMetaClassAndStructors(OSSet, OSCollection)
 OSMetaClassDefineReservedUnused(OSSet, 0);
 OSMetaClassDefineReservedUnused(OSSet, 1);
 OSMetaClassDefineReservedUnused(OSSet, 2);
@@ -115,56 +109,60 @@
 OSSet::initWithSet(const OSSet *inSet,
     unsigned int inCapacity)
 {
-	return initWithArray(inSet->members.get(), inCapacity);
-}
-
-OSSharedPtr<OSSet>
+	return initWithArray(inSet->members, inCapacity);
+}
+
+OSSet *
 OSSet::withCapacity(unsigned int capacity)
 {
-	OSSharedPtr<OSSet> me = OSMakeShared<OSSet>();
+	OSSet *me = new OSSet;
 
 	if (me && !me->initWithCapacity(capacity)) {
-		return nullptr;
+		me->release();
+		return NULL;
 	}
 
 	return me;
 }
 
-OSSharedPtr<OSSet>
+OSSet *
 OSSet::withObjects(const OSObject *objects[],
     unsigned int count,
     unsigned int capacity)
 {
-	OSSharedPtr<OSSet> me = OSMakeShared<OSSet>();
+	OSSet *me = new OSSet;
 
 	if (me && !me->initWithObjects(objects, count, capacity)) {
-		return nullptr;
+		me->release();
+		return NULL;
 	}
 
 	return me;
 }
 
-OSSharedPtr<OSSet>
+OSSet *
 OSSet::withArray(const OSArray *array,
     unsigned int capacity)
 {
-	OSSharedPtr<OSSet> me = OSMakeShared<OSSet>();
+	OSSet *me = new OSSet;
 
 	if (me && !me->initWithArray(array, capacity)) {
-		return nullptr;
+		me->release();
+		return NULL;
 	}
 
 	return me;
 }
 
-OSSharedPtr<OSSet>
+OSSet *
 OSSet::withSet(const OSSet *set,
     unsigned int capacity)
 {
-	OSSharedPtr<OSSet> me = OSMakeShared<OSSet>();
+	OSSet *me = new OSSet;
 
 	if (me && !me->initWithSet(set, capacity)) {
-		return nullptr;
+		me->release();
+		return NULL;
 	}
 
 	return me;
@@ -175,6 +173,7 @@
 {
 	if (members) {
 		(void) members->super::setOptions(0, kImmutable);
+		members->release();
 	}
 
 	super::free();
@@ -226,12 +225,6 @@
 		haveUpdated();
 		return members->setObject(anObject);
 	}
-}
-
-bool
-OSSet::setObject(OSSharedPtr<const OSMetaClassBase> const& anObject)
-{
-	return setObject(anObject.get());
 }
 
 bool
@@ -258,7 +251,7 @@
 bool
 OSSet::merge(const OSSet * set)
 {
-	return merge(set->members.get());
+	return merge(set->members);
 }
 
 void
@@ -275,12 +268,6 @@
 	}
 }
 
-void
-OSSet::removeObject(OSSharedPtr<const OSMetaClassBase> const& anObject)
-{
-	removeObject(anObject.get());
-}
-
 
 bool
 OSSet::containsObject(const OSMetaClassBase *anObject) const
@@ -419,19 +406,18 @@
 	return old;
 }
 
-OSSharedPtr<OSCollection>
+OSCollection *
 OSSet::copyCollection(OSDictionary *cycleDict)
 {
-	OSSharedPtr<OSDictionary> ourCycleDict;
-	OSSharedPtr<OSCollection> ret;
-	OSSharedPtr<OSSet> newSet;
-
-	if (!cycleDict) {
-		ourCycleDict = OSDictionary::withCapacity(16);
-		if (!ourCycleDict) {
-			return nullptr;
-		}
-		cycleDict = ourCycleDict.get();
+	bool allocDict = !cycleDict;
+	OSCollection *ret = NULL;
+	OSSet *newSet = NULL;
+
+	if (allocDict) {
+		cycleDict = OSDictionary::withCapacity(16);
+		if (!cycleDict) {
+			return NULL;
+		}
 	}
 
 	do {
@@ -445,28 +431,41 @@
 			continue; // Couldn't create new set abort
 		}
 		// Insert object into cycle Dictionary
-		cycleDict->setObject((const OSSymbol *) this, newSet.get());
-
-		OSArray *newMembers = newSet->members.get();
+		cycleDict->setObject((const OSSymbol *) this, newSet);
+
+		OSArray *newMembers = newSet->members;
 		newMembers->capacityIncrement = members->capacityIncrement;
 
 		// Now copy over the contents into the new duplicate
 		for (unsigned int i = 0; i < members->count; i++) {
-			OSObject *obj = EXT_CAST(members->array[i].get());
+			OSObject *obj = EXT_CAST(members->array[i]);
 			OSCollection *coll = OSDynamicCast(OSCollection, obj);
 			if (coll) {
-				OSSharedPtr<OSCollection> newColl = coll->copyCollection(cycleDict);
+				OSCollection *newColl = coll->copyCollection(cycleDict);
 				if (newColl) {
-					obj = newColl.get(); // Rely on cycleDict ref for a bit
+					obj = newColl; // Rely on cycleDict ref for a bit
+					newColl->release();
 				} else {
-					return ret;
+					goto abortCopy;
 				}
 			}
+			;
 			newMembers->setObject(obj);
 		}
-
-		ret = os::move(newSet);
+		;
+
+		ret = newSet;
+		newSet = NULL;
 	} while (false);
 
+abortCopy:
+	if (newSet) {
+		newSet->release();
+	}
+
+	if (allocDict) {
+		cycleDict->release();
+	}
+
 	return ret;
 }