On 06/02/2016 09:21 AM, Markus Armbruster wrote:
> Eric Blake <[email protected]> writes:
> 
>> Several spots in the code malloc a string, then wrap it in a
>> QString, which has to duplicate the input.  Adding a new
>> constructor with transfer semantics makes this pattern more
>> efficient, comparable to the just-added transfer semantics to
>> go from QString back to raw string.  Use the new
>> qstring_wrap_str() where it makes sense.
>>
>> The new test still passes under valgrind.
>>
>> Signed-off-by: Eric Blake <[email protected]>
>>

>> +++ b/qobject/qstring.c
>> @@ -66,6 +66,31 @@ QString *qstring_from_str(const char *str)
>>      return qstring_from_substr(str, 0, strlen(str) - 1);
>>  }
>>
>> +/**
>> + * qstring_wrap_str(): Create a new QString around a malloc'd C string
>> + *
>> + * Returns a strong reference, and caller must not use @str any more.
>> + * @str may be NULL, in which case the QString will be "".
> 
> I'm not fond of conflating null pointers and "" (see also the trouble
> with visit_type_str()).  For what it's worth, qstring_from_str(NULL)
> crashes.  Can we reject null?

Probably. I'll add an assert, and update the interface to match if
things still pass with my usage.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to