From 41a778ae6ddea83da05583b64e8d326bb8ba5a7b Mon Sep 17 00:00:00 2001 From: Rene Hexel Date: Sun, 21 Apr 2024 15:05:05 +1000 Subject: [PATCH] Update for gtk-4.14 --- LICENSE | 2 +- README.md | 6 +- Sources/CGLib/glib_bridging.h | 16 +++ Sources/GLib/GLib.swift | 184 ++++++++++++++++++++++++- Sources/GLibObject/GObject-2.0.exclude | 2 + Sources/GModule/GModule-2.0.verbatim | 4 + Sources/Gtk/Gtk-3.0.awk | 43 +++--- 7 files changed, 226 insertions(+), 31 deletions(-) diff --git a/LICENSE b/LICENSE index 12a1d30cd..029692294 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016, 2017, 2018, 2019 Rene Hexel +Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Rene Hexel All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index bfa23509c..527b82ff8 100644 --- a/README.md +++ b/README.md @@ -96,18 +96,18 @@ After that, use the (usual) Build and Test buttons to build/test this package. To build, download Swift from https://swift.org/download/ -- if you are using macOS, make sure you have the command line tools installed as well). Test that your compiler works using `swift --version`, which should give you something like $ swift --version - swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) + swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) Target: arm64-apple-macosx14.0 on macOS, or on Linux you should get something like: $ swift --version - Swift version 5.9 (swift-5.9-RELEASE) + Swift version 5.10 (swift-5.10-RELEASE) Target: x86_64-unknown-linux-gnu ### Gtk 3.22 or higher -The Swift wrappers have been tested with glib-2.56, 2.58, 2.60, 2.62, 2.64, 2.66, 2.68, 2.70, 2.72, 2.74, 2.76 and 2.78, and gdk/gtk 3.22, 3.24 as well as 4.0, 4.2, 4.4, 4.6, 4.8, and 4.10 on the `gtk4` branch. They should work with higher versions, but YMMV. Also make sure you have `gobject-introspection` and its `.gir` files installed. +The Swift wrappers have been tested with glib-2.56, 2.58, 2.60, 2.62, 2.64, 2.66, 2.68, 2.70, 2.72, 2.74, 2.76, 2.78 and 2.80, and gdk/gtk 3.22, 3.24 as well as 4.0, 4.2, 4.4, 4.6, 4.8, 4.10, 4.12, and 4.14 on the `gtk4` branch. They should work with higher versions, but YMMV. Also make sure you have `gobject-introspection` and its `.gir` files installed. #### Linux diff --git a/Sources/CGLib/glib_bridging.h b/Sources/CGLib/glib_bridging.h index 1a4e0b745..107e733ea 100644 --- a/Sources/CGLib/glib_bridging.h +++ b/Sources/CGLib/glib_bridging.h @@ -3,10 +3,12 @@ #include #undef __GLIB_H_INSIDE__ +struct _GAllocator {}; struct _GAsyncQueue {}; struct _GBookmarkFile {}; struct _GBinding {}; struct _GBytes {}; +struct _GCache {}; struct _GChecksum {}; struct _GData {}; struct _GDatagramBased {}; @@ -21,6 +23,7 @@ struct _GMainLoop {}; struct _GMappedFile {}; struct _GMarkupParseContext {}; struct _GMatchInfo {}; +struct _GMemChunk {}; struct _GMemoryMonitor {}; struct _GModule {}; struct _GMutexLocker {}; @@ -31,6 +34,7 @@ struct _GPatternSpec {}; struct _GPowerProfileMonitor {}; struct _GRand {}; struct _GRegex {}; +struct _GRelation {}; struct _GSequence {}; struct _GSequenceNode {}; struct _GSequenceIter {}; @@ -368,3 +372,15 @@ typedef GUriParamsFlags GURIParamsFlags; typedef GUriHideFlags GURIHideFlags; typedef struct _GTreeNode GTreeNode; typedef struct _GStrvBuilder GStrvBuilder; + +#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 80 +extern GType g_threaded_resolver_get_type(void); + +struct _GThreadedResolver {}; +struct _GThreadedResolverClass +{ + GResolverClass parent_class; +}; +typedef struct _GThreadedResolver GThreadedResolver; +typedef struct _GThreadedResolverClass GThreadedResolverClass; +#endif diff --git a/Sources/GLib/GLib.swift b/Sources/GLib/GLib.swift index 6f69ca423..d531732f8 100644 --- a/Sources/GLib/GLib.swift +++ b/Sources/GLib/GLib.swift @@ -145,9 +145,9 @@ extension LogLevelFlags: Hashable {} /// - level: log level (defaults to `.debug`) @inlinable public func g_log(messagePtr: UnsafePointer?, level: LogLevelFlags = .debug) { guard let msg = messagePtr else { return } - #if swift(<5.2) +#if swift(<5.2) g_logv(nil, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: UnsafeMutableRawPointer(mutating: msg))) - #else +#else guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else { print(String(cString: msg)) return @@ -161,7 +161,7 @@ extension LogLevelFlags: Hashable {} logStructuredArray(logLevel: level, fields: &fields, nFields: fields.count) } } - #endif +#endif } /// Logging function @@ -178,9 +178,9 @@ extension LogLevelFlags: Hashable {} withUnsafeMutableBytes(of: &buffer) { guard let buffer = $0.baseAddress else { return } let msg = buffer.assumingMemoryBound(to: CChar.self) - #if swift(<5.2) +#if swift(<5.2) g_logv(domain, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: buffer)) - #else +#else guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else { print(message) return @@ -199,7 +199,7 @@ extension LogLevelFlags: Hashable {} } } } - #endif +#endif } } #endif @@ -216,3 +216,175 @@ extension LogLevelFlags: Hashable {} g_log(message, level: .warning) } } + +#if os(macOS) || os(Linux) +/// Change the mode oft a filesystem object. +/// +/// This function is a wrapper around the `chmod()` system call, +/// changing the mode of the filesystem object pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to query. +/// - mode: The new mode for the object. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_chmod(_ path: UnsafePointer, _ mode: gint) -> CInt { + return chmod(path, mode_t(mode)) +} + +/// Create a file. +/// +/// This function is a wrapper around the `creat()` system call, +/// creating a filesystem object pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to create. +/// - mode: The new mode for the object. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_creat(_ path: UnsafePointer, _ mode: gint) -> CInt { + return creat(path, mode_t(mode)) +} + +/// Open or create a buiffered stream. +/// +/// This function is a wrapper around the `fopen()` system call, +/// creating a filesystem stream object pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to open. +/// - mode: The new mode for the object when created. +/// - Returns: a pointer to the new stream object, `nil` on error. +@inlinable +public func g_fopen(_ path: UnsafePointer, _ mode: UnsafePointer) -> UnsafeMutablePointer? { + return fopen(path, mode) +} + +/// Repen a buiffered stream. +/// +/// This function is a wrapper around the `freopen()` system call, +/// reopening a filesystem stream object pointed to by `path` and +/// associates the stream with the given file pointer. +/// +/// - Parameters: +/// - path: The filesystem path of the object to open. +/// - mode: The new mode for the object when created. +/// - stream: The stream to associate with the file pointer. +/// - Returns: a pointer to the stream object, `nil` on error. +@inlinable +public func g_freopen(_ path: UnsafePointer, _ mode: UnsafePointer, _ stream: UnsafeMutablePointer!) -> UnsafeMutablePointer? { + return freopen(path, mode, stream) +} + +/// Syncronize a filesystem object. +/// +/// This function is a wrapper around the `fsync()` system call, +/// synchronising the files descriptor passed in. +/// +/// - Parameters: +/// - fileDescriptor: The file descriptor to syncronise. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_fsync(_ fileDescriptor: CInt) -> CInt { + return fsync(fileDescriptor) +} + +/// Get information about a filesystem object. +/// +/// This function is a wrapper around the `lstat()` system call, +/// returning information about the file pointed to by `path`, +/// without following symbolic links. +/// +/// - Parameters: +/// - path: The filesystem path of the object to query. +/// - buf: A `GStatBuf` structure to fill in with information about the file. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_lstat(_ path: UnsafePointer, _ buf: UnsafeMutablePointer!) -> CInt { + return lstat(path, buf) +} + +/// Create a directory. +/// +/// This function is a wrapper around the `mkdir()` system call, +/// creating a directory pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the directory to create. +/// - mode: The new mode for the directory. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_mkdir(_ path: UnsafePointer, _ mode: gint) -> CInt { + return mkdir(path, mode_t(mode)) +} + +/// Open a file. +/// +/// This function is a wrapper around the `open()` system call, +/// opening a filesystem object pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to open. +/// - flags: The flags to use when opening the object. +/// - mode: The new mode for the object. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_open(_ path: UnsafePointer, _ flags: CInt, _ mode: gint = 0) -> CInt { + return open(path, flags, mode_t(mode)) +} + +/// Remove a filesystem object. +/// +/// This function is a wrapper around the `remove()` system call, +/// removing the filesystem object pointed to by `path`. +/// +/// - Parameter path: The filesystem path of the object to remove. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_remove(_ path: UnsafePointer) -> CInt { + return remove(path) +} + +/// Rename a filesystem object. +/// +/// This function is a wrapper around the `rename()` system call, +/// renaming the filesystem object pointed to by `old` to `new`. +/// +/// - Parameters: +/// - old: The old filesystem path. +/// - new: The new filesystem path. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_rename(_ old: UnsafePointer, _ new: UnsafePointer) -> CInt { + return rename(old, new) +} + +/// Get information about a filesystem object. +/// +/// This function is a wrapper around the `stat()` system call, +/// returning information about the file pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to query. +/// - buf: A `GStatBuf` structure to fill in with information about the file. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_stat(_ path: UnsafePointer, _ buf: UnsafeMutablePointer!) -> CInt { + return stat(path, buf) +} + +/// Set filesystem object times. +/// +/// This function is a wrapper around the `utime()` system call, +/// setting time information about the file pointed to by `path`. +/// +/// - Parameters: +/// - path: The filesystem path of the object to query. +/// - times: Pointer to a`utimbuf` structure with information about the file access and modification times. +/// - Returns: `0` on success, `-1` on error. +@inlinable +public func g_utime(_ path: UnsafePointer, _ times: UnsafePointer!) -> CInt { + return utime(path, times) +} +#endif + diff --git a/Sources/GLibObject/GObject-2.0.exclude b/Sources/GLibObject/GObject-2.0.exclude index 0548b846c..f7359ed2c 100644 --- a/Sources/GLibObject/GObject-2.0.exclude +++ b/Sources/GLibObject/GObject-2.0.exclude @@ -1,3 +1,5 @@ VaClosureMarshal SignalCVaMarshaller signalSetVaMarshaller +IOCondition + diff --git a/Sources/GModule/GModule-2.0.verbatim b/Sources/GModule/GModule-2.0.verbatim index e69de29bb..54f9d9d07 100644 --- a/Sources/GModule/GModule-2.0.verbatim +++ b/Sources/GModule/GModule-2.0.verbatim @@ -0,0 +1,4 @@ +MODULE_IMPL_AR +MODULE_IMPL_DL +MODULE_IMPL_NONE +MODULE_IMPL_WIN32 diff --git a/Sources/Gtk/Gtk-3.0.awk b/Sources/Gtk/Gtk-3.0.awk index 455168055..340a3c19d 100644 --- a/Sources/Gtk/Gtk-3.0.awk +++ b/Sources/Gtk/Gtk-3.0.awk @@ -5,31 +5,32 @@ BEGIN { depr_init = 0 ; comment = 0 ; slist = 0 ; overr = 0 ; ostock = 0 ; no_fields = 0 ; close_comment = 0; icon_size = 0 ; grp = 0 } -/Creates a new `GtkRecentChooserMenu` widget\.$/ { overr = 1 } +/Creates a new ``RecentChooserMenu`` widget\.$/ { overr = 1 } /a swatch representing the current selected color. When the button/ { overr = 1 } #/Creates a new dialog box/ { overr = 1 } /Creates a new font picker widget/ { overr = 1 } /Creates a new toggle button/ { overr = 1 } -/Creates a new GtkModelButton/ { overr = 1 ; sub("GtkModelButton", "`GtkModelButton`") } -/Creates a new `GtkAboutDialog`\.$/ { overr = 1 } -/Creates a new `GtkCellRendererAccel`/ { overr = 1 } -/Creates a new `GtkCellRendererCombo`/ { overr = 1 } -/Creates a new `GtkCellRendererSpin`/ { overr = 1 } -/Creates a new `GtkCheckButton`/ { overr = 1 } -/Creates a new `GtkCheckMenuItem`/ { overr = 1 } -/Creates a new `GtkComboBoxText`/ { overr = 1 } -/Creates a new `GtkImageMenuItem` with an empty label/ { overr = 1 } -/Creates a new `GtkImageMenuItem` containing a label/ { overr = 1 } -/Creates a new `GtkMenuButton`/ { overr = 1 } -/Creates a new `GtkMenuToolButton`/ { overr = 1 } -/Creates a `GtkSearchEntry`/ { overr = 1 } -/Creates a new `GtkSeparatorMenuItem`/ { overr = 1 } -/Create a new `GtkSeparatorToolItem`/ { overr = 1 } -/Creates a new `GtkTearoffMenuItem`/ { overr = 1 } -/Creates a new `GtkToggleAction`/ { overr = 1 } -/Creates a new `GtkToggleButton`/ { overr = 1 } -/Creates a new `GtkToggleToolButton`/ { overr = 1 } -/Creates a new `GtkRecentAction`/ { ostock = 1 } +/Creates a new GtkModelButton/ { overr = 1 ; sub("GtkModelButton", "``ModelButton``") } +/Create a new GtkSeparatorToolItem/ { overr = 1 ; sub("GtkSeparatorToolItem", "``SeparatorToolItem``.") } +/Creates a new ``AboutDialog``\.$/ { overr = 1 } +/Creates a new ``CellRendererAccel`/ { overr = 1 } +/Creates a new ``CellRendererCombo`/ { overr = 1 } +/Creates a new ``CellRendererSpin`/ { overr = 1 } +/Creates a new ``CheckButton`/ { overr = 1 } +/Creates a new ``CheckMenuItem`/ { overr = 1 } +/Creates a new ``ComboBoxText`/ { overr = 1 } +/Creates a new ``ImageMenuItem`` with an empty label/ { overr = 1 } +/Creates a new ``ImageMenuItem`` containing a label/ { overr = 1 } +/Creates a new ``MenuButton`/ { overr = 1 } +/Creates a new ``MenuToolButton`/ { overr = 1 } +/Creates a ``SearchEntry`/ { overr = 1 } +/Creates a new ``SeparatorMenuItem`/ { overr = 1 } +/Create a new ``SeparatorToolItem`/ { overr = 1 } +/Creates a new ``TearoffMenuItem`/ { overr = 1 } +/Creates a new ``ToggleAction`/ { overr = 1 } +/Creates a new ``ToggleButton`/ { overr = 1 } +/Creates a new ``ToggleToolButton`/ { overr = 1 } +/Creates a new ``RecentAction`/ { ostock = 1 } / the file belongs to/ { grp = 1 } /open .* ColorSelection/ { depr_init = 1 } /public .* ColorSelection/ { depr_init = 1 }