On Mon, May 09, 2011 at 05:24:09PM +0800, Lai Jiangshan wrote: > These VIR_XXXX0 APIs make us confused, use the non-0-suffix APIs instead. > > How these coversions works? The magic is using ##. > #define high_levle_api(fmt, ...) low_levle_api(fmt, ##__VA_ARGS__) > When __VA_ARGS__ is empty, "##" will swallow the "," in "fmt," to avoid compile error. > > example: origin after CPP > high_levle_api("%d", a_int) low_levle_api("%d", a_int) > high_levle_api("a string") low_levle_api("a string") > > About 400 conversions. > > 8 special conversions: > VIR_XXXX0("") -> VIR_XXXX(" ") (avoid empty format) 2 conversions > VIR_XXXX0(string_literal_with_%) -> VIR_XXXX(%->%%) 0 conversions > VIR_XXXX0(non_string_literal) -> VIR_XXXX("%s", non_string_literal) (for security) 6 conversions > > Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx> > --- > daemon/libvirtd.c | 76 ++++++++++---------- > daemon/remote.c | 32 ++++---- > daemon/stream.c | 2 +- > examples/domain-events/events-c/event-test.c | 10 +-- > src/cpu/cpu_x86.c | 4 +- > src/esx/esx_driver.c | 8 +- > src/esx/esx_vi.c | 12 ++-- > src/libvirt.c | 4 +- > src/libxl/libxl_driver.c | 18 ++-- > src/lxc/lxc_conf.c | 4 +- > src/lxc/lxc_container.c | 10 +- > src/lxc/lxc_controller.c | 8 +- > src/lxc/lxc_driver.c | 12 ++-- > src/network/bridge_driver.c | 4 +- > src/node_device/node_device_hal.c | 28 ++++---- > src/node_device/node_device_linux_sysfs.c | 2 +- > src/node_device/node_device_udev.c | 8 +- > src/nwfilter/nwfilter_ebiptables_driver.c | 2 +- > src/openvz/openvz_driver.c | 6 +- > src/phyp/phyp_driver.c | 102 +++++++++++++------------- > src/qemu/qemu_audit.c | 30 ++++---- > src/qemu/qemu_capabilities.c | 4 +- > src/qemu/qemu_cgroup.c | 2 +- > src/qemu/qemu_conf.c | 4 +- > src/qemu/qemu_domain.c | 2 +- > src/qemu/qemu_driver.c | 10 +- > src/qemu/qemu_hotplug.c | 22 +++--- > src/qemu/qemu_migration.c | 14 ++-- > src/qemu/qemu_monitor.c | 2 +- > src/qemu/qemu_monitor_json.c | 36 +++++----- > src/qemu/qemu_monitor_text.c | 8 +- > src/qemu/qemu_process.c | 48 ++++++------ > src/remote/remote_driver.c | 64 ++++++++-------- > src/secret/secret_driver.c | 2 +- > src/storage/storage_backend_logical.c | 2 +- > src/test/test_driver.c | 2 +- > src/uml/uml_conf.c | 2 +- > src/uml/uml_driver.c | 14 ++-- > src/util/bridge.c | 10 +- > src/util/cgroup.c | 4 +- > src/util/command.c | 18 ++-- > src/util/event.c | 4 +- > src/util/event_poll.c | 2 +- > src/util/hash.c | 2 +- > src/util/json.c | 8 +- > src/util/logging.c | 10 +- > src/util/logging.h | 24 ++---- > src/util/pci.c | 4 +- > src/util/util.c | 8 +- > src/util/virtaudit.c | 2 +- > src/vbox/vbox_driver.c | 14 ++-- > src/vbox/vbox_tmpl.c | 32 ++++---- > src/vmx/vmx.c | 4 +- > src/xen/xen_driver.c | 28 ++++---- > src/xen/xen_hypervisor.c | 18 ++-- > src/xen/xen_inotify.c | 12 ++-- > src/xen/xend_internal.c | 2 +- > src/xen/xs_internal.c | 12 ++-- > src/xenxs/xen_sxpr.c | 2 +- > 59 files changed, 415 insertions(+), 425 deletions(-) > diff --git a/src/util/logging.h b/src/util/logging.h > index 0dba78c..e948077 100644 > --- a/src/util/logging.h > +++ b/src/util/logging.h > @@ -32,35 +32,27 @@ > */ > # ifdef ENABLE_DEBUG > # define VIR_DEBUG_INT(category, f, l, fmt,...) \ > - virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, fmt, __VA_ARGS__) > + virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, fmt, ##__VA_ARGS__) > # else > # define VIR_DEBUG_INT(category, f, l, fmt,...) \ > do { } while (0) > # endif /* !ENABLE_DEBUG */ > > # define VIR_INFO_INT(category, f, l, fmt,...) \ > - virLogMessage(category, VIR_LOG_INFO, f, l, 0, fmt, __VA_ARGS__) > + virLogMessage(category, VIR_LOG_INFO, f, l, 0, fmt, ##__VA_ARGS__) > # define VIR_WARN_INT(category, f, l, fmt,...) \ > - virLogMessage(category, VIR_LOG_WARN, f, l, 0, fmt, __VA_ARGS__) > + virLogMessage(category, VIR_LOG_WARN, f, l, 0, fmt, ##__VA_ARGS__) > # define VIR_ERROR_INT(category, f, l, fmt,...) \ > - virLogMessage(category, VIR_LOG_ERROR, f, l, 0, fmt, __VA_ARGS__) > + virLogMessage(category, VIR_LOG_ERROR, f, l, 0, fmt, ##__VA_ARGS__) > > # define VIR_DEBUG(fmt,...) \ > - VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__) > -# define VIR_DEBUG0(msg) \ > - VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, "%s", msg) > + VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__) > # define VIR_INFO(fmt,...) \ > - VIR_INFO_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__) > -# define VIR_INFO0(msg) \ > - VIR_INFO_INT("file." __FILE__, __func__, __LINE__, "%s", msg) > + VIR_INFO_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__) > # define VIR_WARN(fmt,...) \ > - VIR_WARN_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__) > -# define VIR_WARN0(msg) \ > - VIR_WARN_INT("file." __FILE__, __func__, __LINE__, "%s", msg) > + VIR_WARN_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__) > # define VIR_ERROR(fmt,...) \ > - VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__) > -# define VIR_ERROR0(msg) \ > - VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, "%s", msg) > + VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__) ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list