From 5dea37665d262d4a5d22e2bca426dd388c6d2aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= Date: Mon, 23 Jan 2023 22:05:55 -0500 Subject: [PATCH] [webcil] Minor cleanups (#81009) * replace magic constants by strlen(LITERAL) Let the C compiler do the math * Use CopyIfDifferent for webcil converter in WasmAppBuilder * WasmAppHost: serve .webcil as application/octet-stream * Add mime types for webcil in two more places * Always add to _fileWrites But log whether we actually copied anything or not Co-authored-by: Ankit Jain --- src/mono/mono/metadata/assembly.c | 4 ++-- src/mono/mono/metadata/mono-debug.c | 2 +- src/mono/mono/mini/monovm.c | 7 +++++-- src/mono/sample/wasm/Directory.Build.targets | 1 + src/mono/sample/wasm/simple-server/Program.cs | 2 ++ src/mono/wasm/host/WebServerStartup.cs | 2 +- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 18 +++++++++++++----- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/mono/mono/metadata/assembly.c b/src/mono/mono/metadata/assembly.c index adb2ae0d5306ef..6375754f97f04e 100644 --- a/src/mono/mono/metadata/assembly.c +++ b/src/mono/mono/metadata/assembly.c @@ -1460,8 +1460,8 @@ bundled_assembly_match (const char *bundled_name, const char *name) return TRUE; /* if they want a .dll and we have the matching .webcil, return it */ if (g_str_has_suffix (bundled_name, ".webcil") && g_str_has_suffix (name, ".dll")) { - size_t bprefix = strlen (bundled_name) - 7; - size_t nprefix = strlen (name) - 4; + size_t bprefix = strlen (bundled_name) - strlen (".webcil"); + size_t nprefix = strlen (name) - strlen (".dll"); if (bprefix == nprefix && strncmp (bundled_name, name, bprefix) == 0) return TRUE; } diff --git a/src/mono/mono/metadata/mono-debug.c b/src/mono/mono/metadata/mono-debug.c index 958b33657d43a9..993a6fd1edfbec 100644 --- a/src/mono/mono/metadata/mono-debug.c +++ b/src/mono/mono/metadata/mono-debug.c @@ -1105,7 +1105,7 @@ bsymfile_match (BundledSymfile *bsymfile, const char *assembly_name) #ifdef ENABLE_WEBCIL const char *p = strstr (assembly_name, ".webcil"); /* if assembly_name ends with .webcil, check if aname matches, with a .dll extension instead */ - if (p && *(p + 7) == 0) { + if (p && *(p + strlen(".webcil")) == 0) { size_t n = p - assembly_name; if (!strncmp (bsymfile->aname, assembly_name, n) && !strcmp (bsymfile->aname + n, ".dll")) diff --git a/src/mono/mono/mini/monovm.c b/src/mono/mono/mini/monovm.c index 63e25581ac7a61..3730d6b256da56 100644 --- a/src/mono/mono/mini/monovm.c +++ b/src/mono/mono/mini/monovm.c @@ -134,8 +134,11 @@ mono_core_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, c #ifdef ENABLE_WEBCIL else { /* /path/foo.dll -> /path/foo.webcil */ - size_t n = strlen (fullpath) - 4; - char *fullpath2 = g_malloc (n + 8); + size_t n = strlen (fullpath); + if (n < strlen(".dll")) + continue; + n -= strlen(".dll"); + char *fullpath2 = g_malloc (n + strlen(".webcil") + 1); g_strlcpy (fullpath2, fullpath, n + 1); g_strlcpy (fullpath2 + n, ".webcil", 8); if (g_file_test (fullpath2, G_FILE_TEST_IS_REGULAR)) { diff --git a/src/mono/sample/wasm/Directory.Build.targets b/src/mono/sample/wasm/Directory.Build.targets index e9447a94400133..9ef8935b4969c0 100644 --- a/src/mono/sample/wasm/Directory.Build.targets +++ b/src/mono/sample/wasm/Directory.Build.targets @@ -19,6 +19,7 @@ <_ServeMimeTypes>$(_ServeMimeTypes) --mime .mjs=text/javascript <_ServeMimeTypes>$(_ServeMimeTypes) --mime .cjs=text/javascript <_ServeMimeTypes>$(_ServeMimeTypes) --mime .js=text/javascript + <_ServeMimeTypes>$(_ServeMimeTypes) --mime .webcil=application/octet-stream