After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 764083 - Add guards to methods in BaseItem which do not operate on collections
Add guards to methods in BaseItem which do not operate on collections
Status: RESOLVED FIXED
Product: gnome-photos
Classification: Applications
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME photos maintainer(s)
GNOME photos maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-03-23 15:34 UTC by Rafael Fonseca
Modified: 2016-04-05 09:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
base-item: add BaseItem checks for public methods (4.00 KB, patch)
2016-03-29 15:42 UTC, Rafael Fonseca
committed Details | Review
base-item: add checks for functions which do not work on collections (5.01 KB, patch)
2016-03-29 15:42 UTC, Rafael Fonseca
none Details | Review
base-item: Add PHOTOS_IS_BASE_ITEM guards in public functions (4.06 KB, patch)
2016-03-31 14:05 UTC, Debarshi Ray
committed Details | Review
base-item: add checks for functions which don't work on collections (4.86 KB, patch)
2016-03-31 15:33 UTC, Rafael Fonseca
committed Details | Review
base-item: Add guards for functions which do not work on collections (6.46 KB, patch)
2016-03-31 16:15 UTC, Debarshi Ray
committed Details | Review
base-item: Add guard in remaining functions (12.35 KB, patch)
2016-03-31 16:40 UTC, Rafael Fonseca
committed Details | Review

Description Rafael Fonseca 2016-03-23 15:34:53 UTC
Some methods are undefined when the BaseItem refers to a collection. We should add a g_return_if_fail guard in such methods.

Some of the probable candidates are:
 * photos_base_item_create_preview
 * photos_base_item_get_bbox_edited
 * photos_base_item_get_bbox_source
 * photos_base_item_get_surface
 * photos_base_item_get_width
 * photos_base_item_load_async
 * photos_base_item_open
 * photos_base_item_operation_add
 * photos_base_item_operation_get
 * photos_base_item_operation_remove
 * photos_base_item_operations_revert
 * photos_base_item_pipeline_save_async
 * photos_base_item_pipeline_snapshot
 * photos_base_item_print
 * photos_base_item_process_async
 * photos_base_item_save_async
 * photos_base_item_save_guess_sizes_async
Comment 1 Rafael Fonseca 2016-03-29 15:42:24 UTC
Created attachment 324947 [details] [review]
base-item: add BaseItem checks for public methods
Comment 2 Rafael Fonseca 2016-03-29 15:42:50 UTC
Created attachment 324948 [details] [review]
base-item: add checks for functions which do not work on collections
Comment 3 Debarshi Ray 2016-03-31 14:05:10 UTC
Review of attachment 324947 [details] [review]:

Thanks for the patch, Rafael.

::: src/photos-base-item.c
@@ +2206,3 @@
   va_list ap;
 
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));

Should be g_return_val_if_fail.
Comment 4 Debarshi Ray 2016-03-31 14:05:59 UTC
Created attachment 325088 [details] [review]
base-item: Add PHOTOS_IS_BASE_ITEM guards in public functions

Fixed and pushed
Comment 5 Debarshi Ray 2016-03-31 15:14:01 UTC
Review of attachment 324948 [details] [review]:

::: src/photos-base-item.c
@@ +1697,2 @@
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+  g_return_val_if_fail (photos_base_item_is_collection (self), FALSE);

Shouldn't it be the other way round? ie.:
g_return_val_if_fail (!photos_base_item_is_collection (self), FALSE);

Also, I prefer to directly check priv->collection as we do with the other member variables.

@@ +1749,2 @@
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), NULL);
+  g_return_val_if_fail (photos_base_item_is_collection (self), NULL);

Ditto.

@@ +1889,2 @@
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+  g_return_val_if_fail (photos_base_item_is_collection (self), FALSE);

Ditto, etc..
Comment 6 Rafael Fonseca 2016-03-31 15:33:56 UTC
Created attachment 325092 [details] [review]
base-item: add checks for functions which don't work on collections
Comment 7 Debarshi Ray 2016-03-31 16:14:16 UTC
Review of attachment 325092 [details] [review]:

::: src/photos-base-item.c
@@ +1697,2 @@
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), FALSE);
+  g_return_val_if_fail (!self->priv->collection, FALSE);

Better to move this after the "priv = self->priv".

It is a purely nitpicky thing at the moment, but when we start using G_DECLARE_DERIVABLE_TYPE, we will no longer have a separate priv pointer in the _PhotosBaseItem structure. We will have to use the generated photos_base_item_get_instance_private function to get the priv pointer. So things like self->priv->... won't work any more.

Modern GObject best practices recommend against having the priv pointer in the structure because it wastes  one pointer for each type in the hierarchy multiplied by the number of instances. It is argued that the generated function only does pointer arithmetic and likely to get inlined, and hence a better speed vs. memory trade-off.
Comment 8 Debarshi Ray 2016-03-31 16:15:06 UTC
Created attachment 325100 [details] [review]
base-item: Add guards for functions which do not work on collections

Fixed and pushed.
Comment 9 Debarshi Ray 2016-03-31 16:15:53 UTC
I see that there are a few more public methods without the PHOTOS_IS_BASE_ITEM guards. Are you planning to add those too? Or do you want to close this bug?
Comment 10 Rafael Fonseca 2016-03-31 16:40:45 UTC
Created attachment 325101 [details] [review]
base-item: Add guard in remaining functions
Comment 11 Debarshi Ray 2016-04-05 09:02:30 UTC
Review of attachment 325101 [details] [review]:

Looks good to me.