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

add, use a default __exit__ object #10040

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jepler
Copy link
Member

@jepler jepler commented Feb 7, 2025

This just delegates to .deinit().

Also, reuse identity_obj for default __enter__.

Saves about 800 bytes on metro rp2350.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Neat!

Some have

    { MP_ROM_QSTR(MP_QSTR___enter__),    MP_ROM_PTR(&mp_identity_obj) },

and some are

    { MP_ROM_QSTR(MP_QSTR___enter__),          MP_ROM_PTR(&default___enter___obj) },

Are these the same thing? Should there be just one choice?

@jepler
Copy link
Member Author

jepler commented Feb 7, 2025

That's a good question! I used a #define so that default___enter___obj is now mp_identity_obj but I could just change all the references. Or, I could change the few that use mp_identity_obj directly to use the macro, just for consistency.

(I suspect but don't know for sure that mp_identity_object might have been added later after we added default_exit_obj)

It's super sus that this didn't build any boards! ci_set_matrix found the changed files but decided not to build any boards.

from the build log:

Using files list by computing diff
Using jobs list in LAST_FAILED_JOBS
Log: changed_files
  {'shared-bindings/sdioio/SDCard.c', 'shared-bindings/audiobusio/I2SOut.c', 'shared-bindings/keypad_demux/DemuxKeyMatrix.c', 'shared-bindings/busio/SPI.c', 'shared-bindings/audiofilters/Filter.c', 'shared-bindings/audiomixer/Mixer.c', 'shared-bindings/imagecapture/ParallelImageCapture.c', 'shared-bindings/audioio/AudioOut.c', 'shared-bindings/analogio/AnalogIn.c', 'shared-bindings/i2ctarget/I2CTarget.c', 'shared-bindings/analogio/AnalogOut.c', 'ports/espressif/bindings/espnow/ESPNow.c', 'shared-bindings/bitbangio/I2C.c', 'shared-bindings/audiocore/RawSample.c', 'shared-bindings/gifio/GifWriter.c', 'shared-bindings/keypad/ShiftRegisterKeys.c', 'shared-bindings/analogbufio/BufferedIn.c', 'shared-bindings/digitalio/DigitalInOut.c', 'shared-bindings/synthio/Synthesizer.c', 'shared-bindings/pulseio/PulseIn.c', 'shared-bindings/pwmio/PWMOut.c', 'shared-bindings/onewireio/OneWire.c', 'ports/espressif/bindings/espulp/ULP.c', 'shared-bindings/busio/I2C.c', 'shared-bindings/countio/Counter.c', 'shared-bindings/audiofilters/Distortion.c', 'shared-bindings/bitbangio/SPI.c', 'shared-bindings/synthio/MidiTrack.c', 'shared-bindings/audiodelays/Echo.c', 'shared-bindings/audiomp3/MP3Decoder.c', 'shared-bindings/keypad/KeyMatrix.c', 'shared-bindings/rotaryio/IncrementalEncoder.c', 'shared-bindings/gifio/OnDiskGif.c', 'shared-bindings/busio/UART.c', 'shared-bindings/socketpool/Socket.c', 'shared/runtime/context_manager_helpers.h', 'shared-bindings/audiocore/WaveFile.c', 'shared-bindings/frequencyio/FrequencyIn.c', 'shared-bindings/audiopwmio/PWMAudioOut.c', 'shared-bindings/ssl/SSLSocket.c', 'shared-bindings/pulseio/PulseOut.c', 'shared/runtime/context_manager_helpers.c', 'shared-bindings/touchio/TouchIn.c', 'shared-bindings/audiobusio/PDMIn.c', 'shared-bindings/keypad/Keys.c', 'shared-bindings/ps2io/Ps2.c'}
Log: last_failed_jobs
  {}
Running: conditionally
Building docs: False
Building windows: False
Building boards: False

jepler added a commit to jepler/circuitpython that referenced this pull request Feb 7, 2025
Recently in adafruit#10026 this script was altered so that sometimes
items are removed from `boards`. However, this could have side effects.
For instance, when a file like `shared/runtime/context_manager_helpers.c`
is modified, it doesn't match any per-port or per-board rule so
we execute `boards_to_build = all_board_ids`. But if the object
`all_board_ids` refers to has been modified by `boards.remove(board)`
in an earlier iteration, then we don't end up really building all boards.

Noticed during development of adafruit#10040.
This just delegates to .deinit().

Also, change default __enter__ to a macro that reuses the
identically-beving "identity_obj", and harmonize a few sites so that
the naming s consistent.

Saves about 800 bytes on metro rp2350.
There are more exeptions scattered across the codebase, but this is the
only one that foiled my attempts to use grep to check that every object
using default___exit___obj also had a deinit method.
@jepler jepler requested a review from dhalbert February 8, 2025 02:51
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Nice cleanup, one place I noticed.

@@ -259,7 +259,7 @@ static const mp_rom_map_elem_t _zephyr_serial_uart_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&_zephyr_serial_uart_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&_zephyr_serial_uart_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&_zephyr_serial_uart___exit___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&default___exit___obj) },
Copy link
Collaborator

Choose a reason for hiding this comment

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

The zephyr_serial_uart___exit___ code was not deleted in this file. Did you mean to do that?

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