circuitpython/shared/runtime/context_manager_helpers.c
Jeff Epler 8aa1969c61 add, use a default exit object
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.
2025-02-07 15:10:58 -06:00

18 lines
593 B
C

// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include "shared/runtime/context_manager_helpers.h"
#include "py/obj.h"
#include "py/runtime.h"
static mp_obj_t default___exit__(size_t n_args, const mp_obj_t *args) {
mp_obj_t dest[2];
mp_load_method(args[0], MP_QSTR_deinit, dest);
mp_call_method_n_kw(0, 0, dest);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(default___exit___obj, 4, 4, default___exit__);