Skip to content

Commit 2d21ba3

Browse files
committed
Update for glib-2.80
1 parent f720415 commit 2d21ba3

File tree

5 files changed

+201
-7
lines changed

5 files changed

+201
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ on macOS, or on Linux you should get something like:
108108

109109
### Gtk 3.22 or higher
110110

111-
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.
111+
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.
112112

113113
#### Linux
114114

Sources/CGLib/glib_bridging.h

+16
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
#include <glib/gversionmacros.h>
44
#undef __GLIB_H_INSIDE__
55

6+
struct _GAllocator {};
67
struct _GAsyncQueue {};
78
struct _GBookmarkFile {};
89
struct _GBinding {};
910
struct _GBytes {};
11+
struct _GCache {};
1012
struct _GChecksum {};
1113
struct _GData {};
1214
struct _GDatagramBased {};
@@ -21,6 +23,7 @@ struct _GMainLoop {};
2123
struct _GMappedFile {};
2224
struct _GMarkupParseContext {};
2325
struct _GMatchInfo {};
26+
struct _GMemChunk {};
2427
struct _GMemoryMonitor {};
2528
struct _GModule {};
2629
struct _GMutexLocker {};
@@ -31,6 +34,7 @@ struct _GPatternSpec {};
3134
struct _GPowerProfileMonitor {};
3235
struct _GRand {};
3336
struct _GRegex {};
37+
struct _GRelation {};
3438
struct _GSequence {};
3539
struct _GSequenceNode {};
3640
struct _GSequenceIter {};
@@ -368,3 +372,15 @@ typedef GUriParamsFlags GURIParamsFlags;
368372
typedef GUriHideFlags GURIHideFlags;
369373
typedef struct _GTreeNode GTreeNode;
370374
typedef struct _GStrvBuilder GStrvBuilder;
375+
376+
#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 80
377+
extern GType g_threaded_resolver_get_type(void);
378+
379+
struct _GThreadedResolver {};
380+
struct _GThreadedResolverClass
381+
{
382+
GResolverClass parent_class;
383+
};
384+
typedef struct _GThreadedResolver GThreadedResolver;
385+
typedef struct _GThreadedResolverClass GThreadedResolverClass;
386+
#endif

Sources/GLib/GLib.swift

+178-6
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ extension LogLevelFlags: Hashable {}
145145
/// - level: log level (defaults to `.debug`)
146146
@inlinable public func g_log(messagePtr: UnsafePointer<CChar>?, level: LogLevelFlags = .debug) {
147147
guard let msg = messagePtr else { return }
148-
#if swift(<5.2)
148+
#if swift(<5.2)
149149
g_logv(nil, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: UnsafeMutableRawPointer(mutating: msg)))
150-
#else
150+
#else
151151
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
152152
print(String(cString: msg))
153153
return
@@ -161,7 +161,7 @@ extension LogLevelFlags: Hashable {}
161161
logStructuredArray(logLevel: level, fields: &fields, nFields: fields.count)
162162
}
163163
}
164-
#endif
164+
#endif
165165
}
166166

167167
/// Logging function
@@ -178,9 +178,9 @@ extension LogLevelFlags: Hashable {}
178178
withUnsafeMutableBytes(of: &buffer) {
179179
guard let buffer = $0.baseAddress else { return }
180180
let msg = buffer.assumingMemoryBound(to: CChar.self)
181-
#if swift(<5.2)
181+
#if swift(<5.2)
182182
g_logv(domain, level.value, msg, CVaListPointer(_fromUnsafeMutablePointer: buffer))
183-
#else
183+
#else
184184
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
185185
print(message)
186186
return
@@ -199,7 +199,7 @@ extension LogLevelFlags: Hashable {}
199199
}
200200
}
201201
}
202-
#endif
202+
#endif
203203
}
204204
}
205205
#endif
@@ -216,3 +216,175 @@ extension LogLevelFlags: Hashable {}
216216
g_log(message, level: .warning)
217217
}
218218
}
219+
220+
#if os(macOS) || os(Linux)
221+
/// Change the mode oft a filesystem object.
222+
///
223+
/// This function is a wrapper around the `chmod()` system call,
224+
/// changing the mode of the filesystem object pointed to by `path`.
225+
///
226+
/// - Parameters:
227+
/// - path: The filesystem path of the object to query.
228+
/// - mode: The new mode for the object.
229+
/// - Returns: `0` on success, `-1` on error.
230+
@inlinable
231+
public func g_chmod(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
232+
return chmod(path, mode_t(mode))
233+
}
234+
235+
/// Create a file.
236+
///
237+
/// This function is a wrapper around the `creat()` system call,
238+
/// creating a filesystem object pointed to by `path`.
239+
///
240+
/// - Parameters:
241+
/// - path: The filesystem path of the object to create.
242+
/// - mode: The new mode for the object.
243+
/// - Returns: `0` on success, `-1` on error.
244+
@inlinable
245+
public func g_creat(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
246+
return creat(path, mode_t(mode))
247+
}
248+
249+
/// Open or create a buiffered stream.
250+
///
251+
/// This function is a wrapper around the `fopen()` system call,
252+
/// creating a filesystem stream object pointed to by `path`.
253+
///
254+
/// - Parameters:
255+
/// - path: The filesystem path of the object to open.
256+
/// - mode: The new mode for the object when created.
257+
/// - Returns: a pointer to the new stream object, `nil` on error.
258+
@inlinable
259+
public func g_fopen(_ path: UnsafePointer<CChar>, _ mode: UnsafePointer<CChar>) -> UnsafeMutablePointer<FILE>? {
260+
return fopen(path, mode)
261+
}
262+
263+
/// Repen a buiffered stream.
264+
///
265+
/// This function is a wrapper around the `freopen()` system call,
266+
/// reopening a filesystem stream object pointed to by `path` and
267+
/// associates the stream with the given file pointer.
268+
///
269+
/// - Parameters:
270+
/// - path: The filesystem path of the object to open.
271+
/// - mode: The new mode for the object when created.
272+
/// - stream: The stream to associate with the file pointer.
273+
/// - Returns: a pointer to the stream object, `nil` on error.
274+
@inlinable
275+
public func g_freopen(_ path: UnsafePointer<CChar>, _ mode: UnsafePointer<CChar>, _ stream: UnsafeMutablePointer<FILE>!) -> UnsafeMutablePointer<FILE>? {
276+
return freopen(path, mode, stream)
277+
}
278+
279+
/// Syncronize a filesystem object.
280+
///
281+
/// This function is a wrapper around the `fsync()` system call,
282+
/// synchronising the files descriptor passed in.
283+
///
284+
/// - Parameters:
285+
/// - fileDescriptor: The file descriptor to syncronise.
286+
/// - Returns: `0` on success, `-1` on error.
287+
@inlinable
288+
public func g_fsync(_ fileDescriptor: CInt) -> CInt {
289+
return fsync(fileDescriptor)
290+
}
291+
292+
/// Get information about a filesystem object.
293+
///
294+
/// This function is a wrapper around the `lstat()` system call,
295+
/// returning information about the file pointed to by `path`,
296+
/// without following symbolic links.
297+
///
298+
/// - Parameters:
299+
/// - path: The filesystem path of the object to query.
300+
/// - buf: A `GStatBuf` structure to fill in with information about the file.
301+
/// - Returns: `0` on success, `-1` on error.
302+
@inlinable
303+
public func g_lstat(_ path: UnsafePointer<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> CInt {
304+
return lstat(path, buf)
305+
}
306+
307+
/// Create a directory.
308+
///
309+
/// This function is a wrapper around the `mkdir()` system call,
310+
/// creating a directory pointed to by `path`.
311+
///
312+
/// - Parameters:
313+
/// - path: The filesystem path of the directory to create.
314+
/// - mode: The new mode for the directory.
315+
/// - Returns: `0` on success, `-1` on error.
316+
@inlinable
317+
public func g_mkdir(_ path: UnsafePointer<CChar>, _ mode: gint) -> CInt {
318+
return mkdir(path, mode_t(mode))
319+
}
320+
321+
/// Open a file.
322+
///
323+
/// This function is a wrapper around the `open()` system call,
324+
/// opening a filesystem object pointed to by `path`.
325+
///
326+
/// - Parameters:
327+
/// - path: The filesystem path of the object to open.
328+
/// - flags: The flags to use when opening the object.
329+
/// - mode: The new mode for the object.
330+
/// - Returns: `0` on success, `-1` on error.
331+
@inlinable
332+
public func g_open(_ path: UnsafePointer<CChar>, _ flags: CInt, _ mode: gint = 0) -> CInt {
333+
return open(path, flags, mode_t(mode))
334+
}
335+
336+
/// Remove a filesystem object.
337+
///
338+
/// This function is a wrapper around the `remove()` system call,
339+
/// removing the filesystem object pointed to by `path`.
340+
///
341+
/// - Parameter path: The filesystem path of the object to remove.
342+
/// - Returns: `0` on success, `-1` on error.
343+
@inlinable
344+
public func g_remove(_ path: UnsafePointer<CChar>) -> CInt {
345+
return remove(path)
346+
}
347+
348+
/// Rename a filesystem object.
349+
///
350+
/// This function is a wrapper around the `rename()` system call,
351+
/// renaming the filesystem object pointed to by `old` to `new`.
352+
///
353+
/// - Parameters:
354+
/// - old: The old filesystem path.
355+
/// - new: The new filesystem path.
356+
/// - Returns: `0` on success, `-1` on error.
357+
@inlinable
358+
public func g_rename(_ old: UnsafePointer<CChar>, _ new: UnsafePointer<CChar>) -> CInt {
359+
return rename(old, new)
360+
}
361+
362+
/// Get information about a filesystem object.
363+
///
364+
/// This function is a wrapper around the `stat()` system call,
365+
/// returning information about the file pointed to by `path`.
366+
///
367+
/// - Parameters:
368+
/// - path: The filesystem path of the object to query.
369+
/// - buf: A `GStatBuf` structure to fill in with information about the file.
370+
/// - Returns: `0` on success, `-1` on error.
371+
@inlinable
372+
public func g_stat(_ path: UnsafePointer<CChar>, _ buf: UnsafeMutablePointer<GStatBuf>!) -> CInt {
373+
return stat(path, buf)
374+
}
375+
376+
/// Set filesystem object times.
377+
///
378+
/// This function is a wrapper around the `utime()` system call,
379+
/// setting time information about the file pointed to by `path`.
380+
///
381+
/// - Parameters:
382+
/// - path: The filesystem path of the object to query.
383+
/// - times: Pointer to a`utimbuf` structure with information about the file access and modification times.
384+
/// - Returns: `0` on success, `-1` on error.
385+
@inlinable
386+
public func g_utime(_ path: UnsafePointer<CChar>, _ times: UnsafePointer<utimbuf>!) -> CInt {
387+
return utime(path, times)
388+
}
389+
#endif
390+
+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
VaClosureMarshal
22
SignalCVaMarshaller
33
signalSetVaMarshaller
4+
IOCondition
5+

Sources/GModule/GModule-2.0.verbatim

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MODULE_IMPL_AR
2+
MODULE_IMPL_DL
3+
MODULE_IMPL_NONE
4+
MODULE_IMPL_WIN32

0 commit comments

Comments
 (0)