Skip to content

Commit 43e323b

Browse files
committed
WIP on the documentation of the Tuple API testing.
1 parent 4989f1b commit 43e323b

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

doc/sphinx/source/refcount_and_containers.rst

+41-18
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,27 @@
1010
Reference Counts and Python Containers
1111
======================================
1212

13-
Given the descriptions of *New*, *Stolen* and *Borrowed*
14-
references described in the preceeding chapter, this chapter looks
15-
in more detail of how the Python C API works with different containers.
13+
The descriptions of *New*, *Stolen* and *Borrowed* references were described in the preceding chapter.
14+
This chapter looks in more detail of how the Python C API works with different containers, tuple, list, set and dict.
1615

17-
Of particular interest is *Setters*, *Getters* and the behaviour of
18-
``Py_BuildValue``.
16+
Of particular interest is *Setters*, *Getters* and the behaviour of ``Py_BuildValue`` for each of those containers.
17+
This chapter also clarifies the Python documentation where it is inaccurate or misleading.
1918

2019
Buckle up.
2120

2221
--------------------------
2322
Methodology
2423
--------------------------
2524

26-
Firstly a utility function for creating new, uncached, Python objects:
25+
This chapter explores the CPython C API in several ways:
2726

28-
.. code-block:: c
29-
30-
/* This is used to guarantee that Python is not caching a string value when we want to check the
31-
* reference counts after each string creation.
32-
* */
33-
static int debug_test_count = 0;
34-
35-
static PyObject *
36-
new_unique_string(const char *function_name) {
37-
return PyUnicode_FromFormat("%s-%d", function_name, debug_test_count++);
38-
}
27+
* Tests of the CPython C API that can be stepped through in the debugger.
28+
This code is in ``src/cpy/Containers/DebugContainers.h`` and ``src/cpy/Containers/DebugContainers.c``
29+
and ``asserts`` are used to check the results, particularly reference counts.
30+
It is exercised by ``src/main.c``.
31+
* Similar test code is in ``src/cpy/RefCount/cRefCount.c`` which is built into the Python module ``cRefCount``.
32+
This can be run under ``pytest``.
33+
* A review of the Python C API documentation.
3934

4035
Here is an example of exploring reference counts and tuples.
4136

@@ -91,7 +86,7 @@ Here is an example of exploring reference counts and tuples.
9186
Py_RETURN_NONE;
9287
}
9388
94-
89+
Firstly Tuples:
9590

9691
-----------------------
9792
Tuple
@@ -116,6 +111,34 @@ The Python documentation for the `Tuple API <https://docs.python.org/3/c-api/tup
116111
- Steals, leaks original.
117112
- More stuff.
118113

114+
115+
``PyTuple_SetItem()``
116+
---------------------
117+
118+
`PyTuple_SetItem() <https://docs.python.org/3/c-api/tuple.html#c.PyTuple_SetItem>`_
119+
120+
121+
``PyTuple_SET_ITEM()``
122+
---------------------
123+
124+
`PyTuple_SetItem() <https://docs.python.org/3/c-api/tuple.html#c.PyTuple_SET_ITEM>`_
125+
126+
127+
``Py_BuildValue()``
128+
-------------------
129+
130+
`Py_BuildValue() <https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue>`_
131+
132+
133+
``PyTuple_Pack()``
134+
------------------
135+
136+
`PyTuple_Pack() <https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Pack>`_
137+
is a wrapper around
138+
`Py_BuildValue() <https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue>`_
139+
so is not explored any further.
140+
141+
119142
-----------------------
120143
List
121144
-----------------------

0 commit comments

Comments
 (0)