Skip to content

Commit ce1ac3e

Browse files
committed
Merge branch 'main' into intern-dataclass-field-names
2 parents 19594c5 + bfc57d4 commit ce1ac3e

File tree

22 files changed

+349
-264
lines changed

22 files changed

+349
-264
lines changed

Include/internal/pycore_cell.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef Py_INTERNAL_CELL_H
2+
#define Py_INTERNAL_CELL_H
3+
4+
#include "pycore_critical_section.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
#ifndef Py_BUILD_CORE
11+
# error "this header requires Py_BUILD_CORE define"
12+
#endif
13+
14+
// Sets the cell contents to `value` and return previous contents. Steals a
15+
// reference to `value`.
16+
static inline PyObject *
17+
PyCell_SwapTakeRef(PyCellObject *cell, PyObject *value)
18+
{
19+
PyObject *old_value;
20+
Py_BEGIN_CRITICAL_SECTION(cell);
21+
old_value = cell->ob_ref;
22+
cell->ob_ref = value;
23+
Py_END_CRITICAL_SECTION();
24+
return old_value;
25+
}
26+
27+
static inline void
28+
PyCell_SetTakeRef(PyCellObject *cell, PyObject *value)
29+
{
30+
PyObject *old_value = PyCell_SwapTakeRef(cell, value);
31+
Py_XDECREF(old_value);
32+
}
33+
34+
// Gets the cell contents. Returns a new reference.
35+
static inline PyObject *
36+
PyCell_GetRef(PyCellObject *cell)
37+
{
38+
PyObject *res;
39+
Py_BEGIN_CRITICAL_SECTION(cell);
40+
res = Py_XNewRef(cell->ob_ref);
41+
Py_END_CRITICAL_SECTION();
42+
return res;
43+
}
44+
45+
#ifdef __cplusplus
46+
}
47+
#endif
48+
#endif /* !Py_INTERNAL_CELL_H */

0 commit comments

Comments
 (0)