Skip to content

Commit c079f63

Browse files
committed
Small clean-ups
1 parent b8fe280 commit c079f63

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/mono/browser/runtime/pinvoke.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ wasm_dl_is_pinvoke_table (void *handle)
5050
static int
5151
export_compare_key (const void *k1, const void *k2)
5252
{
53-
const char *key1 = ((UnmanagedExport*)k1)->key;
54-
const char *key2 = ((UnmanagedExport*)k2)->key;
55-
56-
return strcmp (key1, key2);
53+
return strcmp (((UnmanagedExport*)k1)->key, ((UnmanagedExport*)k2)->key);
5754
}
5855

5956
static int
@@ -75,7 +72,7 @@ void*
7572
wasm_dl_get_native_to_interp (uint32_t token, const char *key, void *extra_arg)
7673
{
7774
#ifdef GEN_PINVOKE
78-
UnmanagedExport needle = { token, key, NULL };
75+
UnmanagedExport needle = { key, token, NULL };
7976
int count = (sizeof (wasm_native_to_interp_table) / sizeof (UnmanagedExport));
8077

8178
// comparison must match the one used in the PInvokeTableGenerator to ensure the same order

src/mono/browser/runtime/pinvoke.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ typedef struct {
1515
} PinvokeTable;
1616

1717
typedef struct {
18-
uint32_t token;
1918
const char *key;
19+
uint32_t token;
2020
void *func;
2121
} UnmanagedExport;
2222

src/tasks/WasmAppBuilder/JoinedString.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,21 @@ public override string ToString()
9696

9797
internal sealed class JoinedStringStreamWriter : StreamWriter
9898
{
99-
private string CompilerNewLine = Environment.NewLine;
99+
100+
// since we are intentionally using multi-line strings writes,
101+
// we want to capture the compile-time new line
102+
private string CompileTimeNewLine = """
103+
104+
""";
100105

101106
public JoinedStringStreamWriter(Stream stream) : base(stream)
102107
{
103-
NewLine = CompilerNewLine;
108+
NewLine = CompileTimeNewLine;
104109
}
105110

106111
public JoinedStringStreamWriter(string path, bool append) : base(path, append)
107112
{
108-
NewLine = CompilerNewLine;
113+
NewLine = CompileTimeNewLine;
109114
}
110115

111116
#if NET8_0_OR_GREATER

src/tasks/WasmAppBuilder/PInvokeTableGenerator.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,22 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary<string, string> m
136136
var moduleImports = new Dictionary<string, List<string>>();
137137
foreach (var module in modules.Keys)
138138
{
139-
var assemblies_pinvokes = pinvokes
139+
static string ListRefs(IGrouping<string, PInvoke> l) =>
140+
string.Join(", ", l.Select(c => c.Method.DeclaringType!.Module!.Assembly!.GetName()!.Name!).Distinct().OrderBy(n => n));
141+
142+
var imports = pinvokes
140143
.Where(l => l.Module == module && !l.Skip)
141144
.OrderBy(l => l.EntryPoint, StringComparer.Ordinal)
142145
.GroupBy(d => d.EntryPoint, StringComparer.Ordinal)
143-
.Select(l => $"{{\"{EscapeLiteral(l.Key)}\", {CEntryPoint(l.First())}}}, "
144-
+ "// " + string.Join(", ", l.Select(c => c.Method.DeclaringType!.Module!.Assembly!.GetName()!.Name!).Distinct().OrderBy(n => n)) + w.NewLine + " ")
146+
.Select(l => $"{{\"{EscapeLiteral(l.Key)}\", {CEntryPoint(l.First())}}}, // {ListRefs(l)}{w.NewLine} ")
145147
.ToList();
146148

147-
moduleImports[module] = assemblies_pinvokes;
149+
moduleImports[module] = imports;
148150
w.Write(
149151
$$"""
150152
151153
static PinvokeImport {{_fixupSymbolName(module)}}_imports [] = {
152-
{{string.Join("", assemblies_pinvokes)}}{NULL, NULL}
154+
{{string.Join("", imports)}}{NULL, NULL}
153155
};
154156
155157
""");
@@ -388,7 +390,7 @@ private void EmitNativeToInterp(StreamWriter w, List<PInvokeCallback> callbacks)
388390
$$"""
389391
390392
static UnmanagedExport wasm_native_to_interp_table[] = {
391-
{{callbacks.Join($",{w.NewLine} ", cb => $"{{{cb.Token}, \"{EscapeLiteral(cb.Key)}\", {cb.EntrySymbol}}}")}}
393+
{{callbacks.Join($",{w.NewLine} ", cb => $"{{\"{EscapeLiteral(cb.Key)}\", {cb.Token}, {cb.EntrySymbol}}}")}}
392394
};
393395
394396
""");

0 commit comments

Comments
 (0)