[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] fix public header hvm/save.h to be compatible with c++



>>> On 05.10.12 at 14:05, Ben Guthro <ben@xxxxxxxxxx> wrote:
> Including save.h in a C++ application was throwing some errors, as it
> was unhappy about the "new" keyword being used (even when wrapped in
> an "extern C" block)
> 
> This change renames some variables to keep the compiler happy, as well
> as casts the (void*) as appropriate.
> 
> Signed-off-by: Ben Guthro <ben@xxxxxxxxxx>
> 
> diff --git a/xen/include/public/arch-x86/hvm/save.h
> b/xen/include/public/arch-x86/hvm/save.h
> index a82a5ee..20e5061 100644
> --- a/xen/include/public/arch-x86/hvm/save.h
> +++ b/xen/include/public/arch-x86/hvm/save.h
> @@ -269,15 +269,15 @@ struct hvm_hw_cpu_compat {
>  };
> 
>  static inline int _hvm_hw_fix_cpu(void *h) {
> -    struct hvm_hw_cpu *new=h;
> -    struct hvm_hw_cpu_compat *old=h;
> +    struct hvm_hw_cpu *new_cpu = (struct hvm_hw_cpu *)h;
> +    struct hvm_hw_cpu_compat *old_cpu = (struct hvm_hw_cpu_compat *)h;

While I don't mind the variable renames (albeit I'm questioning
whether the headers ought to be honoring the C++ reserved
names in the first place), I dislike the casts - they're redundant
in C (and it is my opinion that due to the mistakes casts can
hide they should be used as sparingly as possible), and at best
undesirable in C++ (you'd want to use static_cast<> there
instead).

Since the function is unused with __XEN__ undefined, I'd
instead suggest putting it inside a respective preprocessor
conditional.

>      /* If we copy from the end backwards, we should
>       * be able to do the modification in-place */
> -    new->error_code=old->error_code;
> -    new->pending_event=old->pending_event;
> -    new->tsc=old->tsc;
> -    new->msr_tsc_aux=0;
> +    new_cpu->error_code=old_cpu->error_code;
> +    new_cpu->pending_event=old_cpu->pending_event;
> +    new_cpu->tsc=old_cpu->tsc;
> +    new_cpu->msr_tsc_aux=0;

Once at it, you could have inserted the missing spaces around
the equal signs at once...

Jan

> 
>      return 0;
>  }




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.