libxl: Enable -Wshadow
PATCH 1/1 libxl: Enable -Wshadow
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1347620983 -3600
# Node ID 58ab3fb73d13e250f334a38599b749640deac190 # Parent 0547430886c507989dd9091ef5f1e2d089a50351
libxl: Enable -Wshadow.
It was convenient to invent $(CFLAGS_LIBXL) to do this.
Various renamings to avoid shadowing standard functions:
- index(3)
- listen(2)
- link(2)
- abort(3)
- abs(3)
Reduced the scope of some variables to avoid conflicts.
Change to libxc is due to the nested hypercall buf macros in set_xen_guest_handle (used in libxl) using the same local private vars.
Build tested only.
tools/libxc/xenctrl.h +12 -12
@@ -236,10 +236,10 @@ typedef struct xc_hypercall_buffer xc_hy* Returns the hypercall_buffer associated with a variable. */ #define HYPERCALL_BUFFER (_name) \ - ({ xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = &XC__HYPERCALL_BUFFER_NAME(_name); \ - (void)(&_val1 == _val2); \ - (_val2)->param_shadow ? (_val2)->param_shadow : (_val2); \ + ({ xc_hypercall_buffer_t _buf1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_buf2 = &XC__HYPERCALL_BUFFER_NAME(_name); \ + (void)(&_buf1 == _buf2); \ + (_buf2)->param_shadow ? (_buf2)->param_shadow : (_buf2); \ })#define HYPERCALL_BUFFER_INIT_NO_BOUNCE .dir = 0, .sz = 0, .ubuf = (void *)-1
@@ -274,10 +274,10 @@ typedef struct xc_hypercall_buffer xc_hy* directly as a hypercall argument. */ #define HYPERCALL_BUFFER_AS_ARG (_name) \ - ({ xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = HYPERCALL_BUFFER(_name); \ - (void)(&_val1 == _val2); \ - (unsigned long)(_val2)->hbuf; \ + ({ xc_hypercall_buffer_t _bufarg1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_bufarg2 = HYPERCALL_BUFFER(_name); \ + (void)(&_bufarg1 == _bufarg2); \ + (unsigned long)(_bufarg2)->hbuf; \ })/*
@@ -287,10 +287,10 @@ typedef struct xc_hypercall_buffer xc_hy#undef set_xen_guest_handle#define set_xen_guest_handle (_hnd, _val) \ do { \ - xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_val2 = HYPERCALL_BUFFER(_val); \ - (void) (&_val1 == _val2); \ - set_xen_guest_handle_raw(_hnd, (_val2)->hbuf); \ + xc_hypercall_buffer_t _bufhnd1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_bufhnd2 = HYPERCALL_BUFFER(_val); \ + (void) (&_bufhnd1 == _bufhnd2); \ + set_xen_guest_handle_raw(_hnd, (_bufhnd2)->hbuf); \ } while (0)/* Use with set_xen_guest_handle in place of NULL */
tools/libxl/Makefile +7 -1
@@ -22,6 +22,12 @@ endif LIBXL_LIBS = LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) +CFLAGS_LIBXL += $(CFLAGS_libxenctrl) +CFLAGS_LIBXL += $(CFLAGS_libxenguest) +CFLAGS_LIBXL += $(CFLAGS_libxenstore) +CFLAGS_LIBXL += $(CFLAGS_libblktapctl) +CFLAGS_LIBXL += -Wshadow + CFLAGS += $(PTHREAD_CFLAGS) LDFLAGS += $(PTHREAD_LDFLAGS) LIBXL_LIBS += $(PTHREAD_LIBS)
@@ -71,7 +77,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_c libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o -$(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h +$(LIBXL_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
tools/libxl/flexarray.c +9 -9
@@ -48,19 +48,19 @@ int flexarray_grow(flexarray_t *array, ireturn 0 ; } -int flexarray_set (flexarray_t *array,unsigned int index,void *ptr) +int flexarray_set (flexarray_t *array,unsigned int idx,void *ptr) { -if (index >= array->size) { +if (idx >= array->size) {int newsize;if (!array->autogrow)return 1 ; - newsize = (array->size *2 < index) ? index +1 : array->size *2 ; + newsize = (array->size *2 < idx) ? idx +1 : array->size *2 ;if (flexarray_grow (array, newsize - array->size))return 2 ; } -if ( index +1 > array->count ) - array->count = index +1 ; - array->data[index] = ptr; +if ( idx +1 > array->count ) + array->count = idx +1 ; + array->data[idx] = ptr;return 0 ; }
@@ -92,11 +92,11 @@ int flexarray_vappend(flexarray_t *arrayreturn ret; } -int flexarray_get (flexarray_t *array,int index,void **ptr) +int flexarray_get (flexarray_t *array,int idx,void **ptr) { -if (index >= array->size) +if (idx >= array->size)return 1 ; - *ptr = array->data[index]; + *ptr = array->data[idx];return 0 ; }
tools/libxl/libxl.c +21 -20
127 lines not on this page · raw message
tools/libxl/libxl_dm.c +6 -6
@@ -379,7 +379,7 @@ static char ** libxl__build_device_model }if (vnc) {int display =0 ; -const char *listen ="127.0.0.1" ; +const char *addr ="127.0.0.1" ;char *vncarg =NULL ;flexarray_append (dm_args,"-vnc" );
@@ -387,16 +387,16 @@ static char ** libxl__build_device_modelif (vnc->display) { display = vnc->display;if (vnc->listen &&strchr (vnc->listen,':' ) ==NULL ) { - listen = vnc->listen; + addr = vnc->listen; } }else if (vnc->listen) { - listen = vnc->listen; + addr = vnc->listen; } -if (strchr (listen,':' ) !=NULL ) - vncarg =libxl__sprintf (gc,"%s" , listen); +if (strchr (addr,':' ) !=NULL ) + vncarg =libxl__sprintf (gc,"%s" , addr);else - vncarg =libxl__sprintf (gc,"%s:%d" , listen, display); + vncarg =libxl__sprintf (gc,"%s:%d" , addr, display);if (vnc->passwd && vnc->passwd[0 ]) { vncarg =libxl__sprintf (gc,"%s,password" , vncarg); }
tools/libxl/libxl_event.c +17 -17
@@ -167,15 +167,15 @@ static void time_insert_finite(libxl__gc }static int time_register_finite (libxl__gc *gc,libxl__ev_time *ev, -struct timeval abs) +struct timeval absolute) {int rc; - rc =OSEVENT_HOOK (timeout_register, &ev->for_app_reg, abs, ev); + rc =OSEVENT_HOOK (timeout_register, &ev->for_app_reg, absolute, ev);if (rc)return rc; ev->infinite =0 ; - ev->abs = abs; + ev->abs = absolute;time_insert_finite (gc, ev);return 0 ;
@@ -202,16 +202,16 @@ static void time_done_debug(libxl__gc *gint libxl__ev_time_register_abs (libxl__gc *gc,libxl__ev_time *ev,libxl__ev_time_callback *func, -struct timeval abs) +struct timeval absolute) {int rc;CTX_LOCK ;DBG ("ev_time=%p register abs=%lu.%06lu" , - ev, (unsigned long )abs.tv_sec, (unsigned long )abs.tv_usec); + ev, (unsigned long )absolute.tv_sec, (unsigned long )absolute.tv_usec); - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; ev->func = func;
@@ -228,7 +228,7 @@ int libxl__ev_time_register_rel(libxl__glibxl__ev_time_callback *func, int milliseconds /* as for poll(2) */) { - struct timeval abs; + struct timeval absolute;int rc;CTX_LOCK ;
@@ -238,10 +238,10 @@ int libxl__ev_time_register_rel(libxl__gif (milliseconds <0 ) { ev->infinite =1 ; }else { - rc =time_rel_to_abs (gc, milliseconds, &abs); + rc =time_rel_to_abs (gc, milliseconds, &absolute);if (rc) goto out; - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; }
@@ -255,26 +255,26 @@ int libxl__ev_time_register_rel(libxl__g }int libxl__ev_time_modify_abs (libxl__gc *gc,libxl__ev_time *ev, -struct timeval abs) +struct timeval absolute) {int rc;CTX_LOCK ;DBG ("ev_time=%p modify abs==%lu.%06lu" , - ev, (unsigned long )abs.tv_sec, (unsigned long )abs.tv_usec); + ev, (unsigned long )absolute.tv_sec, (unsigned long )absolute.tv_usec);assert (libxl__ev_time_isregistered (ev));if (ev->infinite) { - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; }else { - rc =OSEVENT_HOOK (timeout_modify, &ev->for_app_reg, abs); + rc =OSEVENT_HOOK (timeout_modify, &ev->for_app_reg, absolute);if (rc) goto out;LIBXL_TAILQ_REMOVE (&CTX ->etimes, ev, entry); - ev->abs = abs; + ev->abs = absolute;time_insert_finite (gc, ev); }
@@ -288,7 +288,7 @@ int libxl__ev_time_modify_abs(libxl__gcint libxl__ev_time_modify_rel (libxl__gc *gc,libxl__ev_time *ev,int milliseconds) { -struct timeval abs; +struct timeval absolute;int rc;CTX_LOCK ;
@@ -304,10 +304,10 @@ int libxl__ev_time_modify_rel(libxl__gc goto out; } - rc =time_rel_to_abs (gc, milliseconds, &abs); + rc =time_rel_to_abs (gc, milliseconds, &absolute);if (rc) goto out; - rc =libxl__ev_time_modify_abs (gc, ev, abs); + rc =libxl__ev_time_modify_abs (gc, ev, absolute);if (rc) goto out; rc =0 ;
tools/libxl/libxl_exec.c +4 -4
@@ -35,7 +35,7 @@ static void check_open_fds(const char *w#ifdef __linux__size_t len;char path[PATH_MAX ]; -char link[PATH_MAX +1 ]; +char linkpath[PATH_MAX +1 ];#endif flags =fcntl (i,F_GETFD );if ( flags ==-1 ) {
@@ -52,11 +52,11 @@ static void check_open_fds(const char *w#ifdef __linux__snprintf (path,PATH_MAX ,"/proc/%d/fd/%d" ,getpid (), i); - len =readlink (path, link,PATH_MAX ); + len =readlink (path, linkpath,PATH_MAX );if (len >0 ) { - link[len] ='\0' ; + linkpath[len] ='\0' ;fprintf (stderr,"libxl: execing %s: fd %d is open to %s with flags %#x\n" , - what, i, link, flags); + what, i, linkpath, flags); } else#endif fprintf(stderr, "libxl: execing %s: fd %d is open with flags %#x\n",
tools/libxl/libxl_json.c +8 -8
@@ -275,7 +275,7 @@ static int json_object_append_to(libxl__void libxl__json_object_free (libxl__gc *gc,libxl__json_object *obj) { -int index =0 ; +int idx =0 ;if (obj ==NULL )return ;
@@ -287,8 +287,8 @@ void libxl__json_object_free(libxl__gc *case JSON_MAP : {libxl__json_map_node *node =NULL ; -for (index =0 ; index < obj->u.map->count; index++) { -if (flexarray_get (obj->u.map, index, (void **)&node) !=0 ) +for (idx =0 ; idx < obj->u.map->count; idx++) { +if (flexarray_get (obj->u.map, idx, (void **)&node) !=0 )break ;libxl__json_object_free (gc, node->obj);free (node->map_key);
@@ -302,8 +302,8 @@ void libxl__json_object_free(libxl__gc *libxl__json_object *node =NULL ;break ; -for (index =0 ; index < obj->u.array->count; index++) { -if (flexarray_get (obj->u.array, index, (void **)&node) !=0 ) +for (idx =0 ; idx < obj->u.array->count; idx++) { +if (flexarray_get (obj->u.array, idx, (void **)&node) !=0 )break ;libxl__json_object_free (gc, node); node =NULL ;
@@ -359,14 +359,14 @@ const libxl__json_object *libxl__json_ma libxl__json_node_type expected_type) {flexarray_t *maps =NULL ; -int index =0 ; +int idx =0 ;if (libxl__json_object_is_map (o)) {libxl__json_map_node *node =NULL ; maps = o->u.map; -for (index =0 ; index < maps->count; index++) { -if (flexarray_get (maps, index, (void **)&node) !=0 ) +for (idx =0 ; idx < maps->count; idx++) { +if (flexarray_get (maps, idx, (void **)&node) !=0 )return NULL ;if (strcmp (key, node->map_key) ==0 ) { if (expected_type == JSON_ANY
tools/libxl/libxl_pci.c +1 -1
@@ -167,7 +167,6 @@ static int libxl__device_pci_remove_xenschar *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath;int num, i, j;xs_transaction_t t; -unsigned int domain =0 , bus =0 , dev =0 , func =0 ; be_path =libxl__sprintf (gc,"%s/backend/pci/%d/0" ,libxl__xs_get_dompath (gc,0 ), domid); num_devs_path =libxl__sprintf (gc,"%s/num_devs" , be_path);
@@ -188,6 +187,7 @@ static int libxl__device_pci_remove_xens }for (i =0 ; i < num; i++) { +unsigned int domain =0 , bus =0 , dev =0 , func =0 ; xsdev =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/dev-%d" , be_path, i));sscanf (xsdev,PCI_BDF , &domain, &bus, &dev, &func); if (domain == pcidev->domain && bus == pcidev->bus &&
tools/libxl/libxl_qmp.c +4 -4
@@ -171,7 +171,7 @@ static int qmp_register_vnc_callback(lib {GC_INIT (qmp->ctx);const libxl__json_object *obj; -const char *listen, *port; +const char *addr, *port;int rc =-1 ;if (!libxl__json_object_is_map (o)) {
@@ -184,17 +184,17 @@ static int qmp_register_vnc_callback(lib } obj =libxl__json_map_get ("host" , o,JSON_STRING ); - listen =libxl__json_object_get_string (obj); + addr =libxl__json_object_get_string (obj); obj =libxl__json_map_get ("service" , o,JSON_STRING ); port =libxl__json_object_get_string (obj); -if (!listen || !port) { +if (!addr || !port) {LIBXL__LOG (qmp->ctx,LIBXL__LOG_ERROR ,"Failed to retreive VNC connect information." ); goto out; } - rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-listen" , listen); + rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-listen" , addr);if (!rc) rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-port" , port);
Ian Campbell writes ("[PATCH] libxl: Enable -Wshadow"):
Quoted 10 lines
libxl: Enable -Wshadow.
It was convenient to invent $(CFLAGS_LIBXL) to do this.
Various renamings to avoid shadowing standard functions:
- index(3)
- listen(2)
- link(2)
- abort(3)
- abs(3)
Thanks.
Quoted 6 lines
Reduced the scope of some variables to avoid conflicts.
Change to libxc is due to the nested hypercall buf macros in
set_xen_guest_handle(used in libxl) using the same local private vars.Build tested only.
Ian.
Ian Campbell writes ("[PATCH] libxl: Enable -Wshadow"):
Quoted 1 line
libxl: Enable -Wshadow.
Oh I just thought of this:
Quoted 6 lines
diff -r
0547430886c5-r58ab3fb73d13tools/libxc/xenctrl.htools/libxc/xenctrl.h Fri Sep 14 12:09:43 2012 +0100 renamed from tools/libxc/xenctrl.h Fri Sep 14 11:00:40 2012 +0100 +0
-0@@ -236,10 +236,10 @@ typedef struct xc_hypercall_buffer xc_hy * Returns the hypercall_buffer associated with a variable. */
tools/libxc/xenctrl.h Fri Sep 14 12:09:43 2012 +0100 typedef struct xc_hypercall_buffer xc_hy · line 243
Quoted 10 lines
tools/libxc/xenctrl.h Fri Sep 14 12:09:43 2012 +0100 renamed from tools/libxc/xenctrl.h Fri Sep 14 11:00:40 2012 +0100 +4
-4#define HYPERCALL_BUFFER(_name) \ - ({ xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = &XC__HYPERCALL_BUFFER_NAME(_name); \ - (void)(&_val1 == _val2); \ - (_val2)->param_shadow ? (_val2)->param_shadow : (_val2); \ + ({ xc_hypercall_buffer_t _buf1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_buf2 = &XC__HYPERCALL_BUFFER_NAME(_name); \ + (void)(&_buf1 == _buf2); \ + (_buf2)->param_shadow ? (_buf2)->param_shadow : (_buf2); \ })
This should be something like
tools/libxc/xenctrl.h Fri Sep 14 12:09:43 2012 +0100 typedef struct xc_hypercall_buffer xc_hy · line 244
Quoted 1 line
tools/libxc/xenctrl.h Fri Sep 14 12:09:43 2012 +0100 renamed from tools/libxc/xenctrl.h Fri Sep 14 11:00:40 2012 +0100 +1
-0+ ({ xc_hypercall_buffer_t _hcbuf_buf1;
surely ? As there is (and can be) no reasonable rule requiring users of this macro to avoid using the name _val1 or whatever.
If we're doing -Wshadow then macros which introduce local variables like this should give them names qualified somehow for the macro.
Ian.
Quoted 2 lines · Ian Jackson
If we're doing -Wshadow then macros which introduce local variables like this should give them names qualified somehow for the macro.
Done, v2 below.
Since I was touching every line I fixed the line length in those macros too.
8<------------------------------------------------------
# HG changeset patch
# User Ian Campbell <[email protected]> # Date 1347636539 -3600
# Node ID 6aacce1d8650e4fec5ddc524fd9a779e05434b26 # Parent 0547430886c507989dd9091ef5f1e2d089a50351
libxl: Enable -Wshadow.
It was convenient to invent $(CFLAGS_LIBXL) to do this.
Various renamings to avoid shadowing standard functions:
- index(3)
- listen(2)
- link(2)
- abort(3)
- abs(3)
Reduced the scope of some variables to avoid conflicts.
Change to libxc is due to the nested hypercall buf macros in set_xen_guest_handle (used in libxl) using the same local private vars.
Build tested only.
tools/libxc/xenctrl.h +20 -16
@@ -235,11 +235,13 @@ typedef struct xc_hypercall_buffer xc_hy/* * Returns the hypercall_buffer associated with a variable. */ -#define HYPERCALL_BUFFER (_name) \ - ({ xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = &XC__HYPERCALL_BUFFER_NAME(_name); \ - (void)(&_val1 == _val2); \ - (_val2)->param_shadow ? (_val2)->param_shadow : (_val2); \ +#define HYPERCALL_BUFFER (_name) \ + ({ xc_hypercall_buffer_t _hcbuf_buf1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_buf2 = \ + &XC__HYPERCALL_BUFFER_NAME(_name); \ + (void)(&_hcbuf_buf1 == _hcbuf_buf2); \ + (_hcbuf_buf2)->param_shadow ? \ + (_hcbuf_buf2)->param_shadow : (_hcbuf_buf2); \ })#define HYPERCALL_BUFFER_INIT_NO_BOUNCE .dir = 0, .sz = 0, .ubuf = (void *)-1
@@ -273,11 +275,12 @@ typedef struct xc_hypercall_buffer xc_hy* Get the hypercall buffer data pointer in a form suitable for use * directly as a hypercall argument. */ -#define HYPERCALL_BUFFER_AS_ARG (_name) \ - ({ xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_val2 = HYPERCALL_BUFFER(_name); \ - (void)(&_val1 == _val2); \ - (unsigned long)(_val2)->hbuf; \ +#define HYPERCALL_BUFFER_AS_ARG (_name) \ + ({ xc_hypercall_buffer_t _hcbuf_arg1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_name)) *_hcbuf_arg2 = \ + HYPERCALL_BUFFER(_name); \ + (void)(&_hcbuf_arg1 == _hcbuf_arg2); \ + (unsigned long)(_hcbuf_arg2)->hbuf; \ })/*
@@ -285,12 +288,13 @@ typedef struct xc_hypercall_buffer xc_hy* data pointer has been correctly allocated. */ #undef set_xen_guest_handle -#define set_xen_guest_handle (_hnd, _val) \ - do { \ - xc_hypercall_buffer_t _val1; \ - typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_val2 = HYPERCALL_BUFFER(_val); \ - (void) (&_val1 == _val2); \ - set_xen_guest_handle_raw(_hnd, (_val2)->hbuf); \ +#define set_xen_guest_handle (_hnd, _val) \ + do { \ + xc_hypercall_buffer_t _hcbuf_hnd1; \ + typeof(XC__HYPERCALL_BUFFER_NAME(_val)) *_hcbuf_hnd2 = \ + HYPERCALL_BUFFER(_val); \ + (void) (&_hcbuf_hnd1 == _hcbuf_hnd2); \ + set_xen_guest_handle_raw(_hnd, (_hcbuf_hnd2)->hbuf); \ } while (0)/* Use with set_xen_guest_handle in place of NULL */
tools/libxl/Makefile +7 -1
@@ -22,6 +22,12 @@ endif LIBXL_LIBS = LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) +CFLAGS_LIBXL += $(CFLAGS_libxenctrl) +CFLAGS_LIBXL += $(CFLAGS_libxenguest) +CFLAGS_LIBXL += $(CFLAGS_libxenstore) +CFLAGS_LIBXL += $(CFLAGS_libblktapctl) +CFLAGS_LIBXL += -Wshadow + CFLAGS += $(PTHREAD_CFLAGS) LDFLAGS += $(PTHREAD_LDFLAGS) LIBXL_LIBS += $(PTHREAD_LIBS)
@@ -71,7 +77,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_c libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o -$(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h +$(LIBXL_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
tools/libxl/flexarray.c +9 -9
@@ -48,19 +48,19 @@ int flexarray_grow(flexarray_t *array, ireturn 0 ; } -int flexarray_set (flexarray_t *array,unsigned int index,void *ptr) +int flexarray_set (flexarray_t *array,unsigned int idx,void *ptr) { -if (index >= array->size) { +if (idx >= array->size) {int newsize;if (!array->autogrow)return 1 ; - newsize = (array->size *2 < index) ? index +1 : array->size *2 ; + newsize = (array->size *2 < idx) ? idx +1 : array->size *2 ;if (flexarray_grow (array, newsize - array->size))return 2 ; } -if ( index +1 > array->count ) - array->count = index +1 ; - array->data[index] = ptr; +if ( idx +1 > array->count ) + array->count = idx +1 ; + array->data[idx] = ptr;return 0 ; }
@@ -92,11 +92,11 @@ int flexarray_vappend(flexarray_t *arrayreturn ret; } -int flexarray_get (flexarray_t *array,int index,void **ptr) +int flexarray_get (flexarray_t *array,int idx,void **ptr) { -if (index >= array->size) +if (idx >= array->size)return 1 ; - *ptr = array->data[index]; + *ptr = array->data[idx];return 0 ; }
tools/libxl/libxl.c +21 -20
127 lines not on this page · raw message
tools/libxl/libxl_dm.c +6 -6
@@ -379,7 +379,7 @@ static char ** libxl__build_device_model }if (vnc) {int display =0 ; -const char *listen ="127.0.0.1" ; +const char *addr ="127.0.0.1" ;char *vncarg =NULL ;flexarray_append (dm_args,"-vnc" );
@@ -387,16 +387,16 @@ static char ** libxl__build_device_modelif (vnc->display) { display = vnc->display;if (vnc->listen &&strchr (vnc->listen,':' ) ==NULL ) { - listen = vnc->listen; + addr = vnc->listen; } }else if (vnc->listen) { - listen = vnc->listen; + addr = vnc->listen; } -if (strchr (listen,':' ) !=NULL ) - vncarg =libxl__sprintf (gc,"%s" , listen); +if (strchr (addr,':' ) !=NULL ) + vncarg =libxl__sprintf (gc,"%s" , addr);else - vncarg =libxl__sprintf (gc,"%s:%d" , listen, display); + vncarg =libxl__sprintf (gc,"%s:%d" , addr, display);if (vnc->passwd && vnc->passwd[0 ]) { vncarg =libxl__sprintf (gc,"%s,password" , vncarg); }
tools/libxl/libxl_event.c +17 -17
@@ -167,15 +167,15 @@ static void time_insert_finite(libxl__gc }static int time_register_finite (libxl__gc *gc,libxl__ev_time *ev, -struct timeval abs) +struct timeval absolute) {int rc; - rc =OSEVENT_HOOK (timeout_register, &ev->for_app_reg, abs, ev); + rc =OSEVENT_HOOK (timeout_register, &ev->for_app_reg, absolute, ev);if (rc)return rc; ev->infinite =0 ; - ev->abs = abs; + ev->abs = absolute;time_insert_finite (gc, ev);return 0 ;
@@ -202,16 +202,16 @@ static void time_done_debug(libxl__gc *gint libxl__ev_time_register_abs (libxl__gc *gc,libxl__ev_time *ev,libxl__ev_time_callback *func, -struct timeval abs) +struct timeval absolute) {int rc;CTX_LOCK ;DBG ("ev_time=%p register abs=%lu.%06lu" , - ev, (unsigned long )abs.tv_sec, (unsigned long )abs.tv_usec); + ev, (unsigned long )absolute.tv_sec, (unsigned long )absolute.tv_usec); - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; ev->func = func;
@@ -228,7 +228,7 @@ int libxl__ev_time_register_rel(libxl__glibxl__ev_time_callback *func, int milliseconds /* as for poll(2) */) { - struct timeval abs; + struct timeval absolute;int rc;CTX_LOCK ;
@@ -238,10 +238,10 @@ int libxl__ev_time_register_rel(libxl__gif (milliseconds <0 ) { ev->infinite =1 ; }else { - rc =time_rel_to_abs (gc, milliseconds, &abs); + rc =time_rel_to_abs (gc, milliseconds, &absolute);if (rc) goto out; - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; }
@@ -255,26 +255,26 @@ int libxl__ev_time_register_rel(libxl__g }int libxl__ev_time_modify_abs (libxl__gc *gc,libxl__ev_time *ev, -struct timeval abs) +struct timeval absolute) {int rc;CTX_LOCK ;DBG ("ev_time=%p modify abs==%lu.%06lu" , - ev, (unsigned long )abs.tv_sec, (unsigned long )abs.tv_usec); + ev, (unsigned long )absolute.tv_sec, (unsigned long )absolute.tv_usec);assert (libxl__ev_time_isregistered (ev));if (ev->infinite) { - rc =time_register_finite (gc, ev, abs); + rc =time_register_finite (gc, ev, absolute);if (rc) goto out; }else { - rc =OSEVENT_HOOK (timeout_modify, &ev->for_app_reg, abs); + rc =OSEVENT_HOOK (timeout_modify, &ev->for_app_reg, absolute);if (rc) goto out;LIBXL_TAILQ_REMOVE (&CTX ->etimes, ev, entry); - ev->abs = abs; + ev->abs = absolute;time_insert_finite (gc, ev); }
@@ -288,7 +288,7 @@ int libxl__ev_time_modify_abs(libxl__gcint libxl__ev_time_modify_rel (libxl__gc *gc,libxl__ev_time *ev,int milliseconds) { -struct timeval abs; +struct timeval absolute;int rc;CTX_LOCK ;
@@ -304,10 +304,10 @@ int libxl__ev_time_modify_rel(libxl__gc goto out; } - rc =time_rel_to_abs (gc, milliseconds, &abs); + rc =time_rel_to_abs (gc, milliseconds, &absolute);if (rc) goto out; - rc =libxl__ev_time_modify_abs (gc, ev, abs); + rc =libxl__ev_time_modify_abs (gc, ev, absolute);if (rc) goto out; rc =0 ;
tools/libxl/libxl_exec.c +4 -4
@@ -35,7 +35,7 @@ static void check_open_fds(const char *w#ifdef __linux__size_t len;char path[PATH_MAX ]; -char link[PATH_MAX +1 ]; +char linkpath[PATH_MAX +1 ];#endif flags =fcntl (i,F_GETFD );if ( flags ==-1 ) {
@@ -52,11 +52,11 @@ static void check_open_fds(const char *w#ifdef __linux__snprintf (path,PATH_MAX ,"/proc/%d/fd/%d" ,getpid (), i); - len =readlink (path, link,PATH_MAX ); + len =readlink (path, linkpath,PATH_MAX );if (len >0 ) { - link[len] ='\0' ; + linkpath[len] ='\0' ;fprintf (stderr,"libxl: execing %s: fd %d is open to %s with flags %#x\n" , - what, i, link, flags); + what, i, linkpath, flags); } else#endif fprintf(stderr, "libxl: execing %s: fd %d is open with flags %#x\n",
tools/libxl/libxl_json.c +8 -8
@@ -275,7 +275,7 @@ static int json_object_append_to(libxl__void libxl__json_object_free (libxl__gc *gc,libxl__json_object *obj) { -int index =0 ; +int idx =0 ;if (obj ==NULL )return ;
@@ -287,8 +287,8 @@ void libxl__json_object_free(libxl__gc *case JSON_MAP : {libxl__json_map_node *node =NULL ; -for (index =0 ; index < obj->u.map->count; index++) { -if (flexarray_get (obj->u.map, index, (void **)&node) !=0 ) +for (idx =0 ; idx < obj->u.map->count; idx++) { +if (flexarray_get (obj->u.map, idx, (void **)&node) !=0 )break ;libxl__json_object_free (gc, node->obj);free (node->map_key);
@@ -302,8 +302,8 @@ void libxl__json_object_free(libxl__gc *libxl__json_object *node =NULL ;break ; -for (index =0 ; index < obj->u.array->count; index++) { -if (flexarray_get (obj->u.array, index, (void **)&node) !=0 ) +for (idx =0 ; idx < obj->u.array->count; idx++) { +if (flexarray_get (obj->u.array, idx, (void **)&node) !=0 )break ;libxl__json_object_free (gc, node); node =NULL ;
@@ -359,14 +359,14 @@ const libxl__json_object *libxl__json_ma libxl__json_node_type expected_type) {flexarray_t *maps =NULL ; -int index =0 ; +int idx =0 ;if (libxl__json_object_is_map (o)) {libxl__json_map_node *node =NULL ; maps = o->u.map; -for (index =0 ; index < maps->count; index++) { -if (flexarray_get (maps, index, (void **)&node) !=0 ) +for (idx =0 ; idx < maps->count; idx++) { +if (flexarray_get (maps, idx, (void **)&node) !=0 )return NULL ;if (strcmp (key, node->map_key) ==0 ) { if (expected_type == JSON_ANY
tools/libxl/libxl_pci.c +1 -1
@@ -167,7 +167,6 @@ static int libxl__device_pci_remove_xenschar *be_path, *num_devs_path, *num_devs, *xsdev, *tmp, *tmppath;int num, i, j;xs_transaction_t t; -unsigned int domain =0 , bus =0 , dev =0 , func =0 ; be_path =libxl__sprintf (gc,"%s/backend/pci/%d/0" ,libxl__xs_get_dompath (gc,0 ), domid); num_devs_path =libxl__sprintf (gc,"%s/num_devs" , be_path);
@@ -188,6 +187,7 @@ static int libxl__device_pci_remove_xens }for (i =0 ; i < num; i++) { +unsigned int domain =0 , bus =0 , dev =0 , func =0 ; xsdev =libxl__xs_read (gc,XBT_NULL ,libxl__sprintf (gc,"%s/dev-%d" , be_path, i));sscanf (xsdev,PCI_BDF , &domain, &bus, &dev, &func); if (domain == pcidev->domain && bus == pcidev->bus &&
tools/libxl/libxl_qmp.c +4 -4
@@ -171,7 +171,7 @@ static int qmp_register_vnc_callback(lib {GC_INIT (qmp->ctx);const libxl__json_object *obj; -const char *listen, *port; +const char *addr, *port;int rc =-1 ;if (!libxl__json_object_is_map (o)) {
@@ -184,17 +184,17 @@ static int qmp_register_vnc_callback(lib } obj =libxl__json_map_get ("host" , o,JSON_STRING ); - listen =libxl__json_object_get_string (obj); + addr =libxl__json_object_get_string (obj); obj =libxl__json_map_get ("service" , o,JSON_STRING ); port =libxl__json_object_get_string (obj); -if (!listen || !port) { +if (!addr || !port) {LIBXL__LOG (qmp->ctx,LIBXL__LOG_ERROR ,"Failed to retreive VNC connect information." ); goto out; } - rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-listen" , listen); + rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-listen" , addr);if (!rc) rc =qmp_write_domain_console_item (gc, qmp->domid,"vnc-port" , port);
Ian Jackson
Acked-byIan Campbell writes ("Re: [PATCH] libxl: Enable -Wshadow"):
Quoted 8 lines · Ian Jackson
Quoted 2 lines
If we're doing -Wshadow then macros which introduce local variables like this should give them names qualified somehow for the macro.
Done, v2 below.
Since I was touching every line I fixed the line length in those macros too.
:-).
Thanks,
Ian.
Ian Campbell
AppliedQuoted 7 lines · Ian Jackson
Ian Campbell writes ("Re: [PATCH] libxl: Enable -Wshadow"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
If we're doing -Wshadow then macros which introduce local variables like this should give them names qualified somehow for the macro.
Done, v2 below.
Quoted 8 lines
Quoted 2 lines
Since I was touching every line I fixed the line length in those macros too.
:-).
Thanks,
Acked-by Ian Jackson <[email protected]>
Applied, thanks.