Skip to content

Commit cc5e0e5

Browse files
committed
[WIP] Groundwork for loading new type maps
1 parent 201cdd7 commit cc5e0e5

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/monodroid/jni/embedded-assemblies.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,25 +447,41 @@ EmbeddedAssemblies::gather_bundled_assemblies_from_apk (const char* apk, monodro
447447
}
448448

449449
#if defined (DEBUG) || !defined (ANDROID)
450+
bool
451+
EmbeddedAssemblies::typemap_load_index (const char *index_path)
452+
{
453+
return false;
454+
}
455+
450456
void
451457
EmbeddedAssemblies::try_load_typemaps_from_directory (const char *path)
452458
{
453459
// read the entire typemap file into a string
454460
// process the string using the add_type_mapping
455-
char *dir_path = utils.path_combine (path, "typemaps");
456-
if (dir_path == nullptr || !utils.directory_exists (dir_path)) {
457-
log_warn (LOG_DEFAULT, "directory does not exist: `%s`", dir_path);
458-
free (dir_path);
461+
simple_pointer_guard<char[]> dir_path (utils.path_combine (path, "typemaps"));
462+
463+
if (!utils.directory_exists (dir_path)) {
464+
log_warn (LOG_DEFAULT, "directory does not exist: `%s`", dir_path.get ());
459465
return;
460466
}
461467

462468
monodroid_dir_t *dir;
463469
if ((dir = utils.monodroid_opendir (dir_path)) == nullptr) {
464-
log_warn (LOG_DEFAULT, "could not open directory: `%s`", dir_path);
465-
free (dir_path);
470+
log_warn (LOG_DEFAULT, "could not open directory: `%s`", dir_path.get ());
466471
return;
467472
}
468473

474+
simple_pointer_guard<char[]> index_path (utils.path_combine (dir_path, "typemap.index"));
475+
if (!utils.file_exists (index_path)) {
476+
log_fatal (LOG_ASSEMBLY, "TypeMap data index file not found: %s", index_path.get ());
477+
exit (FATAL_EXIT_NO_ASSEMBLIES); // TODO: use a new error code here
478+
}
479+
480+
if (!typemap_load_index (index_path)) {
481+
log_fatal (LOG_ASSEMBLY, "Unable to load TypeMap data index from '%s'", index_path.get ());
482+
exit (FATAL_EXIT_NO_ASSEMBLIES); // TODO: use a new error code here
483+
}
484+
469485
monodroid_dirent_t *e;
470486
while ((e = androidSystem.readdir (dir)) != nullptr) {
471487
#if WINDOWS
@@ -489,8 +505,6 @@ EmbeddedAssemblies::try_load_typemaps_from_directory (const char *path)
489505
}
490506
}
491507
utils.monodroid_closedir (dir);
492-
free (dir_path);
493-
return;
494508
}
495509
#endif
496510

src/monodroid/jni/embedded-assemblies.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace xamarin::android::internal {
7272
void extract_int (const char **header, const char *source_apk, const char *source_entry, const char *key_name, int *value);
7373
#if defined (DEBUG) || !defined (ANDROID)
7474
bool add_type_mapping (TypeMappingInfo **info, const char *source_apk, const char *source_entry, const char *addr);
75+
bool typemap_load_index (const char *index_path);
7576
#endif // DEBUG || !ANDROID
7677
bool register_debug_symbols_for_assembly (const char *entry_name, MonoBundledAssembly *assembly, const mono_byte *debug_contents, int debug_size);
7778

0 commit comments

Comments
 (0)