On 02/01/2013 03:50 PM, Clint Adams wrote:
> That is a good idea, but it won't solve the UTF-8 problem, since
> json_string() will happily accept invalid UTF-8.

really?  that sounds like a bug in either the library or its documentation:

  file:///usr/share/doc/libjansson-doc/html/apiref.html#string

says:

>> json_t *json_string(const char *value)
>>     Return value: New reference.
>> 
>>     Returns a new JSON string, or NULL on error. value must be a valid
>>     UTF-8 encoded Unicode string.


-----------

>  This means
> libmsv will need to either punt to the caller like jansson does,
> or perform validation through iconv or something else.

blech, that sounds ugly.

>> And of course, remember to deallocate the objects whatever objects were
>> allocated once the HTTP POST has returned.  I confess i don't really
>> grok libjansson's memory management model with all this "borrowed
>> reference" stuff as well as i'd like, though.
> 
> Presumably judicious use of json_decref will make the garbage
> collection work like magic.

yep, but if you json_decref before returning a char* pointing to a
string response, you'd be returning deallocated data -- definitely not a
safe thing.  so either you ask the caller to provide a buffer for you to
write string responses in, or you don't deallocate the response buffer
and indicate to the caller how they're now responsible for disposing of it.

the joys of passing strings in C!

        --dkg


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to