[Libvirt-cim] [PATCH] [CU][RFC] Correct a few API issues

Jay Gagnon grendel at linux.vnet.ibm.com
Tue Nov 27 21:27:10 UTC 2007


Dan Smith wrote:
> # HG changeset patch
> # User Dan Smith <danms at us.ibm.com>
> # Date 1196194806 28800
> # Node ID 256b237ba19f9e178719ed657f2b9a8f0d44d433
> # Parent  64e4f6355b52e4b7bcc984ec557610a1fa9a9786
> [CU][RFC] Correct a few API issues
> that I think need to be resolved before we snap a release.
>
> Some of the cu_get_* functions returned values instead of a CMPIrc's
> like everything else, so this changes that.  Also, return const char *'s
> from the broker memory so that the callers don't need to free the result.
>
> This will require some work in libvirt-cim to make sure the new API is
> adhered to properly.  If this is okay with people, I'll follow up with a
> patch to libvirt-cim to make those changes.  Any other discussion about
> things that should change in the libcmpiutil API is welcomed.
>
> Changes from last time:
>  - Fix cu_get_str_prop() to return a const broker string as well
>
> Patch set to make associated changes to libvirt-cim to follow...
>
> Signed-off-by: Dan Smith <danms at us.ibm.com>
>
>
>
>  CMPIrc cu_get_str_prop(const CMPIInstance *inst,
>                         const char *prop,
> -                       char **target)
> +                       const char **target)
>  {
>          CMPIData value;
>          CMPIStatus s;
> @@ -198,8 +211,7 @@ CMPIrc cu_get_str_prop(const CMPIInstanc
>          if ((prop_val = CMGetCharPtr(value.value.string)) == NULL)
>                  return CMPI_RC_ERROR;
>
> -        if ((*target = strdup(prop_val)) == NULL)
> -                return CMPI_RC_ERROR;
> +        *target = prop_val;
>
>          return CMPI_RC_OK;
>  }
The "callers don't need to free the result" part was not immediately
obvious to me so I want to make sure I understand it.  My guess is that
adding the const makes it so that callers can't modify the resulting
string, which means that we can just hand them all pointers to the same
string, so there is no need to strdup, so they don't have to free?  Is
that close?

-- 

-Jay




More information about the Libvirt-cim mailing list