Skip to content

Commit

Permalink
Update for glib-2.80
Browse files Browse the repository at this point in the history
  • Loading branch information
rhx committed Apr 21, 2024
1 parent f720415 commit 2d21ba3
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ on macOS, or on Linux you should get something like:

### 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, 4.10, and 4.12 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

Expand Down
16 changes: 16 additions & 0 deletions Sources/CGLib/glib_bridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#include <glib/gversionmacros.h>
#undef __GLIB_H_INSIDE__

struct _GAllocator {};
struct _GAsyncQueue {};
struct _GBookmarkFile {};
struct _GBinding {};
struct _GBytes {};
struct _GCache {};
struct _GChecksum {};
struct _GData {};
struct _GDatagramBased {};
Expand All @@ -21,6 +23,7 @@ struct _GMainLoop {};
struct _GMappedFile {};
struct _GMarkupParseContext {};
struct _GMatchInfo {};
struct _GMemChunk {};
struct _GMemoryMonitor {};
struct _GModule {};
struct _GMutexLocker {};
Expand All @@ -31,6 +34,7 @@ struct _GPatternSpec {};
struct _GPowerProfileMonitor {};
struct _GRand {};
struct _GRegex {};
struct _GRelation {};
struct _GSequence {};
struct _GSequenceNode {};
struct _GSequenceIter {};
Expand Down Expand Up @@ -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
184 changes: 178 additions & 6 deletions Sources/GLib/GLib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ extension LogLevelFlags: Hashable {}
/// - level: log level (defaults to `.debug`)
@inlinable public func g_log(messagePtr: UnsafePointer<CChar>?, 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
Expand All @@ -161,7 +161,7 @@ extension LogLevelFlags: Hashable {}
logStructuredArray(logLevel: level, fields: &fields, nFields: fields.count)
}
}
#endif
#endif
}

/// Logging function
Expand All @@ -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
Expand All @@ -199,7 +199,7 @@ extension LogLevelFlags: Hashable {}
}
}
}
#endif
#endif
}
}
#endif
Expand All @@ -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<CChar>, _ 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<CChar>, _ 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<CChar>, _ mode: UnsafePointer<CChar>) -> UnsafeMutablePointer<FILE>? {
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<CChar>, _ mode: UnsafePointer<CChar>, _ stream: UnsafeMutablePointer<FILE>!) -> UnsafeMutablePointer<FILE>? {
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<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> 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<CChar>, _ 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<CChar>, _ 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<CChar>) -> 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<CChar>, _ new: UnsafePointer<CChar>) -> 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<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> 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<CChar>, _ times: UnsafePointer<utimbuf>!) -> CInt {
return utime(path, times)
}
#endif

2 changes: 2 additions & 0 deletions Sources/GLibObject/GObject-2.0.exclude
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VaClosureMarshal
SignalCVaMarshaller
signalSetVaMarshaller
IOCondition

4 changes: 4 additions & 0 deletions Sources/GModule/GModule-2.0.verbatim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODULE_IMPL_AR
MODULE_IMPL_DL
MODULE_IMPL_NONE
MODULE_IMPL_WIN32

0 comments on commit 2d21ba3

Please sign in to comment.