11/* Sentinel object implementation */
22
33#include "Python.h"
4+ #include "descrobject.h" // PyMemberDef
45#include "pycore_ceval.h" // _PyThreadState_GET()
56#include "pycore_interpframe.h" // _PyFrame_IsIncomplete()
67#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK()
78#include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow()
89#include "pycore_typeobject.h" // _Py_BaseObject_RichCompare()
910#include "pycore_unionobject.h" // _Py_union_from_tuple()
10- #include "structmember.h" // PyMemberDef
1111
1212typedef struct {
1313 PyObject_HEAD
@@ -30,15 +30,13 @@ static PyObject *
3030caller (void )
3131{
3232 _PyInterpreterFrame * f = _PyThreadState_GET ()-> current_frame ;
33- if (f == NULL ) {
34- Py_RETURN_NONE ;
35- }
3633 if (f == NULL || PyStackRef_IsNull (f -> f_funcobj )) {
3734 Py_RETURN_NONE ;
3835 }
39- PyObject * r = PyFunction_GetModule (PyStackRef_AsPyObjectBorrow (f -> f_funcobj ));
36+ PyFunctionObject * func = _PyFrame_GetFunction (f );
37+ assert (PyFunction_Check (func ));
38+ PyObject * r = PyFunction_GetModule ((PyObject * )func );
4039 if (!r ) {
41- PyErr_Clear ();
4240 Py_RETURN_NONE ;
4341 }
4442 return Py_NewRef (r );
@@ -49,16 +47,12 @@ sentinel_new_with_module(PyTypeObject *type, PyObject *name, PyObject *module)
4947{
5048 assert (PyUnicode_Check (name ));
5149
52- Py_INCREF (name );
53- Py_INCREF (module );
5450 sentinelobject * self = PyObject_GC_New (sentinelobject , type );
5551 if (self == NULL ) {
56- Py_DECREF (name );
57- Py_DECREF (module );
5852 return NULL ;
5953 }
60- self -> name = name ;
61- self -> module = module ;
54+ self -> name = Py_NewRef ( name ) ;
55+ self -> module = Py_NewRef ( module ) ;
6256 _PyObject_GC_TRACK (self );
6357 return (PyObject * )self ;
6458}
@@ -105,13 +99,20 @@ PySentinel_New(const char *name, const char *module_name)
10599 return sentinel ;
106100}
107101
108- static void
109- sentinel_dealloc (PyObject * op )
102+ static int
103+ sentinel_clear (PyObject * op )
110104{
111- _PyObject_GC_UNTRACK (op );
112105 sentinelobject * self = sentinelobject_CAST (op );
113106 Py_CLEAR (self -> name );
114107 Py_CLEAR (self -> module );
108+ return 0 ;
109+ }
110+
111+ static void
112+ sentinel_dealloc (PyObject * op )
113+ {
114+ _PyObject_GC_UNTRACK (op );
115+ sentinel_clear (op );
115116 Py_TYPE (op )-> tp_free (op );
116117}
117118
@@ -124,15 +125,6 @@ sentinel_traverse(PyObject *op, visitproc visit, void *arg)
124125 return 0 ;
125126}
126127
127- static int
128- sentinel_clear (PyObject * op )
129- {
130- sentinelobject * self = sentinelobject_CAST (op );
131- Py_CLEAR (self -> name );
132- Py_CLEAR (self -> module );
133- return 0 ;
134- }
135-
136128static PyObject *
137129sentinel_repr (PyObject * op )
138130{
0 commit comments