@@ -456,11 +456,13 @@ CFDataRef CFDataCreateWithBytesNoCopy(CFAllocatorRef allocator, const uint8_t *b
456
456
return __CFDataInit (allocator , kCFImmutable , length , bytes , length , bytesDeallocator );
457
457
}
458
458
459
- CFDataRef CFDataCreateCopy (CFAllocatorRef allocator , CFDataRef data ) {
459
+ static CFDataRef _CFDataCreateCopyAllowingBridging (CFAllocatorRef allocator , CFDataRef data , Boolean allowBridging ) {
460
460
Boolean allowRetain = true;
461
461
if (allowRetain ) {
462
- CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), CFDataRef , (NSData * )data , copy );
463
- CF_SWIFT_FUNCDISPATCHV (CFDataGetTypeID (), CFDataRef , (CFSwiftRef )data , NSObject .copyWithZone , NULL );
462
+ if (allowBridging ) {
463
+ CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), CFDataRef , (NSData * )data , copy );
464
+ CF_SWIFT_FUNCDISPATCHV (CFDataGetTypeID (), CFDataRef , (CFSwiftRef )data , NSData .copy );
465
+ }
464
466
465
467
// If the data isn't mutable...
466
468
if (!__CFDataIsMutable (data )) {
@@ -485,6 +487,16 @@ CFDataRef CFDataCreateCopy(CFAllocatorRef allocator, CFDataRef data) {
485
487
return __CFDataInit (allocator , kCFImmutable , length , CFDataGetBytePtr (data ), length , NULL );
486
488
}
487
489
490
+ CFDataRef CFDataCreateCopy (CFAllocatorRef allocator , CFDataRef data ) {
491
+ return _CFDataCreateCopyAllowingBridging (allocator , data , true);
492
+ }
493
+
494
+ #if DEPLOYMENT_RUNTIME_SWIFT
495
+ CF_CROSS_PLATFORM_EXPORT CFDataRef _CFDataCreateCopyNoBridging (CFAllocatorRef allocator , CFDataRef data ) {
496
+ return _CFDataCreateCopyAllowingBridging (allocator , data , false);
497
+ }
498
+ #endif
499
+
488
500
CF_PRIVATE CFMutableDataRef _CFDataCreateFixedMutableWithBuffer (CFAllocatorRef allocator , CFIndex capacity , const uint8_t * bytes , CFAllocatorRef bytesDeallocator ) {
489
501
return (CFMutableDataRef )__CFDataInit (allocator , kCFFixedMutable , capacity , bytes , 0 , bytesDeallocator );
490
502
}
@@ -501,9 +513,17 @@ CFMutableDataRef CFDataCreateMutableCopy(CFAllocatorRef allocator, CFIndex capac
501
513
502
514
CFIndex CFDataGetLength (CFDataRef data ) {
503
515
CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), CFIndex , (NSData * )data , length );
516
+ CF_SWIFT_FUNCDISPATCHV (CFDataGetTypeID (), CFIndex , (CFSwiftRef )data , NSData .length );
517
+ __CFGenericValidateType (data , CFDataGetTypeID ());
518
+ return __CFDataLength (data );
519
+ }
520
+
521
+ #if DEPLOYMENT_RUNTIME_SWIFT
522
+ CF_CROSS_PLATFORM_EXPORT CFIndex _CFDataGetLengthNoBridging (CFDataRef data ) {
504
523
__CFGenericValidateType (data , CFDataGetTypeID ());
505
524
return __CFDataLength (data );
506
525
}
526
+ #endif
507
527
508
528
CF_PRIVATE uint8_t * _CFDataGetBytePtrNonObjC (CFDataRef data ) {
509
529
__CFGenericValidateType (data , CFDataGetTypeID ());
@@ -512,21 +532,42 @@ CF_PRIVATE uint8_t *_CFDataGetBytePtrNonObjC(CFDataRef data) {
512
532
513
533
const uint8_t * CFDataGetBytePtr (CFDataRef data ) {
514
534
CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), const uint8_t * , (NSData * )data , bytes );
535
+ CF_SWIFT_FUNCDISPATCHV (CFDataGetTypeID (), const uint8_t * , (CFSwiftRef )data , NSData .bytePtr );
515
536
return _CFDataGetBytePtrNonObjC (data );
516
537
}
517
538
539
+ #if DEPLOYMENT_RUNTIME_SWIFT
540
+ CF_CROSS_PLATFORM_EXPORT const uint8_t * _CFDataGetBytePtrNoBridging (CFDataRef data ) {
541
+ return _CFDataGetBytePtrNonObjC (data );
542
+ }
543
+ #endif
544
+
518
545
uint8_t * CFDataGetMutableBytePtr (CFMutableDataRef data ) {
519
546
CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), uint8_t * , (NSMutableData * )data , mutableBytes );
520
547
CFAssert1 (__CFDataIsMutable (data ), __kCFLogAssertion , "%s(): data is immutable" , __PRETTY_FUNCTION__ );
521
548
return _CFDataGetBytePtrNonObjC (data );
522
549
}
523
550
551
+ #if DEPLOYMENT_RUNTIME_SWIFT
552
+ CF_CROSS_PLATFORM_EXPORT uint8_t * _CFDataGetMutableBytePtrNoBridging (CFDataRef data ) {
553
+ return _CFDataGetBytePtrNonObjC (data );
554
+ }
555
+ #endif
556
+
524
557
void CFDataGetBytes (CFDataRef data , CFRange range , uint8_t * buffer ) {
525
558
CF_OBJC_FUNCDISPATCHV (CFDataGetTypeID (), void , (NSData * )data , getBytes :(void * )buffer range :NSMakeRange (range .location , range .length ));
559
+ CF_SWIFT_FUNCDISPATCHV (CFDataGetTypeID (), void , (CFSwiftRef )data , NSData .getBytes , range , buffer );
526
560
__CFDataValidateRange (data , range , __PRETTY_FUNCTION__ );
527
561
memmove (buffer , _CFDataGetBytePtrNonObjC (data ) + range .location , range .length );
528
562
}
529
563
564
+ #if DEPLOYMENT_RUNTIME_SWIFT
565
+ CF_CROSS_PLATFORM_EXPORT void _CFDataGetBytesNoBridging (CFDataRef data , CFRange range , void * buffer ) {
566
+ __CFDataValidateRange (data , range , __PRETTY_FUNCTION__ );
567
+ memmove (buffer , _CFDataGetBytePtrNonObjC (data ) + range .location , range .length );
568
+ }
569
+ #endif
570
+
530
571
/* Allocates new block of data with at least numNewValues more bytes than the current length. If clear is true, the new bytes up to at least the new length with be zeroed. */
531
572
static void __CFDataGrow (CFMutableDataRef data , CFIndex numNewValues , Boolean clear ) {
532
573
CFIndex oldLength = __CFDataLength (data );
0 commit comments