On Fri, Jun 22, 2007 at 09:30:40AM -0700, Mark Glines wrote:
> On Fri, 7 Nov 2008 15:28:40 -0700
> chromatic <[EMAIL PROTECTED]> wrote:
> > On Friday 22 June 2007 02:07:32 Nicholas Clark wrote:
> > > I think that you need something like this
> > > /* concatenating with "" ensures that only literal strings are
> > > accepted as argument */ #define STR_WITH_LEN(s) (s ""),
> > > (sizeof(s)-1)
> > >
> > > /* STR_WITH_LEN() shortcuts */
> > > #define newSVpvs(str) Perl_newSVpvn(aTHX_ STR_WITH_LEN(str))
> >
> > I'm not sure that's what I was asking.
> >
> > string_from_cstring()'s third parameter can be either the length of
> > the string or zero. If it's zero, the function will call strlen() to
> > get the string's length.
>
> It uses sizeof, not strlen. So, it pushes the calculation to
> compile-time, so you only have to do it once, and never at runtime.
>
> Also, using sizeof() will fix some cases that strlen() doesn't handle
> correctly, specifically, strings containing explicit null characters.
> src/objects.c has a few examples of that. string_to_cstring(interp,
> "\0", 0) will get the size wrong, but string_to_cstring_literal(interp,
> "\0") will get it right. So I don't really see a good excuse for not
> using it everywhere.
I think you mean "string_from_cstring_literal", not
"string_to_cstring_literal". At least I _hope_ that's
what you mean. :-)
Also, out of curiosity, do we really need "cstring" in the name?
How about simply...?
string_from_literal(interp, "Foo")
(I'm not opposed to leaving 'cstring' in the name if it's important
to somehow make it clear that the literal is a cstring literal, I'm
just asking the question.)
Pm