Skip to content
Draft
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
3 changes: 3 additions & 0 deletions Doc/data/stable_abi.dat

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

9 changes: 8 additions & 1 deletion Include/boolobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ extern "C" {

// PyBool_Type is declared by object.h

#define PyBool_Check(x) Py_IS_TYPE((x), &PyBool_Type)
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 16)
PyAPI_FUNC(int) PyBool_Check(PyObject *x);
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 16)
# define PyBool_Check(x) Py_IS_TYPE((x), &PyBool_Type)
#else
# define PyBool_Check(x) PyBool_Check(_PyObject_CAST(x))
#endif

/* Py_False and Py_True are the only two bools in existence. */

Expand Down
13 changes: 11 additions & 2 deletions Include/bytesobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ functions should be applied to NULL pointer.
PyAPI_DATA(PyTypeObject) PyBytes_Type;
PyAPI_DATA(PyTypeObject) PyBytesIter_Type;

#define PyBytes_Check(op) \
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 16)
PyAPI_FUNC(int) PyBytes_Check(PyObject *op);
PyAPI_FUNC(int) PyBytes_CheckExact(PyObject *op);
#endif
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 16)
# define PyBytes_Check(op) \
PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
#define PyBytes_CheckExact(op) Py_IS_TYPE((op), &PyBytes_Type)
# define PyBytes_CheckExact(op) Py_IS_TYPE((op), &PyBytes_Type)
#else
# define PyBytes_Check(op) PyBytes_Check(_PyObject_CAST(op))
# define PyBytes_CheckExact(op) PyBytes_CheckExact(_PyObject_CAST(op))
#endif

PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
Expand Down
3 changes: 3 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In the Limited C API 3.16 and newer, :c:func:`PyBool_Check` is now available
as a function instead of a macro.

In the Limited C API 3.16 and newer, :c:func:`PyBytes_Check` and
:c:func:`PyBytes_CheckExact` are now available as functions instead of macros.
9 changes: 9 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2831,3 +2831,12 @@

[function.PyObject_CallFinalizerFromDealloc]
added = '3.15'

[function.PyBool_Check]
added = '3.16'

[function.PyBytes_Check]
added = '3.16'

[function.PyBytes_CheckExact]
added = '3.16'
5 changes: 5 additions & 0 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ struct _longobject _Py_TrueStruct = {
{ 1 }
}
};

// Implementations for the Stable ABI

#undef PyBool_Check
int PyBool_Check(PyObject *x) { return Py_IS_TYPE(x, &PyBool_Type); }
9 changes: 9 additions & 0 deletions Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3915,3 +3915,12 @@ PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...)
Py_ssize_t size = buf - byteswriter_data(writer);
return PyBytesWriter_Resize(writer, size);
}


// Implementations for the Stable ABI

#undef PyBytes_Check
int PyBytes_Check(PyObject *op) { return PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS); }

#undef PyBytes_CheckExact
int PyBytes_CheckExact(PyObject *op) { return Py_IS_TYPE(op, &PyBytes_Type); }
3 changes: 3 additions & 0 deletions PC/python3dll.c

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

Loading