[glib/wip/ghandle: 3/16] gpoll: introduce new ghandle type
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/ghandle: 3/16] gpoll: introduce new ghandle type
- Date: Fri, 19 Dec 2014 17:25:33 +0000 (UTC)
commit 19499579f9eb3de59e6ba75e430f9189ff818c3c
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Dec 18 13:23:05 2014 -0500
gpoll: introduce new ghandle type
We've long discussed having a ghandle type corresponding to HANDLE on windows
and an int (fd) elsewhere. Let's add that now.
We continue to maintain the 'fd' field as being an integer on Windows in order
to avoid warnings about implicit casts in existing software. 'ghandleint' was
introduced for that purpose.
docs/reference/glib/glib-sections.txt | 4 +++
glib/docs.c | 38 +++++++++++++++++++++++++++++++++
glib/gpoll.h | 26 ++++++++++++++++------
3 files changed, 61 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index d34600f..aaac897 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -544,6 +544,10 @@ g_child_watch_add
g_child_watch_add_full
<SUBSECTION>
+ghandle
+ghandleint
+%G_HANDLE_NULL
+g_handle_is_valid
GPollFD
g_poll
G_POLLFD_FORMAT
diff --git a/glib/docs.c b/glib/docs.c
index 43c9f27..abccc6b 100644
--- a/glib/docs.c
+++ b/glib/docs.c
@@ -2370,5 +2370,43 @@
* Since: 2.6
*/
+/* ghandle {{{1 */
+/**
+ * ghandle:
+ *
+ * Corresponds to a HANDLE on Windows and a file descriptor elsewhere.
+ *
+ * Since: 2.44
+ */
+
+/**
+ * ghandleint:
+ *
+ * An integer with the same size as #ghandle. Used in #GPollFD as the
+ * 'fd' field.
+ *
+ * Since: 2.44
+ */
+
+/**
+ * G_HANDLE_INVALID:
+ *
+ * A value used to denote an invalid handle. Can always be safely
+ * compared to #ghandle.
+ *
+ * See also g_handle_is_valid().
+ *
+ * Since: 2.44
+ */
+
+/**
+ * g_handle_is_valid:
+ * @handle: a #ghandle
+ *
+ * Checks if a #ghandle is valid (ie: not equal to G_HANDLE_NULL).
+ *
+ * Since: 2.44
+ */
+
/* Epilogue {{{1 */
/* vim: set foldmethod=marker: */
diff --git a/glib/gpoll.h b/glib/gpoll.h
index f28e3c5..44f33ec 100644
--- a/glib/gpoll.h
+++ b/glib/gpoll.h
@@ -74,6 +74,24 @@ typedef gint (*GPollFunc) (GPollFD *ufds,
guint nfsd,
gint timeout_);
+#ifdef G_OS_WIN32
+typedef gintptr ghandleint;
+typedef gpointer ghandle;
+#define G_HANDLE_NULL (NULL)
+#else
+typedef gint ghandleint;
+typedef gint ghandle;
+#define G_HANDLE_NULL (-1)
+#endif
+
+G_STATIC_ASSERT(sizeof (ghandle) == sizeof (ghandleint));
+
+static inline gboolean
+g_handle_is_valid (ghandle handle)
+{
+ return handle != G_HANDLE_NULL;
+}
+
/**
* GPollFD:
* @fd: the file descriptor to poll (or a HANDLE on Win32)
@@ -89,13 +107,7 @@ typedef gint (*GPollFunc) (GPollFD *ufds,
*/
struct _GPollFD
{
-#if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
-#ifndef __GTK_DOC_IGNORE__
- gint64 fd;
-#endif
-#else
- gint fd;
-#endif
+ ghandleint fd;
gushort events;
gushort revents;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]