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

[WebIDL] Generate correct code when a pointer is returned from an interface method #21944

Merged
merged 1 commit into from
May 15, 2024

Conversation

agnickolov
Copy link
Contributor

@agnickolov agnickolov commented May 14, 2024

This fixes the problem reported under issue #14745. The previous two PRs were never completed:
#15651
#14795

Those developers are no longer involved with the project this issue is blocking and it fell to me to get it through to completion. I cleaned up the test code a bit from the earlier PRs as well. Please look at the previous PRs for details.

var self = Module['getCache'](Module['%s'])[$0];
if (!self.hasOwnProperty('%s')) throw 'a JSImplementation must implement all functions, you forgot %s::%s.';
%sself['%s'](%s)%s;
}, (ptrdiff_t)this%s);
}''' % (c_return_type, func_name, dec_args, maybe_const,
basic_return, 'INT' if c_return_type not in C_FLOATS else 'DOUBLE',
basic_return, c_return_type, 'INT' if c_return_type not in C_FLOATS else 'DOUBLE',
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have EM_ASM_PTR now that we should probably use for pointer returns.

I wonder if use that then we don't need the above cast?

Maybe create a new em_asm_macro variable here that can hold the name of the macro to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a 2.5 years old PR. I can investigate with your hint and perhaps offer an improved version. I know very little about the project internals, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored it with your suggestion, but the type cast cannot be avoided - the C++ compiler still raises an error for incompatible types. I incorporated the use of EM_ASM_PTR instead of EM_ASM_INT and extracted into a variable as you suggested.

@agnickolov
Copy link
Contributor Author

agnickolov commented May 14, 2024

I'm concerned that I'm getting test failures with the fixed code.

At least one of the failures seems to be due to a configuration issue. The following unexpected line appears in the test output:
+Warning: Enlarging memory arrays, this is not fast! 16908288,25296896
I'm not sure what should be done about it, however.

Another test appears to be failing due to unmet memory management expectations. Again I have no clue what to do about that. The failures are likely caused by the newly added test allocating new objects and thus changing the memory layout.

I ended up rearranging the WebIDL test code. Hopefully that fixes the test issues. The heap checks were getting thrown off, so I moved the new test before those.

@sbc100 sbc100 changed the title Fixed WebIDL Binder to generate correct code when a pointer is return… Fixed WebIDL Binder to generate correct code when a pointer is returned from an interface method May 14, 2024
@sbc100 sbc100 changed the title Fixed WebIDL Binder to generate correct code when a pointer is returned from an interface method [WebIDL] Generate correct code when a pointer is returned from an interface method May 14, 2024
@agnickolov
Copy link
Contributor Author

All tests appear to be passing, but an archive check seems to have stalled...

return &m_ObjectProvider;
}
private:
ObjectProvider m_ObjectProvider;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it really take this complex set of interwoven classes to reproduce this issue? i.e. do you need both a provider and a factory here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, yes. A single level of indirection does not expose the issue.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

lgtm with one last comment

@sbc100 sbc100 merged commit c20fa7b into emscripten-core:main May 15, 2024
29 checks passed
@agnickolov agnickolov deleted the issue-14745 branch May 15, 2024 16:03
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.

None yet

2 participants