summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-02-22 20:41:00 +0100
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-02-22 20:41:00 +0100
commit75d0b02b3f78241938a15f07e9a5fce4251acae7 (patch)
treea649e3058772ba204175381e5debd8fd07d35ec3
parent4c05086661bd486490442318934a57b93304aa0e (diff)
Throw an error when sleep time is negative.
-rw-r--r--shared-bindings/time/__init__.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index ad0e93375..36e63d36f 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -64,10 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);
//|
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_PY_BUILTINS_FLOAT
- common_hal_time_delay_ms(1000 * mp_obj_get_float(seconds_o));
+ float seconds = mp_obj_get_float(seconds_o);
#else
- common_hal_time_delay_ms(1000 * mp_obj_get_int(seconds_o));
+ int seconds = mp_obj_get_int(seconds_o);
#endif
+ if (seconds < 0) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "sleep length must be non-negative"));
+ }
+ common_hal_time_delay_ms(1000 * seconds);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);