[Python-Dev] PEP 393 Summer of Code Project

Stefan Behnel stefan_ml at behnel.de
Wed Aug 24 08:57:54 CEST 2011


Torsten Becker, 24.08.2011 04:41:
> Also, common, now simple, checks for "unicode->str == NULL" would look
> more ambiguous with a union ("unicode->str.latin1 == NULL").

You could just add yet another field "any", i.e.

     union {
        unsigned char* latin1;
        Py_UCS2* ucs2;
        Py_UCS4* ucs4;
        void* any;
     } str;

That way, the above test becomes

     if (!unicode->str.any)

or

     if (unicode->str.any == NULL)

Or maybe even call it "initialised" to match the intended purpose:

     if (!unicode->str.initialised)

That being said, I don't mind "unicode->str.latin1 == NULL" either, given 
that it will (as mentioned by others) be hidden behind a macro most of the 
time anyway.

Stefan



More information about the Python-Dev mailing list