Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Fixes wasi http header bug and adds a test for it #1215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

silesmo
Copy link
Member

@silesmo silesmo commented Mar 15, 2025

Fixes a bug where headers returned from a C# component wouldn't be properly set. Adds a test for it and some cleanup.

@silesmo silesmo requested review from jsturtevant and yowl March 15, 2025 14:44
Copy link
Collaborator

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the fix here around the alignment? How was the issue presenting?

@@ -889,13 +889,13 @@ impl Bindgen for FunctionBindgen<'_, '_> {
"
void* {address};
if (({size} * {list}.Count) < 1024) {{
var {ret_area} = stackalloc {element_type}[({array_size}*{list}.Count)+1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this moved the logic to add the additional 1 to the dotnet_aligned_array function, we should update

var {ret_area} = stackalloc {element_type}[{array_size}+1];
as well.

@@ -889,13 +889,13 @@ impl Bindgen for FunctionBindgen<'_, '_> {
"
void* {address};
if (({size} * {list}.Count) < 1024) {{
var {ret_area} = stackalloc {element_type}[({array_size}*{list}.Count)+1];
{address} = (void*)(((int){ret_area}) + ({align} - 1) & -{align});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this line is still required or in some cases this won't align properly since stackalloc won't align on the correct memory boundary (dotnet/csharplang#1799). Unless something else is subtly addressing this?

Copy link
Collaborator

@pavelsavara pavelsavara Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor void* AlignStackPtr(void* stackAddress, uint alignment) helper and use it everywhere.

@@ -754,7 +754,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
"
);
}
results.push(format!("(nint){ptr}"));
results.push(format!("(int){ptr}"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

@@ -26,6 +26,8 @@ interface test {
list-roundtrip: func(a: list<u8>) -> list<u8>;

string-roundtrip: func(a: string) -> string;

wasi-http-headers-roundtrip: func(a: list<tuple<string, list<u8>>>) -> list<tuple<string, list<u8>>>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to add this to https://github.com/bytecodealliance/wit-bindgen/tree/main/tests/runtime-new/lists since this test has moved to the new framework #1221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants