|
2 | 2 |
|
3 | 3 | // See also: |
4 | 4 | // https://docs.python.org/3/library/time.html |
5 | | -pub use time::*; |
| 5 | +use crate::{builtins::PyModule, PyRef, VirtualMachine}; |
| 6 | + |
| 7 | +pub use decl::time; |
| 8 | + |
| 9 | +pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> { |
| 10 | + #[cfg(not(target_env = "msvc"))] |
| 11 | + #[cfg(not(target_arch = "wasm32"))] |
| 12 | + unsafe { |
| 13 | + c_tzset() |
| 14 | + }; |
| 15 | + decl::make_module(vm) |
| 16 | +} |
| 17 | + |
| 18 | +#[cfg(not(target_env = "msvc"))] |
| 19 | +#[cfg(not(target_arch = "wasm32"))] |
| 20 | +extern "C" { |
| 21 | + #[link_name = "daylight"] |
| 22 | + static c_daylight: std::ffi::c_int; |
| 23 | + // pub static dstbias: std::ffi::c_int; |
| 24 | + #[link_name = "timezone"] |
| 25 | + static c_timezone: std::ffi::c_long; |
| 26 | + #[link_name = "tzname"] |
| 27 | + static c_tzname: [*const std::ffi::c_char; 2]; |
| 28 | + #[link_name = "tzset"] |
| 29 | + fn c_tzset(); |
| 30 | +} |
6 | 31 |
|
7 | 32 | #[pymodule(name = "time", with(platform))] |
8 | | -mod time { |
| 33 | +mod decl { |
9 | 34 | use crate::{ |
10 | 35 | builtins::{PyStrRef, PyTypeRef}, |
11 | 36 | function::{Either, FuncArgs, OptionalArg}, |
@@ -110,6 +135,37 @@ mod time { |
110 | 135 | Ok(get_perf_time(vm)?.as_nanos()) |
111 | 136 | } |
112 | 137 |
|
| 138 | + // #[pyfunction] |
| 139 | + // fn tzset() { |
| 140 | + // unsafe { super::_tzset() }; |
| 141 | + // } |
| 142 | + |
| 143 | + #[cfg(not(target_env = "msvc"))] |
| 144 | + #[cfg(not(target_arch = "wasm32"))] |
| 145 | + #[pyattr] |
| 146 | + fn timezone(_vm: &VirtualMachine) -> std::ffi::c_long { |
| 147 | + unsafe { super::c_timezone } |
| 148 | + } |
| 149 | + |
| 150 | + #[cfg(not(target_env = "msvc"))] |
| 151 | + #[cfg(not(target_arch = "wasm32"))] |
| 152 | + #[pyattr] |
| 153 | + fn daylight(_vm: &VirtualMachine) -> std::ffi::c_int { |
| 154 | + unsafe { super::c_daylight } |
| 155 | + } |
| 156 | + |
| 157 | + #[cfg(not(target_env = "msvc"))] |
| 158 | + #[cfg(not(target_arch = "wasm32"))] |
| 159 | + #[pyattr] |
| 160 | + fn tzname(vm: &VirtualMachine) -> crate::builtins::PyTupleRef { |
| 161 | + use crate::builtins::tuple::IntoPyTuple; |
| 162 | + |
| 163 | + unsafe fn to_str(s: *const std::ffi::c_char) -> String { |
| 164 | + std::ffi::CStr::from_ptr(s).to_string_lossy().into_owned() |
| 165 | + } |
| 166 | + unsafe { (to_str(super::c_tzname[0]), to_str(super::c_tzname[1])) }.into_pytuple(vm) |
| 167 | + } |
| 168 | + |
113 | 169 | fn pyobj_to_date_time( |
114 | 170 | value: Either<f64, i64>, |
115 | 171 | vm: &VirtualMachine, |
@@ -384,7 +440,7 @@ mod time { |
384 | 440 | #[pymodule(sub)] |
385 | 441 | mod platform { |
386 | 442 | #[allow(unused_imports)] |
387 | | - use super::{SEC_TO_NS, US_TO_NS}; |
| 443 | + use super::decl::{SEC_TO_NS, US_TO_NS}; |
388 | 444 | #[cfg_attr(target_os = "macos", allow(unused_imports))] |
389 | 445 | use crate::{ |
390 | 446 | builtins::{PyNamespace, PyStrRef}, |
@@ -621,7 +677,7 @@ mod platform { |
621 | 677 | #[cfg(windows)] |
622 | 678 | #[pymodule] |
623 | 679 | mod platform { |
624 | | - use super::{time_muldiv, MS_TO_NS, SEC_TO_NS}; |
| 680 | + use super::decl::{time_muldiv, MS_TO_NS, SEC_TO_NS}; |
625 | 681 | use crate::{ |
626 | 682 | builtins::{PyNamespace, PyStrRef}, |
627 | 683 | stdlib::os::errno_err, |
|
0 commit comments