|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] libxl: Introduce LIBXL_DOMAIN_TYPE_INVALID to make gcc happy
On 05/23/12 15:12, Dario Faggioli wrote:
> On Wed, 2012-05-23 at 14:49 +0200, Dario Faggioli wrote:
>> Problem arises
>> with auto-generated code, e.g., in gentypes.py for build_info related
>> functions. In this case, in fact, the libxl_domain_type enum is the key
>> of the keyed-union. For those cases, I was thinking at something like
>> the below:
>>
>> if isinstance(ty, idl.KeyedUnion):
>> if parent is None:
>> raise Exception("KeyedUnion type must have a parent")
>> s += "switch (%s) {\n" % (parent + ty.keyvar.name)
>> for f in ty.fields:
>> (nparent,fexpr) = ty.member(v, f, parent is None)
>> s += "case %s:\n" % f.enumname
>> s += libxl_C_type_dispose(f.type, fexpr, indent + " ",
>> nparent)
>> s += " break;\n"
>> + s += "default:\n break;\n";
>> s += "}\n"
>>
>> Would it make sense?
>>
> Like this thing below.
>
> Christoph, this ended up extending what you sent at the very beginning
> of this thread, so I think we should both sign-off-by it (and thus it
> took the liberty going ahead and adding yours), do you agree?
Yes, I agree.
Christoph
>
> <-----------------------
>
> libxl: introduce LIBXL_DOMAIN_TYPE_INVALID
>
> To avoid recent gcc complaining about:
> libxl.c: In function âlibxl_primary_console_execâ:
> libxl.c:1233:9: error: case value â4294967295â not in enumerated type
> âlibxl_domain_typeâ [-Werror=switch]
>
> Adjust code pieces where -Wswitch makes it claim that
> LIBXL_DOMAIN_TYPE_INVALID is not handled.
>
> Signed-off-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
> Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
>
> diff -r 6dc80df50fa8 tools/libxl/gentest.py
> --- a/tools/libxl/gentest.py Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/gentest.py Wed May 23 15:05:20 2012 +0200
> @@ -37,6 +37,8 @@ def gen_rand_init(ty, v, indent = " "
> s += "case %s:\n" % f.enumname
> s += gen_rand_init(f.type, fexpr, indent + " ", nparent)
> s += " break;\n"
> + s += "default:\n";
> + s += " break;\n";
> s += "}\n"
> elif isinstance(ty, idl.Struct) \
> and (parent is None or ty.json_fn is None):
> diff -r 6dc80df50fa8 tools/libxl/gentypes.py
> --- a/tools/libxl/gentypes.py Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/gentypes.py Wed May 23 15:05:20 2012 +0200
> @@ -65,6 +65,8 @@ def libxl_C_type_dispose(ty, v, indent =
> s += "case %s:\n" % f.enumname
> s += libxl_C_type_dispose(f.type, fexpr, indent + " ",
> nparent)
> s += " break;\n"
> + s += "default:\n";
> + s += " break;\n";
> s += "}\n"
> elif isinstance(ty, idl.Struct) and (parent is None or ty.dispose_fn is
> None):
> for f in [f for f in ty.fields if not f.const]:
> @@ -98,6 +100,8 @@ def _libxl_C_type_init(ty, v, indent = "
> s += "case %s:\n" % f.enumname
> s += _libxl_C_type_init(f.type, fexpr, " ", nparent)
> s += " break;\n"
> + s += "default:\n";
> + s += " break;\n";
> s += "}\n"
> else:
> if ty.keyvar.init_val:
> @@ -177,6 +181,8 @@ def libxl_C_type_gen_json(ty, v, indent
> s += "case %s:\n" % f.enumname
> s += libxl_C_type_gen_json(f.type, fexpr, indent + " ",
> nparent)
> s += " break;\n"
> + s += "default:\n";
> + s += " break;\n";
> s += "}\n"
> elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is
> None):
> s += "s = yajl_gen_map_open(hand);\n"
> diff -r 6dc80df50fa8 tools/libxl/libxl.c
> --- a/tools/libxl/libxl.c Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/libxl.c Wed May 23 15:05:20 2012 +0200
> @@ -1230,7 +1230,7 @@ int libxl_primary_console_exec(libxl_ctx
> case LIBXL_DOMAIN_TYPE_PV:
> rc = libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSOLE_TYPE_PV);
> break;
> - case -1:
> + case LIBXL_DOMAIN_TYPE_INVALID:
> LOG(ERROR,"unable to get domain type for
> domid=%"PRIu32,domid_vm);
> rc = ERROR_FAIL;
> break;
> diff -r 6dc80df50fa8 tools/libxl/libxl_dm.c
> --- a/tools/libxl/libxl_dm.c Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/libxl_dm.c Wed May 23 15:05:20 2012 +0200
> @@ -257,6 +257,8 @@ static char ** libxl__build_device_model
> for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++)
> flexarray_append(dm_args, b_info->extra_hvm[i]);
> break;
> + case LIBXL_DOMAIN_TYPE_INVALID:
> + break;
> }
> flexarray_append(dm_args, NULL);
> return (char **) flexarray_contents(dm_args);
> @@ -505,6 +507,8 @@ static char ** libxl__build_device_model
> for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++)
> flexarray_append(dm_args, b_info->extra_hvm[i]);
> break;
> + case LIBXL_DOMAIN_TYPE_INVALID:
> + break;
> }
>
> ram_size = libxl__sizekb_to_mb(b_info->max_memkb - b_info->video_memkb);
> diff -r 6dc80df50fa8 tools/libxl/libxl_dom.c
> --- a/tools/libxl/libxl_dom.c Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/libxl_dom.c Wed May 23 15:05:20 2012 +0200
> @@ -33,9 +33,9 @@ libxl_domain_type libxl__domain_type(lib
>
> ret = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
> if (ret != 1)
> - return -1;
> + return LIBXL_DOMAIN_TYPE_INVALID;
> if (info.domain != domid)
> - return -1;
> + return LIBXL_DOMAIN_TYPE_INVALID;
> if (info.flags & XEN_DOMINF_hvm_guest)
> return LIBXL_DOMAIN_TYPE_HVM;
> else
> diff -r 6dc80df50fa8 tools/libxl/libxl_types.idl
> --- a/tools/libxl/libxl_types.idl Tue May 22 16:30:11 2012 +0200
> +++ b/tools/libxl/libxl_types.idl Wed May 23 15:05:20 2012 +0200
> @@ -30,6 +30,7 @@ MemKB = UInt(64, init_val = "LIBXL_MEMKB
> #
>
> libxl_domain_type = Enumeration("domain_type", [
> + (-1, "INVALID"),
> (1, "HVM"),
> (2, "PV"),
> ])
>
>
--
---to satisfy European Law for business letters:
Advanced Micro Devices GmbH
Einsteinring 24, 85689 Dornach b. Muenchen
Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd
Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |