Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:45

0001 #ifndef Py_INTERNAL_CELL_H
0002 #define Py_INTERNAL_CELL_H
0003 
0004 #include "pycore_critical_section.h"
0005 
0006 #ifdef __cplusplus
0007 extern "C" {
0008 #endif
0009 
0010 #ifndef Py_BUILD_CORE
0011 #  error "this header requires Py_BUILD_CORE define"
0012 #endif
0013 
0014 // Sets the cell contents to `value` and return previous contents. Steals a
0015 // reference to `value`.
0016 static inline PyObject *
0017 PyCell_SwapTakeRef(PyCellObject *cell, PyObject *value)
0018 {
0019     PyObject *old_value;
0020     Py_BEGIN_CRITICAL_SECTION(cell);
0021     old_value = cell->ob_ref;
0022     cell->ob_ref = value;
0023     Py_END_CRITICAL_SECTION();
0024     return old_value;
0025 }
0026 
0027 static inline void
0028 PyCell_SetTakeRef(PyCellObject *cell, PyObject *value)
0029 {
0030     PyObject *old_value = PyCell_SwapTakeRef(cell, value);
0031     Py_XDECREF(old_value);
0032 }
0033 
0034 // Gets the cell contents. Returns a new reference.
0035 static inline PyObject *
0036 PyCell_GetRef(PyCellObject *cell)
0037 {
0038     PyObject *res;
0039     Py_BEGIN_CRITICAL_SECTION(cell);
0040     res = Py_XNewRef(cell->ob_ref);
0041     Py_END_CRITICAL_SECTION();
0042     return res;
0043 }
0044 
0045 #ifdef __cplusplus
0046 }
0047 #endif
0048 #endif   /* !Py_INTERNAL_CELL_H */