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

Calling methods on uninitialized objects crashes MicroPython #805

Closed
laurensvalk opened this issue Nov 17, 2022 · 4 comments
Closed

Calling methods on uninitialized objects crashes MicroPython #805

laurensvalk opened this issue Nov 17, 2022 · 4 comments
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: MicroPython Issues related to the MicroPython programming language

Comments

@laurensvalk
Copy link
Member

On closer inspection, [the crash] isn't due to inheritance per se. It also crashes with simply PUPDevice.read(PUPDevice, 0). Simpler types (StopWatch) also misbehave to a lesser extent.
It's perhaps just because we don't assert the type of self in each of our methods.

Originally posted by @laurensvalk in #777 (comment)

@laurensvalk
Copy link
Member Author

I see your WIP commmit now. That's nice for a more descriptive error, but we shouldn't need it to just fix the crash. Just enabling MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG suffices to raise a TypeError.

Originally posted by @laurensvalk in #777 (comment)

@laurensvalk
Copy link
Member Author

It only fixes crashing in cases like to list.append(str, 0) and only for MicroPython builtins, not in any Pybricks code. The WIP branch extends it to fix Pybricks code like PUPDevice.read(PUPDevice, 0).

Originally posted by @dlech in #777 (comment)

@laurensvalk
Copy link
Member Author

laurensvalk commented Nov 17, 2022

On master:

PUPDevice.read(PUPDevice, 0)

Crashes.

Enable MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG

PUPDevice.read(PUPDevice, 0)
>>> TypeError: argument should be a '' not a 'type'

WIP Branch

PUPDevice.read(PUPDevice, 0)
>>> TypeError: argument should be a '' not a 'type'

This also sets MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG but that doesn't do anything extra because mp_check_self expands to either nothing or an assert.

@laurensvalk
Copy link
Member Author

It looks like MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG enables the standard check but disables mp_check_self; they should not both be used in this form.

laurensvalk added a commit to pybricks/pybricks-micropython that referenced this issue Nov 17, 2022
laurensvalk added a commit to pybricks/pybricks-micropython that referenced this issue Nov 17, 2022
@dlech dlech added bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: MicroPython Issues related to the MicroPython programming language labels Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: MicroPython Issues related to the MicroPython programming language
Projects
None yet
Development

No branches or pull requests

2 participants