summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cppext/extension.cpp
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-12-13 14:12:07 (GMT)
committerGitHub <noreply@github.com>2024-12-13 14:12:07 (GMT)
commit78095c905238af73e71b3c2c39f7cd5557ae91cc (patch)
tree30463a6ddbf03ca3ced9109dcd569cbaceebca17 /Lib/test/test_cppext/extension.cpp
parent0f38b897f933849f01293af622482c5b8502a2b4 (diff)
downloadcpython-78095c905238af73e71b3c2c39f7cd5557ae91cc.zip
cpython-78095c905238af73e71b3c2c39f7cd5557ae91cc.tar.gz
cpython-78095c905238af73e71b3c2c39f7cd5557ae91cc.tar.bz2
[3.13] gh-127906: Test the limited C API in test_cppext (GH-127916) (#127919)
gh-127906: Test the limited C API in test_cppext (GH-127916) (cherry picked from commit d05a4e6a0d366b854a3103cae0c941811fd48c4c) Co-authored-by: Victor Stinner <vstinner@python.org>
Diffstat (limited to 'Lib/test/test_cppext/extension.cpp')
-rw-r--r--Lib/test/test_cppext/extension.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp
index ab485b6..500d591 100644
--- a/Lib/test/test_cppext/extension.cpp
+++ b/Lib/test/test_cppext/extension.cpp
@@ -62,6 +62,7 @@ test_api_casts(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
Py_ssize_t refcnt = Py_REFCNT(obj);
assert(refcnt >= 1);
+#ifndef Py_LIMITED_API
// gh-92138: For backward compatibility, functions of Python C API accepts
// "const PyObject*". Check that using it does not emit C++ compiler
// warnings.
@@ -74,6 +75,7 @@ test_api_casts(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
assert(PyTuple_GET_SIZE(const_obj) == 2);
PyObject *one = PyTuple_GET_ITEM(const_obj, 0);
assert(PyLong_AsLong(one) == 1);
+#endif
// gh-92898: StrongRef doesn't inherit from PyObject but has an operator to
// cast to PyObject*.
@@ -106,6 +108,12 @@ test_unicode(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
}
assert(PyUnicode_Check(str));
+
+ assert(PyUnicode_GetLength(str) == 3);
+ assert(PyUnicode_ReadChar(str, 0) == 'a');
+ assert(PyUnicode_ReadChar(str, 1) == 'b');
+
+#ifndef Py_LIMITED_API
assert(PyUnicode_GET_LENGTH(str) == 3);
// gh-92800: test PyUnicode_READ()
@@ -121,6 +129,7 @@ test_unicode(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
assert(PyUnicode_READ(ukind, const_data, 2) == 'c');
assert(PyUnicode_READ_CHAR(str, 1) == 'b');
+#endif
Py_DECREF(str);
Py_RETURN_NONE;