Skip to contentSkip to conversation

Fixes for Cocoa backend

GIT PULL In review Andreas Färber 3 participants 13 messages Jun 14, 2011 – Jun 27, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

Hello,

I've collected a number of warning and usability fixes for the Cocoa frontend and Darwin host. Please pull.

Cc Blue Swirl <[email protected]>

The following changes since commit 0b862cedf36d927818c50584ddd611b0370673df:

configure: Detect and don't try to use older libcurl (2011-06-13 21:16:27 +0200)

are available in the git repository at:
git://repo.or.cz/qemu/afaerber.git cocoa-for-upstream

Alexandre Raymond (5):
Fix compilation warning due to incorrectly specified type
Cocoa: avoid displaying window when command-line contains '-h' or

    '-help'

Remove warning in printf due to type mismatch
configure: Fix check for fdatasync()
Darwin: Fix compilation warning regarding the deprecated daemon()
function

Andreas Färber (4):
Fix libfdt warnings on Darwin
cocoa: Provide central qemu_main() prototype
cocoa: Revert dependency on VNC
cocoa: Avoid warning related to multiple handleEvent: definitions

Tristan Gingold (1):
cocoa: do not create a spurious window for -version

 Makefile.objs           |    2 +-
 audio/coreaudio.c       |    2 +-
 configure               |    8 +++++++-
 libfdt_env.h            |    8 ++------
 osdep.h                 |    1 +
 oslib-posix.c           |   16 ++++++++++++++++
 qemu-common.h           |    5 +++++
 qemu-nbd.c              |    2 +-
 target-lm32/translate.c |    2 +-
 ui/cocoa.m              |   25 ++++++++++++++++++-------
 10 files changed, 53 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.5.3
#1 lore raw

PATCH 1/10 cocoa: do not create a spurious window for -version

From: Tristan Gingold <[email protected]>

When invoked with -version, qemu will exit just after displaying the version, so there is no need to create a window.
Also handles --XXX options.

---
 ui/cocoa.m |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
ui/cocoa.m +12 -3
index 20f91bc..1ff1ac6 100644
@@ -865,10 +865,19 @@ int main (int argc, const char * argv[]) {
 
     /* In case we don't need to display a window, let's not do that */
     for (i = 1; i < argc; i++) {
-        if (!strcmp(argv[i], "-vnc") ||
-            !strcmp(argv[i], "-nographic") ||
-            !strcmp(argv[i], "-curses")) {
+        const char *opt = argv[i];
+
+        if (opt[0] == '-') {
+            /* Treat --foo the same as -foo.  */
+            if (opt[1] == '-') {
+                opt++;
+            }
+            if (!strcmp(opt, "-vnc") ||
+                !strcmp(opt, "-nographic") ||
+                !strcmp(opt, "-version") ||
+                !strcmp(opt, "-curses")) {
                 return qemu_main(gArgc, gArgv);
+            }
         }
     }
 
Signature · 1 line
1.7.5.3
#2 lore raw

PATCH 2/10 Fix compilation warning due to incorrectly specified type

From: Alexandre Raymond <[email protected]>

In audio/coreaudio.c, a variable named "str" was assigned "const char" values, which resulted in the following warnings:

-----8<-----
audio/coreaudio.c: In function ‘coreaudio_logstatus’:
audio/coreaudio.c:59: warning: initialization discards qualifiers from pointer target type audio/coreaudio.c:63: warning: assignment discards qualifiers from pointer target type (...)
-----8<-----

---
 audio/coreaudio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
audio/coreaudio.c +1 -1
index 0a26413..3bd75cd 100644
@@ -56,7 +56,7 @@ typedef struct coreaudioVoiceOut {
 
 static void coreaudio_logstatus (OSStatus status)
 {
-    char *str = "BUG";
+    const char *str = "BUG";
 
     switch(status) {
     case kAudioHardwareNoError:
Signature · 1 line
1.7.5.3
#3 lore raw

PATCH 3/10 Cocoa: avoid displaying window when command-line contains '-h' or '-help'

From: Alexandre Raymond <[email protected]>

There was already a check in place to avoid displaying a window in certain modes such as vnc, nographic or curses.

Add a check for '-h' and '-help' to avoid displaying a window for a split- second before showing the usage information.

---
 ui/cocoa.m |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
ui/cocoa.m +2 -1
index 1ff1ac6..e1312d3 100644
@@ -872,7 +872,8 @@ int main (int argc, const char * argv[]) {
             if (opt[1] == '-') {
                 opt++;
             }
-            if (!strcmp(opt, "-vnc") ||
+            if (!strcmp(opt, "-h") || !strcmp(opt, "-help") ||
+                !strcmp(opt, "-vnc") ||
                 !strcmp(opt, "-nographic") ||
                 !strcmp(opt, "-version") ||
                 !strcmp(opt, "-curses")) {
Signature · 1 line
1.7.5.3
#4 lore raw

PATCH 4/10 Remove warning in printf due to type mismatch

From: Alexandre Raymond <[email protected]>

----8<----
qemu/target-lm32/translate.c: In function ‘gen_intermediate_code_internal’:
qemu/target-lm32/translate.c:1135: warning: format ‘%zd’ expects type ‘signed size_t’, but argument 4 has type ‘int’ ----8<----

Both gen_opc_ptr and gen_opc_buf are "uint16_t *". The difference between pointers is a ptrdiff_t so printf needs '%td'.

---
 target-lm32/translate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
target-lm32/translate.c +1 -1
index eb21158..5e19725 100644
@@ -1132,7 +1132,7 @@ static void gen_intermediate_code_internal(CPUState *env,
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         qemu_log("\n");
         log_target_disas(pc_start, dc->pc - pc_start, 0);
-        qemu_log("\nisize=%d osize=%zd\n",
+        qemu_log("\nisize=%d osize=%td\n",
             dc->pc - pc_start, gen_opc_ptr - gen_opc_buf);
     }
 #endif
Signature · 1 line
1.7.5.3
#5 lore raw

PATCH 5/10 configure: Fix check for fdatasync()

From: Alexandre Raymond <[email protected]>

Under Darwin, a symbol exists for the fdatasync() function, so that our link test succeeds. However _POSIX_SYNCHRONIZED_IO is set to '-1'.

According to POSIX:2008, a value of -1 means the feature is not supported. A value of 0 means supported at compilation time, and a value greater 0 means supported at both compilation and run time.

Enable fdatasync() only if _POSIX_SYNCHRONIZED_IO is '>0'.

---
 configure |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
configure +7 -1
index c931ae8..6101f4e 100755
@@ -2461,7 +2461,13 @@ fi
 fdatasync=no
 cat > $TMPC << EOF
 #include <unistd.h>
-int main(void) { return fdatasync(0); }
+int main(void) {
+#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
+return fdatasync(0);
+#else
+#abort Not supported
+#endif
+}
 EOF
 if compile_prog "" "" ; then
     fdatasync=yes
Signature · 1 line
1.7.5.3
#6 lore raw

PATCH 6/10 Fix libfdt warnings on Darwin

Building with libfdt results in the following warnings on Mac OS X:

CC ppc-softmmu/device_tree.o
In file included from /Users/andreas/QEMU/latest64/include/libfdt.h:54,
from /Users/andreas/QEMU/qemu/device_tree.c:26:
/Users/andreas/QEMU/qemu/libfdt_env.h:25:20: warning: endian.h: No such file or directory /Users/andreas/QEMU/qemu/libfdt_env.h:26:22: warning: byteswap.h: No such file or directory /Users/andreas/QEMU/qemu/libfdt_env.h:28:5: warning: "__BYTE_ORDER" is not defined /Users/andreas/QEMU/qemu/libfdt_env.h:28:21: warning: "__BIG_ENDIAN" is not defined

Since QEMU's copy of libfdt_env.h only uses bswap_32() and bswap_64(), let QEMU's bswap.h take care of the headers and use its endianness define.

---
 libfdt_env.h |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
libfdt_env.h +2 -6
index ee0419f..90d7f3b 100644
@@ -19,13 +19,9 @@
 #ifndef _LIBFDT_ENV_H
 #define _LIBFDT_ENV_H
 
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-#include <endian.h>
-#include <byteswap.h>
+#include "bswap.h"
 
-#if __BYTE_ORDER == __BIG_ENDIAN
+#ifdef HOST_WORDS_BIGENDIAN
 #define fdt32_to_cpu(x)		(x)
 #define cpu_to_fdt32(x)		(x)
 #define fdt64_to_cpu(x)		(x)
Signature · 1 line
1.7.5.3
#7 lore raw

PATCH 7/10 cocoa: Provide central qemu_main() prototype

This fixes a missing prototype warning in vl.c and obsoletes the prototype in cocoa.m. Adjust callers in cocoa.m to supply third argument, which is currently only used on Linux/ppc.

The prototype is designed so that it could be shared with SDL and other frontends, if desired.

Cc Alexandre Raymond <[email protected]>
---
 qemu-common.h |    5 +++++
 ui/cocoa.m    |    6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)
qemu-common.h +5 -0
index 39fabc9..109498d 100644
@@ -132,6 +132,11 @@ static inline char *realpath(const char *path, char *resolved_path)
 
 #endif /* !defined(NEED_CPU_H) */
 
+/* main function, renamed */
+#if defined(CONFIG_COCOA)
+int qemu_main(int argc, char **argv, char **envp);
+#endif
+
 /* bottom halves */
 typedef void QEMUBHFunc(void *opaque);
 
ui/cocoa.m +3 -3
index e1312d3..1c54759 100644
@@ -23,6 +23,7 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#include <crt_externs.h>
 
 #include "qemu-common.h"
 #include "console.h"
@@ -61,7 +62,6 @@ typedef struct {
     int bitsPerPixel;
 } QEMUScreen;
 
-int qemu_main(int argc, char **argv); // main defined in qemu/vl.c
 NSWindow *normalWindow;
 id cocoaView;
 static DisplayChangeListener *dcl;
@@ -794,7 +794,7 @@ static int cocoa_keycode_to_qemu(int keycode)
     COCOA_DEBUG("QemuCocoaAppController: startEmulationWithArgc\n");
 
     int status;
-    status = qemu_main(argc, argv);
+    status = qemu_main(argc, argv, *_NSGetEnviron());
     exit(status);
 }
 
@@ -877,7 +877,7 @@ int main (int argc, const char * argv[]) {
                 !strcmp(opt, "-nographic") ||
                 !strcmp(opt, "-version") ||
                 !strcmp(opt, "-curses")) {
-                return qemu_main(gArgc, gArgv);
+                return qemu_main(gArgc, gArgv, *_NSGetEnviron());
             }
         }
     }
Signature · 1 line
1.7.5.3
#8 lore raw

PATCH 8/10 cocoa: Revert dependency on VNC

In 821601ea5b02a68ada479731a4d3d07a9876632a (Make VNC support optional) cocoa.o was moved from ui-obj-$(CONFIG_COCOA) to vnc-obj-$(CONFIG_COCOA), adding a dependency on $(CONFIG_VNC). That must've been unintentional.

Cc Jes Sorensen <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 Makefile.objs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Makefile.objs +1 -1
index 52d8b23..509ab39 100644
@@ -128,6 +128,7 @@ common-obj-y += $(addprefix audio/, $(audio-obj-y))
 
 ui-obj-y += keymaps.o
 ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
+ui-obj-$(CONFIG_COCOA) += cocoa.o
 ui-obj-$(CONFIG_CURSES) += curses.o
 vnc-obj-y += vnc.o d3des.o
 vnc-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o
@@ -135,7 +136,6 @@ vnc-obj-y += vnc-enc-tight.o vnc-palette.o
 vnc-obj-y += vnc-enc-zrle.o
 vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
-vnc-obj-$(CONFIG_COCOA) += cocoa.o
 ifdef CONFIG_VNC_THREAD
 vnc-obj-y += vnc-jobs-async.o
 else
Signature · 1 line
1.7.5.3
#9 lore raw

PATCH 9/10 cocoa: Avoid warning related to multiple handleEvent: definitions

Avoid compiler confusion as to which method signature to use for the
handleEvent: selector on OSX >= 10.6 by making the variable type-safe as opposed to generic 'id' type.
Requires moving the variable definition to after the class definition.

----8<----
ui/cocoa.m: In function ‘cocoa_refresh’:
ui/cocoa.m:997: warning: multiple methods named ‘-handleEvent:’ found /System/Library/Frameworks/AppKit.framework/Headers/NSTextInputContext.h:84: warning: using ‘-(BOOL)handleEvent:(NSEvent *)theEvent’ ui/cocoa.m:272: warning: also found ‘-(void)handleEvent:(NSEvent *)event’
----8<---

---
 ui/cocoa.m |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
ui/cocoa.m +2 -1
index 1c54759..515e684 100644
@@ -63,7 +63,6 @@ typedef struct {
 } QEMUScreen;
 
 NSWindow *normalWindow;
-id cocoaView;
 static DisplayChangeListener *dcl;
 
 int gArgc;
@@ -278,6 +277,8 @@ static int cocoa_keycode_to_qemu(int keycode)
 - (QEMUScreen) gscreen;
 @end
 
+QemuCocoaView *cocoaView;
+
 @implementation QemuCocoaView
 - (id)initWithFrame:(NSRect)frameRect
 {
Signature · 1 line
1.7.5.3
#10 lore raw

PATCH 10/10 Darwin: Fix compilation warning regarding the deprecated daemon() function

From: Alexandre Raymond <[email protected]>

Changes since v1: create a wrapper function named qemu_daemon() in oslib-posix.c instead of putting the OS specific workaround in qemu-nbd.c directly.

On OSX >= 10.5, daemon() is deprecated, resulting in the following warning:
----8<----
qemu-nbd.c: In function ‘main’:
qemu-nbd.c:371: warning: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:289) ----8<----

The following trick, used in mDNSResponder, takes care of this warning:
http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-258.18/mDNSPosix/PosixDaemon.c

On OSX, it temporarily renames the daemon() function before including stdlib.h and declares it manually as an extern function. This way, the compiler does not see the declaration from stdlib.h and thus does not display the warning.

---
 osdep.h       |    1 +
 oslib-posix.c |   16 ++++++++++++++++
 qemu-nbd.c    |    2 +-
 3 files changed, 18 insertions(+), 1 deletions(-)
osdep.h +1 -0
index 970d767..6eb9a49 100644
@@ -88,6 +88,7 @@
 # define QEMU_GNUC_PREREQ(maj, min) 0
 #endif
 
+int qemu_daemon(int nochdir, int noclose);
 void *qemu_memalign(size_t alignment, size_t size);
 void *qemu_vmalloc(size_t size);
 void qemu_vfree(void *ptr);
oslib-posix.c +16 -0
index 7bc5f7c..3a18e86 100644
@@ -26,11 +26,27 @@
  * THE SOFTWARE.
  */
 
+/* The following block of code temporarily renames the daemon() function so the
+   compiler does not see the warning associated with it in stdlib.h on OSX */
+#ifdef __APPLE__
+#define daemon qemu_fake_daemon_function
+#include <stdlib.h>
+#undef daemon
+extern int daemon(int, int);
+#endif
+
 #include "config-host.h"
 #include "sysemu.h"
 #include "trace.h"
 #include "qemu_socket.h"
 
+
+
+int qemu_daemon(int nochdir, int noclose)
+{
+    return daemon(nochdir, noclose);
+}
+
 void *qemu_oom_check(void *ptr)
 {
     if (ptr == NULL) {
qemu-nbd.c +1 -1
index 110d78e..d91c02c 100644
@@ -359,7 +359,7 @@ int main(int argc, char **argv)
 
         if (!verbose) {
             /* detach client and server */
-            if (daemon(0, 0) == -1) {
+            if (qemu_daemon(0, 0) == -1) {
                 err(EXIT_FAILURE, "Failed to daemonize");
             }
         }
Signature · 1 line
1.7.5.3
#11 lore raw

Re: [Qemu-devel] [PATCH 08/10] cocoa: Revert dependency on VNC

In reply to Andreas Färber
Quoted 10 lines · Andreas Färber

In 821601ea5b02a68ada479731a4d3d07a9876632a (Make VNC support optional) cocoa.o was moved from ui-obj-$(CONFIG_COCOA) to vnc-obj-$(CONFIG_COCOA), adding a dependency on $(CONFIG_VNC). That must've been unintentional.

Cc Jes Sorensen <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 Makefile.objs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Looks like an error from my side, sorry about that.

Patch looks good.

Jes

#12 lore raw
In reply to Andreas Färber
Quoted 6 lines · Andreas Färber

Hello,

I've collected a number of warning and usability fixes for the Cocoa frontend and Darwin host. Please pull.

Cc Blue Swirl <[email protected]>

Thanks, pulled.

Quoted 41 lines

The following changes since commit 0b862cedf36d927818c50584ddd611b0370673df:

 configure: Detect and don't try to use older libcurl (2011-06-13 21:16:27 +0200)

are available in the git repository at:
 git://repo.or.cz/qemu/afaerber.git cocoa-for-upstream

Alexandre Raymond (5):
 Fix compilation warning due to incorrectly specified type
 Cocoa: avoid displaying window when command-line contains '-h' or '-help'
 Remove warning in printf due to type mismatch
 configure: Fix check for fdatasync()
 Darwin: Fix compilation warning regarding the deprecated daemon() function

Andreas Färber (4):
 Fix libfdt warnings on Darwin
 cocoa: Provide central qemu_main() prototype
 cocoa: Revert dependency on VNC
 cocoa: Avoid warning related to multiple handleEvent: definitions

Tristan Gingold (1):
 cocoa: do not create a spurious window for -version

 Makefile.objs           |    2 +- audio/coreaudio.c       |    2 +-
 configure               |    8 +++++++- libfdt_env.h            |    8 ++------
 osdep.h                 |    1 +
 oslib-posix.c           |   16 ++++++++++++++++ qemu-common.h           |    5 +++++
 qemu-nbd.c              |    2 +- target-lm32/translate.c |    2 +-
 ui/cocoa.m              |   25 ++++++++++++++++++-------

 10 files changed, 53 insertions(+), 18 deletions(-)

--
1.7.5.3