Skip to content

Commit f5ad70c

Browse files
glib: Auto generate various win32 functions
1 parent 2ef90b6 commit f5ad70c

File tree

8 files changed

+160
-142
lines changed

8 files changed

+160
-142
lines changed

glib/Gir.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,41 @@ manual = [
5555
[[object]]
5656
name = "GLib.*"
5757
status = "generate"
58+
[[object.function]]
59+
name = "win32_locale_filename_from_utf8"
60+
cfg_condition = "windows"
61+
ignore = true # TODO: implement me
62+
[[object.function]]
63+
name = "win32_get_windows_version"
64+
cfg_condition = "windows"
65+
[[object.function]]
66+
name = "win32_getlocale"
67+
cfg_condition = "windows"
68+
[[object.function]]
69+
name = "win32_check_windows_version"
70+
cfg_condition = "windows"
71+
[[object.function]]
72+
name = "win32_error_message"
73+
cfg_condition = "windows"
74+
[[object.function]]
75+
name = "win32_ftruncate"
76+
cfg_condition = "windows"
77+
ignore = true # TODO: implement me
78+
[[object.function]]
79+
name = "win32_get_command_line"
80+
cfg_condition = "windows"
81+
[[object.function]]
82+
name = "win32_get_package_installation_directory"
83+
cfg_condition = "windows"
84+
ignore = true # TODO: implement me
85+
[[object.function]]
86+
name = "win32_get_package_installation_directory_of_module"
87+
cfg_condition = "windows"
88+
manual = true
89+
[[object.function]]
90+
name = "win32_get_package_installation_subdirectory"
91+
cfg_condition = "windows"
92+
ignore = true # TODO: implement me
5893
[[object.function]]
5994
pattern = "(assertion_message_cmpint|assert_warning|assertion_message|assertion_message_cmpnum|assertion_message_cmpstr|warn_message|return_if_fail_warning)"
6095
ignore = true # Not useful assertions functions
@@ -886,3 +921,8 @@ status = "generate"
886921
name = "GLib.Uri"
887922
status = "generate"
888923
concurrency = "send+sync"
924+
925+
[[object]]
926+
name = "GLib.Win32OSType"
927+
status = "generate"
928+
cfg_condition = "windows"

glib/src/auto/enums.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,3 +2352,49 @@ impl FromGlib<ffi::GVariantClass> for VariantClass {
23522352
}
23532353
}
23542354
}
2355+
2356+
#[cfg(windows)]
2357+
#[cfg_attr(docsrs, doc(cfg(windows)))]
2358+
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
2359+
#[non_exhaustive]
2360+
#[doc(alias = "GWin32OSType")]
2361+
pub enum Win32OSType {
2362+
#[doc(alias = "G_WIN32_OS_ANY")]
2363+
Any,
2364+
#[doc(alias = "G_WIN32_OS_WORKSTATION")]
2365+
Workstation,
2366+
#[doc(alias = "G_WIN32_OS_SERVER")]
2367+
Server,
2368+
#[doc(hidden)]
2369+
__Unknown(i32),
2370+
}
2371+
2372+
#[cfg(windows)]
2373+
#[doc(hidden)]
2374+
impl IntoGlib for Win32OSType {
2375+
type GlibType = ffi::GWin32OSType;
2376+
2377+
#[inline]
2378+
fn into_glib(self) -> ffi::GWin32OSType {
2379+
match self {
2380+
Self::Any => ffi::G_WIN32_OS_ANY,
2381+
Self::Workstation => ffi::G_WIN32_OS_WORKSTATION,
2382+
Self::Server => ffi::G_WIN32_OS_SERVER,
2383+
Self::__Unknown(value) => value,
2384+
}
2385+
}
2386+
}
2387+
2388+
#[cfg(windows)]
2389+
#[doc(hidden)]
2390+
impl FromGlib<ffi::GWin32OSType> for Win32OSType {
2391+
#[inline]
2392+
unsafe fn from_glib(value: ffi::GWin32OSType) -> Self {
2393+
match value {
2394+
ffi::G_WIN32_OS_ANY => Self::Any,
2395+
ffi::G_WIN32_OS_WORKSTATION => Self::Workstation,
2396+
ffi::G_WIN32_OS_SERVER => Self::Server,
2397+
value => Self::__Unknown(value),
2398+
}
2399+
}
2400+
}

glib/src/auto/functions.rs

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#[cfg(feature = "v2_66")]
66
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
77
use crate::FileSetContentsFlags;
8+
#[cfg(windows)]
9+
#[cfg_attr(docsrs, doc(cfg(windows)))]
10+
use crate::Win32OSType;
811
use crate::{
912
translate::*, Bytes, ChecksumType, Error, FileTest, FormatSizeFlags, Pid, Source, SpawnFlags,
1013
UserDirectory,
@@ -969,71 +972,49 @@ pub fn uuid_string_random() -> crate::GString {
969972
unsafe { from_glib_full(ffi::g_uuid_string_random()) }
970973
}
971974

972-
//#[doc(alias = "g_win32_check_windows_version")]
973-
//pub fn win32_check_windows_version(major: i32, minor: i32, spver: i32, os_type: /*Ignored*/Win32OSType) -> bool {
974-
// unsafe { TODO: call ffi:g_win32_check_windows_version() }
975-
//}
975+
#[cfg(windows)]
976+
#[cfg_attr(docsrs, doc(cfg(windows)))]
977+
#[doc(alias = "g_win32_check_windows_version")]
978+
pub fn win32_check_windows_version(
979+
major: i32,
980+
minor: i32,
981+
spver: i32,
982+
os_type: Win32OSType,
983+
) -> bool {
984+
unsafe {
985+
from_glib(ffi::g_win32_check_windows_version(
986+
major,
987+
minor,
988+
spver,
989+
os_type.into_glib(),
990+
))
991+
}
992+
}
976993

994+
#[cfg(windows)]
995+
#[cfg_attr(docsrs, doc(cfg(windows)))]
977996
#[doc(alias = "g_win32_error_message")]
978997
pub fn win32_error_message(error: i32) -> crate::GString {
979998
unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
980999
}
9811000

982-
#[doc(alias = "g_win32_ftruncate")]
983-
pub fn win32_ftruncate(f: i32, size: u32) -> i32 {
984-
unsafe { ffi::g_win32_ftruncate(f, size) }
985-
}
986-
1001+
#[cfg(windows)]
1002+
#[cfg_attr(docsrs, doc(cfg(windows)))]
9871003
#[doc(alias = "g_win32_get_command_line")]
9881004
pub fn win32_get_command_line() -> Vec<crate::GString> {
9891005
unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_win32_get_command_line()) }
9901006
}
9911007

992-
#[doc(alias = "g_win32_get_package_installation_directory")]
993-
pub fn win32_get_package_installation_directory(package: &str, dll_name: &str) -> crate::GString {
994-
unsafe {
995-
from_glib_full(ffi::g_win32_get_package_installation_directory(
996-
package.to_glib_none().0,
997-
dll_name.to_glib_none().0,
998-
))
999-
}
1000-
}
1001-
1002-
//#[doc(alias = "g_win32_get_package_installation_directory_of_module")]
1003-
//pub fn win32_get_package_installation_directory_of_module(hmodule: /*Unimplemented*/Option<Basic: Pointer>) -> crate::GString {
1004-
// unsafe { TODO: call ffi:g_win32_get_package_installation_directory_of_module() }
1005-
//}
1006-
1007-
#[doc(alias = "g_win32_get_package_installation_subdirectory")]
1008-
pub fn win32_get_package_installation_subdirectory(
1009-
package: &str,
1010-
dll_name: &str,
1011-
subdir: &str,
1012-
) -> crate::GString {
1013-
unsafe {
1014-
from_glib_full(ffi::g_win32_get_package_installation_subdirectory(
1015-
package.to_glib_none().0,
1016-
dll_name.to_glib_none().0,
1017-
subdir.to_glib_none().0,
1018-
))
1019-
}
1020-
}
1021-
1008+
#[cfg(windows)]
1009+
#[cfg_attr(docsrs, doc(cfg(windows)))]
10221010
#[doc(alias = "g_win32_get_windows_version")]
10231011
pub fn win32_get_windows_version() -> u32 {
10241012
unsafe { ffi::g_win32_get_windows_version() }
10251013
}
10261014

1015+
#[cfg(windows)]
1016+
#[cfg_attr(docsrs, doc(cfg(windows)))]
10271017
#[doc(alias = "g_win32_getlocale")]
10281018
pub fn win32_getlocale() -> crate::GString {
10291019
unsafe { from_glib_full(ffi::g_win32_getlocale()) }
10301020
}
1031-
1032-
#[doc(alias = "g_win32_locale_filename_from_utf8")]
1033-
pub fn win32_locale_filename_from_utf8(utf8filename: &str) -> crate::GString {
1034-
unsafe {
1035-
from_glib_full(ffi::g_win32_locale_filename_from_utf8(
1036-
utf8filename.to_glib_none().0,
1037-
))
1038-
}
1039-
}

glib/src/auto/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub use self::enums::UnicodeType;
5656
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
5757
pub use self::enums::UriError;
5858
pub use self::enums::VariantClass;
59+
#[cfg(windows)]
60+
#[cfg_attr(docsrs, doc(cfg(windows)))]
61+
pub use self::enums::Win32OSType;
5962

6063
mod flags;
6164
#[cfg(feature = "v2_66")]

glib/src/win32.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,7 @@
22

33
use std::path::PathBuf;
44

5-
use crate::{translate::*, GString, StrV};
6-
7-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
8-
pub enum OSType {
9-
#[doc(alias = "G_WIN32_OS_ANY")]
10-
Any,
11-
#[doc(alias = "G_WIN32_OS_WORKSTATION")]
12-
Workstation,
13-
#[doc(alias = "G_WIN32_OS_SERVER")]
14-
Server,
15-
}
16-
17-
#[doc(hidden)]
18-
impl IntoGlib for OSType {
19-
type GlibType = ffi::GWin32OSType;
20-
21-
#[inline]
22-
fn into_glib(self) -> Self::GlibType {
23-
match self {
24-
Self::Any => ffi::G_WIN32_OS_ANY,
25-
Self::Workstation => ffi::G_WIN32_OS_WORKSTATION,
26-
Self::Server => ffi::G_WIN32_OS_SERVER,
27-
}
28-
}
29-
}
30-
31-
#[doc(alias = "g_win32_check_windows_version")]
32-
pub fn check_windows_version(major: i32, minor: i32, spver: i32, os_type: OSType) -> bool {
33-
unsafe {
34-
from_glib(ffi::g_win32_check_windows_version(
35-
major,
36-
minor,
37-
spver,
38-
os_type.into_glib(),
39-
))
40-
}
41-
}
42-
43-
#[doc(alias = "g_win32_get_command_line")]
44-
#[doc(alias = "get_command_line")]
45-
pub fn command_line() -> StrV {
46-
unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_win32_get_command_line()) }
47-
}
48-
49-
#[doc(alias = "g_win32_error_message")]
50-
pub fn error_message(error: i32) -> GString {
51-
unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
52-
}
53-
54-
#[doc(alias = "g_win32_getlocale")]
55-
pub fn getlocale() -> GString {
56-
unsafe { from_glib_full(ffi::g_win32_getlocale()) }
57-
}
5+
use crate::translate::*;
586

597
#[doc(alias = "g_win32_get_package_installation_directory_of_module")]
608
#[doc(alias = "get_package_installation_directory_of_module")]

glib/sys/Gir.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,34 @@ name = "GLib.*"
6969
status = "generate"
7070
[[object.function]]
7171
name = "win32_locale_filename_from_utf8"
72-
cfg_condition = "window"
72+
cfg_condition = "windows"
7373
[[object.function]]
7474
name = "win32_get_windows_version"
75-
cfg_condition = "window"
75+
cfg_condition = "windows"
7676
[[object.function]]
7777
name = "win32_getlocale"
78-
cfg_condition = "window"
78+
cfg_condition = "windows"
7979
[[object.function]]
8080
name = "win32_check_windows_version"
81-
cfg_condition = "window"
81+
cfg_condition = "windows"
8282
[[object.function]]
8383
name = "win32_error_message"
84-
cfg_condition = "window"
84+
cfg_condition = "windows"
8585
[[object.function]]
8686
name = "win32_ftruncate"
87-
cfg_condition = "window"
87+
cfg_condition = "windows"
8888
[[object.function]]
8989
name = "win32_get_command_line"
90-
cfg_condition = "window"
90+
cfg_condition = "windows"
9191
[[object.function]]
9292
name = "win32_get_package_installation_directory"
93-
cfg_condition = "window"
93+
cfg_condition = "windows"
9494
[[object.function]]
9595
name = "win32_get_package_installation_directory_of_module"
96-
cfg_condition = "window"
96+
cfg_condition = "windows"
9797
[[object.function]]
9898
name = "win32_get_package_installation_subdirectory"
99-
cfg_condition = "window"
99+
cfg_condition = "windows"
100100
[[object.function]]
101101
name = "unix_get_passwd_entry"
102102
cfg_condition = "unix"
@@ -138,7 +138,7 @@ status = "ignore"
138138
[[object]]
139139
name = "GLib.Win32OSType"
140140
status = "generate"
141-
cfg_condition = "window"
141+
cfg_condition = "windows"
142142

143143
[[object]]
144144
name = "GLib.macro__has_attribute___noreturn__"

0 commit comments

Comments
 (0)