[vlc-devel] [PATCH 1/2] macOS: Add swapoutOverride function to CompatibilityFixes

David Fuhrmann david.fuhrmann at gmail.com
Thu Jun 22 18:55:02 CEST 2017


> Am 21.06.2017 um 02:09 schrieb Marvin Scholz <epirat07 at gmail.com>:
> 
> This adds a swaputOverride function, which swaps out the implementation
> of a overridden method of a Class with its base implementation from the
> superclass.
> ---
> .../package/macosx/VLC.xcodeproj/project.pbxproj   |  4 ++
> modules/gui/macosx/CompatibilityFixes.h            |  6 ++-
> modules/gui/macosx/CompatibilityFixes.m            | 45 ++++++++++++++++++++++
> modules/gui/macosx/Makefile.am                     |  1 +
> 4 files changed, 55 insertions(+), 1 deletion(-)
> create mode 100644 modules/gui/macosx/CompatibilityFixes.m
> 
> diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
> index 8a09ae8089..067888764b 100644
> --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
> +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
> @@ -75,6 +75,7 @@
> 		6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */; };
> 		6B4D50961E7A7D16004479B5 /* NSSound+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */; };
> 		6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */; };
> +		6B6FFF701EF9EC350001CEB1 /* CompatibilityFixes.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */; };
> 		6B8166291EBFC34300C26F1B /* VLCDefaultValueSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */; };
> 		6B81662A1EBFC34300C26F1B /* VLCDefaultValueSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */; };
> 		6B81662B1EBFC35D00C26F1B /* VLCVoutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C2583F161B593D00185AAD /* VLCVoutWindowController.m */; };
> @@ -132,6 +133,7 @@
> 		6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSlider.m; sourceTree = "<group>"; };
> 		6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSliderCell.h; sourceTree = "<group>"; };
> 		6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSliderCell.m; sourceTree = "<group>"; };
> +		6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CompatibilityFixes.m; sourceTree = "<group>"; };
> 		6B8223FE1E4D2A8F00833BE1 /* About.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = About.xib; sourceTree = "<group>"; };
> 		6B8223FF1E4D2A9000833BE1 /* AddonManager.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddonManager.xib; sourceTree = "<group>"; };
> 		6B8224001E4D2A9000833BE1 /* AudioEffects.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AudioEffects.xib; sourceTree = "<group>"; };
> @@ -881,6 +883,7 @@
> 				DCE7BD0708A5724D007B10AE /* VLCBookmarksWindowController.h */,
> 				DCE7BD0608A5724D007B10AE /* VLCBookmarksWindowController.m */,
> 				CCB0BB3013FAC9F40095BD0A /* CompatibilityFixes.h */,
> +				6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */,
> 				E0382C00160BA09E0031D7FF /* VLCControlsBarCommon.h */,
> 				E0382C01160BA09E0031D7FF /* VLCControlsBarCommon.m */,
> 				7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */,
> @@ -1925,6 +1928,7 @@
> 				1C3113DB1E508C6900D4DD76 /* VLCStringUtility.m in Sources */,
> 				6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */,
> 				1C3113DD1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.m in Sources */,
> +				6B6FFF701EF9EC350001CEB1 /* CompatibilityFixes.m in Sources */,
> 				1C3113DF1E508C6900D4DD76 /* VLCVideoEffectsWindowController.m in Sources */,
> 				1C3113E11E508C6900D4DD76 /* VLCVoutView.m in Sources */,
> 				1C3113E31E508C6900D4DD76 /* VLCPlaylist.m in Sources */,
> diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
> index f98679c18d..0a0a51cb7b 100644
> --- a/modules/gui/macosx/CompatibilityFixes.h
> +++ b/modules/gui/macosx/CompatibilityFixes.h
> @@ -1,10 +1,11 @@
> /*****************************************************************************
>  * CompatibilityFixes.h: MacOS X interface module
>  *****************************************************************************
> - * Copyright (C) 2011-2012 VLC authors and VideoLAN
> + * Copyright (C) 2011-2017 VLC authors and VideoLAN
>  * $Id$
>  *
>  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
> + *          Marvin Scholz <epirat07 -at- gmail -dot- com>
>  *
>  * This program is free software; you can redistribute it and/or modify
>  * it under the terms of the GNU General Public License as published by
> @@ -52,3 +53,6 @@ typedef NS_OPTIONS(NSUInteger, NSStatusItemBehavior) {
> typedef NSUInteger NSWindowStyleMask;
> 
> #endif
> +
> +void swapoutOverride(Class cls, SEL selector);
> +
> diff --git a/modules/gui/macosx/CompatibilityFixes.m b/modules/gui/macosx/CompatibilityFixes.m
> new file mode 100644
> index 0000000000..6dcbe2cb3d
> --- /dev/null
> +++ b/modules/gui/macosx/CompatibilityFixes.m
> @@ -0,0 +1,45 @@
> +/*****************************************************************************
> + * CompatibilityFixes.h: MacOS X interface module
> + *****************************************************************************
> + * Copyright (C) 2011-2017 VLC authors and VideoLAN
> + * $Id$
> + *
> + * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
> + *          Marvin Scholz <epirat07 -at- gmail -dot- com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + *****************************************************************************/
> +
> +#import "CompatibilityFixes.h"
> +#import <objc/runtime.h>
> +
> +/**
> + Swaps out the implementation of the method at @c selector in Class @c cls
> + with the implementation of that method from the superclass.
> + 
> + @param cls         The class which this selector belongs to
> + @param selector    The selector of whom to swap the implementation
> + 
> + @note  The @c cls must be a subclass of another class and both
> +        must implement the @c selector for this function to work as expected!
> + */
> +void swapoutOverride(Class cls, SEL selector)
> +{
> +    Method subclassMeth = class_getInstanceMethod(cls, selector);
> +    IMP baseImp = class_getMethodImplementation([cls superclass], selector);
> +
> +    if (subclassMeth && baseImp)
> +        method_setImplementation(subclassMeth, baseImp);
> +}
> diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
> index 4e074ecd05..ae54903af4 100644
> --- a/modules/gui/macosx/Makefile.am
> +++ b/modules/gui/macosx/Makefile.am
> @@ -20,6 +20,7 @@ libmacosx_plugin_la_SOURCES = \
> 	gui/macosx/applescript.h gui/macosx/applescript.m \
> 	gui/macosx/AppleRemote.h gui/macosx/AppleRemote.m \
> 	gui/macosx/CompatibilityFixes.h \
> +	gui/macosx/CompatibilityFixes.m \

Hi Marvin,

Logic itself looks ok for me. But Please put the .m file in one line with the .h file in Makefile.am, as it is done for the other lines.

BR. David



More information about the vlc-devel mailing list