Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: users

cherokee_buffer_add [please check!]

 

 

Cherokee users RSS feed   Index | Next | Previous | View Threaded


skinkie at xs4all

May 26, 2008, 6:42 PM

Post #1 of 5 (299 views)
Permalink
cherokee_buffer_add [please check!]

I think I cannot sleep if someone doesn't pick this one up.


Could any of the core devs *verify* the correct working of
cherokee_buffer_add

Shouldn't this end up in the same output?

cherokee_buffer_add(buf, "TEST", sizeof("TEST"));
cherokee_buffer_add_str(buf, "TEST");


In the first line, the output gets an extra garbage char.



Stefan (working hard)
_______________________________________________
Cherokee mailing list
Cherokee[at]cherokee-project.com
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee


alvaro at sun

May 26, 2008, 10:27 PM

Post #2 of 5 (276 views)
Permalink
Re: cherokee_buffer_add [please check!] [In reply to]

On 27 May 2008, at 03:42, Stefan de Konink wrote:

> I think I cannot sleep if someone doesn't pick this one up.
>
> Could any of the core devs *verify* the correct working of
> cherokee_buffer_add
>
> Shouldn't this end up in the same output?
>
> cherokee_buffer_add(buf, "TEST", sizeof("TEST"));

I bet you meant strlen() rather than sizeof(). :-)

sizeof() gives you the total amount of memory that a certain static
data or data type requires. In this case it returns 5 because that is
actually the memory that it needed to allocate to copy the string:
"TEST\0".

> cherokee_buffer_add_str(buf, "TEST");

Yeah, this is kind of tricky. By Cherokee's notation, *_str() means
that the method works with an *STATIC* string. Even it they look very
similar there is a quite big difference between static data and
pointers to data:

/* sizeof ("hello world") = 12 */
/* strlen ("hello world") = 11 */

and

char *test = "hello world";
/* sizeof (test) = 4 */
/* strlen (test) = 11 */

.. the joys of C, you know!

> In the first line, the output gets an extra garbage char.

I hope I've got back to you quick enough for you to have some
sleeping :-)

--
Greetings, alo.

_______________________________________________
Cherokee mailing list
Cherokee[at]cherokee-project.com
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee


skinkie at xs4all

May 27, 2008, 2:13 AM

Post #3 of 5 (281 views)
Permalink
Re: cherokee_buffer_add [please check!] [In reply to]

Alvaro Lopez Ortega schreef:
> On 27 May 2008, at 03:42, Stefan de Konink wrote:
>
>> I think I cannot sleep if someone doesn't pick this one up.
>>
>> Could any of the core devs *verify* the correct working of
>> cherokee_buffer_add
>>
>> Shouldn't this end up in the same output?
>>
>> cherokee_buffer_add(buf, "TEST", sizeof("TEST"));
>
> I bet you meant strlen() rather than sizeof(). :-)

No I meant sizeof ;)

> sizeof() gives you the total amount of memory that a certain static data
> or data type requires. In this case it returns 5 because that is
> actually the memory that it needed to allocate to copy the string:
> "TEST\0".
>
>> cherokee_buffer_add_str(buf, "TEST");
>
> Yeah, this is kind of tricky. By Cherokee's notation, *_str() means that
> the method works with an *STATIC* string. Even it they look very similar
> there is a quite big difference between static data and pointers to data:
>
> /* sizeof ("hello world") = 12 */
> /* strlen ("hello world") = 11 */
>
> and
>
> char *test = "hello world";
> /* sizeof (test) = 4 */
> /* strlen (test) = 11 */
>
> .. the joys of C, you know!
>
>> In the first line, the output gets an extra garbage char.
>
> I hope I've got back to you quick enough for you to have some sleeping :-)

:) and I'll continue to work :) Thanks for the explanation.


Stefan
_______________________________________________
Cherokee mailing list
Cherokee[at]cherokee-project.com
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee


adefacc at tin

May 30, 2008, 12:20 PM

Post #4 of 5 (264 views)
Permalink
Re: cherokee_buffer_add [please check!] [In reply to]

Stefan de Konink wrote:
>
> I think I cannot sleep if someone doesn't pick this one up.
>
> Could any of the core devs *verify* the correct working of
> cherokee_buffer_add
>
> Shouldn't this end up in the same output?
>
> cherokee_buffer_add(buf, "TEST", sizeof("TEST"));
> cherokee_buffer_add_str(buf, "TEST");
>
> In the first line, the output gets an extra garbage char.

Yes, as Alvaro has explained in a subsequent reply,
it's the zero terminating char.

Anyway, I think that some of cherokee_buffer_* functions
could have a better name and cherokee_buffer_add_str()
is one of these; I would use:

cherokee_buffer_add_mem()
and
cherokee_buffer_add_cstr()

to better explain the kind of arguments they take
(memory pointer + size and literal constant string).

--
Nick Name: A.D.F.
E-Mail-Format: Plain Text only (please); view using font Courier New
--
_______________________________________________
Cherokee mailing list
Cherokee[at]cherokee-project.com
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee


alvaro at gnu

May 30, 2008, 12:34 PM

Post #5 of 5 (263 views)
Permalink
Re: cherokee_buffer_add [please check!] [In reply to]

On 30 May 2008, at 21:48, A.D.F. wrote:
>
> Anyway, I think that some of cherokee_buffer_* functions
> could have a better name and cherokee_buffer_add_str()
> is one of these; I would use:
>
> cherokee_buffer_add_mem()
> and
> cherokee_buffer_add_cstr()
>
> to better explain the kind of arguments they take
> (memory pointer + size and literal constant string).

That's a good point, actually.

I do agree on renaming cherokee_buffer_add_str() to
cherokee_buffer_add_literal(), cherokee_buffer_add_lit() or something
similar. The 'str' suffix does not describe it properly, that is clear.

--
Greetings, alo.
http://www.alobbs.com/

_______________________________________________
Cherokee mailing list
Cherokee[at]cherokee-project.com
http://cherokee-project.com/cgi-bin/mailman/listinfo/cherokee

Cherokee users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.