@@ -74,7 +74,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) {
74
74
STATIC mp_obj_t mod_urandom_getrandbits (mp_obj_t num_in ) {
75
75
int n = mp_obj_get_int (num_in );
76
76
if (n > 32 || n == 0 ) {
77
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError ) );
77
+ mp_raise_ValueError ( NULL );
78
78
}
79
79
uint32_t mask = ~0 ;
80
80
// Beware of C undefined behavior when shifting by >= than bit size
@@ -102,7 +102,7 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
102
102
if (start > 0 ) {
103
103
return mp_obj_new_int (yasmarang_randbelow (start ));
104
104
} else {
105
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError )) ;
105
+ goto error ;
106
106
}
107
107
} else {
108
108
mp_int_t stop = mp_obj_get_int (args [1 ]);
@@ -111,7 +111,7 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
111
111
if (start < stop ) {
112
112
return mp_obj_new_int (start + yasmarang_randbelow (stop - start ));
113
113
} else {
114
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError )) ;
114
+ goto error ;
115
115
}
116
116
} else {
117
117
// range(start, stop, step)
@@ -122,15 +122,18 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
122
122
} else if (step < 0 ) {
123
123
n = (stop - start + step + 1 ) / step ;
124
124
} else {
125
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError )) ;
125
+ goto error ;
126
126
}
127
127
if (n > 0 ) {
128
128
return mp_obj_new_int (start + step * yasmarang_randbelow (n ));
129
129
} else {
130
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError )) ;
130
+ goto error ;
131
131
}
132
132
}
133
133
}
134
+
135
+ error :
136
+ mp_raise_ValueError (NULL );
134
137
}
135
138
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mod_urandom_randrange_obj , 1 , 3 , mod_urandom_randrange );
136
139
@@ -140,7 +143,7 @@ STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) {
140
143
if (a <= b ) {
141
144
return mp_obj_new_int (a + yasmarang_randbelow (b - a + 1 ));
142
145
} else {
143
- nlr_raise ( mp_obj_new_exception ( & mp_type_ValueError ) );
146
+ mp_raise_ValueError ( NULL );
144
147
}
145
148
}
146
149
STATIC MP_DEFINE_CONST_FUN_OBJ_2 (mod_urandom_randint_obj , mod_urandom_randint );
0 commit comments