qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Ivanov <iv...@isle.spb.ru>
Subject Re: pn_data_put_string question
Date Wed, 18 Feb 2015 14:14:29 GMT
Ok so then the following code:

   const char  *op;
   pn_data_put_string(content, pn_bytes(strlen(op), op));

Gives me an error:

   error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
      pn_data_put_string(content, pn_bytes(strlen(op), op));

If I use pn_bytes_dup instead, an error goes away, but I'm afraid this will
result in memory leak.

If put_string does not save the pn_bytes_t::start pointer internally but
rather makes a copy I guess it should be safe to force the const_cast<char *>
for pn_bytes_t::start?

Best regards,
18.02.2015 16:20, Rafael Schloming пишет:
> I just pushed a quick update of the docs that will hopefully make this
> clear, but pn_data_get_string (and similar) copies the bytes passed to it
> into an internal area inside the pn_data_t. The converse,
> pn_data_get_string(...) returns a pointer to the internal bytes, so those
> need to be copied if you are going to clear or free the pn_data_t.
> 
> --Rafael
> 
> On Wed, Feb 18, 2015 at 4:35 AM, Michael Ivanov <ivans@logit-ag.de> wrote:
> 
>> Greetings!
>>
>> I need to confirm a point about pn_data_put_string usage. Second argument
>> is
>> pn_bytes_t which contains pointer to text buffer and actual length of the
>> string
>> in bytes. When this value is assigned to data node does it mean that the
>> ownership
>> of the string buffer is transfered to data object? Will pn_data_clear (or
>> pn_data_free)
>> try to free such buffers? Or is it assumed that the string memory will be
>> managed
>> outside of pn_data_t?
>>
>> Best regards,
>> --
>>  \   / |                                   |
>>  (OvO) |  Mikhail Iwanow                   |
>>  (^^^) |      Voice:   +7 (911) 223-1300   |
>>   \^/  |      E-mail:  ivans@logit-ag.de   |
>>   ^ ^  |                                   |
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>
> 


-- 
 \   / |			           |
 (OvO) |  Михаил Иванов                    |
 (^^^) |      Тел.:    +7(911) 223-1300    |
  \^/  |      E-mail:  ivans@isle.spb.ru   |
  ^ ^  |                                   |

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Mime
View raw message