Weird code in apple_remote

Tor Lillqvist tml at iki.fi
Mon May 7 12:54:27 PDT 2012


I noticed that when I run LO master built against the 10.6 SDK (with
Clang from Xcode 4.3.2, if it matters), I see messages like this:

2012-05-07 22:12:34.637 soffice[65405:6a03] ***
+[AppleRemote<0x38f578c> init]: cannot init a class object.
2012-05-07 22:12:34.641 soffice[65405:6a03] (
	0   CoreFoundation                      0x9b795b67 __raiseError + 231
	1   libobjc.A.dylib                     0x9a8a5149 objc_exception_throw + 155
	2   CoreFoundation                      0x9b798c2d +[NSObject init] + 237
	3   libAppleRemotelo.dylib              0x038efa73 +[RemoteControl
sendDistributedNotification:targetBundleIdentifier:] + 51
	4   libAppleRemotelo.dylib              0x038efbc2 +[RemoteControl
sendFinishedNotifcationForAppIdentifier:] + 50
	5   libAppleRemotelo.dylib              0x038f0f8f
-[HIDRemoteControlDevice stopListening:] + 319
	6   libAppleRemotelo.dylib              0x038f00b2
-[RemoteControlContainer stopListening:] + 98
	7   libvcllo.dylib                      0x027d7ba8
-[VCL_NSApplication applicationWillResignActive:] + 104

At first the message "cannot init a class object" sounded a but terse
and obscure, but after some thinking and googling I realized that it
actually means exactly what it says...

The code in question is in apple_remote/source/RemoteControl.m, in the
class method +sendDistributedNotification:targetBundleIdentifier: .
Look:

+ (void) sendDistributedNotification: (NSString*) notificationName
targetBundleIdentifier: (NSString*) targetIdentifier
{
    if ( (self = [super init]) ) {
   ...

WTF? As far as I understand, it makes no sense to call [super init] in
a class method.

The well-known "init" is an instance method. In a class method, I
guess "self" refers to the class object for the class, so the code
does compile, even if it is equivalent to using "this" in a static
class method in C++, more or less. So the code tries to call the
instance method "init" of the RemoteControl class's superclass's
(which is NSObject) (meta)class object... That makes no sense, does
it? Do class objects even have "init" methods? Can there be some weird
(accidentally working?) mechanism that actually makes the code
necessary and sane, at least if built against the 10.4 and earlier
SDKs?

Googling I find for instance
http://www.iphonedevsdk.com/forum/objective-c-python-ruby-development/58572-simple-question.html#post243571
.

It would be interesting to know why qɔᴉɹə added that code when he
adapted Martin Kahr's Apple Remote Control code to OOo. Unfortunately
I can't find the upstream version of Martin Kahr's code that the
OOo/LO code is based upon, so I can't extract the exact changes he
did.

The current upstream at
https://github.com/martinkahr/apple_remote_control starts with an
initial import in 2009, while qɔᴉɹə's adaptation of it for OOo is from
CWS appleremote01 which was integrated in 2008.

It probably would be a good idea to update the apple_remote code to
the latest version of Martin Kahr's code, and then try to re-apply
those changes by qɔᴉɹə that still make sense. If only one had time to
investigate more... But anyway, I probably will at least remove that
obviously (?) bogus line of code. I don't have a remote control so I
can't check if the code still works after that, though... and I only
have 10.7...

--tml


More information about the LibreOffice mailing list