[vlc-commits] macOS: Add comments explaining ownership passing

Marvin Scholz git at videolan.org
Mon Apr 3 09:35:36 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon Apr  3 09:34:02 2017 +0200| [7794fa5a2f9a0eda6ddf7f0922108fbb51dfc5ea] | committer: Marvin Scholz

macOS: Add comments explaining ownership passing

This adds comments that should make it clearer how ownership is handled
and passed back and forth between ARC and non-ARC in the
VLCExtensionDialogProvider.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7794fa5a2f9a0eda6ddf7f0922108fbb51dfc5ea
---

 modules/gui/macosx/VLCExtensionsDialogProvider.m | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/modules/gui/macosx/VLCExtensionsDialogProvider.m b/modules/gui/macosx/VLCExtensionsDialogProvider.m
index 953bd33..a96b439 100644
--- a/modules/gui/macosx/VLCExtensionsDialogProvider.m
+++ b/modules/gui/macosx/VLCExtensionsDialogProvider.m
@@ -375,12 +375,20 @@ static void extensionDialogCallback(extension_dialog_t *p_ext_dialog,
             continue; /* Some widgets may be NULL at this point */
 
         BOOL shouldDestroy = widget->b_kill;
+
+        /* Ownership should not be transfered back to ARC here, as
+         * we might just want to update something.
+         */
         NSView *control = (__bridge NSView *)widget->p_sys_intf;
         BOOL update = widget->b_update;
 
         if (!control && !shouldDestroy) {
             control = createControlFromWidget(widget, self);
             updateControlFromWidget(control, widget, self);
+            /* Ownership needs to be given-up, if ARC would remain with the
+             * ownership, the object could be freed while it is still referenced
+             * and the invalid reference would be used later.
+             */
             widget->p_sys_intf = (__bridge_retained void *)control;
             update = YES; // Force update and repositionning
             [control setHidden:widget->b_hide];
@@ -408,6 +416,9 @@ static void extensionDialogCallback(extension_dialog_t *p_ext_dialog,
         if (shouldDestroy) {
             VLCDialogGridView *gridView = (VLCDialogGridView *)[dialogWindow contentView];
             [gridView removeSubview:control];
+            /* Explicitily release here, as we do not have transfered ownership to ARC,
+             * given that not in all cases we want to destroy the widget.
+             */
             CFRelease(widget->p_sys_intf);
             widget->p_sys_intf = NULL;
         }



More information about the vlc-commits mailing list