Skip to content

Commit 05825a0

Browse files
committed
fix raw_code is_generator and is_async
1 parent 757e91f commit 05825a0

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

py/emitglue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
7373
rc->kind = MP_CODE_BYTECODE;
7474
rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0;
7575
// CIRCUITPY-CHANGE: async and generator are distinguished
76+
// For async, BOTH is_generator and is_async will be set.
7677
rc->is_async = (scope_flags & MP_SCOPE_FLAG_ASYNC) != 0;
7778
rc->fun_data = code;
7879
rc->children = children;
@@ -137,6 +138,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, cons
137138
rc->kind = kind;
138139
rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0;
139140
// CIRCUITPY-CHANGE: async and generator are distinguished
141+
// For async, BOTH is_generator and is_async will be set.
140142
rc->is_async = (scope_flags & MP_SCOPE_FLAG_ASYNC) != 0;
141143
rc->fun_data = fun_data;
142144

@@ -219,6 +221,8 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
219221
// Check for a generator function, and if so change the type of the object
220222
// CIRCUITPY-CHANGE: distinguish generators and async
221223
#if MICROPY_PY_ASYNC_AWAIT
224+
// For async, BOTH is_async and is_generator will be set,
225+
// so check is_async first.
222226
if ((rc->is_async) != 0) {
223227
((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_coro_wrap;
224228
} else
@@ -242,8 +246,8 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
242246
fun = mp_obj_new_fun_bc(def_args, rc->fun_data, context, rc->children);
243247
// check for generator functions and if so change the type of the object
244248
// CIRCUITPY-CHANGE: distinguish generators and async
245-
// A coroutine is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR,
246-
// so check for ASYNC first.
249+
// For async, BOTH is_async and is_generator will be set,
250+
// so check is_async first.
247251
#if MICROPY_PY_ASYNC_AWAIT
248252
if ((rc->is_async) != 0) {
249253
((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_coro_wrap;

py/emitglue.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ static inline bool mp_proto_fun_is_bytecode(mp_proto_fun_t proto_fun) {
7474
typedef struct _mp_raw_code_t {
7575
uint8_t proto_fun_indicator[2];
7676
uint8_t kind; // of type mp_raw_code_kind_t; only 3 bits used
77-
bool is_generator;
78-
bool is_async;
77+
// CIRCUITPY-CHANGE: distinguish generator and async
78+
// For async, BOTH is_generator and is_async will be set.
79+
bool is_generator : 1;
80+
bool is_async : 1;
7981
const void *fun_data;
8082
struct _mp_raw_code_t **children;
8183
#if MICROPY_PERSISTENT_CODE_SAVE
@@ -105,8 +107,10 @@ typedef struct _mp_raw_code_t {
105107
typedef struct _mp_raw_code_truncated_t {
106108
uint8_t proto_fun_indicator[2];
107109
uint8_t kind;
108-
bool is_generator;
109-
bool is_async;
110+
// CIRCUITPY-CHANGE: distinguish generator and async
111+
// For async, BOTH is_generator and is_async will be set.
112+
bool is_generator : 1;
113+
bool is_async : 1;
110114
const void *fun_data;
111115
struct _mp_raw_code_t **children;
112116
#if MICROPY_PERSISTENT_CODE_SAVE

tools/mpy-tool.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ class Config:
126126
MP_PERSISTENT_OBJ_COMPLEX = 9
127127
MP_PERSISTENT_OBJ_TUPLE = 10
128128

129+
129130
MP_SCOPE_FLAG_GENERATOR = 0x01
130-
MP_SCOPE_FLAG_VIPERRELOC = 0x10
131-
MP_SCOPE_FLAG_VIPERRODATA = 0x20
132-
MP_SCOPE_FLAG_VIPERBSS = 0x40
133-
# CIRCUITPY-CHANGE: async is distinct from generator
134-
MP_SCOPE_FLAG_ASYNC = 0x80
131+
# CIRCUITPY-CHANGE: async is distinct from generator; flag constants are different
132+
MP_SCOPE_FLAG_ASYNC = 0x10
133+
MP_SCOPE_FLAG_VIPERRELOC = 0x20
134+
MP_SCOPE_FLAG_VIPERRODATA = 0x40
135+
MP_SCOPE_FLAG_VIPERBSS = 0x80
135136

136137
MP_BC_MASK_EXTRA_BYTE = 0x9E
137138

0 commit comments

Comments
 (0)