Skip to contentSkip to conversation

ui/cocoa.m: Fix compiler and runtime warnings on 10.8

PATCH Applied Peter Maydell 3 participants 11 messages Apr 22, 2013 – May 28, 2013

lore
Share & tools
lore
#0 lore raw

v3 cover ui/cocoa.m: Fix compiler and runtime warnings on 10.8

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.11.4
#1 lore raw

PATCH v3 1/4 ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable

On MacOSX 10.8 QEMU provokes system log messages:
11/03/2013 17:03:29.998 qemu-system-arm[42586]: objc[42586]: Object 0x7ffbf9c2f3b0 of class NSScreen autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

11/03/2013 17:03:29.999 qemu-system-arm[42586]: objc[42586]: Object 0x7ffbf9c3a010 of class NSConcreteMapTable autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug

This is because we call back into Cocoa from threads other than the UI thread (specifically from the CPU thread). Since we created these threads via the POSIX API rather than NSThread, they don't have automatically created autorelease pools. Guard all the functions where QEMU can call back into the Cocoa UI code with autorelease pools so that we don't leak any Cocoa objects.

---
 ui/cocoa.m | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
ui/cocoa.m +10 -1
index d51462a..833c6ed 100644
@@ -960,6 +960,8 @@ int main (int argc, const char * argv[]) {
 static void cocoa_update(DisplayChangeListener *dcl,
                          int x, int y, int w, int h)
 {
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
     COCOA_DEBUG("qemu_cocoa: cocoa_update\n");
 
     NSRect rect;
@@ -973,18 +975,24 @@ static void cocoa_update(DisplayChangeListener *dcl,
             h * [cocoaView cdy]);
     }
     [cocoaView setNeedsDisplayInRect:rect];
+
+    [pool release];
 }
 
 static void cocoa_switch(DisplayChangeListener *dcl,
                          DisplaySurface *surface)
 {
-    COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
+    COCOA_DEBUG("qemu_cocoa: cocoa_switch\n");
     [cocoaView switchSurface:surface];
+    [pool release];
 }
 
 static void cocoa_refresh(DisplayChangeListener *dcl)
 {
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
     COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
 
     if (kbd_mouse_is_absolute()) {
@@ -1007,6 +1015,7 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
         }
     } while(event != nil);
     graphic_hw_update(NULL);
+    [pool release];
 }
 
 static void cocoa_cleanup(void)
Signature · 1 line
1.7.11.4
#2 lore raw

PATCH v3 2/4 ui/cocoa.m: Avoid deprecated CPS* functions

In reply to Peter Maydell

The functions CPSGetCurrentProcess and CPSEnableForegroundOperation are deprecated in newer versions of MacOSX and cause warning messages to be logged to the system log. Instead, use the new preferred method of promoting our console process up to a graphical app with menubar and Dock icon, which is TransformProcessType. (This function came in with MacOSX 10.3, so there's no need to retain the old method as we don't support anything earlier than 10.3 anyway.)

---
 ui/cocoa.m | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
ui/cocoa.m +6 -17
index 833c6ed..e3e1204 100644
@@ -851,22 +851,10 @@ QemuCocoaView *cocoaView;
 
 
 
-// Dock Connection
-typedef struct CPSProcessSerNum
-{
-        UInt32                lo;
-        UInt32                hi;
-} CPSProcessSerNum;
-
-OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
-OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
-
 int main (int argc, const char * argv[]) {
 
     gArgc = argc;
     gArgv = (char **)argv;
-    CPSProcessSerNum PSN;
     int i;
 
     /* In case we don't need to display a window, let's not do that */
@@ -890,12 +878,13 @@ int main (int argc, const char * argv[]) {
     }
 
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-    [NSApplication sharedApplication];
 
-    if (!CPSGetCurrentProcess(&PSN))
-        if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
-            if (!CPSSetFrontProcess(&PSN))
-                [NSApplication sharedApplication];
+    // Pull this console process up to being a fully-fledged graphical
+    // app with a menubar and Dock icon
+    ProcessSerialNumber psn = { 0, kCurrentProcess };
+    TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+
+    [NSApplication sharedApplication];
 
     // Add menus
     NSMenu      *menu;
Signature · 1 line
1.7.11.4
#3 lore raw

PATCH v3 3/4 ui/cocoa.m: Avoid deprecated NSOpenPanel filename method

In reply to Peter Maydell

Avoid the NSOpenPanel filename method (deprecated in MacOSX 10.6) in favour of using the URL method and extracting the path from the resulting NSUrl object.

---
 ui/cocoa.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ui/cocoa.m +1 -1
index e3e1204..9ff688d 100644
@@ -810,7 +810,7 @@ QemuCocoaView *cocoaView;
         exit(0);
     } else if(returnCode == NSOKButton) {
         const char *bin = "qemu";
-        char *img = (char*)[ [ sheet filename ] cStringUsingEncoding:NSASCIIStringEncoding];
+        char *img = (char*)[ [ [ sheet URL ] path ] cStringUsingEncoding:NSASCIIStringEncoding];
 
         char **argv = (char**)malloc( sizeof(char*)*3 );
 
Signature · 1 line
1.7.11.4
#4 lore raw

PATCH v3 4/4 ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

In reply to Peter Maydell

In MacOSX 10.6 and above the NSOpenPanel beginSheetForDirectory method is deprecated. Use the preferred replacements instead. We retain the original code for use on earlier MacOSX versions because the replacement methods don't exist before 10.6.

---
 ui/cocoa.m | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
ui/cocoa.m +15 -1
index 9ff688d..cee93be 100644
@@ -35,6 +35,9 @@
 #ifndef MAC_OS_X_VERSION_10_5
 #define MAC_OS_X_VERSION_10_5 1050
 #endif
+#ifndef MAC_OS_X_VERSION_10_6
+#define MAC_OS_X_VERSION_10_6 1060
+#endif
 
 
 //#define DEBUG
@@ -771,9 +774,20 @@ QemuCocoaView *cocoaView;
         NSOpenPanel *op = [[NSOpenPanel alloc] init];
         [op setPrompt:@"Boot image"];
         [op setMessage:@"Select the disk image you want to boot.\n\nHit the \"Cancel\" button to quit"];
-        [op beginSheetForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"img",@"iso",@"dmg",@"qcow",@"cow",@"cloop",@"vmdk",nil]
+        NSArray *filetypes = [NSArray arrayWithObjects:@"img", @"iso", @"dmg",
+                                 @"qcow", @"cow", @"cloop", @"vmdk", nil];
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
+        [op setAllowedFileTypes:filetypes];
+        [op beginSheetModalForWindow:normalWindow
+            completionHandler:^(NSInteger returnCode)
+            { [self openPanelDidEnd:op
+                  returnCode:returnCode contextInfo:NULL ]; } ];
+#else
+        // Compatibility code for pre-10.6, using deprecated method
+        [op beginSheetForDirectory:nil file:nil types:filetypes
               modalForWindow:normalWindow modalDelegate:self
               didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
+#endif
     } else {
         // or launch QEMU, with the global args
         [self startEmulationWithArgc:gArgc argv:(char **)gArgv];
Signature · 1 line
1.7.11.4
#5 lore raw
In reply to Peter Maydell

Ping!

-- PMM

Quoted 36 lines · Peter Maydell

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

--
1.7.11.4

#6 lore raw

Ping again! This patchset has now been on the list for eleven weeks without any review.

thanks
-- PMM

Quoted 41 lines · Peter Maydell

Ping!

-- PMM

Quoted 36 lines · Peter Maydell

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

--
1.7.11.4

#7 lore raw
Quoted 2 lines · Peter Maydell

Ping again! This patchset has now been on the list for eleven weeks without any review.

Objective C is a foreign language. Andreas is the Cocoa maintainer so I've been waiting for him. Andreas, if you don't have time to look at these patches, I can apply them directly.

Regards,

Anthony Liguori

Quoted 46 lines

thanks
-- PMM

Quoted 41 lines · Peter Maydell

Ping!

-- PMM

Quoted 36 lines · Peter Maydell

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

--
1.7.11.4

#8 lore raw

Am 28.05.2013 19:01, schrieb Anthony Liguori:

Quoted 6 lines
Quoted 2 lines · Peter Maydell

Ping again! This patchset has now been on the list for eleven weeks without any review.

Objective C is a foreign language.

For that reason I've been applying our C Coding Style for indentation and spacing, but the code was full of // comments that I did not bother to change.

Quoted 3 lines

Andreas is the Cocoa maintainer so
I've been waiting for him. Andreas, if you don't have time to look at these patches, I can apply them directly.

I've looked at the patches today seeing the ping and they look fine - I wasn't properly CC'ed before (get_maintainer.pl would've spared the typo!) and so they were simply not in my mailbox.

I'll try to test on v10.5 tonight. Peter and me had already agreed upfront that there's no point in maintaining < v10.3 code any more.

BTW if Peter or someone wants to take over Cocoa (co-)maintenance that would be fine with me.

Regards,
Andreas

Quoted 53 lines

Regards,

Anthony Liguori

Quoted 46 lines

thanks
-- PMM

Quoted 41 lines · Peter Maydell

Ping!

-- PMM

Quoted 36 lines · Peter Maydell

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

--
1.7.11.4

#9 lore raw
Quoted 3 lines · Andreas Färber

I've looked at the patches today seeing the ping and they look fine - I wasn't properly CC'ed before (get_maintainer.pl would've spared the typo!) and so they were simply not in my mailbox.

Augh, sorry -- no idea where that other address came from. (it doesn't bounce, or I'd have noticed before; I wonder what poor unfortunate has been being sent qemu patches...)

Quoted 5 lines

I'll try to test on v10.5 tonight. Peter and me had already agreed upfront that there's no point in maintaining < v10.3 code any more.

BTW if Peter or someone wants to take over Cocoa (co-)maintenance that would be fine with me.

I don't object to being listed as a co-maintainer if you think it would be helpful, though the only MacOS system I have is this 10.8 one.

thanks
-- PMM

#10 lore raw
In reply to Peter Maydell

Am 22.04.2013 22:29, schrieb Peter Maydell:

Quoted 9 lines

These patches fix various compiler and runtime warnings QEMU provokes on MacOSX 10.8. The first two fix a leak and some deprecated functions which cause warnings in the system log when QEMU runs. The second two avoid some functions which cause compile time warnings about use of functions deprecated in 10.6.

I believe from my reading of the documentation that these changes should still work OK on 10.3, but I don't have any way of testing that.

Quoted 8 lines

Andreas: I don't write much ObjC so I don't really have a feel for what is good coding style. I mostly tried to follow the existing code (eg "//" style comments) and QEMU's C style (eg 80 cols max). I'm happy to change any of the indentation or whatever to suit your preferences.

With this patch set the only remaining compile time warnings from clang on 10.8 are about deprecated methods in audio/coreaudio.c.

And it doesn't introduce any new issues on v10.5.

Thanks, applied to cocoa-for-upstream (with shortened prefix):
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/cocoa-for-upstream

Sorry for the delay, pull coming up.

Andreas

Quoted 14 lines

Changes v2->v3:
* rebased again
Changes v1->v2:
* rebased and fixed up following recent console changes

Peter Maydell (4):
ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable ui/cocoa.m: Avoid deprecated CPS* functions ui/cocoa.m: Avoid deprecated NSOpenPanel filename method ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory

 ui/cocoa.m | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)