Skip to content

bpo-47168: List feature macros in the stable ABI manifest, improve tests #32415

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

Merged
merged 9 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Misc/stable_abi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# value may change.
# - typedef: A C typedef which is used in other definitions in the limited API.
# Its size/layout/signature must not change.
# - ifdef: A feature macro: other items may be conditional on whether the macro
# is defined or not.

# Each top-level item can have details defined below it:
# - added: The version in which the item was added to the stable ABI.
Expand All @@ -41,6 +43,10 @@
# of the stable ABI.
# - a combination of the above (functions that were called by macros that
# were public in the past)
# - doc: for `ifdef`, the blurb added in documentation
# - windows: for `ifdef`, this macro is defined on Windows. (This info is used
# to generate the DLL manifest and needs to be available on all platforms.)
# `maybe` marks macros defined on some but not all Windows builds.

# For structs, one of the following must be set:
# - opaque: The struct name is available in the Limited API, but its members
Expand All @@ -59,6 +65,24 @@
# https://docs.python.org/3/c-api/stable.html#stable


# Feature macros for optional functionality:

ifdef MS_WINDOWS
doc on Windows
windows
ifdef HAVE_FORK
doc on platforms with fork()
ifdef USE_STACKCHECK
doc on platforms with USE_STACKCHECK
windows maybe
ifdef PY_HAVE_THREAD_NATIVE_ID
doc on platforms with native thread IDs
windows
ifdef Py_REF_DEBUG
doc when Python is compiled in debug mode (with Py_REF_DEBUG)
windows maybe


# Mentioned in PEP 384:

struct PyObject
Expand Down
49 changes: 49 additions & 0 deletions Modules/_testcapi_feature_macros.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Generated by Tools/scripts/stable_abi.py

// Add an entry in dict `result` for each Stable ABI feature macro.

#ifdef HAVE_FORK
res = PyDict_SetItemString(result, "HAVE_FORK", Py_True);
#else
res = PyDict_SetItemString(result, "HAVE_FORK", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

#ifdef MS_WINDOWS
res = PyDict_SetItemString(result, "MS_WINDOWS", Py_True);
#else
res = PyDict_SetItemString(result, "MS_WINDOWS", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

#ifdef PY_HAVE_THREAD_NATIVE_ID
res = PyDict_SetItemString(result, "PY_HAVE_THREAD_NATIVE_ID", Py_True);
#else
res = PyDict_SetItemString(result, "PY_HAVE_THREAD_NATIVE_ID", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

#ifdef Py_REF_DEBUG
res = PyDict_SetItemString(result, "Py_REF_DEBUG", Py_True);
#else
res = PyDict_SetItemString(result, "Py_REF_DEBUG", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

#ifdef USE_STACKCHECK
res = PyDict_SetItemString(result, "USE_STACKCHECK", Py_True);
#else
res = PyDict_SetItemString(result, "USE_STACKCHECK", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

13 changes: 13 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5919,6 +5919,18 @@ frame_getlasti(PyObject *self, PyObject *frame)
return PyLong_FromLong(lasti);
}

static PyObject *
get_feature_macros(PyObject *self, PyObject *Py_UNUSED(args))
{
PyObject *result = PyDict_New();
if (!result) {
return NULL;
}
int res;
#include "_testcapi_feature_macros.inc"
return result;
}


static PyObject *negative_dictoffset(PyObject *, PyObject *);
static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *);
Expand Down Expand Up @@ -6214,6 +6226,7 @@ static PyMethodDef TestMethods[] = {
{"frame_getgenerator", frame_getgenerator, METH_O, NULL},
{"frame_getbuiltins", frame_getbuiltins, METH_O, NULL},
{"frame_getlasti", frame_getlasti, METH_O, NULL},
{"get_feature_macros", get_feature_macros, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};

Expand Down
2 changes: 2 additions & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading