diff options
author | therzok <marius.ungureanu@xamarin.com> | 2019-05-12 03:24:20 +0300 |
---|---|---|
committer | therzok <marius.ungureanu@xamarin.com> | 2019-05-23 20:06:21 +0300 |
commit | efb5d2414a05486f237412935fe4627525d02b66 (patch) | |
tree | 518b41c59c832e2bba199d19f32c389b35ef3c71 /main/build/MacOSX/monostub.mm | |
parent | 9d128cbdcb2ddd5fd8a8072d6a74fa8ad6b17507 (diff) |
Reduce code duplication
Diffstat (limited to 'main/build/MacOSX/monostub.mm')
-rw-r--r-- | main/build/MacOSX/monostub.mm | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/main/build/MacOSX/monostub.mm b/main/build/MacOSX/monostub.mm index 1a897a72cb..67e9b95a2e 100644 --- a/main/build/MacOSX/monostub.mm +++ b/main/build/MacOSX/monostub.mm @@ -63,7 +63,7 @@ show_alert (NSString *msg, NSString *appName, NSString *mono_download_url) #endif static void -exit_with_message (const char *reason, char *argv0) +exit_with_message (const char *reason, const char *argv0) { NSString *appName = nil; NSDictionary *plist = [[NSBundle mainBundle] infoDictionary]; @@ -301,15 +301,15 @@ run_md_bundle_if_needed(NSString *appDir, int argc, char **argv) name = dlopen ("@loader_path/../Resources/lib/monodevelop/bin/" #name ".dylib", RTLD_LAZY); \ } -bool should_load_xammac_registrar(char *appName) +bool should_load_xammac_registrar(const char *appName) { void *libxammac; LOAD_DYLIB(libxammac); if (!libxammac) { fprintf (stderr, "Failed to load libxammac.dylib: %s\n", dlerror ()); - NSString *msg = @"This application requires Xamarin.Mac native library side-by-side."; - exit_with_message ((char *)[msg UTF8String], appName); + const char *msg = "This application requires Xamarin.Mac native library side-by-side."; + exit_with_message (msg, appName); } #if STATIC_REGISTRAR @@ -325,6 +325,13 @@ bool should_load_xammac_registrar(char *appName) #endif } +#define LOAD_SYMBOL(symbol_type, symbol_name, libName, frameworkName, appName) \ + symbol_type symbol_name = (symbol_type) dlsym (libName, #symbol_type); \ + if (!symbol_name) { \ + fprintf (stderr, "Could not load " #symbol_type "(): %s\n", dlerror ()); \ + exit_with_message ("Failed to load the " frameworkName " framework.", appName); \ + } + int main (int argc, char **argv) { //clock_t start = clock(); @@ -414,7 +421,7 @@ int main (int argc, char **argv) if (libmono == NULL) { fprintf (stderr, "Failed to load libmono%s-2.0.dylib: %s\n", use_sgen ? "sgen" : "", dlerror ()); NSString *msg = [NSString stringWithFormat:@"This application requires Mono %s or newer.", [req_mono_version UTF8String]]; - exit_with_message ((char *)[msg UTF8String], argv[0]); + exit_with_message ([msg UTF8String], argv[0]); } if (should_load_xammac_registrar (argv[0])) @@ -422,29 +429,15 @@ int main (int argc, char **argv) try_load_gobject_tracker (libmono, argv [0]); - mono_main _mono_main = (mono_main) dlsym (libmono, "mono_main"); - if (!_mono_main) { - fprintf (stderr, "Could not load mono_main(): %s\n", dlerror ()); - exit_with_message ("Failed to load the Mono framework.", argv[0]); - } - - mono_free _mono_free = (mono_free) dlsym (libmono, "mono_free"); - if (!_mono_free) { - fprintf (stderr, "Could not load mono_free(): %s\n", dlerror ()); - exit_with_message ("Failed to load the Mono framework.", argv[0]); - } - - mono_get_runtime_build_info _mono_get_runtime_build_info = (mono_get_runtime_build_info) dlsym (libmono, "mono_get_runtime_build_info"); - if (!_mono_get_runtime_build_info) { - fprintf (stderr, "Could not load mono_get_runtime_build_info(): %s\n", dlerror ()); - exit_with_message ("Failed to load the Mono framework.", argv[0]); - } + LOAD_SYMBOL(mono_main, _mono_main, libmono, "Mono", argv[0]); + LOAD_SYMBOL(mono_free, _mono_free, libmono, "Mono", argv[0]); + LOAD_SYMBOL(mono_get_runtime_build_info, _mono_get_runtime_build_info, libmono, "Mono", argv[0]); char *mono_version = _mono_get_runtime_build_info (); if (!check_mono_version (mono_version, [req_mono_version UTF8String])) { NSString *msg = [NSString stringWithFormat:@"This application requires a newer version (%s+) of the Mono framework.", [req_mono_version UTF8String]]; - exit_with_message ((char *)[msg UTF8String], argv[0]); + exit_with_message ([msg UTF8String], argv[0]); } extra_argv = get_mono_env_options (&extra_argc); |