graphics/
stubs.rs

1use core::ffi::{c_char, c_int, c_void};
2
3use abi_declarations::{
4    xila_memory_allocate_core, xila_memory_compare, xila_memory_copy, xila_memory_deallocate,
5    xila_memory_move, xila_memory_reallocate, xila_memory_set, xila_string_compare,
6    xila_string_compare_bounded, xila_string_concatenate, xila_string_copy,
7    xila_string_copy_bounded, xila_string_duplicate, xila_string_duplicate_bounded,
8    xila_string_get_length,
9};
10
11/// Set a block of memory to a specific value
12///
13/// # Safety
14/// This function is unsafe because it dereferences raw pointers.
15#[unsafe(no_mangle)]
16pub unsafe extern "C" fn lv_memset(destination: *mut c_void, value: u8, size: usize) {
17    unsafe { xila_memory_set(destination, value as c_int, size) };
18}
19
20/// Deinitialize the memory manager
21///
22/// # Safety
23/// This function is unsafe because it may involve low-level memory operations.
24#[unsafe(no_mangle)]
25pub unsafe extern "C" fn lv_mem_deinit() {
26    log::information!("Deinitializing memory manager");
27    // This function is a no-op in this stub.
28    // In a real implementation, you would clean up memory resources here.
29}
30
31/// Initialize the memory manager
32///
33/// # Safety
34/// This function is unsafe because it may involve low-level memory operations.
35#[unsafe(no_mangle)]
36pub unsafe extern "C" fn lv_mem_init() {
37    log::information!("Initializing memory manager");
38    // This function is a no-op in this stub.
39    // In a real implementation, you would set up memory resources here.
40}
41
42/// Allocate a block of memory
43///
44/// # Safety
45/// This function is unsafe because it dereferences raw pointers.
46#[unsafe(no_mangle)]
47pub unsafe extern "C" fn lv_malloc_core(size: usize) -> *mut c_void {
48    unsafe { xila_memory_allocate_core(size) }
49}
50
51/// Free a block of memory
52///
53/// # Safety
54/// This function is unsafe because it dereferences raw pointers.
55#[unsafe(no_mangle)]
56pub unsafe extern "C" fn lv_free_core(pointer: *mut c_void) {
57    unsafe { xila_memory_deallocate(pointer) }
58}
59
60/// Reallocate a block of memory
61///
62/// # Safety
63/// This function is unsafe because it dereferences raw pointers.
64#[unsafe(no_mangle)]
65pub unsafe extern "C" fn lv_realloc_core(pointer: *mut c_void, new_size: usize) -> *mut c_void {
66    unsafe { xila_memory_reallocate(pointer, new_size) }
67}
68
69/// Copy a block of memory from source to destination
70///
71/// # Safety
72/// This function is unsafe because it dereferences raw pointers.
73#[unsafe(no_mangle)]
74pub unsafe extern "C" fn lv_memcpy(
75    destination: *mut c_void,
76    source: *const c_void,
77    size: usize,
78) -> *mut c_void {
79    unsafe { xila_memory_copy(destination, source, size) }
80}
81
82/// Compare two strings
83///
84/// # Safety
85/// This function is unsafe because it dereferences raw pointers.
86#[unsafe(no_mangle)]
87pub unsafe extern "C" fn lv_strcmp(str1: *const c_char, str2: *const c_char) -> c_int {
88    unsafe { xila_string_compare(str1, str2) }
89}
90
91/// Get the length of a string
92///
93/// # Safety
94/// This function is unsafe because it dereferences raw pointers.
95#[unsafe(no_mangle)]
96pub unsafe extern "C" fn lv_strlen(string: *const c_char) -> usize {
97    unsafe { xila_string_get_length(string) }
98}
99
100/// Format a string
101///
102/// # Safety
103/// This function is unsafe because it dereferences raw pointers.
104#[unsafe(no_mangle)]
105pub unsafe extern "C" fn lv_snprintf(
106    _: *mut c_char,
107    _: usize,
108    _: *const c_char,
109    _: *mut c_void,
110) -> c_int {
111    log::information!("Formatting string (not implemented in this stub)");
112    // This function is not implemented in this stub.
113    // In a real implementation, you would handle formatted output here.
114    0
115}
116
117/// Format a string with variable arguments
118///
119/// # Safety
120/// This function is unsafe because it dereferences raw pointers.
121#[unsafe(no_mangle)]
122pub unsafe extern "C" fn lv_vsnprintf(
123    _: *mut c_char,
124    _: usize,
125    _: *const c_char,
126    _: *mut c_void,
127) -> c_int {
128    log::information!("Formatting string with variable arguments (not implemented in this stub)");
129    // This function is not implemented in this stub.
130    // In a real implementation, you would handle formatted output here.
131    0
132}
133
134/// Copy a string from source to destination
135///
136/// # Safety
137/// This function is unsafe because it dereferences raw pointers.
138#[unsafe(no_mangle)]
139pub unsafe extern "C" fn lv_strcpy(destination: *mut c_char, source: *const c_char) -> *mut c_char {
140    unsafe { xila_string_copy(destination, source) }
141}
142
143/// Copy a string up to a given size
144///
145/// # Safety
146/// This function is unsafe because it dereferences raw pointers.
147#[unsafe(no_mangle)]
148pub unsafe extern "C" fn lv_strncpy(
149    destination: *mut c_char,
150    source: *const c_char,
151    size: usize,
152) -> *mut c_char {
153    unsafe { xila_string_copy_bounded(destination, source, size) }
154}
155
156/// Duplicate a string
157///
158/// # Safety
159/// This function is unsafe because it dereferences raw pointers.
160#[unsafe(no_mangle)]
161pub unsafe extern "C" fn lv_strdup(string: *const c_char) -> *mut c_char {
162    unsafe { xila_string_duplicate(string) }
163}
164
165/// Move a block of memory from source to destination
166///
167/// # Safety
168/// This function is unsafe because it dereferences raw pointers.
169#[unsafe(no_mangle)]
170pub unsafe extern "C" fn lv_memmove(
171    destination: *mut c_void,
172    source: *const c_void,
173    size: usize,
174) -> *mut c_void {
175    unsafe { xila_memory_move(destination, source, size) }
176}
177
178/// Duplicate a string up to a given size
179///
180/// # Safety
181/// This function is unsafe because it dereferences raw pointers.
182#[unsafe(no_mangle)]
183pub unsafe extern "C" fn lv_strndup(string: *const c_char, size: usize) -> *mut c_char {
184    unsafe { xila_string_duplicate_bounded(string, size) }
185}
186
187/// Compare two memory areas up to a given size
188///
189/// # Safety
190/// This function is unsafe because it dereferences raw pointers.
191#[unsafe(no_mangle)]
192pub unsafe extern "C" fn lv_memcmp(ptr1: *const c_void, ptr2: *const c_void, size: usize) -> c_int {
193    unsafe { xila_memory_compare(ptr1, ptr2, size) }
194}
195
196/// Concatenate two strings
197///
198/// # Safety
199/// This function is unsafe because it dereferences raw pointers.
200#[unsafe(no_mangle)]
201pub unsafe extern "C" fn lv_strcat(destination: *mut c_char, source: *const c_char) -> *mut c_char {
202    unsafe { xila_string_concatenate(destination, source) }
203}
204
205/// Compare two strings up to a given size
206///
207/// # Safety
208///
209/// This function is unsafe because it dereferences raw pointers.
210#[unsafe(no_mangle)]
211pub unsafe extern "C" fn lv_strncmp(
212    str1: *const c_char,
213    str2: *const c_char,
214    size: usize,
215) -> c_int {
216    unsafe { xila_string_compare_bounded(str1, str2, size) }
217}