``n`` (:class:`int`) [:c:type:`Py_ssize_t`]
Convert a C :c:type:`Py_ssize_t` to a Python integer.
+ ``p`` (:class:`bool`) [int]
+ Convert a C :c:expr:`int` to a Python :class:`bool` object.
+ .. versionadded:: 3.14
+
``c`` (:class:`bytes` of length 1) [char]
Convert a C :c:expr:`int` representing a byte to a Python :class:`bytes` object of
length 1.
and get an attribute of the module.
(Contributed by Victor Stinner in :gh:`128911`.)
+* Add support for a new ``p`` format unit in :c:func:`Py_BuildValue` that allows to
+ take a C integer and produce a Python :class:`bool` object. (Contributed by
+ Pablo Galindo in :issue:`45325`.)
+
Limited C API changes
---------------------
Py_RETURN_NONE;
}
+static PyObject *
+test_buildvalue_p(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *res = Py_BuildValue("p", 3);
+ if (res == NULL) {
+ return NULL;
+ }
+ if (!Py_IsTrue(res)) {
+ Py_DECREF(res);
+ return raiseTestError(self, "test_buildvalue_p", "Py_BuildValue(\"p\", 3) returned wrong result");
+ }
+ Py_DECREF(res);
+
+ res = Py_BuildValue("p", 0);
+ if (res == NULL) {
+ return NULL;
+ }
+ if (!Py_IsFalse(res)) {
+ Py_DECREF(res);
+ return raiseTestError(self, "test_buildvalue_p", "Py_BuildValue(\"p\", 0) returned wrong result");
+ }
+ Py_DECREF(res);
+
+ Py_RETURN_NONE;
+}
static PyObject *
pyobject_repr_from_null(PyObject *self, PyObject *Py_UNUSED(ignored))
{"py_buildvalue", py_buildvalue, METH_VARARGS},
{"py_buildvalue_ints", py_buildvalue_ints, METH_VARARGS},
{"test_buildvalue_N", test_buildvalue_N, METH_NOARGS},
+ {"test_buildvalue_p", test_buildvalue_p, METH_NOARGS},
{"test_reftracer", test_reftracer, METH_NOARGS},
{"_test_thread_state", test_thread_state, METH_VARARGS},
{"gilstate_ensure_release", gilstate_ensure_release, METH_NOARGS},