1#[cfg(not(any(feature = "plugin-api-v0", feature = "plugin-api-v1")))]
4use crate::sys::{GArray, GByteArray};
5use std::ffi::c_void;
6
7#[cfg(not(windows))]
8unsafe extern "C" {
9 pub(crate) fn g_free(mem: *mut c_void);
11}
12
13#[cfg(all(
14 not(windows),
15 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
16))]
17unsafe extern "C" {
18 pub(crate) fn g_byte_array_new() -> *mut GByteArray;
20 pub(crate) fn g_byte_array_free(array: *mut GByteArray, free_segment: bool) -> *mut u8;
22 pub(crate) fn g_array_free(array: *mut GArray, free_segment: bool) -> *mut u8;
24}
25
26#[cfg(windows)]
27lazy_static::lazy_static! {
28 static ref G_FREE : libloading::os::windows::Symbol<unsafe extern "C" fn(*mut c_void)> = {
29 let lib =
30 libloading::os::windows::Library::open_already_loaded("libglib-2.0-0.dll")
31 .expect("libglib-2.0-0.dll should already be loaded");
32 unsafe{lib.get(b"g_free").expect("find g_free")}
36 };
37}
38
39#[cfg(all(
40 windows,
41 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
42))]
43lazy_static::lazy_static! {
44 static ref G_BYTE_ARRAY_NEW: libloading::os::windows::Symbol<unsafe extern "C" fn() -> *mut GByteArray> = {
45 let lib =
46 libloading::os::windows::Library::open_already_loaded("libglib-2.0-0.dll")
47 .expect("libglib-2.0-0.dll should already be loaded");
48 unsafe{lib.get(b"g_byte_array_new").expect("find g_byte_array_new")}
52 };
53}
54
55#[cfg(all(
56 windows,
57 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
58))]
59lazy_static::lazy_static! {
60 static ref G_BYTE_ARRAY_FREE: libloading::os::windows::Symbol<unsafe extern "C" fn(*mut c_void, bool) -> *mut u8> = {
61 let lib =
62 libloading::os::windows::Library::open_already_loaded("libglib-2.0-0.dll")
63 .expect("libglib-2.0-0.dll should already be loaded");
64 unsafe{lib.get(b"g_byte_array_free").expect("find g_byte_array_free")}
68 };
69}
70
71#[cfg(all(
72 windows,
73 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
74))]
75lazy_static::lazy_static! {
76 static ref G_ARRAY_FREE: libloading::os::windows::Symbol<unsafe extern "C" fn(*mut c_void, bool) -> *mut u8> = {
77 let lib =
78 libloading::os::windows::Library::open_already_loaded("libglib-2.0-0.dll")
79 .expect("libglib-2.0-0.dll should already be loaded");
80 unsafe{lib.get(b"g_array_free").expect("find g_array_free")}
84 };
85}
86
87#[cfg(windows)]
88pub(crate) unsafe fn g_free(mem: *mut c_void) {
97 unsafe { G_FREE(mem) }
98}
99
100#[cfg(all(
101 windows,
102 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
103))]
104pub(crate) unsafe fn g_byte_array_new() -> *mut GByteArray {
112 unsafe { G_BYTE_ARRAY_NEW() }
113}
114
115#[cfg(all(
116 windows,
117 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
118))]
119pub(crate) unsafe fn g_byte_array_free(array: *mut GByteArray, free_segment: bool) -> *mut u8 {
128 unsafe { G_BYTE_ARRAY_FREE(array as *mut c_void, free_segment) }
129}
130
131#[cfg(all(
132 windows,
133 not(any(feature = "plugin-api-v0", feature = "plugin-api-v1"))
134))]
135pub(crate) unsafe fn g_array_free(array: *mut GArray, free_segment: bool) -> *mut u8 {
143 unsafe { G_ARRAY_FREE(array as *mut c_void, free_segment) }
144}