[Python-3000] Lazy strings (was Re: Py3k release schedule worries)

Larry Hastings larry at hastings.org
Fri Jan 12 23:17:43 CET 2007


Guido van Rossum wrote:
> I like having a function (not macro) that returns pointer and length 
> through output variables.
I proposed a macro because I planned some cheap inlining.  Casts and 
parentheses omitted for *cough* clarity:
    #define PyUnicode_VALUE(self, p, len) ((self->str != NULL) ? (p = 
self->str, len = self->length, 1) : PyUnicode_ComputeValue(self, &p, &len))

> I don't like having a separate 'success' return value; in that case, 
> you could just set p to NULL and len to -1. Or if you like shortcuts, 
> you could make p the return value and len an output parameter, or vice 
> versa.
>
> Experiment, see what results in the cleanest code in typical usage.
Ah, but you see, I think this looks cleanest:

    if (!PyUnicode_VALUE(self, p, len))
        /* failure, p and len are unchanged */
        return;
    /* success, p and len are now valid, continue processing */

But I suspected you might prefer something else, which is why I asked.

Lacking more concrete guidance, I'll do it that way and let you tell me 
to change it.  :)

Cheers,


/larry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070112/0ff231c4/attachment.htm 


More information about the Python-3000 mailing list