* [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8
@ 2013-03-12 12:48 Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable Peter Maydell
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Peter Maydell @ 2013-03-12 12:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
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.
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 | 54 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 34 insertions(+), 20 deletions(-)
--
1.7.11.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable
2013-03-12 12:48 [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8 Peter Maydell
@ 2013-03-12 12:48 ` Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 2/4] ui/cocoa.m: Avoid deprecated CPS* functions Peter Maydell
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2013-03-12 12:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
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.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index ca42413..6e9f751 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -971,6 +971,8 @@ int main (int argc, const char * argv[]) {
#pragma mark qemu
static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
COCOA_DEBUG("qemu_cocoa: cocoa_update\n");
NSRect rect;
@@ -984,17 +986,22 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
h * [cocoaView cdy]);
}
[cocoaView setNeedsDisplayInRect:rect];
+ [pool release];
}
static void cocoa_resize(DisplayState *ds)
{
- COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ COCOA_DEBUG("qemu_cocoa: cocoa_resize\n");
[cocoaView resizeContentToWidth:(int)(ds_get_width(ds)) height:(int)(ds_get_height(ds)) displayState:ds];
+ [pool release];
}
static void cocoa_refresh(DisplayState *ds)
{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
if (kbd_mouse_is_absolute()) {
@@ -1017,11 +1024,15 @@ static void cocoa_refresh(DisplayState *ds)
}
} while(event != nil);
vga_hw_update();
+ [pool release];
}
static void cocoa_setdata(DisplayState *ds)
{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
[cocoaView updateDataOffset:ds];
+ [pool release];
}
static void cocoa_cleanup(void)
--
1.7.11.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/4] ui/cocoa.m: Avoid deprecated CPS* functions
2013-03-12 12:48 [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8 Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable Peter Maydell
@ 2013-03-12 12:48 ` Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 3/4] ui/cocoa.m: Avoid deprecated NSOpenPanel filename method Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 4/4] ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2013-03-12 12:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
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.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 6e9f751..b40af59 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -863,22 +863,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 */
@@ -902,12 +890,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;
--
1.7.11.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/4] ui/cocoa.m: Avoid deprecated NSOpenPanel filename method
2013-03-12 12:48 [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8 Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 2/4] ui/cocoa.m: Avoid deprecated CPS* functions Peter Maydell
@ 2013-03-12 12:48 ` Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 4/4] ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2013-03-12 12:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
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.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index b40af59..2df481d 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -822,7 +822,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 );
--
1.7.11.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 4/4] ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory
2013-03-12 12:48 [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8 Peter Maydell
` (2 preceding siblings ...)
2013-03-12 12:48 ` [Qemu-devel] [PATCH 3/4] ui/cocoa.m: Avoid deprecated NSOpenPanel filename method Peter Maydell
@ 2013-03-12 12:48 ` Peter Maydell
3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2013-03-12 12:48 UTC (permalink / raw)
To: qemu-devel; +Cc: Andreas Färber, patches
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.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
ui/cocoa.m | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 2df481d..96f7880 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -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
@@ -783,9 +786,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];
--
1.7.11.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-03-12 12:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-12 12:48 [Qemu-devel] [PATCH 0/4] ui/cocoa.m: Fix compiler and runtime warnings on 10.8 Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 1/4] ui/cocoa.m: Fix leaks of NSScreen and NSConcreteMapTable Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 2/4] ui/cocoa.m: Avoid deprecated CPS* functions Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 3/4] ui/cocoa.m: Avoid deprecated NSOpenPanel filename method Peter Maydell
2013-03-12 12:48 ` [Qemu-devel] [PATCH 4/4] ui/cocoa.m: Avoid deprecated NSOpenPanel beginSheetForDirectory Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).