Module: OS::Mac::FFI::CoreFoundation Private
- Extended by:
- NativeLibrary
- Defined in:
- os/mac/ffi/core_foundation.rb
Overview
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
CoreFoundation.framework wrapper
Methods that create Core Foundation objects follow the Create Rule: the
caller owns the result and must release it deterministically with
CoreFoundation.release, usually via CoreFoundation.with_release_pool. Constant accessors return
borrowed references that must not be released. Ownership must not be
handed to the garbage collector: a GC-time CFRelease can run on the
child side of fork (e.g. in Utils.popen), where Core Foundation is
not fork-safe.
https://github.com/Homebrew/brew/issues/23606
Defined Under Namespace
Classes: ReleasePool
Class Method Summary collapse
-
.dictionary_create(hash) ⇒ Fiddle::Pointer
private
CoreFoundation/CFDictionary.h: CFDictionaryRef CFDictionaryCreate( CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);.
-
.release(ptr) ⇒ void
private
CoreFoundation/CFBase.h: void CFRelease(CFTypeRef cf);.
-
.string_create(string) ⇒ Fiddle::Pointer
private
CoreFoundation/CFString.h: CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);.
-
.type_dictionary_key_call_backs ⇒ Fiddle::Pointer
private
CoreFoundation/CFDictionary.h: extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;.
-
.type_dictionary_value_call_backs ⇒ Fiddle::Pointer
private
CoreFoundation/CFDictionary.h: extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks.
-
.url_create_with_file_system_path(path) ⇒ Fiddle::Pointer
private
CoreFoundation/CFURL.h: CFURLRef CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStringRef filePath, CFURLPathStyle pathStyle, Boolean isDirectory);.
-
.url_quarantine_properties_key ⇒ Fiddle::Pointer
private
CoreFoundation/CFURL.h: extern const CFStringRef kCFURLQuarantinePropertiesKey;.
-
.url_set_resource_property_for_key(url, key, value) ⇒ Boolean
private
CoreFoundation/CFURL.h: Boolean CFURLSetResourcePropertyForKey(CFURLRef url, CFStringRef key, CFTypeRef value, CFErrorRef *error);.
-
.with_release_pool(&_block) ⇒ T.type_parameter(:U)
private
Yields a ReleasePool and drains it when the block finishes, releasing every tracked object even if the block raises.
Class Method Details
.dictionary_create(hash) ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFDictionary.h:
CFDictionaryRef CFDictionaryCreate(
CFAllocatorRef allocator,
const void **keys,
const void **values,
CFIndex numValues,
const CFDictionaryKeyCallBacks *keyCallBacks,
const CFDictionaryValueCallBacks *valueCallBacks);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'os/mac/ffi/core_foundation.rb', line 118 def self.dictionary_create(hash) size = Fiddle::SIZEOF_VOIDP * hash.size Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) do |keys| Fiddle::Pointer.malloc(size, Fiddle::RUBY_FREE) do |values| # Convert array of pointers to continous stream of pointers in the C buffer keys[0, size] = hash.keys.pack("J*") values[0, size] = hash.values.pack("J*") return function( "CFDictionaryCreate", [ Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP ], Fiddle::TYPE_VOIDP, ).call( nil, keys, values, hash.size, type_dictionary_key_call_backs, type_dictionary_value_call_backs ) end end end |
.release(ptr) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
CoreFoundation/CFBase.h:
void CFRelease(CFTypeRef cf);
63 64 65 66 67 |
# File 'os/mac/ffi/core_foundation.rb', line 63 def self.release(ptr) return if ptr.null? function("CFRelease", [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOID).call(ptr) end |
.string_create(string) ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFString.h:
CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'os/mac/ffi/core_foundation.rb', line 87 def self.string_create(string) cf_encoding = case string.encoding when Encoding::UTF_8 0x08000100 # kCFStringEncodingUTF8 when Encoding::US_ASCII 0x0600 # kCFStringEncodingASCII when Encoding::ASCII_8BIT, Encoding::ISO8859_1 # ASCII-8BIT could be anything, so just use Latin-1 0x0201 # kCFStringEncodingISOLatin1 else # Try convert to UTF-8 and move on string = string.encode(Encoding::UTF_8) 0x08000100 end function( "CFStringCreateWithCString", [Fiddle::TYPE_VOIDP, Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_UINT32_T], Fiddle::TYPE_VOIDP, ).call(nil, string, cf_encoding) end |
.type_dictionary_key_call_backs ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFDictionary.h:
extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
72 |
# File 'os/mac/ffi/core_foundation.rb', line 72 def self.type_dictionary_key_call_backs = constant("kCFTypeDictionaryKeyCallBacks") |
.type_dictionary_value_call_backs ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFDictionary.h:
extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks
77 |
# File 'os/mac/ffi/core_foundation.rb', line 77 def self.type_dictionary_value_call_backs = constant("kCFTypeDictionaryValueCallBacks") |
.url_create_with_file_system_path(path) ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFURL.h:
CFURLRef CFURLCreateWithFileSystemPath(CFAllocatorRef allocator,
CFStringRef filePath, CFURLPathStyle pathStyle, Boolean isDirectory);
143 144 145 146 147 148 149 |
# File 'os/mac/ffi/core_foundation.rb', line 143 def self.url_create_with_file_system_path(path) function( "CFURLCreateWithFileSystemPath", [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_LONG, Fiddle::TYPE_BOOL], Fiddle::TYPE_VOIDP, ).call(nil, path, 0, false) end |
.url_quarantine_properties_key ⇒ Fiddle::Pointer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFURL.h:
extern const CFStringRef kCFURLQuarantinePropertiesKey;
82 |
# File 'os/mac/ffi/core_foundation.rb', line 82 def self.url_quarantine_properties_key = constant("kCFURLQuarantinePropertiesKey", dereference: true) |
.url_set_resource_property_for_key(url, key, value) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
CoreFoundation/CFURL.h:
Boolean CFURLSetResourcePropertyForKey(CFURLRef url, CFStringRef key, CFTypeRef value, CFErrorRef *error);
154 155 156 157 158 159 160 |
# File 'os/mac/ffi/core_foundation.rb', line 154 def self.url_set_resource_property_for_key(url, key, value) function( "CFURLSetResourcePropertyForKey", [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP], Fiddle::TYPE_BOOL, ).call(url, key, value, nil) end |
.with_release_pool(&_block) ⇒ T.type_parameter(:U)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Yields a ReleasePool and drains it when the block finishes, releasing every tracked object even if the block raises.
53 54 55 56 57 58 |
# File 'os/mac/ffi/core_foundation.rb', line 53 def self.with_release_pool(&_block) pool = ReleasePool.new yield pool ensure pool&.drain end |