this repo has no description
1
fork

Configure Feed

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

Kill old Foundation directory, CoreServices updates for CFNetwork

+27 -735
+2 -2
src/CoreServices/DriverServices.h
··· 19 19 20 20 #ifndef DRIVERSERVICES_H 21 21 #define DRIVERSERVICES_H 22 - #include "MacTypes.h" 23 - #include <climits> 22 + #include <MacTypes.h> 23 + #include <limits.h> 24 24 25 25 #ifdef __cplusplus 26 26 extern "C" {
+22
src/CoreServices/FixMath.cpp
··· 19 19 20 20 #include "FixMath.h" 21 21 #include <cmath> 22 + #include <limits> 23 + 24 + namespace Darling 25 + { 26 + static const int32_t InfPlus = std::numeric_limits<int32_t>::max(); 27 + static const int32_t InfMinus = std::numeric_limits<int32_t>::min(); 28 + static const int32_t FixedRatio = 0x10000; 29 + static const int32_t FractRatio = 0x40000000; 30 + 31 + template <typename T> int32_t checkNumberBounds(T t) 32 + { 33 + if (t < -0x1p31f) 34 + return InfMinus; 35 + else if (t > 0x1p31f) 36 + return InfPlus; 37 + else 38 + return int32_t(t); 39 + } 40 + 41 + 42 + } 43 + 22 44 23 45 float FixedToFloat(Fixed f) 24 46 {
-22
src/CoreServices/FixMath.h
··· 23 23 #include <stdint.h> 24 24 25 25 #ifdef __cplusplus 26 - #include <limits> 27 - 28 - namespace Darling 29 - { 30 - static const int32_t InfPlus = std::numeric_limits<int32_t>::max(); 31 - static const int32_t InfMinus = std::numeric_limits<int32_t>::min(); 32 - static const int32_t FixedRatio = 0x10000; 33 - static const int32_t FractRatio = 0x40000000; 34 - 35 - template <typename T> int32_t checkNumberBounds(T t) 36 - { 37 - if (t < -0x1p31f) 38 - return InfMinus; 39 - else if (t > 0x1p31f) 40 - return InfPlus; 41 - else 42 - return int32_t(t); 43 - } 44 - 45 - 46 - } 47 - 48 26 extern "C" { 49 27 #endif 50 28
+2 -1
src/CoreServices/MacErrors.h
··· 1 1 #ifndef MACERRORS_H 2 2 #define MACERRORS_H 3 3 #include <CoreFoundation/CFBase.h> 4 + #include <MacTypes.h> 4 5 5 6 inline OSStatus makeOSStatus(int errNo) { return 100000 + errNo; } 6 7 7 8 #define memFullErr -108 8 9 #define internalComponentErr -2070 9 - #define noErr 0 10 + //#define noErr 0 10 11 #define unimpErr -4 11 12 #define fnfErr -43 // file not found 12 13 #define paramErr -50
+1 -1
src/CoreServices/MacTypes.h
··· 18 18 typedef uint64_t UInt64; 19 19 typedef float Float32; 20 20 typedef double Float64; 21 - #endif 22 21 23 22 typedef Fixed* FixedPtr; 24 23 typedef Fract* FractPtr; 25 24 typedef UnsignedFixed* UnsignedFixedPtr; 26 25 typedef short ShortFixed; 27 26 typedef ShortFixed * ShortFixedPtr; // 8/8 27 + #endif 28 28 //typedef int64_t wide; 29 29 //typedef uint64_t UnsignedWide; 30 30 //typedef uint64_t AbsoluteTime;
-37
src/Foundation/CMakeLists.txt
··· 1 - project(Foundation) 2 - 3 - cmake_minimum_required(VERSION 2.4.0) 4 - if(COMMAND cmake_policy) 5 - cmake_policy(SET CMP0003 NEW) 6 - endif(COMMAND cmake_policy) 7 - 8 - #if (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 9 - # message(FATAL_ERROR "Clang is the only supported compiler.") 10 - #endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 11 - 12 - #configure_file(config.h.in config.h) 13 - add_definitions(-D__STDC_LIMIT_MACROS) 14 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fconstant-string-class=NSConstantString") 15 - #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks") 16 - 17 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 18 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 19 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util) 20 - 21 - set(Foundation_SRCS 22 - NameTranslate.cpp 23 - NSDarwinBundle.mm 24 - NSAppleEventDescriptor.mm 25 - NSAppleEventManager.mm 26 - ) 27 - 28 - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/darling") 29 - #SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags") 30 - SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 31 - SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 32 - 33 - add_library(Foundation SHARED ${Foundation_SRCS}) 34 - target_link_libraries(Foundation -lgnustep-base) 35 - 36 - install(TARGETS Foundation DESTINATION "${CMAKE_INSTALL_LIBDIR}/darling") 37 -
-94
src/Foundation/NSAppleEventDescriptor.h
··· 1 - #ifndef NSAPPLEEVENTDESCRIPTOR_H 2 - #define NSAPPLEEVENTDESCRIPTOR_H 3 - #include <Foundation/NSObject.h> 4 - #include <Foundation/NSData.h> 5 - #include <Foundation/NSString.h> 6 - #include <CoreServices/MacTypes.h> 7 - 8 - typedef int AEEventClass; 9 - typedef int AEEventID; 10 - typedef int AEReturnID; 11 - typedef UInt32 AEKeyword; 12 - typedef int AETransactionID; 13 - typedef int DescType; 14 - 15 - struct AEDesc; 16 - 17 - @interface NSAppleEventDescriptor : NSObject 18 - 19 - + (NSAppleEventDescriptor *)appleEventWithEventClass:(AEEventClass)eventClass 20 - eventID:(AEEventID)eventID 21 - targetDescriptor:(NSAppleEventDescriptor *)addressDescriptor 22 - returnID:(AEReturnID)returnID 23 - transactionID:(AETransactionID)transactionID; 24 - 25 - + (NSAppleEventDescriptor *)descriptorWithBoolean:(Boolean)boolean; 26 - + (NSAppleEventDescriptor *)descriptorWithDescriptorType:(DescType)descriptorType 27 - bytes:(const void *)bytes 28 - length:(NSUInteger)byteCount; 29 - 30 - + (NSAppleEventDescriptor *)descriptorWithDescriptorType:(DescType)descriptorType 31 - data:(NSData *)data; 32 - 33 - + (NSAppleEventDescriptor *)descriptorWithEnumCode:(OSType)enumerator; 34 - + (NSAppleEventDescriptor *)descriptorWithInt32:(SInt32)signedInt; 35 - + (NSAppleEventDescriptor *)descriptorWithString:(NSString *)string; 36 - + (NSAppleEventDescriptor *)descriptorWithTypeCode:(OSType)typeCode; 37 - + (NSAppleEventDescriptor *)listDescriptor; 38 - + (NSAppleEventDescriptor *)nullDescriptor; 39 - + (NSAppleEventDescriptor *)recordDescriptor; 40 - 41 - - (id)initListDescriptor; 42 - - (id)initRecordDescriptor; 43 - - (id)initWithAEDescNoCopy:(const AEDesc *)aeDesc; 44 - - (id)initWithDescriptorType:(DescType)descriptorType 45 - bytes:(const void *)bytes 46 - length:(NSUInteger)byteCount; 47 - - (id)initWithDescriptorType:(DescType)descriptorType 48 - data:(NSData *)data; 49 - - (id)initWithEventClass:(AEEventClass)eventClass 50 - eventID:(AEEventID)eventID 51 - targetDescriptor:(NSAppleEventDescriptor *)addressDescriptor 52 - returnID:(AEReturnID)returnID 53 - transactionID:(AETransactionID)transactionID; 54 - 55 - - (const AEDesc *)aeDesc; 56 - - (NSAppleEventDescriptor *)attributeDescriptorForKeyword:(AEKeyword)keyword; 57 - 58 - - (Boolean)booleanValue; 59 - - (SInt32)int32Value; 60 - - (NSString *)stringValue; 61 - 62 - - (DescType)descriptorType; 63 - - (OSType)enumCodeValue; 64 - - (AEEventClass)eventClass; 65 - - (AEEventID)eventID; 66 - - (AETransactionID)transactionID; 67 - - (OSType)typeCodeValue; 68 - 69 - - (NSAppleEventDescriptor *)coerceToDescriptorType:(DescType)descriptorType; 70 - - (NSData *)data; 71 - - (NSAppleEventDescriptor *)descriptorAtIndex:(NSInteger)anIndex; 72 - - (NSAppleEventDescriptor *)descriptorForKeyword:(AEKeyword)keyword; 73 - 74 - - (void)insertDescriptor:(NSAppleEventDescriptor *)descriptor 75 - atIndex:(NSInteger)anIndex; 76 - - (void)removeDescriptorAtIndex:(NSInteger)anIndex; 77 - - (void)removeDescriptorWithKeyword:(AEKeyword)keyword; 78 - - (void)removeParamDescriptorWithKeyword:(AEKeyword)keyword; 79 - 80 - - (AEKeyword)keywordForDescriptorAtIndex:(NSInteger)anIndex; 81 - - (NSInteger)numberOfItems; 82 - - (NSAppleEventDescriptor *)paramDescriptorForKeyword:(AEKeyword)keyword; 83 - - (AEReturnID)returnID; 84 - 85 - - (void)setAttributeDescriptor:(NSAppleEventDescriptor *)descriptor 86 - forKeyword:(AEKeyword)keyword; 87 - - (void)setDescriptor:(NSAppleEventDescriptor *)descriptor 88 - forKeyword:(AEKeyword)keyword; 89 - - (void)setParamDescriptor:(NSAppleEventDescriptor *)descriptor 90 - forKeyword:(AEKeyword)keyword; 91 - 92 - @end 93 - 94 - #endif
-284
src/Foundation/NSAppleEventDescriptor.mm
··· 1 - #include "NSAppleEventDescriptor.h" 2 - #include <util/debug.h> 3 - 4 - @implementation NSAppleEventDescriptor 5 - 6 - 7 - + (NSAppleEventDescriptor *)appleEventWithEventClass:(AEEventClass)eventClass 8 - eventID:(AEEventID)eventID 9 - targetDescriptor:(NSAppleEventDescriptor *)addressDescriptor 10 - returnID:(AEReturnID)returnID 11 - transactionID:(AETransactionID)transactionID 12 - { 13 - return [[[self alloc] initWithEventClass: eventClass 14 - eventID: eventID 15 - targetDescriptor: addressDescriptor 16 - returnID: returnID 17 - transactionID: transactionID] autorelease]; 18 - } 19 - 20 - + (NSAppleEventDescriptor *)descriptorWithBoolean:(Boolean)boolean 21 - { 22 - STUB(); 23 - return [[self alloc] init]; 24 - } 25 - 26 - + (NSAppleEventDescriptor *)descriptorWithDescriptorType:(DescType)descriptorType 27 - bytes:(const void *)bytes 28 - length:(NSUInteger)byteCount 29 - { 30 - return [[[self alloc] initWithDescriptorType: descriptorType 31 - bytes: bytes 32 - length: byteCount] autorelease]; 33 - } 34 - 35 - + (NSAppleEventDescriptor *)descriptorWithDescriptorType:(DescType)descriptorType 36 - data:(NSData *)data 37 - { 38 - return [[[self alloc] initWithDescriptorType: descriptorType 39 - data: data] autorelease]; 40 - } 41 - 42 - + (NSAppleEventDescriptor *)descriptorWithEnumCode:(OSType)enumerator 43 - { 44 - STUB(); 45 - return [[self alloc] init]; 46 - } 47 - 48 - + (NSAppleEventDescriptor *)descriptorWithInt32:(SInt32)signedInt 49 - { 50 - STUB(); 51 - return [[self alloc] init]; 52 - } 53 - 54 - + (NSAppleEventDescriptor *)descriptorWithString:(NSString *)string 55 - { 56 - STUB(); 57 - return [[self alloc] init]; 58 - } 59 - 60 - + (NSAppleEventDescriptor *)descriptorWithTypeCode:(OSType)typeCode 61 - { 62 - STUB(); 63 - return [[self alloc] init]; 64 - } 65 - 66 - + (NSAppleEventDescriptor *)listDescriptor 67 - { 68 - return [[[self alloc] initListDescriptor] autorelease]; 69 - } 70 - 71 - + (NSAppleEventDescriptor *)nullDescriptor 72 - { 73 - STUB(); 74 - return [[self alloc] init]; 75 - } 76 - 77 - + (NSAppleEventDescriptor *)recordDescriptor 78 - { 79 - return [[[self alloc] initRecordDescriptor] autorelease]; 80 - } 81 - 82 - - (id)initListDescriptor 83 - { 84 - STUB(); 85 - return [self init]; 86 - } 87 - 88 - - (id)initRecordDescriptor 89 - { 90 - STUB(); 91 - return [self init]; 92 - } 93 - 94 - - (id)initWithAEDescNoCopy:(const AEDesc *)aeDesc 95 - { 96 - STUB(); 97 - return [self init]; 98 - } 99 - 100 - - (id)initWithDescriptorType:(DescType)descriptorType 101 - bytes:(const void *)bytes 102 - length:(NSUInteger)byteCount 103 - { 104 - STUB(); 105 - return [self init]; 106 - } 107 - 108 - - (id)initWithDescriptorType:(DescType)descriptorType 109 - data:(NSData *)data 110 - { 111 - STUB(); 112 - return [self init]; 113 - } 114 - 115 - - (id)initWithEventClass:(AEEventClass)eventClass 116 - eventID:(AEEventID)eventID 117 - targetDescriptor:(NSAppleEventDescriptor *)addressDescriptor 118 - returnID:(AEReturnID)returnID 119 - transactionID:(AETransactionID)transactionID 120 - { 121 - STUB(); 122 - return [self init]; 123 - } 124 - 125 - - (const AEDesc *)aeDesc 126 - { 127 - STUB(); 128 - return NULL; 129 - } 130 - 131 - - (NSAppleEventDescriptor *)attributeDescriptorForKeyword:(AEKeyword)keyword 132 - { 133 - STUB(); 134 - return NULL; 135 - } 136 - 137 - - (Boolean)booleanValue 138 - { 139 - STUB(); 140 - return false; 141 - } 142 - 143 - - (SInt32)int32Value 144 - { 145 - STUB(); 146 - return 0; 147 - } 148 - 149 - - (NSString *)stringValue 150 - { 151 - STUB(); 152 - return NULL; 153 - } 154 - 155 - - (DescType)descriptorType 156 - { 157 - STUB(); 158 - return 0; 159 - } 160 - 161 - - (OSType)enumCodeValue 162 - { 163 - STUB(); 164 - return 0; 165 - } 166 - 167 - - (AEEventClass)eventClass 168 - { 169 - STUB(); 170 - return 0; 171 - } 172 - 173 - - (AEEventID)eventID 174 - { 175 - STUB(); 176 - return 0; 177 - } 178 - 179 - - (AETransactionID)transactionID 180 - { 181 - STUB(); 182 - return 0; 183 - } 184 - 185 - - (OSType)typeCodeValue 186 - { 187 - STUB(); 188 - return 0; 189 - } 190 - 191 - - (NSAppleEventDescriptor *)coerceToDescriptorType:(DescType)descriptorType 192 - { 193 - STUB(); 194 - return NULL; 195 - } 196 - 197 - - (NSData *)data 198 - { 199 - STUB(); 200 - return NULL; 201 - } 202 - 203 - - (NSAppleEventDescriptor *)descriptorAtIndex:(NSInteger)anIndex 204 - { 205 - STUB(); 206 - return NULL; 207 - } 208 - 209 - - (NSAppleEventDescriptor *)descriptorForKeyword:(AEKeyword)keyword 210 - { 211 - STUB(); 212 - return NULL; 213 - } 214 - 215 - 216 - - (void)insertDescriptor:(NSAppleEventDescriptor *)descriptor 217 - atIndex:(NSInteger)anIndex 218 - { 219 - STUB(); 220 - } 221 - 222 - - (void)removeDescriptorAtIndex:(NSInteger)anIndex 223 - { 224 - STUB(); 225 - } 226 - 227 - - (void)removeDescriptorWithKeyword:(AEKeyword)keyword 228 - { 229 - STUB(); 230 - } 231 - 232 - - (void)removeParamDescriptorWithKeyword:(AEKeyword)keyword 233 - { 234 - STUB(); 235 - } 236 - 237 - 238 - - (AEKeyword)keywordForDescriptorAtIndex:(NSInteger)anIndex 239 - { 240 - STUB(); 241 - return 0; 242 - } 243 - 244 - - (NSInteger)numberOfItems 245 - { 246 - STUB(); 247 - return 0; 248 - } 249 - 250 - - (NSAppleEventDescriptor *)paramDescriptorForKeyword:(AEKeyword)keyword 251 - { 252 - STUB(); 253 - return 0; 254 - } 255 - 256 - - (AEReturnID)returnID 257 - { 258 - STUB(); 259 - return 0; 260 - } 261 - 262 - 263 - - (void)setAttributeDescriptor:(NSAppleEventDescriptor *)descriptor 264 - forKeyword:(AEKeyword)keyword 265 - { 266 - STUB(); 267 - } 268 - 269 - - (void)setDescriptor:(NSAppleEventDescriptor *)descriptor 270 - forKeyword:(AEKeyword)keyword 271 - 272 - { 273 - STUB(); 274 - } 275 - 276 - - (void)setParamDescriptor:(NSAppleEventDescriptor *)descriptor 277 - forKeyword:(AEKeyword)keyword 278 - { 279 - STUB(); 280 - } 281 - 282 - 283 - 284 - @end
-32
src/Foundation/NSAppleEventManager.h
··· 1 - #ifndef NSAPPLEEVENTMANAGER_H 2 - #define NSAPPLEEVENTMANAGER_H 3 - #include "NSAppleEventDescriptor.h" 4 - 5 - typedef const struct __NSAppleEventManagerSuspension *NSAppleEventManagerSuspensionID; 6 - struct AppleEvent; 7 - 8 - @interface NSAppleEventManager : NSObject 9 - 10 - + (NSAppleEventManager *)sharedAppleEventManager; 11 - 12 - - (NSAppleEventDescriptor *)appleEventForSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID; 13 - - (NSAppleEventDescriptor *)currentAppleEvent; 14 - - (NSAppleEventDescriptor *)currentReplyAppleEvent; 15 - 16 - - (OSErr)dispatchRawAppleEvent:(const AppleEvent *)theAppleEvent 17 - withRawReply:(AppleEvent *)theReply 18 - handlerRefCon:(UInt32)handlerRefcon; 19 - - (void)removeEventHandlerForEventClass:(AEEventClass)eventClass 20 - andEventID:(AEEventID)eventID; 21 - - (NSAppleEventDescriptor *)replyAppleEventForSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID; 22 - - (void)resumeWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID; 23 - - (void)setCurrentAppleEventAndReplyEventWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID; 24 - - (void)setEventHandler:(id)handler 25 - andSelector:(SEL)handleEventSelector 26 - forEventClass:(AEEventClass)eventClass 27 - andEventID:(AEEventID)eventID; 28 - - (NSAppleEventManagerSuspensionID)suspendCurrentAppleEvent; 29 - 30 - @end 31 - 32 - #endif
-76
src/Foundation/NSAppleEventManager.mm
··· 1 - #include "NSAppleEventManager.h" 2 - #include <util/debug.h> 3 - #include <CoreServices/MacErrors.h> 4 - 5 - @implementation NSAppleEventManager 6 - 7 - + (NSAppleEventManager *)sharedAppleEventManager 8 - { 9 - static NSAppleEventManager* instance = [[NSAppleEventManager alloc] init]; 10 - 11 - return instance; 12 - } 13 - 14 - - (NSAppleEventDescriptor *)appleEventForSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID 15 - { 16 - STUB(); 17 - return NULL; 18 - } 19 - 20 - - (NSAppleEventDescriptor *)currentAppleEvent 21 - { 22 - STUB(); 23 - return NULL; 24 - } 25 - 26 - - (NSAppleEventDescriptor *)currentReplyAppleEvent 27 - { 28 - STUB(); 29 - return NULL; 30 - } 31 - 32 - - (OSErr)dispatchRawAppleEvent:(const AppleEvent *)theAppleEvent 33 - withRawReply:(AppleEvent *)theReply 34 - handlerRefCon:(UInt32)handlerRefcon 35 - { 36 - STUB(); 37 - return unimpErr; 38 - } 39 - 40 - - (void)removeEventHandlerForEventClass:(AEEventClass)eventClass 41 - andEventID:(AEEventID)eventID 42 - { 43 - STUB(); 44 - } 45 - 46 - - (NSAppleEventDescriptor *)replyAppleEventForSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID 47 - { 48 - STUB(); 49 - return NULL; 50 - } 51 - 52 - - (void)resumeWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID 53 - { 54 - STUB(); 55 - } 56 - 57 - - (void)setCurrentAppleEventAndReplyEventWithSuspensionID:(NSAppleEventManagerSuspensionID)suspensionID 58 - { 59 - STUB(); 60 - } 61 - 62 - - (void)setEventHandler:(id)handler 63 - andSelector:(SEL)handleEventSelector 64 - forEventClass:(AEEventClass)eventClass 65 - andEventID:(AEEventID)eventID 66 - { 67 - STUB(); 68 - } 69 - 70 - - (NSAppleEventManagerSuspensionID)suspendCurrentAppleEvent 71 - { 72 - STUB(); 73 - return NULL; 74 - } 75 - 76 - @end
-25
src/Foundation/NSDarwinBundle.h
··· 1 - #ifndef NSDARWINBUNDLE_H 2 - #define NSDARWINBUNDLE_H 3 - #import <Foundation/NSBundle.h> 4 - 5 - @interface NSDarwinBundle : NSBundle 6 - 7 - @end 8 - 9 - // NSBundle private implementation details 10 - @interface NSBundle (Private) 11 - + (long) _loadModuleWithFilename: (NSString*)filename 12 - errorStream: (FILE*)errorStream 13 - loadCallback: (void (*)(Class, struct objc_category *))loadCallback 14 - header: (void**)header 15 - debugFilename: (NSString*)debugFilename; 16 - @end 17 - 18 - @interface NSBundle (NSBundle_Darling) 19 - 20 - +(NSBundle*) x_mainBundle; 21 - 22 - @end 23 - 24 - #endif 25 -
-119
src/Foundation/NSDarwinBundle.mm
··· 1 - #include "NSDarwinBundle.h" 2 - #import <Foundation/NSAutoreleasePool.h> 3 - #import <Foundation/NSProcessInfo.h> 4 - #include <string> 5 - #include <algorithm> 6 - #include <unistd.h> 7 - #include <util/debug.h> 8 - #include <libdyld/MachOMgr.h> 9 - #include <libdyld/MachOObject.h> 10 - #include <libdyld/dl_public.h> 11 - 12 - extern int g_argc asm("NXArgc"); 13 - extern char** g_argv asm("NXArgv"); 14 - static NSBundle* _mainBundle = 0; 15 - static NSAutoreleasePool* g_pool = 0; 16 - 17 - static void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel); 18 - 19 - __attribute__((constructor)) static void myinit() 20 - { 21 - if (g_argv != nullptr) 22 - GSInitializeProcess(g_argc, g_argv, environ); 23 - LOG << "Swizzling methods in NSBundle\n"; 24 - 25 - // MethodSwizzle(objc_getMetaClass("NSBundle"), @selector(mainBundle), @selector(x_mainBundle)); 26 - //[NSBundle mainBundle]; 27 - 28 - // Many OS X apps assume that there is a "default" autorelease pool provided 29 - g_pool = [[NSAutoreleasePool alloc] init]; 30 - } 31 - 32 - __attribute__((destructor)) static void myexit() 33 - { 34 - [g_pool drain]; 35 - g_pool = 0; 36 - } 37 - 38 - @implementation NSDarwinBundle 39 - + (long) _loadModuleWithFilename: (NSString*)filename 40 - errorStream: (FILE*)errorStream 41 - loadCallback: (void (*)(Class, struct objc_category *))loadCallback 42 - header: (void**)header 43 - debugFilename: (NSString*)debugFilename 44 - { 45 - const char* path = [filename UTF8String]; 46 - void* lib = __darwin_dlopen(path, DARWIN_RTLD_LAZY); 47 - 48 - // TODO: report loaded classes via loadCallback 49 - 50 - if (!lib) 51 - fprintf(errorStream, "Failed to __darwin_dlopen: %s\n", __darwin_dlerror()); 52 - 53 - return lib ? 0 : 1; 54 - } 55 - 56 - @end 57 - 58 - @implementation NSBundle (NSBundle_Darling) 59 - 60 - //+(NSBundle*) x_mainBundle 61 - +(NSBundle*) mainBundle 62 - { 63 - LOG << "x_mainBundle() called\n"; 64 - if (!_mainBundle) 65 - { 66 - std::string path = Darling::MachOMgr::instance()->mainModule()->path(); 67 - size_t pos; 68 - 69 - //size_t pos = path.find_last_of('/'); 70 - //if (pos == std::string::npos) 71 - // return nil; 72 - 73 - //path.resize(pos+1); 74 - //path += "Resources"; 75 - 76 - if ((pos = path.rfind("Contents/")) != std::string::npos) 77 - { 78 - path.resize(pos+8); 79 - } 80 - else if ((pos = path.rfind(".app/")) != std::string::npos) 81 - { 82 - // "path.endsWith()" 83 - // if (path.compare(path.size()-7, 7, "/MacOS/") == 0) 84 - // path.resize(path.size() - 7); 85 - path.resize(pos+4); 86 - } 87 - 88 - LOG << "NSBundle::x_mainBundle(): deduced " << path << " as resource path\n"; 89 - 90 - _mainBundle = [self alloc]; 91 - _mainBundle = [_mainBundle initWithPath:[NSString stringWithUTF8String:path.c_str()]]; 92 - } 93 - 94 - return _mainBundle; 95 - } 96 - 97 - @end 98 - 99 - struct objc_method 100 - { 101 - SEL selector; 102 - const char* types; 103 - IMP imp; 104 - }; 105 - 106 - void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel) 107 - { 108 - Method orig_method, alt_method; 109 - 110 - orig_method = (Method) class_getInstanceMethod(aClass, orig_sel); 111 - alt_method = (Method) class_getInstanceMethod(aClass, alt_sel); 112 - 113 - if (orig_method && alt_method) 114 - { 115 - std::swap(orig_method->types, alt_method->types); 116 - std::swap(orig_method->imp, alt_method->imp); 117 - } 118 - } 119 -
-42
src/Foundation/NameTranslate.cpp
··· 1 - #include <cstring> 2 - #include <string> 3 - #include <map> 4 - 5 - namespace Darling 6 - { 7 - typedef bool (*DlsymHookFunc)(char* symName); 8 - void registerDlsymHook(DlsymHookFunc func); 9 - void deregisterDlsymHook(DlsymHookFunc func); 10 - }; 11 - 12 - static const std::map<std::string, std::string> g_mapping { 13 - std::make_pair<std::string,std::string>("OBJC_CLASS_$_NSBundle", "_OBJC_CLASS_NSDarwinBundle"), 14 - std::make_pair<std::string,std::string>("OBJC_METACLASS_$_NSBundle", "_OBJC_METACLASS_NSDarwinBundle"), 15 - }; 16 - 17 - static bool NameTranslator(char* symName); 18 - 19 - __attribute__((constructor)) 20 - static void initTranslation() 21 - { 22 - Darling::registerDlsymHook(NameTranslator); 23 - } 24 - 25 - __attribute__((destructor)) 26 - static void exitTranslation() 27 - { 28 - Darling::deregisterDlsymHook(NameTranslator); 29 - } 30 - 31 - static bool NameTranslator(char* name) 32 - { 33 - auto it = g_mapping.find(name); 34 - if (it != g_mapping.end()) 35 - { 36 - strcpy(name, it->second.c_str()); 37 - return true; 38 - } 39 - 40 - return false; 41 - } 42 -