Skip to content

Commit 9f9dd62

Browse files
committed
transpile: add memcpy of str literal macro test to macros.c snapshot (os-specific)
1 parent 14916d7 commit 9f9dd62

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

c2rust-transpile/tests/snapshots/os-specific/macros.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <errno.h>
22
#include <stdbool.h>
3+
#include <string.h>
34

45
bool errno_is_error() { return errno != 0; }
56

@@ -17,3 +18,13 @@ int size_of_dynamic(int n) {
1718
return SIZE;
1819
}
1920
#endif
21+
22+
// From Lua's `lobject.c`.
23+
24+
#define POS "\"]"
25+
/* number of chars of a literal string without the ending \0 */
26+
#define LL(x) (sizeof(x) / sizeof(char) - 1)
27+
28+
void memcpy_str_literal(char *out) {
29+
memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
30+
}

c2rust-transpile/tests/snapshots/[email protected]

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ input_file: c2rust-transpile/tests/snapshots/os-specific/macros.c
1414
)]
1515
extern "C" {
1616
fn __errno_location() -> *mut std::ffi::c_int;
17+
fn memcpy(
18+
__dest: *mut std::ffi::c_void,
19+
__src: *const std::ffi::c_void,
20+
__n: size_t,
21+
) -> *mut std::ffi::c_void;
1722
}
23+
pub type size_t = usize;
1824
#[no_mangle]
1925
pub unsafe extern "C" fn errno_is_error() -> bool {
2026
return *__errno_location() != 0 as std::ffi::c_int;
@@ -24,3 +30,15 @@ pub unsafe extern "C" fn size_of_const() -> std::ffi::c_int {
2430
let mut a: [std::ffi::c_int; 10] = [0; 10];
2531
return ::core::mem::size_of::<[std::ffi::c_int; 10]>() as std::ffi::c_int;
2632
}
33+
#[no_mangle]
34+
pub unsafe extern "C" fn memcpy_str_literal(mut out: *mut std::ffi::c_char) {
35+
memcpy(
36+
out as *mut std::ffi::c_void,
37+
b"\"]\0" as *const u8 as *const std::ffi::c_char as *const std::ffi::c_void,
38+
(::core::mem::size_of::<[std::ffi::c_char; 3]>() as size_t)
39+
.wrapping_div(::core::mem::size_of::<std::ffi::c_char>() as size_t)
40+
.wrapping_sub(1 as size_t)
41+
.wrapping_add(1 as size_t)
42+
.wrapping_mul(::core::mem::size_of::<std::ffi::c_char>() as size_t),
43+
);
44+
}

c2rust-transpile/tests/snapshots/[email protected]

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ input_file: c2rust-transpile/tests/snapshots/os-specific/macros.c
1414
)]
1515
extern "C" {
1616
fn __error() -> *mut std::ffi::c_int;
17+
fn memcpy(
18+
__dst: *mut std::ffi::c_void,
19+
__src: *const std::ffi::c_void,
20+
__n: size_t,
21+
) -> *mut std::ffi::c_void;
1722
}
23+
pub type __darwin_size_t = usize;
24+
pub type size_t = __darwin_size_t;
1825
#[no_mangle]
1926
pub unsafe extern "C" fn errno_is_error() -> bool {
2027
return *__error() != 0 as std::ffi::c_int;
@@ -24,3 +31,15 @@ pub unsafe extern "C" fn size_of_const() -> std::ffi::c_int {
2431
let mut a: [std::ffi::c_int; 10] = [0; 10];
2532
return ::core::mem::size_of::<[std::ffi::c_int; 10]>() as std::ffi::c_int;
2633
}
34+
#[no_mangle]
35+
pub unsafe extern "C" fn memcpy_str_literal(mut out: *mut std::ffi::c_char) {
36+
memcpy(
37+
out as *mut std::ffi::c_void,
38+
b"\"]\0" as *const u8 as *const std::ffi::c_char as *const std::ffi::c_void,
39+
(::core::mem::size_of::<[std::ffi::c_char; 3]>() as size_t)
40+
.wrapping_div(::core::mem::size_of::<std::ffi::c_char>() as size_t)
41+
.wrapping_sub(1 as size_t)
42+
.wrapping_add(1 as size_t)
43+
.wrapping_mul(::core::mem::size_of::<std::ffi::c_char>() as size_t),
44+
);
45+
}

0 commit comments

Comments
 (0)