After mentioning "avoid global variables" as a potential
addition to HACKING, I did some quick tests and spotted
a few that are easy to eliminate. This is useful even
if we don't end up automating the check:
Clean up the global name space.
* src/qemu_conf.c: Add "static" and "const" attributes to some
globals.
* src/qemu_conf.h: Update a declaration.
* src/qemu_driver.c (qemud_driver): Declare static.
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 15779b7..d03d989 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -231,35 +231,35 @@ void qemudFreeVM(struct qemud_vm *vm) {
/* The list of possible machine types for various architectures,
as supported by QEMU - taken from 'qemu -M ?' for each arch */
-static const char *arch_info_x86_machines[] = {
+static const char *const arch_info_x86_machines[] = {
"pc", "isapc", NULL
};
-static const char *arch_info_mips_machines[] = {
+static const char *const arch_info_mips_machines[] = {
"mips", NULL
};
-static const char *arch_info_sparc_machines[] = {
+static const char *const arch_info_sparc_machines[] = {
"sun4m", NULL
};
-static const char *arch_info_ppc_machines[] = {
+static const char *const arch_info_ppc_machines[] = {
"g3bw", "mac99", "prep", NULL
};
/* Feature flags for the architecture info */
-struct qemu_feature_flags arch_info_i686_flags [] = {
+static const struct qemu_feature_flags const arch_info_i686_flags [] = {
{ "pae", 1, 1 },
{ "acpi", 1, 1 },
{ "apic", 1, 0 },
{ NULL, -1, -1 }
};
-struct qemu_feature_flags arch_info_x86_64_flags [] = {
+static const struct qemu_feature_flags const arch_info_x86_64_flags [] = {
{ "acpi", 1, 1 },
{ "apic", 1, 0 },
{ NULL, -1, -1 }
};
/* The archicture tables for supported QEMU archs */
-struct qemu_arch_info qemudArchs[] = {
+const struct qemu_arch_info const qemudArchs[] = {
/* i686 must be in position 0 */
{ "i686", 32, arch_info_x86_machines, "qemu",
arch_info_i686_flags },
/* x86_64 must be in position 1 */
diff --git a/src/qemu_conf.h b/src/qemu_conf.h
index 69342cb..e2c7514 100644
--- a/src/qemu_conf.h
+++ b/src/qemu_conf.h
@@ -426,11 +426,11 @@ struct qemu_feature_flags {
struct qemu_arch_info {
const char *arch;
int wordsize;
- const char **machines;
+ const char *const *machines;
const char *binary;
const struct qemu_feature_flags *fflags;
};
-extern struct qemu_arch_info qemudArchs[];
+extern const struct qemu_arch_info const qemudArchs[];
#endif /* WITH_QEMU */
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index c96fb45..dee6ba6 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -107,7 +107,7 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn,
struct qemud_driver *driver,
struct qemud_network *network);
-struct qemud_driver *qemu_driver = NULL;
+static struct qemud_driver *qemu_driver = NULL;
static
--
1.5.4.rc1.11.gd2f82
Show replies by date
Jim Meyering wrote:
After mentioning "avoid global variables" as a potential
addition to HACKING, I did some quick tests and spotted
a few that are easy to eliminate. This is useful even
if we don't end up automating the check:
Clean up the global name space.
* src/qemu_conf.c: Add "static" and "const" attributes to some
globals.
* src/qemu_conf.h: Update a declaration.
* src/qemu_driver.c (qemud_driver): Declare static.
+1.
These structures were originally shared between files, but lots of code
refactoring since seems to make that obsolete.
Rich.
--
Emerging Technologies, Red Hat -
http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
On Mon, Jan 14, 2008 at 12:33:56PM +0000, Richard W.M. Jones wrote:
Jim Meyering wrote:
>After mentioning "avoid global variables" as a potential
>addition to HACKING, I did some quick tests and spotted
>a few that are easy to eliminate. This is useful even
>if we don't end up automating the check:
>
> Clean up the global name space.
> * src/qemu_conf.c: Add "static" and "const" attributes to some
> globals.
> * src/qemu_conf.h: Update a declaration.
> * src/qemu_driver.c (qemud_driver): Declare static.
+1.
These structures were originally shared between files, but lots of code
refactoring since seems to make that obsolete.
ACK
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules:
http://search.cpan.org/~danberr/ -=|
|=- Projects:
http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|