[libvirt] [PATCH 01/15] maint: avoid 'const fooPtr' in public API

Eric Blake eblake at redhat.com
Tue Oct 8 17:24:58 UTC 2013


'const fooPtr' is the same as 'foo * const' (the pointer won't
change, but it's contents can).  But in general, if an interface
is trying to be const-correct, it should be using 'const foo *'
(the pointer is to data that can't be changed).

Fix up offenders in the public API.  Note that this is an API change;
but see commit 6ac6f59, where we first argued that this change is
harmless (but with that commit not actually making the change that it
claimed to be making):

    Although this is an API change (not ABI though), real callers won't be
    impacted. Why?
     1. these callback members are read-only, so it is less likely that
    someone is trying to assign into the struct members.
     2. The only way to register a virConnectDomainEventGraphicsCallback is
    to cast it through a call to virConnectDomainEventRegisterAny.  That is,
    even if the user's callback function leaves out the const, we never use
    the typedef as the direct type of any API parameter.  Since they are
    already casting their function pointer into a munged type before
    registering it, their code will continue to compile.

* include/libvirt/libvirt.h.in
(virConnectDomainEventGraphicsCallback): Use intended type.
---
 include/libvirt/libvirt.h.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 83c219e..0a1911c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -4691,10 +4691,10 @@ typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
 typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
                                                       virDomainPtr dom,
                                                       int phase,
-                                                      const virDomainEventGraphicsAddressPtr local,
-                                                      const virDomainEventGraphicsAddressPtr remote,
+                                                      const virDomainEventGraphicsAddress *local,
+                                                      const virDomainEventGraphicsAddress *remote,
                                                       const char *authScheme,
-                                                      const virDomainEventGraphicsSubjectPtr subject,
+                                                      const virDomainEventGraphicsSubject *subject,
                                                       void *opaque);

 /**
-- 
1.8.3.1




More information about the libvir-list mailing list