Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-91744: Add semi-stable C API tier #91789

Closed
wants to merge 14 commits into from
Closed

Conversation

encukou
Copy link
Member

@encukou encukou commented Apr 21, 2022

This adds the semi-stable API tier witth a few initial functions/types. Adding more is left to another PR.

@encukou encukou marked this pull request as draft April 21, 2022 16:07
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is PyInterpreterState_SetEvalFrameFunc() really usable in the semi-stable API? The second parameter type comes from the internal C API. There is nothing to inspect a _PyInterpreterFrame structure in the semi-stable API.

I don't know how debuggers use PyInterpreterState_SetEvalFrameFunc().

cc @markshannon

@vstinner
Copy link
Member

See also #91788

@vstinner
Copy link
Member

See also #91906

Copy link

@h-vetinari h-vetinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments from taking a look out of curiosity

Include/README.rst Outdated Show resolved Hide resolved
Doc/whatsnew/3.11.rst Outdated Show resolved Hide resolved
Comment on lines 21 to 27
There are two tiers of API with different stability exepectations,
enabled by specific macros:

- :c:macro:`Py_USING_SEMI_STABLE_API` exposes API that may change
without deprecation warnings.
- :c:macro:`Py_LIMITED_API` exposes API that is compatible across
several minor releases.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exepectations -> expectations

One could also say: "there are two public tiers of the API" (emphasis just to show addition); underscored resp. Py_BUILD_CORE are arguably a tier as well...?

I've struck out the "two" because I think it would be clearer to expose the full hierarchy, à la:

Suggested change
There are two tiers of API with different stability exepectations,
enabled by specific macros:
- :c:macro:`Py_USING_SEMI_STABLE_API` exposes API that may change
without deprecation warnings.
- :c:macro:`Py_LIMITED_API` exposes API that is compatible across
several minor releases.
There are three public tiers of the API with different stability
expectations, two of which need to be enabled by specific macros:
- :c:macro:`Py_LIMITED_API` exposes API that is compatible across
several minor releases.
- (no macro): default C-API covered by :pep:`387`.
- :c:macro:`Py_USING_SEMI_STABLE_API` exposes API that may change
without deprecation warnings between minor releases.

I'd also suggest to lead with the most stable one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By “There are two tiers of API with different stability expectations” I wanted to present them as being additional, different from the default that's covered in the preceding paragraphs.
The order matches the detailed sections below, which would be somewhat tricky to reorder -- the one-paragraph semi-stable tier would feel lost if it was at the end.

Doc/c-api/stable.rst Outdated Show resolved Hide resolved
Doc/c-api/code.rst Outdated Show resolved Hide resolved
use :c:func:`PyCode_NewEmpty` instead.

Since the definition of the bytecode changes often, calling
:c:func:`PyCode_New` directly can bind you to a precise Python version.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: better "can directly" than "directly can" (or directly at the very end)

Copy link
Member Author

@encukou encukou Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not “can directly bind you”, but “calling :c:func:PyCode_New directly” (as opposed to PyCode_Replace for example)

@@ -0,0 +1,10 @@
Defining :c:macro:`Py_USING_SEMI_STABLE_API` will expose "semi-stable API",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth considering to stay consistent with the spelling of "semi-stable" / "semistable". Currently the include folders are named like the latter (which I think looks good in a path), mentions in the docs like here often have the hyphen.

Even though the hyphen is grammatically slightly more correct, my personal preference would be without.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which also opens the question if the macro should be Py_USING_SEMI_STABLE_API or Py_USING_SEMISTABLE_API

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have hope that someone will come up with a better name. Python-dev is usually so good at bikeshedding!
I'll postpone renaming for now.

@encukou
Copy link
Member Author

encukou commented Apr 28, 2022

Thank you for the comments!

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected the API and macro to mention "unstable" rather than "semi-stable" (Py_USING_SEMI_STABLE_API => Py_USING_UNSTABLE_API).

PyObject *, PyObject *, PyObject *, int, PyObject *,
PyObject *);
/* same as struct above */
/* See Include/semi-stable/code.h for PyCode_New* */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this comment is useful.

Suggested change
/* See Include/semi-stable/code.h for PyCode_New* */
/* See Include/unstable/code.h for PyCode_New* */

@@ -61,6 +61,10 @@
# define Py_BUILD_CORE
#endif

// Expose unstable API when building Python
#ifdef Py_BUILD_CORE
#define Py_USING_UNSTABLE_API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define Py_USING_UNSTABLE_API
# define Py_USING_UNSTABLE_API

Comment on lines +381 to +385
#ifdef Py_USING_UNSTABLE_API
#define _Py_NEWLY_UNSTABLE(VERSION_UNUSED)
#else
#define _Py_NEWLY_UNSTABLE(VERSION) Py_DEPRECATED(VERSION)
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef Py_USING_UNSTABLE_API
#define _Py_NEWLY_UNSTABLE(VERSION_UNUSED)
#else
#define _Py_NEWLY_UNSTABLE(VERSION) Py_DEPRECATED(VERSION)
#endif
#ifdef Py_USING_UNSTABLE_API
# define _Py_NEWLY_UNSTABLE(VERSION_UNUSED)
#else
# define _Py_NEWLY_UNSTABLE(VERSION) Py_DEPRECATED(VERSION)
#endif

PyObject *, PyObject *, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, int, PyObject *,
PyObject *);
/* same as struct PyCodeObject */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to move the comment before the function definition: "same parameters as PyCodeObject structure members".


/* Frame evaluation API (added for PEP-523) */

struct _PyInterpreterFrame;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?


- :c:macro:`Py_USING_SEMI_STABLE_API` exposes API that may change
without deprecation warnings.
- :c:macro:`Py_LIMITED_API` limits exposed API to API that is compatible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is API repeated on purpose?

Suggested change
- :c:macro:`Py_LIMITED_API` limits exposed API to API that is compatible
- :c:macro:`Py_LIMITED_API` limits exposed API that is compatible

@@ -219,6 +201,11 @@ typedef enum _PyCodeLocationInfoKind {
PY_CODE_LOCATION_INFO_NONE = 15
} _PyCodeLocationInfoKind;

#define Py_UNSTABLE_CODE_H
#include "unstable/code.h"
#undef Py_UNSTABLE_CODE_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to include it in top-level Include/code.h, as done in Include/pystate.h.

- :c:func:`PyInterpreterState_GetEvalFrameFunc`
- :c:func:`PyInterpreterState_SetEvalFrameFunc`
- :c:type:`PyFrameEvalFunction`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention also _PyFrameEvalFunction type which is renamed?

@encukou
Copy link
Member Author

encukou commented Aug 10, 2022

I'm deferring the PEP. Thanks for the comments, I'll take them into account next time I try.

@encukou encukou closed this Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants