Consider the code at the bottom. I am convinced it’s broken and should not compile. Line 224 has a static_cast
from NSURL*
to CFURLRef
with no bridging which I believe will break the reference count. Line 42 even enforces the use of ARC which should statically detect such a cast and result in a hard compilation error.
It certainly won’t compile for me which seems like the correct behaviour. (Side note, there’s an obvious fix by replacing the static_cast
with a bridge cast, but this isn’t too relevant to the question).
However, the code is taken from the public VST3 SDK code, a very popular audio programming framework with thousands of users worldwide and it’s been like this for the past 3 years which tells me it can’t be that broken after all.
My question is, under what set of circumstances will this code compile that I’m clearly missing? Other than conditionally compiling the code out which doesn’t seem to be the case?
https://github.com/steinbergmedia/vst3_public_sdk/blob/3f20bcbf36283b1e5c450e088571be6226cd4e64/source/vst/hosting/module_mac.mm#L224
// line 42
#if !__has_feature(objc_arc)
#error this file needs to be compiled with automatic reference counting enabled
#endif
// line 219
for (NSURL* url in enumerator)
{
if ([[[url lastPathComponent] pathExtension] isEqualToString:@"vst3"])
{
CFPtr<CFArrayRef> archs (
CFBundleCopyExecutableArchitecturesForURL (static_cast<CFURLRef> (url)));
if (archs)
result.emplace_back ([url.path UTF8String]);
}