Skip to content

Conversation

dkimitsa
Copy link
Contributor

@dkimitsa dkimitsa commented Jan 9, 2021

Bug

structures are not being copied and only their pointer being marshalled (same as in case of @ByRef). This causes number of bugs:

  • expected the copy but struct points to source struct/value. as result changes of "copy" causes changes in the source
  • struct might be located in R/O segment and any try to modify it cause GPF gitter.

The fix

make a copy of structure on heap as its required by @byval

Side effect of the fix

The fix breaks existing code that is built around this bug. An example is CGRect constructor that stops working:

public CGRect(double x, double y, double width, double height) {
    getOrigin().setX(x).setY(y);
    getSize().setWidth(width).setHeight(height);
}

After the fix getOrigin()/getSize() return a copy (byValue) structures. And changes to them doesn't affect CGRect struct itself anymore.

As result structures are not being copied and their pointer being marshalled (same as in case of @ByRef). This causes number of bugs:
- expected the copy but struct points to source struct/value. as result changes of "copy" causes changes in the source
- struct might be located in R/O segment and any try to modify it cause GPF.

The fix: to make a copy of structure on heap as its required by @byval
@dkimitsa
Copy link
Contributor Author

dkimitsa commented Jan 9, 2021

long read in post

@Tom-Ski Tom-Ski merged commit a309360 into MobiVM:master Jan 18, 2021
@dkimitsa dkimitsa deleted the fix/global_by_value_structs branch January 20, 2021 01:21
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.

2 participants