On 03/11/2014 09:10 PM, Chunyan Liu wrote: >>>> >>> Could be if changing qemu_opt_get return value type, but just as said >>> before, >>> that will affect many codes. >> >> Also, changing an existing function that returns 'const char *' into now >> returning 'char *' will NOT break any callers if the semantics remain >> unchanged (what WILL break is if the semantics change where the callers >> must now free the result) > > > Yes, that's the only change, we need to free the result. There are more > than 200 > places using qemu_opt_get in existing code, we need to checkout the related > files > and free the result one by one.
You can still write your helper function so that if 'del' is true, you strdup, if 'del' is false, you return the in-place memory. You'll have to cast away const in the helper, but qemu_opt_get can then restore the const and you don't have to adjust any existing callers, while still sharing the underlying implementation rather than duplicating code. But I guess I'll wait for v23 to see what you actually do in response to my suggestions. If nothing else, please document design decisions in your commit message (for example, if you choose to duplicate code rather than share code in a common helper, explain that the duplication is because one function returns malloc'd memory while the other returns in-place memory). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature