On Thu, 22 Jul 2021, 6:01 pm Petr Viktorin, <encu...@gmail.com> wrote:

>
>
> On 21. 07. 21 14:18, Nick Coghlan wrote:
> > On Mon, 19 Jul 2021 at 21:32, Petr Viktorin <encu...@gmail.com> wrote:
> >> The proposal assumes that in the future, ``PyLocals_Get``, and thus
> >> ``locals()``, will never gain another kind of return value, however
> >> unlikely that is.
> >> AFAICS, code that uses this will usually check for a single special case
> >> and fall back (or error) for the other(s), so I think it'd be reasonable
> >> to make this an "enum" with two values. e.g.:
> >>
> >> int PyLocals_GetReturnBehavior();  # better name?
> >> #define PyLocals_DIRECT_REFERENCE 0
> >> #define PyLocals_SHALLOW_COPY 1
> >
> > After looking at PyUnicode_Kind, PySendResult, and other already
> > public enums for inspiration, my proposed spelling is as follows:
> >
> > ====================
> > 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 *);
> > ====================
> >
> > The PyLocals_UNDEFINED case comes from PyLocals_GetKind() needing an
> > error value to return when the query API is called with no active
> > thread state.
> >
> > I've updated the draft reference implementation to use this API, and
> > added the associated PEP changes to the review PR at
> > https://github.com/python/peps/pull/2038/files
>
> 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.
>

Hmm, I was copying an example that is already in the stable ABI
(PySendResult).

I think it's new in 3.10, though, so it should still be possible to fix
that.

Cheers,
Nick.

>
_______________________________________________
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/IEZADZNWFHVDIYVWTITW7ZSS27NIQDSB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to