File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -218,8 +218,12 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args
218
218
size_t n_state , state_size ;
219
219
DECODE_CODESTATE_SIZE (self -> bytecode , n_state , state_size );
220
220
221
- // allocate state for locals and stack
222
221
mp_code_state_t * code_state ;
222
+ // If we use m_new_obj_var(), then on no memory, MemoryError will be
223
+ // raised. But this is not correct exception for a function call,
224
+ // RuntimeError should be raised instead. So, we use m_new_obj_var_maybe(),
225
+ // return NULL, then vm.c takes the needed action (either raise
226
+ // RuntimeError or fallback to stack allocation).
223
227
code_state = m_new_obj_var_maybe (mp_code_state_t , byte , state_size );
224
228
if (!code_state ) {
225
229
return NULL ;
Original file line number Diff line number Diff line change @@ -937,6 +937,9 @@ unwind_jump:;
937
937
deep_recursion_error :
938
938
mp_exc_recursion_depth ();
939
939
}
940
+ #else
941
+ // If we couldn't allocate codestate on heap, in
942
+ // non non-strict case fall thru to stack allocation.
940
943
#endif
941
944
}
942
945
#endif
@@ -974,6 +977,9 @@ unwind_jump:;
974
977
else {
975
978
goto deep_recursion_error ;
976
979
}
980
+ #else
981
+ // If we couldn't allocate codestate on heap, in
982
+ // non non-strict case fall thru to stack allocation.
977
983
#endif
978
984
}
979
985
#endif
@@ -1008,6 +1014,9 @@ unwind_jump:;
1008
1014
else {
1009
1015
goto deep_recursion_error ;
1010
1016
}
1017
+ #else
1018
+ // If we couldn't allocate codestate on heap, in
1019
+ // non non-strict case fall thru to stack allocation.
1011
1020
#endif
1012
1021
}
1013
1022
#endif
@@ -1045,6 +1054,9 @@ unwind_jump:;
1045
1054
else {
1046
1055
goto deep_recursion_error ;
1047
1056
}
1057
+ #else
1058
+ // If we couldn't allocate codestate on heap, in
1059
+ // non non-strict case fall thru to stack allocation.
1048
1060
#endif
1049
1061
}
1050
1062
#endif
You can’t perform that action at this time.
0 commit comments