[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH v4 21/28] qstring: Add qstring_wrap
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH v4 21/28] qstring: Add qstring_wrap_str() |
Date: |
Thu, 9 Jun 2016 10:31:42 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 06/02/2016 09:21 AM, Markus Armbruster wrote:
> Eric Blake <address@hidden> 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 <address@hidden>
>>
>> +++ 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
signature.asc
Description: OpenPGP digital signature