[Spice-devel,spice-common] allow log.c to compile under MSVC++

Submitted by Aric Stewart on April 17, 2012, 2:36 p.m.

Details

Message ID 4F8D8004.3060001@codeweavers.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Aric Stewart April 17, 2012, 2:36 p.m.
---
  common/log.c |   12 ++++++++++++
  1 files changed, 12 insertions(+), 0 deletions(-)

   static const char * spice_log_level_to_string(SpiceLogLevel level)
  {
+#ifdef _MSC_VER
+    /* MSVC++ does not implement C99 */
+    static const char *to_string[] = {
+         "ERROR",
+         "CRITICAL",
+         "Warning",
+         "Info",
+         "Debug"};
+#else
      static const char *to_string[] = {
          [ SPICE_LOG_LEVEL_ERROR ] = "ERROR",
          [ SPICE_LOG_LEVEL_CRITICAL ] = "CRITICAL",
@@ -39,6 +50,7 @@ static const char * 
spice_log_level_to_string(SpiceLogLevel level)
          [ SPICE_LOG_LEVEL_INFO ] = "Info",
          [ SPICE_LOG_LEVEL_DEBUG ] = "Debug",
      };
+#endif
      const char *str = NULL;
        if (level < SPICE_N_ELEMENTS(to_string)) {

Patch hide | download patch | download mbox

diff --git a/common/log.c b/common/log.c
index ef4da06..3cbcef6 100644
--- a/common/log.c
+++ b/common/log.c
@@ -22,7 +22,9 @@ 
  #include <stdlib.h>
  #include <stdio.h>
  #include <sys/types.h>
+#ifndef _MSC_VER
  #include <unistd.h>
+#endif
   #include "log.h"
  #include "backtrace.h"
@@ -32,6 +34,15 @@  static int abort_level = -1;

Comments

On Tue, Apr 17, 2012 at 09:36:52AM -0500, Aric Stewart wrote:
> ---
>  common/log.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 

ACK and pushing.

> diff --git a/common/log.c b/common/log.c
> index ef4da06..3cbcef6 100644
> --- a/common/log.c
> +++ b/common/log.c
> @@ -22,7 +22,9 @@
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <sys/types.h>
> +#ifndef _MSC_VER
>  #include <unistd.h>
> +#endif
>   #include "log.h"
>  #include "backtrace.h"
> @@ -32,6 +34,15 @@ static int abort_level = -1;
>   static const char * spice_log_level_to_string(SpiceLogLevel level)
>  {
> +#ifdef _MSC_VER
> +    /* MSVC++ does not implement C99 */
> +    static const char *to_string[] = {
> +         "ERROR",
> +         "CRITICAL",
> +         "Warning",
> +         "Info",
> +         "Debug"};
> +#else
>      static const char *to_string[] = {
>          [ SPICE_LOG_LEVEL_ERROR ] = "ERROR",
>          [ SPICE_LOG_LEVEL_CRITICAL ] = "CRITICAL",
> @@ -39,6 +50,7 @@ static const char *
> spice_log_level_to_string(SpiceLogLevel level)
>          [ SPICE_LOG_LEVEL_INFO ] = "Info",
>          [ SPICE_LOG_LEVEL_DEBUG ] = "Debug",
>      };
> +#endif
>      const char *str = NULL;
>        if (level < SPICE_N_ELEMENTS(to_string)) {
> -- 
> 1.6.0.rc1.64.g61192
> 


> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
On Tue, Apr 17, 2012 at 06:58:59PM +0300, Alon Levy wrote:
> On Tue, Apr 17, 2012 at 09:36:52AM -0500, Aric Stewart wrote:
> > ---
> >  common/log.c |   12 ++++++++++++
> >  1 files changed, 12 insertions(+), 0 deletions(-)
> > 
> 
> ACK and pushing.
> 
> > diff --git a/common/log.c b/common/log.c
> > index ef4da06..3cbcef6 100644
> > --- a/common/log.c
> > +++ b/common/log.c
> > @@ -22,7 +22,9 @@
> >  #include <stdlib.h>
> >  #include <stdio.h>
> >  #include <sys/types.h>
> > +#ifndef _MSC_VER
> >  #include <unistd.h>
> > +#endif
> >   #include "log.h"
> >  #include "backtrace.h"
> > @@ -32,6 +34,15 @@ static int abort_level = -1;
> >   static const char * spice_log_level_to_string(SpiceLogLevel level)
> >  {
> > +#ifdef _MSC_VER
> > +    /* MSVC++ does not implement C99 */
> > +    static const char *to_string[] = {
> > +         "ERROR",
> > +         "CRITICAL",
> > +         "Warning",
> > +         "Info",
> > +         "Debug"};
> > +#else
> >      static const char *to_string[] = {
> >          [ SPICE_LOG_LEVEL_ERROR ] = "ERROR",
> >          [ SPICE_LOG_LEVEL_CRITICAL ] = "CRITICAL",
> > @@ -39,6 +50,7 @@ static const char *
> > spice_log_level_to_string(SpiceLogLevel level)
> >          [ SPICE_LOG_LEVEL_INFO ] = "Info",
> >          [ SPICE_LOG_LEVEL_DEBUG ] = "Debug",
> >      };
> > +#endif

For what it's worth, I would have suggested just using the first construct
even on linux, but this way is fine with me too.

Christophe