From a35396840f497c283f2db1bb85050aba4d9a9989 Mon Sep 17 00:00:00 2001 From: meancoot Date: Thu, 12 Dec 2013 14:49:18 -0500 Subject: [PATCH] =?UTF-8?q?(Apple)=20Replace=20obj-c=E2=80=99s=20built=20i?= =?UTF-8?q?n=20boxing=20with=20macros=20that=20can=20be=20used=20with=20ol?= =?UTF-8?q?der=20versions=20of=20the=20os=20x=20build=20tools.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apple/OSX/platform.m | 4 ++-- apple/OSX/settings.m | 16 ++++++------- apple/common/RAGameView.m | 2 +- apple/common/RetroArch_Apple.h | 6 +++++ apple/common/utility.m | 22 ++++++++--------- apple/iOS/browser.m | 6 ++--- apple/iOS/menu.m | 44 +++++++++++++++++----------------- apple/iOS/platform.m | 2 +- 8 files changed, 54 insertions(+), 48 deletions(-) diff --git a/apple/OSX/platform.m b/apple/OSX/platform.m index 44bc700c3a..8b1c3a432e 100644 --- a/apple/OSX/platform.m +++ b/apple/OSX/platform.m @@ -114,7 +114,7 @@ static const void* const associated_core_key = &associated_core_key; const core_info_list_t* cores = apple_core_info_list_get(); for (int i = 0; cores && i != cores->count; i ++) { - NSString* desc = @(cores->list[i].display_name); + NSString* desc = BOXSTRING(cores->list[i].display_name); objc_setAssociatedObject(desc, associated_core_key, apple_get_core_id(&cores->list[i]), OBJC_ASSOCIATION_RETAIN_NONATOMIC); [cb addItemWithObjectValue:desc]; } @@ -225,7 +225,7 @@ static const void* const associated_core_key = &associated_core_key; - (void)loadingCore:(const NSString*)core withFile:(const char*)file { if (file) - [NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:[NSURL fileURLWithPath:@(file)]]; + [NSDocumentController.sharedDocumentController noteNewRecentDocumentURL:[NSURL fileURLWithPath:BOXSTRING(file)]]; } - (void)unloadingCore:(const NSString*)core diff --git a/apple/OSX/settings.m b/apple/OSX/settings.m index 5ddfc698da..8a3b25c08f 100644 --- a/apple/OSX/settings.m +++ b/apple/OSX/settings.m @@ -69,12 +69,12 @@ static const void* associated_name_tag = (void*)&associated_name_tag; // Set value switch (aSetting->type) { - case ST_INT: self.numericValue = @(*aSetting->value.integer); break; - case ST_UINT: self.numericValue = @(*aSetting->value.unsigned_integer); break; - case ST_FLOAT: self.numericValue = @(*aSetting->value.fraction); break; - case ST_STRING: self.stringValue = @( aSetting->value.string); break; - case ST_PATH: self.stringValue = @( aSetting->value.string); break; - case ST_BOOL: self.booleanValue = *aSetting->value.boolean; break; + case ST_INT: self.numericValue = BOXINT (*aSetting->value.integer); break; + case ST_UINT: self.numericValue = BOXUINT (*aSetting->value.unsigned_integer); break; + case ST_FLOAT: self.numericValue = BOXFLOAT (*aSetting->value.fraction); break; + case ST_STRING: self.stringValue = BOXSTRING( aSetting->value.string); break; + case ST_PATH: self.stringValue = BOXSTRING( aSetting->value.string); break; + case ST_BOOL: self.booleanValue = *aSetting->value.boolean; break; case ST_BIND: [self updateInputString]; break; default: break; } @@ -121,7 +121,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; - (void)updateInputString { char buffer[256]; - self.stringValue = @(setting_data_get_string_representation(_setting, buffer, sizeof(buffer))); + self.stringValue = BOXSTRING(setting_data_get_string_representation(_setting, buffer, sizeof(buffer))); } - (void)dismissBinder @@ -304,7 +304,7 @@ static const void* associated_name_tag = (void*)&associated_name_tag; const rarch_setting_t* setting = &setting_data[[item intValue]]; if ([tableColumn.identifier isEqualToString:@"title"]) - return [self labelAccessoryFor:@(setting->short_description) onTable:outlineView]; + return [self labelAccessoryFor:BOXSTRING(setting->short_description) onTable:outlineView]; else if([tableColumn.identifier isEqualToString:@"accessory"]) { RASettingCell* s = nil; diff --git a/apple/common/RAGameView.m b/apple/common/RAGameView.m index 012cedc8f9..e0983464fd 100644 --- a/apple/common/RAGameView.m +++ b/apple/common/RAGameView.m @@ -528,7 +528,7 @@ gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name) { #ifdef MAC_OS_X_VERSION_10_7 return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID), - (__bridge CFStringRef)@(symbol_name)); + (__bridge CFStringRef)BOXSTRING(symbol_name)); #else return (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(CFBundleGetBundleWithIdentifier(GLFrameworkID), (CFStringRef)symbol_name); diff --git a/apple/common/RetroArch_Apple.h b/apple/common/RetroArch_Apple.h index b3c233b46a..422bab0ebc 100644 --- a/apple/common/RetroArch_Apple.h +++ b/apple/common/RetroArch_Apple.h @@ -72,4 +72,10 @@ extern NSString *apple_get_core_display_name(NSString *core_id); // frontend/platform/platform_apple.c extern void apple_frontend_post_event(void (*fn)(void*), void* userdata); +// +#define BOXSTRING(x) [NSString stringWithUTF8String:x] +#define BOXINT(x) [NSNumber numberWithInt:x] +#define BOXUINT(x) [NSNumber numberWithUnsignedInt:x] +#define BOXFLOAT(x) [NSNumber numberWithDouble:x] + #endif diff --git a/apple/common/utility.m b/apple/common/utility.m index ed975fbcaf..09a940ff28 100644 --- a/apple/common/utility.m +++ b/apple/common/utility.m @@ -50,7 +50,7 @@ NSString* objc_get_value_from_config(config_file_t* config, NSString* name, NSSt if (config) config_get_string(config, [name UTF8String], &data); - NSString* result = data ? @(data) : defaultValue; + NSString* result = data ? BOXSTRING(data) : defaultValue; free(data); return result; } @@ -59,13 +59,13 @@ NSString* objc_get_value_from_config(config_file_t* config, NSString* name, NSSt NSString *apple_get_core_id(const core_info_t *core) { char buf[PATH_MAX]; - return @(apple_core_info_get_id(core, buf, sizeof(buf))); + return BOXSTRING(apple_core_info_get_id(core, buf, sizeof(buf))); } NSString *apple_get_core_display_name(NSString *core_id) { const core_info_t *core = apple_core_info_list_get_by_id(core_id.UTF8String); - return core ? @(core->display_name) : core_id; + return core ? BOXSTRING(core->display_name) : core_id; } // Number formatter class for setting strings @@ -78,25 +78,25 @@ NSString *apple_get_core_display_name(NSString *core_id) if (setting->min != setting->max) { - self.minimum = @(setting->min); - self.maximum = @(setting->max); + self.minimum = BOXFLOAT(setting->min); + self.maximum = BOXFLOAT(setting->max); } else { if (setting->type == ST_INT) { - self.minimum = @(INT_MIN); - self.maximum = @(INT_MAX); + self.minimum = BOXINT(INT_MIN); + self.maximum = BOXINT(INT_MAX); } else if (setting->type == ST_UINT) { - self.minimum = @(0); - self.maximum = @(UINT_MAX); + self.minimum = BOXUINT(0); + self.maximum = BOXUINT(UINT_MAX); } else if (setting->type == ST_FLOAT) { - self.minimum = @(FLT_MIN); - self.maximum = @(FLT_MAX); + self.minimum = BOXFLOAT(FLT_MIN); + self.maximum = BOXFLOAT(FLT_MAX); } } } diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 8530092e54..30e0672151 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -56,7 +56,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar + (RADirectoryItem*)directoryItemFromElement:(struct string_list_elem*)element { RADirectoryItem* item = [RADirectoryItem new]; - item.path = @(element->data); + item.path = BOXSTRING(element->data); item.isDirectory = element->attr.b; return item; } @@ -100,7 +100,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar { _path = path ? path : NSHomeDirectory(); _directoryDelegate = delegate; - _extensions = extensions ? @(extensions) : 0; + _extensions = extensions ? BOXSTRING(extensions) : 0; self = [super initWithStyle:UITableViewStylePlain]; self.hidesHeaders = YES; @@ -327,7 +327,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar { const char* basename = path_basename(contents->elems[i].data); - RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:@(basename) association:@(contents->elems[i].data) + RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(basename) association:BOXSTRING(contents->elems[i].data) action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL]; [items addObject:item]; } diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index ecb422a16c..80fee20a4d 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -27,12 +27,12 @@ static void RunActionSheet(const char* title, const struct string_list* items, UIView* parent, id delegate) { UIActionSheet* actionSheet = [UIActionSheet new]; - actionSheet.title = @(title); + actionSheet.title = BOXSTRING(title); actionSheet.delegate = delegate; for (int i = 0; i < items->size; i ++) { - [actionSheet addButtonWithTitle:@(items->elems[i].data)]; + [actionSheet addButtonWithTitle:BOXSTRING(items->elems[i].data)]; } actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"]; @@ -193,11 +193,11 @@ static void RunActionSheet(const char* title, const struct string_list* items, U } char buffer[256]; - result.textLabel.text = @(self.setting->short_description); + result.textLabel.text = BOXSTRING(self.setting->short_description); if (self.setting) { - result.detailTextLabel.text = @(setting_data_get_string_representation(self.setting, buffer, sizeof(buffer))); + result.detailTextLabel.text = BOXSTRING(setting_data_get_string_representation(self.setting, buffer, sizeof(buffer))); if (self.setting->type == ST_PATH) result.detailTextLabel.text = [result.detailTextLabel.text lastPathComponent]; @@ -207,7 +207,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U - (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Enter new value" message:@(self.setting->short_description) delegate:self + UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Enter new value" message:BOXSTRING(self.setting->short_description) delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; alertView.alertViewStyle = UIAlertViewStylePlainTextInput; @@ -215,7 +215,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U char buffer[256]; field.delegate = self.formatter; - field.placeholder = @(setting_data_get_string_representation(self.setting, buffer, sizeof(buffer))); + field.placeholder = BOXSTRING(setting_data_get_string_representation(self.setting, buffer, sizeof(buffer))); [alertView show]; } @@ -263,7 +263,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U result.accessoryView = [UISwitch new]; } - result.textLabel.text = @(self.setting->short_description); + result.textLabel.text = BOXSTRING(self.setting->short_description); [(id)result.accessoryView removeTarget:nil action:NULL forControlEvents:UIControlEventValueChanged]; [(id)result.accessoryView addTarget:self action:@selector(handleBooleanSwitch:) forControlEvents:UIControlEventValueChanged]; @@ -294,7 +294,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U - (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller { - NSString* path = [@(self.setting->value.string) stringByDeletingLastPathComponent]; + NSString* path = [BOXSTRING(self.setting->value.string) stringByDeletingLastPathComponent]; RADirectoryList* list = [[RADirectoryList alloc] initWithPath:path extensions:self.setting->values forDirectory:false delegate:self]; [controller.navigationController pushViewController:list animated:YES]; } @@ -355,7 +355,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U - (void)wasSelectedOnTableView:(UITableView *)tableView ofController:(UIViewController *)controller { self.alert = [[UIAlertView alloc] initWithTitle:@"RetroArch" - message:@(self.setting->short_description) + message:BOXSTRING(self.setting->short_description) delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Clear Keyboard", @"Clear Joystick", @"Clear Axis", nil]; @@ -518,10 +518,10 @@ static void RunActionSheet(const char* title, const struct string_list* items, U for (int i = 0; _history && i != rom_history_size(_history); i ++) { - RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:@(path_basename(apple_rom_history_get_path(weakSelf.history, i))) - action:^{ apple_run_core(@(apple_rom_history_get_core_path(weakSelf.history, i)), - apple_rom_history_get_path(weakSelf.history, i)); } - detail:^{ return @(apple_rom_history_get_core_name(weakSelf.history, i)); }]; + RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(path_basename(apple_rom_history_get_path(weakSelf.history, i))) + action:^{ apple_run_core(BOXSTRING(apple_rom_history_get_core_path(weakSelf.history, i)), + apple_rom_history_get_path(weakSelf.history, i)); } + detail:^{ return BOXSTRING(apple_rom_history_get_core_name(weakSelf.history, i)); }]; [section addObject:item]; } } @@ -548,14 +548,14 @@ static void RunActionSheet(const char* title, const struct string_list* items, U { if ((self = [super initWithStyle:UITableViewStyleGrouped])) { - self.title = @(group->name); + self.title = BOXSTRING(group->name); NSMutableArray* settings = nil; for (const rarch_setting_t* i = group + 1; i->type != ST_END_GROUP; i ++) { if (i->type == ST_SUB_GROUP) - settings = [NSMutableArray arrayWithObjects:@(i->name), nil]; + settings = [NSMutableArray arrayWithObjects:BOXSTRING(i->name), nil]; else if (i->type == ST_END_SUB_GROUP) { if (settings.count) @@ -592,7 +592,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U if ((self = [super initWithStyle:UITableViewStyleGrouped])) { if (apple_core_info_has_custom_config(core.UTF8String)) - _pathToSave = @(apple_core_info_get_custom_config(core.UTF8String, buffer, sizeof(buffer))); + _pathToSave = BOXSTRING(apple_core_info_get_custom_config(core.UTF8String, buffer, sizeof(buffer))); else _pathToSave = apple_platform.globalConfigFile; @@ -612,7 +612,7 @@ static void RunActionSheet(const char* title, const struct string_list* items, U for (const rarch_setting_t* i = setting_data; i->type != ST_NONE; i ++) if (i->type == ST_GROUP) - [settings addObject:[RAMenuItemBasic itemWithDescription:@(i->name) action: + [settings addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING(i->name) action: ^{ [weakSelf.navigationController pushViewController:[[RASettingsGroupMenu alloc] initWithGroup:i] animated:YES]; }]]; @@ -677,7 +677,7 @@ static const void* const associated_core_key = &associated_core_key; const core_info_list_t* core_list = apple_core_info_list_get(); for (int i = 0; i < core_list->count; i ++) - [cores addObject:[RAMenuItemBasic itemWithDescription:@(core_list->list[i].display_name) + [cores addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING(core_list->list[i].display_name) association:apple_get_core_id(&core_list->list[i]) action: ^(id userdata) { [weakSelf showCoreConfigFor:userdata]; } detail: ^(id userdata) { return apple_core_info_has_custom_config([userdata UTF8String]) ? @"[Custom]" : @"[Global]"; }]]; @@ -718,7 +718,7 @@ static const void* const associated_core_key = &associated_core_key; char path[PATH_MAX]; apple_core_info_get_custom_config(core_id.UTF8String, path, sizeof(path)); - if (![[NSFileManager defaultManager] copyItemAtPath:apple_platform.globalConfigFile toPath:@(path) error:nil]) + if (![[NSFileManager defaultManager] copyItemAtPath:apple_platform.globalConfigFile toPath:BOXSTRING(path) error:nil]) RARCH_WARN("Could not create custom config at %s", path); [self.tableView reloadData]; } @@ -752,9 +752,9 @@ static const void* const associated_core_key = &associated_core_key; if (options) { for (int i = 0; i != core_option_size(options); i ++) - [section addObject:[RAMenuItemBasic itemWithDescription:@(core_option_get_desc(options, i)) association:nil + [section addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING(core_option_get_desc(options, i)) association:nil action:^{ [weakSelf editValue:i]; } - detail:^{ return @(core_option_get_val(options, i)); }]]; + detail:^{ return BOXSTRING(core_option_get_val(options, i)); }]]; } else [section addObject:[RAMenuItemBasic itemWithDescription:@"The running core has no options." action:NULL]]; @@ -911,7 +911,7 @@ static const void* const associated_core_key = &associated_core_key; { char buffer[1024]; while (fgets(buffer, 1024, file)) - [data addObject:[RAMenuItemBasic itemWithDescription:@(buffer) action:NULL]]; + [data addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING(buffer) action:NULL]]; fclose(file); } else diff --git a/apple/iOS/platform.m b/apple/iOS/platform.m index ddfbbe6ac7..feed9af655 100644 --- a/apple/iOS/platform.m +++ b/apple/iOS/platform.m @@ -310,7 +310,7 @@ static void handle_touch_event(NSArray* touches) _enabledOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; // Set bluetooth mode - ios_set_bluetooth_mode(@(apple_frontend_settings.bluetooth_mode)); + ios_set_bluetooth_mode(BOXSTRING(apple_frontend_settings.bluetooth_mode)); ios_set_logging_state([RetroArch_iOS get].logPath.UTF8String, apple_frontend_settings.logging_enabled); }