Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Source/CFPropertyList.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ CFPropertyListCreateDeepCopy (CFAllocatorRef alloc, CFPropertyListRef plist,
CFPropertyListRef copy;
CFTypeID typeID;

CFPropertyListInitTypeIDs ();
typeID = CFGetTypeID (plist);
if (typeID == _kCFArrayTypeID)
{
Expand Down Expand Up @@ -293,7 +294,7 @@ CFPropertyListCreateDeepCopy (CFAllocatorRef alloc, CFPropertyListRef plist,
ctx.alloc = alloc;
ctx.container = (CFTypeRef) array;
range = CFRangeMake (0, cnt);
CFArrayApplyFunction (array, range, CFArrayCopyFunction, &ctx);
CFArrayApplyFunction (plist, range, CFArrayCopyFunction, &ctx);

copy = array;
}
Expand Down Expand Up @@ -338,7 +339,7 @@ CFPropertyListCreateDeepCopy (CFAllocatorRef alloc, CFPropertyListRef plist,
ctx.opts = opts;
ctx.alloc = alloc;
ctx.container = (CFTypeRef) dict;
CFDictionaryApplyFunction (dict, CFDictionaryCopyFunction, &ctx);
CFDictionaryApplyFunction (plist, CFDictionaryCopyFunction, &ctx);

copy = dict;
}
Expand Down
41 changes: 41 additions & 0 deletions Tests/CFPropertyList/deepcopy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "CoreFoundation/CFPropertyList.h"
#include "CoreFoundation/CFArray.h"
#include "CoreFoundation/CFDictionary.h"
#include "CoreFoundation/CFString.h"
#include "../CFTesting.h"

/* CFPropertyListCreateDeepCopy of mutable containers. */

int main (void)
{
CFMutableArrayRef arr;
CFArrayRef acopy;
CFMutableDictionaryRef dict;
CFDictionaryRef dcopy;

arr = CFArrayCreateMutable (NULL, 0, &kCFTypeArrayCallBacks);
CFArrayAppendValue (arr, CFSTR ("a"));
CFArrayAppendValue (arr, CFSTR ("b"));
acopy = CFPropertyListCreateDeepCopy (NULL, arr,
kCFPropertyListMutableContainers);
PASS_CF(acopy != NULL && CFArrayGetCount (acopy) == 2,
"Deep copy of a mutable array has 2 elements.");
PASS_CF(CFArrayGetCount (acopy) == 2
&& CFEqual (CFArrayGetValueAtIndex (acopy, 0), CFSTR ("a"))
&& CFEqual (CFArrayGetValueAtIndex (acopy, 1), CFSTR ("b")),
"Deep-copied array elements are preserved.");

dict = CFDictionaryCreateMutable (NULL, 0,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue (dict, CFSTR ("k"), CFSTR ("v"));
dcopy = CFPropertyListCreateDeepCopy (NULL, dict,
kCFPropertyListMutableContainers);
PASS_CF(dcopy != NULL && CFDictionaryGetCount (dcopy) == 1,
"Deep copy of a mutable dictionary has 1 entry.");
PASS_CF(CFDictionaryGetCount (dcopy) == 1
&& CFEqual (CFDictionaryGetValue (dcopy, CFSTR ("k")), CFSTR ("v")),
"Deep-copied dictionary value is preserved.");

return 0;
}
Loading