[libvirt] [PATCH v1 01/14] conf: Fix virDomainDeviceGetInfo const correctness

Michal Privoznik posted 14 patches 8 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCH v1 01/14] conf: Fix virDomainDeviceGetInfo const correctness
Posted by Michal Privoznik 8 years, 3 months ago
This function is not changing passed domain definition.
Therefore, mark the argument as 'const'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c | 2 +-
 src/conf/domain_conf.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 25d48f977..31684df54 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3501,7 +3501,7 @@ int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
 }
 
 virDomainDeviceInfoPtr
-virDomainDeviceGetInfo(virDomainDeviceDefPtr device)
+virDomainDeviceGetInfo(const virDomainDeviceDef *device)
 {
     switch ((virDomainDeviceType) device->type) {
     case VIR_DOMAIN_DEVICE_DISK:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a42efcfa6..1e007346f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2756,7 +2756,7 @@ virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
                                              virDomainXMLOptionPtr xmlopt);
 int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
                                   int type);
-virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device);
+virDomainDeviceInfoPtr virDomainDeviceGetInfo(const virDomainDeviceDef *device);
 void virDomainTPMDefFree(virDomainTPMDefPtr def);
 
 typedef int (*virDomainDeviceInfoCallback)(virDomainDefPtr def,
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 01/14] conf: Fix virDomainDeviceGetInfo const correctness
Posted by Martin Kletzander 8 years, 3 months ago
On Thu, Oct 19, 2017 at 10:10:56AM +0200, Michal Privoznik wrote:
>This function is not changing passed domain definition.
>Therefore, mark the argument as 'const'.
>

Is there any other reason for this then just your new code using const?
I don't see any pointer that's passed through your later code that would
be const nowadays, so why would we play the const-correctness game here
when it doesn't make much sense in C when the pointer is to a struct
since the const doesn't propagate?

If s/const virDomainDeviceDef/virDomainDeviceDef/ on your later patch
makes this one unnecessary, then NACK to this.  If there is a reason,
however, feel free to keep this in.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 01/14] conf: Fix virDomainDeviceGetInfo const correctness
Posted by Michal Privoznik 8 years, 3 months ago
On 10/19/2017 11:55 AM, Martin Kletzander wrote:
> On Thu, Oct 19, 2017 at 10:10:56AM +0200, Michal Privoznik wrote:
>> This function is not changing passed domain definition.
>> Therefore, mark the argument as 'const'.
>>
> 
> Is there any other reason for this then just your new code using const?
> I don't see any pointer that's passed through your later code that would
> be const nowadays, so why would we play the const-correctness game here
> when it doesn't make much sense in C when the pointer is to a struct
> since the const doesn't propagate?
> 
> If s/const virDomainDeviceDef/virDomainDeviceDef/ on your later patch
> makes this one unnecessary, then NACK to this.  If there is a reason,
> however, feel free to keep this in.

Well, later in 08/14 I am indeed calling this from function which takes
const virDomainDeviceDef * and I can change it to virDomainDeviceDefPtr.
And while I think this patch still makes things better (solves const
correctness), I don't want it to be show stopper. Thus I'm dropping it.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list