Skip to content

WebIDL Binder fixed octet[] evaluation in argument lists #15023

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

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

Conversation

CDLlo
Copy link

@CDLlo CDLlo commented Sep 10, 2021

Hello, this PR is to fix an issue which is caused by an inconsistency in webidl_binder.py which handles argument lists differently between the JSimplementations and the standard implementation. Essentially the construction of full_args consumes both the isarray and const attributes of raw while the construction of dec_args can at most consume const and never checks isarray. Swapping raw.type.name with full_typename(raw), and removing the const check to avoid double consts, allows for both cases to check both attributes and handle them properly.

Since the issue is present in the generated glue code, the unit test written for this simply checks that the JS implementation specific section of the glue code has the proper pointer argument.

If you have any questions about the specifics of the underlying bug let me know and I can elaborate to the best of my ability.

@welcome
Copy link

welcome bot commented Sep 10, 2021

Thank you for submitting a pull request! Someone will be along to review it shortly.

@CDLlo
Copy link
Author

CDLlo commented Sep 13, 2021

@sbc100 could you look over this when you get a chance?

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

This looks right to me, but see my comment on the test.

else {
console.log('JSimplementation array argument failure')
}

Copy link
Member

Choose a reason for hiding this comment

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

It would be better to test this in a more direct way than to look for a text match in the output, I think. That is, like the other tests above, to run some code that would have failed (or not even compiled) before this fix. An advantage of doing it that way is that small text output changes (say, whitespace or line breaks) would not break the test, and also, seeing running code end to end is nice.

Copy link
Author

Choose a reason for hiding this comment

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

I'll be pushing a pared down version of the unit test since each type saw the same behaviour. The reason I originally did the test above is that it avoided throwing an error message and allowed the testing script to terminate normally. The new test will actually be running the example function and without the fix will throw an error instead of terminating. Expected error below:

error: cannot initialize a parameter of type 'char' with an lvalue of type 'char *'
return self->charArrayTest(arg);
^~~
note: passing argument to parameter 'arg' here
bool charArrayTest(char arg) {

Note, in the process of rewriting the unit test for this I noticed there seems to be a similar issue with overlooking square brackets denoting arrays in the return type of functions. eg

byte[] exampleMethod(); --> char exampleMethod() {...

I avoided remedying that issue since this pr is specifically related to array types in argument lists, but I am fairly certain the issue stems from how the return_type variable is created around webidl_binder.py line 675 once again not being given an opportunity for the isArray attribute to be accounted for. Though since that variable is used in several places it is a little more tricky to ensure a fix does not adversely affect any other parts of the code.

@@ -287,5 +287,14 @@ if (isMemoryGrowthAllowed) {

//

const fs = require('fs')
const data = fs.readFileSync('glue.cpp', 'utf8')
if (data.includes("int uCharArrayTest(const unsigned char* arg, int size)")) {
Copy link
Member

Choose a reason for hiding this comment

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

What would this text have been before this fix, btw?

Copy link
Author

Choose a reason for hiding this comment

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

The current implementation would generate int uCharArrayTest(const unsigned char arg, int size) for the JS implementation

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks! Makes sense.

@kripken
Copy link
Member

kripken commented Sep 16, 2021

I'm not sure why CI failed to run here. Can you try merging in latest upstream main?

@CDLlo
Copy link
Author

CDLlo commented Sep 16, 2021

Updated with latest main commits

@@ -109,5 +109,6 @@ Assertion failed: [CHECK FAILED] Parent::Parent(val:val): Expecting <integer>
Parent:42
Assertion failed: [CHECK FAILED] Parent::voidStar(something:something): Expecting <pointer>
Assertion failed: [CHECK FAILED] StringUser::Print(anotherString:anotherString): Expecting <string>
true
Copy link
Collaborator

Choose a reason for hiding this comment

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

strcmp returns zero if the strings match so wouldn't we expect to see false here?

Copy link
Author

Choose a reason for hiding this comment

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

That would be correct, I needed to malloc some memory beforehand to get the test to work properly.

@CDLlo
Copy link
Author

CDLlo commented Sep 21, 2021

Is there anything else I could do to polish off this PR?

@CDLlo CDLlo requested a review from kripken September 27, 2021 03:45
@CDLlo CDLlo requested a review from sbc100 October 4, 2021 19:06
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. @kripken do you want to take one more like?

@sbc100
Copy link
Collaborator

sbc100 commented Nov 24, 2021

Perhaps a better title could be give to this PR?

@CDLlo CDLlo changed the title Issue-14827 WebIdl Binder fixed octet[] evaluation in argument lists Nov 29, 2021
@CDLlo CDLlo changed the title WebIdl Binder fixed octet[] evaluation in argument lists WebIDL Binder fixed octet[] evaluation in argument lists Nov 29, 2021
@CDLlo
Copy link
Author

CDLlo commented Nov 30, 2021

Updated PR name to reflect the content of the changes

Arguments which were arrays were not getting an array pointer in the argument list for only the JSimplementation glue code. This was due to passing raw.type.name to type_to_c which did not allow for the square brackets to be processed. Note that since this fix pertains to the generated glue code, testing without the fix in place will throw an error in the tester due to mismatched argument types.
@kripken
Copy link
Member

kripken commented Dec 2, 2021

Oddly CI still has not started up here. I filed an issue with CircleCI (https://support.circleci.com/hc/en-us/requests/100681 although I don't think anyone but me can open that; pasting it here so if I follow up later I don't need to search for it).

@kripken
Copy link
Member

kripken commented Dec 2, 2021

CircleCI may have resolved this on their end - please add another commit here to verify that things work (like merging in latest main). Also in #15651. Again, sorry for the annoyance...

@kripken
Copy link
Member

kripken commented Dec 8, 2021

I did a manual conflict resolution on a file here, which caused commits to be added, and now tests seem to start. There are some errors though, which look real.

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.

octet[] evaluated to char rather than char* for argument list in C++ Glue code
3 participants