wxdragon_sys/lib.rs
1#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
2
3// Include the generated FFI bindings (from bindgen)
4include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
5
6// Conditionally include the pre-generated constants based on target OS
7// Assumes files are located in `rust/wxdragon-sys/src/generated_constants/`
8#[cfg(target_os = "macos")]
9include!("generated_constants/wx_osx_constants.rs");
10
11#[cfg(target_os = "windows")]
12include!("generated_constants/wx_msw_constants.rs");
13
14#[cfg(target_os = "linux")]
15include!("generated_constants/wx_gtk_constants.rs");
16
17// Fallback or error for unsupported OS for constants, if necessary.
18// Alternatively, you could have a `wx_common_constants.rs` if some constants are universal
19// and only OS-specific parts are in the files above.
20#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "linux")))]
21compile_error!("Target OS not supported by pre-generated constants. Please add a constants file for this OS.");
22
23mod logging4c;
24
25// Type alias for convenience maybe?
26// pub type wxWindow_t = self::wxd_Window_t; // Example
27
28// Additional constants or utility functions specific to the sys crate itself
29// (if any are ever needed, usually this file is minimal)
30
31// REMOVED redundant/incorrect manual definitions and extern block.
32// Bindgen now generates wxd_EVT_* constants directly from wxdragon.h
33// into the included bindings.rs file.
34
35// Need to find the actual values for these constants. // REMOVED Comment
36
37/// Function to properly free a string that was allocated by Rust using CString::into_raw().
38/// This must be called instead of C's free() for strings allocated by Rust.
39/// # Safety
40/// The caller (C++) must ensure `str_ptr` is a valid pointer obtained from
41/// `CString::into_raw()` and that it hasn't been freed already.
42#[unsafe(no_mangle)]
43#[allow(clippy::not_unsafe_ptr_arg_deref)]
44pub extern "C" fn wxd_Variant_Free_Rust_String(str_ptr: *mut std::os::raw::c_char) {
45 if !str_ptr.is_null() {
46 // Reconstitute the CString and let it drop, properly freeing the memory
47 // that was allocated by Rust's allocator
48 unsafe {
49 let _cstring = std::ffi::CString::from_raw(str_ptr);
50 // Drop happens automatically when `_cstring` goes out of scope here.
51 }
52 }
53}