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/
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com