Skip to content

Commit 127fd17

Browse files
committed
unix/modutime: Use extmod version of time module.
No API or functional change. Signed-off-by: Damien George <[email protected]>
1 parent 996a1f9 commit 127fd17

File tree

6 files changed

+14
-43
lines changed

6 files changed

+14
-43
lines changed

ports/unix/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ SRC_C += \
201201
mpthreadport.c \
202202
input.c \
203203
modmachine.c \
204-
modtime.c \
205204
moduselect.c \
206205
alloc.c \
207206
fatfs_port.c \

ports/unix/modtime.c renamed to ports/unix/modutime.c

+8-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2014-2017 Paul Sokolovsky
7-
* Copyright (c) 2014-2017 Damien P. George
7+
* Copyright (c) 2014-2023 Damien P. George
88
*
99
* Permission is hereby granted, free of charge, to any person obtaining a copy
1010
* of this software and associated documentation files (the "Software"), to deal
@@ -25,20 +25,15 @@
2525
* THE SOFTWARE.
2626
*/
2727

28-
#include "py/mpconfig.h"
29-
#if MICROPY_PY_UTIME
30-
3128
#include <unistd.h>
3229
#include <errno.h>
3330
#include <string.h>
3431
#include <time.h>
3532
#include <sys/time.h>
3633
#include <math.h>
3734

38-
#include "py/runtime.h"
39-
#include "py/smallint.h"
4035
#include "py/mphal.h"
41-
#include "extmod/modutime.h"
36+
#include "py/runtime.h"
4237

4338
#ifdef _WIN32
4439
static inline int msec_sleep_tv(struct timeval *tv) {
@@ -66,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
6661
#error Unsupported clock() implementation
6762
#endif
6863

69-
STATIC mp_obj_t mod_time_time(void) {
64+
STATIC mp_obj_t mp_utime_time_get(void) {
7065
#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
7166
struct timeval tv;
7267
gettimeofday(&tv, NULL);
@@ -76,7 +71,6 @@ STATIC mp_obj_t mod_time_time(void) {
7671
return mp_obj_new_int((mp_int_t)time(NULL));
7772
#endif
7873
}
79-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_time_obj, mod_time_time);
8074

8175
// Note: this is deprecated since CPy3.3, but pystone still uses it.
8276
STATIC mp_obj_t mod_time_clock(void) {
@@ -91,7 +85,7 @@ STATIC mp_obj_t mod_time_clock(void) {
9185
}
9286
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock);
9387

94-
STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
88+
STATIC mp_obj_t mp_utime_sleep(mp_obj_t arg) {
9589
#if MICROPY_PY_BUILTINS_FLOAT
9690
struct timeval tv;
9791
mp_float_t val = mp_obj_get_float(arg);
@@ -130,7 +124,6 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
130124
#endif
131125
return mp_const_none;
132126
}
133-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_time_sleep_obj, mod_time_sleep);
134127

135128
STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) {
136129
time_t t;
@@ -207,31 +200,8 @@ STATIC mp_obj_t mod_time_mktime(mp_obj_t tuple) {
207200
}
208201
MP_DEFINE_CONST_FUN_OBJ_1(mod_time_mktime_obj, mod_time_mktime);
209202

210-
STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
211-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
212-
{ MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) },
213-
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mod_time_sleep_obj) },
214-
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
215-
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },
216-
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mod_time_time_obj) },
217-
{ MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj) },
218-
{ MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj) },
219-
{ MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj) },
220-
{ MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj) },
221-
{ MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj) },
222-
{ MP_ROM_QSTR(MP_QSTR_time_ns), MP_ROM_PTR(&mp_utime_time_ns_obj) },
223-
{ MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mod_time_gmtime_obj) },
224-
{ MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mod_time_localtime_obj) },
203+
#define MICROPY_PY_UTIME_EXTRA_GLOBALS \
204+
{ MP_ROM_QSTR(MP_QSTR_clock), MP_ROM_PTR(&mod_time_clock_obj) }, \
205+
{ MP_ROM_QSTR(MP_QSTR_gmtime), MP_ROM_PTR(&mod_time_gmtime_obj) }, \
206+
{ MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&mod_time_localtime_obj) }, \
225207
{ MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&mod_time_mktime_obj) },
226-
};
227-
228-
STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table);
229-
230-
const mp_obj_module_t mp_module_time = {
231-
.base = { &mp_type_module },
232-
.globals = (mp_obj_dict_t *)&mp_module_time_globals,
233-
};
234-
235-
MP_REGISTER_MODULE(MP_QSTR_utime, mp_module_time);
236-
237-
#endif // MICROPY_PY_UTIME

ports/unix/variants/mpconfigvariant_common.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696

9797
// Enable the unix-specific "time" module.
9898
#define MICROPY_PY_UTIME (1)
99-
#define MICROPY_PY_UTIME_MP_HAL (1)
99+
#define MICROPY_PY_UTIME_TIME_TIME_NS (1)
100+
#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1)
101+
#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c"
100102

101103
// Enable the utimeq module used by the previous (v2) version of uasyncio.
102104
#define MICROPY_PY_UTIMEQ (1)

ports/windows/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ SRC_C = \
5757
ports/unix/main.c \
5858
ports/unix/input.c \
5959
ports/unix/modmachine.c \
60-
ports/unix/modtime.c \
6160
ports/unix/gccollect.c \
6261
windows_mphal.c \
6362
realpath.c \

ports/windows/micropython.vcxproj

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
<ClCompile Include="$(PyBaseDir)ports\unix\gccollect.c"/>
9595
<ClCompile Include="$(PyBaseDir)ports\unix\input.c"/>
9696
<ClCompile Include="$(PyBaseDir)ports\unix\main.c"/>
97-
<ClCompile Include="$(PyBaseDir)ports\unix\modtime.c"/>
9897
<ClCompile Include="$(PyBaseDir)ports\unix\modmachine.c" />
9998
<ClCompile Include="$(PyVariantDir)*.c" />
10099
</ItemGroup>

ports/windows/mpconfigport.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@
140140
#define MICROPY_PY_UOS_SYSTEM (1)
141141
#define MICROPY_PY_UOS_URANDOM (1)
142142
#define MICROPY_PY_UTIME (1)
143-
#define MICROPY_PY_UTIME_MP_HAL (1)
143+
#define MICROPY_PY_UTIME_TIME_TIME_NS (1)
144+
#define MICROPY_PY_UTIME_CUSTOM_SLEEP (1)
145+
#define MICROPY_PY_UTIME_INCLUDEFILE "ports/unix/modutime.c"
144146
#define MICROPY_PY_UERRNO (1)
145147
#define MICROPY_PY_UCTYPES (1)
146148
#define MICROPY_PY_UZLIB (1)

0 commit comments

Comments
 (0)