Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions rules/time/tgt_refcount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ fn f4(a0: Ptr<::libc::time_t>, a1: Ptr<Tm>) -> Ptr<Tm> {
}
}

fn f5(a0: Ptr<::libc::time_t>, a1: Ptr<Tm>) -> Ptr<Tm> {
let __res = a1.clone();
match jiff::Timestamp::from_second(a0.read()) {
Ok(__ts) => {
let __dt = __ts.to_zoned(jiff::tz::TimeZone::system());
let __info = __dt.time_zone().to_offset_info(__ts);
let __zone: Vec<u8> = __info.abbreviation().bytes().chain([0]).collect();
let __isdst = if __info.dst().is_dst() { 1 } else { 0 };
__res.with_mut(|__tm| {
*__tm = Tm::from_zoned(&__dt);
*__tm.tm_isdst.borrow_mut() = __isdst;
*__tm.tm_zone.borrow_mut() = Ptr::alloc_array(__zone.into_boxed_slice());
});
__res
}
Err(_) => {
libcc2rs::cpp2rust_errno().write(::libc::EOVERFLOW);
Ptr::null()
}
}
}

fn f6(a0: Ptr<u8>, a1: usize, a2: Ptr<u8>, a3: Ptr<Tm>) -> usize {
let __dt = a3.with(|__tm| __tm.to_civil());
let __text = match __dt {
Expand Down
55 changes: 53 additions & 2 deletions tests/unit/out/refcount/sys_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,57 @@ pub fn test_gmtime_r_2() {
({ print_tm_1(1721126096_i64) });
({ print_tm_1(4102444800_i64) });
}
pub fn test_strftime_3() {
pub fn print_local_tm_3(t: i64) {
let t: Value<i64> = Rc::new(RefCell::new(t));
let tm: Value<libcc2rs::Tm> = Rc::new(RefCell::new(Default::default()));
assert!(
(((!(({
let __res = (tm.as_pointer()).clone();
match jiff::Timestamp::from_second((t.as_pointer()).read()) {
Ok(__ts) => {
let __dt = __ts.to_zoned(jiff::tz::TimeZone::system());
let __info = __dt.time_zone().to_offset_info(__ts);
let __zone: Vec<u8> = __info.abbreviation().bytes().chain([0]).collect();
let __isdst = if __info.dst().is_dst() { 1 } else { 0 };
__res.with_mut(|__tm| {
*__tm = Tm::from_zoned(&__dt);
*__tm.tm_isdst.borrow_mut() = __isdst;
*__tm.tm_zone.borrow_mut() = Ptr::alloc_array(__zone.into_boxed_slice());
});
__res
}
Err(_) => {
libcc2rs::cpp2rust_errno().write(::libc::EOVERFLOW);
Ptr::null()
}
}
})
.is_null())) as i32)
!= 0)
);
println!(
"{}-{}-{} {}:{}:{} wday={} yday={} {} gmtoff={} isdst={}",
(*(*tm.borrow()).tm_year.borrow()),
(*(*tm.borrow()).tm_mon.borrow()),
(*(*tm.borrow()).tm_mday.borrow()),
(*(*tm.borrow()).tm_hour.borrow()),
(*(*tm.borrow()).tm_min.borrow()),
(*(*tm.borrow()).tm_sec.borrow()),
(*(*tm.borrow()).tm_wday.borrow()),
(*(*tm.borrow()).tm_yday.borrow()),
(*(*tm.borrow()).tm_zone.borrow()),
(*(*tm.borrow()).tm_gmtoff.borrow()),
(*(*tm.borrow()).tm_isdst.borrow())
);
}
pub fn test_localtime_r_4() {
({ print_local_tm_3(0_i64) });
({ print_local_tm_3(951782400_i64) });
({ print_local_tm_3(1704067199_i64) });
({ print_local_tm_3(1721126096_i64) });
({ print_local_tm_3(1735689600_i64) });
}
pub fn test_strftime_5() {
let t: Value<i64> = Rc::new(RefCell::new(1721126096_i64));
let tm: Value<libcc2rs::Tm> = Rc::new(RefCell::new(Default::default()));
assert!(
Expand Down Expand Up @@ -263,6 +313,7 @@ pub fn main() {
fn main_0() -> i32 {
({ test_time_0() });
({ test_gmtime_r_2() });
({ test_strftime_3() });
({ test_localtime_r_4() });
({ test_strftime_5() });
return 0;
}
40 changes: 38 additions & 2 deletions tests/unit/out/unsafe/sys_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,42 @@ pub unsafe fn test_gmtime_r_2() {
(unsafe { print_tm_1(1721126096_i64) });
(unsafe { print_tm_1(4102444800_i64) });
}
pub unsafe fn test_strftime_3() {
pub unsafe fn print_local_tm_3(mut t: i64) {
let mut tm: ::libc::tm = unsafe { std::mem::zeroed() };
assert!(
(((!((libc::localtime_r(
(&mut t as *mut i64).cast_const(),
(&mut tm as *mut ::libc::tm)
))
.is_null())) as i32)
!= 0)
);
printf(
(c"%d-%d-%d %d:%d:%d wday=%d yday=%d %s gmtoff=%ld isdst=%d\n"
.as_ptr()
.cast_mut())
.cast_const() as *const i8,
tm.tm_year,
tm.tm_mon,
tm.tm_mday,
tm.tm_hour,
tm.tm_min,
tm.tm_sec,
tm.tm_wday,
tm.tm_yday,
tm.tm_zone,
tm.tm_gmtoff,
tm.tm_isdst,
);
}
pub unsafe fn test_localtime_r_4() {
(unsafe { print_local_tm_3(0_i64) });
(unsafe { print_local_tm_3(951782400_i64) });
(unsafe { print_local_tm_3(1704067199_i64) });
(unsafe { print_local_tm_3(1721126096_i64) });
(unsafe { print_local_tm_3(1735689600_i64) });
}
pub unsafe fn test_strftime_5() {
let mut t: i64 = 1721126096_i64;
let mut tm: ::libc::tm = unsafe { std::mem::zeroed() };
assert!(
Expand Down Expand Up @@ -137,6 +172,7 @@ pub fn main() {
unsafe fn main_0() -> i32 {
(unsafe { test_time_0() });
(unsafe { test_gmtime_r_2() });
(unsafe { test_strftime_3() });
(unsafe { test_localtime_r_4() });
(unsafe { test_strftime_5() });
return 0;
}
17 changes: 17 additions & 0 deletions tests/unit/sys_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ static void test_gmtime_r(void) {
print_tm(4102444800);
}

static void print_local_tm(time_t t) {
struct tm tm;
assert(localtime_r(&t, &tm) != NULL);
printf("%d-%d-%d %d:%d:%d wday=%d yday=%d %s gmtoff=%ld isdst=%d\n",
tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
tm.tm_wday, tm.tm_yday, tm.tm_zone, tm.tm_gmtoff, tm.tm_isdst);
}

static void test_localtime_r(void) {
print_local_tm(0);
print_local_tm(951782400);
print_local_tm(1704067199);
print_local_tm(1721126096);
print_local_tm(1735689600);
}

static void test_strftime(void) {
time_t t = 1721126096;
struct tm tm;
Expand All @@ -54,6 +70,7 @@ static void test_strftime(void) {
int main(void) {
test_time();
test_gmtime_r();
test_localtime_r();
test_strftime();
return 0;
}
Loading