[glib] doc: clarify that _get_instance_private() is NULL-safe
- From: Xavier Claessens <xclaesse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] doc: clarify that _get_instance_private() is NULL-safe
- Date: Tue, 22 Sep 2015 15:16:01 +0000 (UTC)
commit 32811598f384ac165a812b4dde8fb1ad4df2d420
Author: Xavier Claessens <xavier claessens collabora com>
Date: Tue Sep 15 16:42:10 2015 -0400
doc: clarify that _get_instance_private() is NULL-safe
https://bugzilla.gnome.org/show_bug.cgi?id=755083
gobject/gtype.h | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 611e637..f4cbf2f 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1823,6 +1823,8 @@ guint g_type_get_type_registration_serial (void);
* {
* MyObjectPrivate *priv = my_object_get_instance_private (obj);
*
+ * g_return_val_if_fail (MY_IS_OBJECT (obj), 0);
+ *
* return priv->foo;
* }
*
@@ -1832,6 +1834,8 @@ guint g_type_get_type_registration_serial (void);
* {
* MyObjectPrivate *priv = my_object_get_instance_private (obj);
*
+ * g_return_if_fail (MY_IS_OBJECT (obj));
+ *
* if (priv->bar != bar)
* priv->bar = bar;
* }
@@ -1843,6 +1847,10 @@ guint g_type_get_type_registration_serial (void);
* Also note that private structs added with these macros must have a struct
* name of the form `TypeNamePrivate`.
*
+ * It is safe to call _get_instance_private on %NULL or invalid object since
+ * it's only adding an offset to the instance pointer. In that case the returned
+ * pointer must not be dereferenced.
+ *
* Since: 2.38
*/
#define G_ADD_PRIVATE(TypeName) { \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]