this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add SoftLinking framework/library/header/thing

I'm not sure what it is (it's not exactly a framework or library because it doesn't have any compiled code, not even a static library). I guess it's a single header that has an include structure setup like a framework.

+98
+98
src/softlinking/include/SoftLinking/SoftLinking.h
··· 1 + // i'm not sure where to put this header, since it's neither a "basic" header 2 + // nor a framework header (it doesn't even have it's own library from what i can tell) 3 + 4 + #ifndef _SOFTLINKING_SOFTLINKING_H_ 5 + #define _SOFTLINKING_SOFTLINKING_H_ 6 + 7 + #import <Foundation/Foundation.h> 8 + #import <CoreFoundation/CoreFoundation.h> 9 + #import <dispatch/dispatch.h> 10 + 11 + // certain aspects of this file (such as framework, function, and constant loading) 12 + // can be implemented in plain C, but because it can also load Objective-C classes, 13 + // we have to use `NSBundle`s too, which are Objective-C only 14 + // 15 + // that's okay, though, because it this only seems to be used in Objective-C code 16 + 17 + #define SOFT_LINK_STRINGIFY_INTERNAL2(x) #x 18 + #define SOFT_LINK_STRINGIFY_INTERNAL1(x) SOFT_LINK_STRINGIFY_INTERNAL2(x) 19 + #define SOFT_LINK_NSSTRINGIFY(x) @ SOFT_LINK_STRINGIFY_INTERNAL1(x) 20 + #define SOFT_LINK_CFSTRINGIFY(x) CFSTR(SOFT_LINK_STRINGIFY_INTERNAL1(x)) 21 + 22 + #define SOFT_LINK_FRAMEWORK(_location, _name) \ 23 + static CFBundleRef softlink_get_cfbundle_ ## _name () { \ 24 + static CFBundleRef bundle = NULL; \ 25 + static dispatch_once_t once_handle; \ 26 + dispatch_once(&once_handle, ^{ \ 27 + CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/System/Library/" #_location "/" #_name ".framework"), kCFURLPOSIXPathStyle, true); \ 28 + if (!url) \ 29 + return; \ 30 + bundle = CFBundleCreate(kCFAllocatorDefault, url); \ 31 + CFRelease(url); \ 32 + }); \ 33 + return bundle; \ 34 + }; \ 35 + static NSBundle* softlink_get_nsbundle_ ## _name () { \ 36 + static NSBundle* bundle = nil; \ 37 + static dispatch_once_t once_handle; \ 38 + dispatch_once(&once_handle, ^{ \ 39 + NSString* path = @"/System/Library/" #_location "/" #_name ".framework"; \ 40 + bundle = [NSBundle bundleWithPath: path]; \ 41 + }); \ 42 + return bundle; \ 43 + }; \ 44 + static int is ## _name ## Available () { \ 45 + /* this is probably not the best way to do this */ \ 46 + if (softlink_get_cfbundle_ ## _name ()) \ 47 + return 1; \ 48 + return 0; \ 49 + }; 50 + 51 + // not sure what the difference between safe and regular is 52 + #define SOFT_LINK_FRAMEWORK_SAFE(_location, _name) SOFT_LINK_FRAMEWORK(_location, _name) 53 + 54 + #define SOFT_LINK_CLASS(_framework, _name) \ 55 + static Class get ## _name ## Class () { \ 56 + static Class class = Nil; \ 57 + static dispatch_once_t once_handle; \ 58 + dispatch_once(&once_handle, ^{ \ 59 + NSBundle* bundle = softlink_get_nsbundle_ ## _framework (); \ 60 + class = [bundle classNamed: SOFT_LINK_NSSTRINGIFY(_name)]; \ 61 + }); \ 62 + return class; \ 63 + }; 64 + 65 + #define SOFT_LINK_CONSTANT(_framework, _name, _type) \ 66 + static _type get ## _name () { \ 67 + static _type* constant = NULL; \ 68 + static dispatch_once_t once_handle; \ 69 + dispatch_once(&once_handle, ^{ \ 70 + CFBundleRef bundle = softlink_get_cfbundle_ ## _framework (); \ 71 + if (bundle) \ 72 + constant = CFBundleGetDataPointerForName(bundle, SOFT_LINK_CFSTRINGIFY(_name)); \ 73 + }); \ 74 + /* 75 + i'm not sure what to do if the symbol can't be found since 76 + there's no way to tell the caller that an error occurred 77 + */ \ 78 + return *constant; \ 79 + }; 80 + 81 + // i'm unsure about that last macro parameter: `_call_pattern` 82 + // it seems to just be a repetition of the parameter names 83 + // but i'm guessing that that would be used to modify the arguments to the "soft" variant before passing 84 + // them onto the "hard" function 85 + #define SOFT_LINK_FUNCTION(_framework, _name, _soft_name, _return_type, _parameters, _call_pattern) \ 86 + static _return_type _soft_name _parameters { \ 87 + static _return_type (*func) _parameters = NULL; \ 88 + static dispatch_once_t once_handle; \ 89 + dispatch_once(&once_handle, ^{ \ 90 + CFBundleRef bundle = softlink_get_cfbundle_ ## _framework (); \ 91 + if (bundle) \ 92 + func = CFBundleGetFunctionPointerForName(bundle, SOFT_LINK_CFSTRINGIFY(_name)); \ 93 + }); \ 94 + /* again, here i'm unsure about what to do if the symbol's not there */ \ 95 + return func _call_pattern; \ 96 + }; 97 + 98 + #endif // _SOFTLINKING_SOFTLINKING_H_