[glibmm] Gio::UnixFDList, UnixFDMessage: Fix array lengths in steal_fds()
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::UnixFDList, UnixFDMessage: Fix array lengths in steal_fds()
- Date: Fri, 12 Dec 2014 18:15:02 +0000 (UTC)
commit fe0e25c8f1af8c3553c14608a672a3447361e18a
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Fri Dec 12 18:48:05 2014 +0100
Gio::UnixFDList, UnixFDMessage: Fix array lengths in steal_fds()
* gio/src/unixfdlist.[hg|ccg]: Hand-code both constructors that take a
Glib::ArrayHandle<int>, and call g_unix_fd_list_new_from_array() in them.
* gio/src/unixfdlist.ccg: Don't subtract 1 from the length returned by
g_unix_fd_list_[peek|steal]_fds().
* gio/src/unixfdmessage.hg: get_fd_list(): Add refreturn.
* gio/src/unixfdmessage.ccg: Don't subtract 1 from the length returned by
g_unix_fd_message_steal_fds(). Bug #741365.
gio/src/unixfdlist.ccg | 41 +++++++++++++++++++++++++++++++----------
gio/src/unixfdlist.hg | 7 ++-----
gio/src/unixfdmessage.ccg | 7 +++----
gio/src/unixfdmessage.hg | 7 ++-----
4 files changed, 38 insertions(+), 24 deletions(-)
---
diff --git a/gio/src/unixfdlist.ccg b/gio/src/unixfdlist.ccg
index 4fbed4d..aa26c9c 100644
--- a/gio/src/unixfdlist.ccg
+++ b/gio/src/unixfdlist.ccg
@@ -1,5 +1,3 @@
-// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-
/* Copyright (C) 2010 The giomm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -24,24 +22,47 @@ namespace Gio
{
UnixFDList::UnixFDList(const Glib::ArrayHandle<int>& fds)
-: _CONSTRUCT("fds", fds.data(), "n_fds", fds.size())
-{}
+:
+ // Mark this class as non-derived to allow C++ vfuncs to be skipped.
+ Glib::ObjectBase(0),
+ // g_unix_fd_list_new_from_array() must be called.
+ // Its parameters don't correspond to properties.
+ // _CONSTRUCT() + g_unit_fd_list_append() is not an alternative.
+ // g_unit_fd_list_append() duplicates the file descriptor,
+ // but g_unix_fd_list_new_from_array() does not.
+ Glib::Object((GObject*)g_unix_fd_list_new_from_array(fds.data(), fds.size()))
+{
+}
+
+UnixFDList::UnixFDList(const Glib::ArrayHandle<int>& fds, int n_fds)
+:
+ // Mark this class as non-derived to allow C++ vfuncs to be skipped.
+ Glib::ObjectBase(0),
+ // g_unix_fd_list_new_from_array() must be called.
+ // Its parameters don't correspond to properties.
+ // _CONSTRUCT() + g_unit_fd_list_append() is not an alternative.
+ // g_unit_fd_list_append() duplicates the file descriptor,
+ // but g_unix_fd_list_new_from_array() does not.
+ Glib::Object((GObject*)g_unix_fd_list_new_from_array(fds.data(), n_fds))
+{
+}
const Glib::ArrayHandle<int> UnixFDList::peek_fds() const
{
int length = 0;
- const int* fds = g_unix_fd_list_peek_fds(const_cast<GUnixFDList*>(gobj()),
- &length);
- // (length - 1) is used because the array is terminated with a -1.
- return Glib::ArrayHandle<int>(fds, length - 1, Glib::OWNERSHIP_NONE);
+ const int* fds = g_unix_fd_list_peek_fds(const_cast<GUnixFDList*>(gobj()), &length);
+ // The array is terminated with a -1, but that terminating element is
+ // not included in the length that g_unix_fd_list_peek_fds() returns.
+ return Glib::ArrayHandle<int>(fds, length, Glib::OWNERSHIP_NONE);
}
Glib::ArrayHandle<int> UnixFDList::steal_fds()
{
int length = 0;
const int* fds = g_unix_fd_list_steal_fds(gobj(), &length);
- // (length - 1) is used because the array is terminated with a -1.
- return Glib::ArrayHandle<int>(fds, length - 1, Glib::OWNERSHIP_DEEP);
+ // The array is terminated with a -1, but that terminating element is
+ // not included in the length that g_unix_fd_list_steal_fds() returns.
+ return Glib::ArrayHandle<int>(fds, length, Glib::OWNERSHIP_DEEP);
}
} // namespace Gio
diff --git a/gio/src/unixfdlist.hg b/gio/src/unixfdlist.hg
index 4ff3ec4..6525f32 100644
--- a/gio/src/unixfdlist.hg
+++ b/gio/src/unixfdlist.hg
@@ -1,5 +1,3 @@
-// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-
/* Copyright (C) 2010 The giomm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -26,7 +24,6 @@ _PINCLUDE(glibmm/private/object_p.h)
namespace Gio
{
-
/** UnixFDList - An object containing a set of UNIX file descriptors.
* A UnixFDList contains a list of file descriptors. It owns the file
* descriptors that it contains, closing them when finalized.
@@ -49,8 +46,8 @@ protected:
explicit UnixFDList(const Glib::ArrayHandle<int>& fds);
-#m4 _CONVERSION(`const Glib::ArrayHandle<int>&', `const gint*', `$3.data()')
- _WRAP_CTOR(UnixFDList(const Glib::ArrayHandle<int>& fds, int n_fds), g_unix_fd_list_new_from_array)
+ explicit UnixFDList(const Glib::ArrayHandle<int>& fds, int n_fds);
+ _IGNORE(g_unix_fd_list_new_from_array)
public:
_WRAP_METHOD_DOCS_ONLY(g_unix_fd_list_new)
diff --git a/gio/src/unixfdmessage.ccg b/gio/src/unixfdmessage.ccg
index ec38df4..d112bb6 100644
--- a/gio/src/unixfdmessage.ccg
+++ b/gio/src/unixfdmessage.ccg
@@ -1,5 +1,3 @@
-// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-
/* Copyright (C) 2010 The giomm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -28,8 +26,9 @@ Glib::ArrayHandle<int> UnixFDMessage::steal_fds()
{
int length = 0;
const int* fds = g_unix_fd_message_steal_fds(gobj(), &length);
- // (length - 1) is used because the array is terminated with a -1.
- return Glib::ArrayHandle<int>(fds, length - 1, Glib::OWNERSHIP_DEEP);
+ // The array is terminated with a -1, but that terminating element is
+ // not included in the length that g_unix_fd_message_steal_fds() returns.
+ return Glib::ArrayHandle<int>(fds, length, Glib::OWNERSHIP_DEEP);
}
} // namespace Gio
diff --git a/gio/src/unixfdmessage.hg b/gio/src/unixfdmessage.hg
index 05a1e10..d54c8e6 100644
--- a/gio/src/unixfdmessage.hg
+++ b/gio/src/unixfdmessage.hg
@@ -1,5 +1,3 @@
-// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
-
/* Copyright (C) 2010 The giomm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -57,12 +55,11 @@ public:
_WRAP_METHOD_DOCS_ONLY(g_unix_fd_message_new_with_fd_list)
_WRAP_CREATE(const Glib::RefPtr<UnixFDList>& fd_list)
- _WRAP_METHOD(Glib::RefPtr<UnixFDList> get_fd_list(), g_unix_fd_message_get_fd_list)
- _WRAP_METHOD(Glib::RefPtr<const UnixFDList> get_fd_list() const, g_unix_fd_message_get_fd_list,
constversion)
+ _WRAP_METHOD(Glib::RefPtr<UnixFDList> get_fd_list(), g_unix_fd_message_get_fd_list, refreturn)
+ _WRAP_METHOD(Glib::RefPtr<const UnixFDList> get_fd_list() const, g_unix_fd_message_get_fd_list, refreturn,
constversion)
_WRAP_METHOD(bool append_fd(int fd), g_unix_fd_message_append_fd, errthrow)
-
/** Returns the array of file descriptors that is contained in this object.
*
* After this call, the descriptors are no longer contained in message.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]