Patchwork cocoa: Provide central qemu_main() prototype

login
register
mail settings
Submitter Andreas Färber
Date May 29, 2011, 7:58 p.m.
Message ID <1306699131-59195-1-git-send-email-andreas.faerber@web.de>
Download mbox | patch
Permalink /patch/97849/
State New
Headers show

Comments

Andreas Färber - May 29, 2011, 7:58 p.m.
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 <cerbere@gmail.com>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 qemu-common.h |    5 +++++
 ui/cocoa.m    |    6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)
Alexandre Raymond - May 29, 2011, 11:53 p.m.
Hi Andreas,

Just thinking out loud here : wouldn't it make more sense to put the
main() of each gui framework directly in its corresponding file and
select the right one in the makefile using the configure options?

so you'd have
-no gui -> ui/no_gui.c:main() -> qemu_main()    === compile with no_gui.c + vl.c
-sdl -> ui/sdl.c:main() -> qemu_main() === compile with sdl.c + vl.c
-cocoa -> ui/cocoa.m:main() -> qemu_main() === compile with cocoa.m + vl.c

with ui/no_gui.c, ui/sdl.c and ui/cocoa.m each having their own main():
----8<----
...
int main(...) {
    return qemu_main(....);
}
...
----8<----

and definitively rename main() to qemu_main() in vl.c ?

Alexandre

On Sun, May 29, 2011 at 3:58 PM, Andreas Färber <andreas.faerber@web.de> wrote:
> 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 <cerbere@gmail.com>
> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
> ---
>  qemu-common.h |    5 +++++
>  ui/cocoa.m    |    6 +++---
>  2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/qemu-common.h b/qemu-common.h
> index b851b20..218289c 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -131,6 +131,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);
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index 1ff1ac6..6566e46 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -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);
>  }
>
> @@ -876,7 +876,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());
>             }
>         }
>     }
> --
> 1.7.5.3
>
>
Andreas Färber - June 2, 2011, 11:33 a.m.
Am 30.05.2011 um 01:53 schrieb Alexandre Raymond:

> Just thinking out loud here : wouldn't it make more sense to put the
> main() of each gui framework directly in its corresponding file and
> select the right one in the makefile using the configure options?
>
> so you'd have
> -no gui -> ui/no_gui.c:main() -> qemu_main()    === compile with  
> no_gui.c + vl.c
> -sdl -> ui/sdl.c:main() -> qemu_main() === compile with sdl.c + vl.c
> -cocoa -> ui/cocoa.m:main() -> qemu_main() === compile with cocoa.m  
> + vl.c
>
> with ui/no_gui.c, ui/sdl.c and ui/cocoa.m each having their own  
> main():
> ----8<----
> ...
> int main(...) {
>    return qemu_main(....);
> }
> ...
> ----8<----
>
> and definitively rename main() to qemu_main() in vl.c ?

Anthony, waiting on your comment here as it's an overall UI  
architectural question.

To me that sounds the wrong direction to fix this... The only frontend  
that forces another main() function on us seems to be SDL under some  
circumstances. For Cocoa that was a QEMU-internal choice.

Instead of always renaming our main() function, maybe we can introduce  
some general hooks from our main() that the frontends can use to  
initialize them? One hook would need to be before processing of  
options (since launching a Cocoa app may add some Cocoa-specific  
parameters from the desktop or AppleScript/Automator) and another one  
once the options are processed and it's clear what display mode we're  
in.

So should we go ahead with my patch for the next pull or do some  
reorganization touching all frontends?

Andreas

> On Sun, May 29, 2011 at 3:58 PM, Andreas Färber <andreas.faerber@web.de 
> > wrote:
>> 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 <cerbere@gmail.com>
>> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
>> ---
>>  qemu-common.h |    5 +++++
>>  ui/cocoa.m    |    6 +++---
>>  2 files changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/qemu-common.h b/qemu-common.h
>> index b851b20..218289c 100644
>> --- a/qemu-common.h
>> +++ b/qemu-common.h
>> @@ -131,6 +131,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);
>>
>> diff --git a/ui/cocoa.m b/ui/cocoa.m
>> index 1ff1ac6..6566e46 100644
>> --- a/ui/cocoa.m
>> +++ b/ui/cocoa.m
>> @@ -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);
>>  }
>>
>> @@ -876,7 +876,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());
>>             }
>>         }
>>     }
>> --
>> 1.7.5.3
Andreas Färber - June 9, 2011, 6:30 p.m.
Am 29.05.2011 um 21:58 schrieb Andreas Färber:

> 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 <cerbere@gmail.com>
> Signed-off-by: Andreas Färber <andreas.faerber@web.de>

Applied to the cocoa branch.

Andreas

> ---
> qemu-common.h |    5 +++++
> ui/cocoa.m    |    6 +++---
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/qemu-common.h b/qemu-common.h
> index b851b20..218289c 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -131,6 +131,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);
>
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index 1ff1ac6..6566e46 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -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);
> }
>
> @@ -876,7 +876,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());
>             }
>         }
>     }
> -- 
> 1.7.5.3
>
>

Patch

diff --git a/qemu-common.h b/qemu-common.h
index b851b20..218289c 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -131,6 +131,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);
 
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 1ff1ac6..6566e46 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -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);
 }
 
@@ -876,7 +876,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());
             }
         }
     }