On 22. 07. 21 15:03, Ethan Furman wrote:
On 7/22/21 1:01 AM, Petr Viktorin wrote:
 > On 21. 07. 21 14:18, Nick Coghlan wrote:

 >> ====================
 >> typedef enum {
 >>      PyLocals_UNDEFINED = -1;
 >>      PyLocals_DIRECT_REFERENCE = 0,
 >>      PyLocals_SHALLOW_COPY = 1
 >> } PyLocals_Kind;
 >>
 >> PyLocals_Kind PyLocals_GetKind(void);
 >> PyLocals_Kind PyFrame_GetLocalsKind(PyFrameObject *);
 >> ====================
 >
> Please don't put the enum in the stable ABI. If we would add another value and then
 > an older extension would receive it, we'd get undefined behavior.

Probably a stupid question, but wouldn't the same thing happen if we didn't use an enum, added another option later, and on older extension received that newer value?

No.
Consider code like:
if (PyLocals_GetKind() == PyLocals_DIRECT_REFERENCE) {
 ...
}
where PyLocals_GetKind() is defined as above, but returns 4.

Technically it's undefined behavior, so the compiler could decide to wipe your disk or eat your pets in this case, but that's not very realistic. More realistically, the compiler is free to only look at the last two bits of the value, so 4 will be equivalent to 0, and the comparison will be true. There are definitely architestures/compilers that do tricks similar to that.

But if PyLocals_GetKind() returns an int, 4 != 0 isn't a problem.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/HFH5MG3LXYEI4YPO3MTDVXTVO7XCUXEA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to