Skip to content

Commit 79e54a6

Browse files
committed
Region: staticmethod
1 parent 9618e73 commit 79e54a6

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

Objects/funcobject.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ functools_copy_attr(PyObject *wrapper, PyObject *wrapped, PyObject *name)
14581458
int res = PyObject_GetOptionalAttr(wrapped, name, &value);
14591459
if (value != NULL) {
14601460
res = PyObject_SetAttr(wrapper, name, value);
1461-
Py_DECREF(value);
1461+
PyRegion_CLEARLOCAL(value);
14621462
}
14631463
return res;
14641464
}
@@ -1821,8 +1821,8 @@ sm_dealloc(PyObject *self)
18211821
{
18221822
staticmethod *sm = _PyStaticMethod_CAST(self);
18231823
_PyObject_GC_UNTRACK((PyObject *)sm);
1824-
Py_XDECREF(sm->sm_callable);
1825-
Py_XDECREF(sm->sm_dict);
1824+
PyRegion_CLEAR(sm, sm->sm_callable);
1825+
PyRegion_CLEAR(sm, sm->sm_dict);
18261826
Py_TYPE(sm)->tp_free((PyObject *)sm);
18271827
}
18281828

@@ -1839,8 +1839,8 @@ static int
18391839
sm_clear(PyObject *self)
18401840
{
18411841
staticmethod *sm = _PyStaticMethod_CAST(self);
1842-
Py_CLEAR(sm->sm_callable);
1843-
Py_CLEAR(sm->sm_dict);
1842+
PyRegion_CLEAR(sm, sm->sm_callable);
1843+
PyRegion_CLEAR(sm, sm->sm_dict);
18441844
return 0;
18451845
}
18461846

@@ -1854,7 +1854,7 @@ sm_descr_get(PyObject *self, PyObject *obj, PyObject *type)
18541854
"uninitialized staticmethod object");
18551855
return NULL;
18561856
}
1857-
return Py_NewRef(sm->sm_callable);
1857+
return PyRegion_NewRef(sm->sm_callable);
18581858
}
18591859

18601860
static int
@@ -1867,7 +1867,8 @@ sm_init(PyObject *self, PyObject *args, PyObject *kwds)
18671867
return -1;
18681868
if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
18691869
return -1;
1870-
Py_XSETREF(sm->sm_callable, Py_NewRef(callable));
1870+
if (PyRegion_XSETNEWREF(sm, sm->sm_callable, callable))
1871+
return -1;
18711872

18721873
if (functools_wraps((PyObject *)sm, sm->sm_callable) < 0) {
18731874
return -1;
@@ -2010,6 +2011,7 @@ PyTypeObject PyStaticMethod_Type = {
20102011
PyType_GenericNew, /* tp_new */
20112012
PyObject_GC_Del, /* tp_free */
20122013
.tp_reachable = _PyObject_ReachableVisitTypeAndTraverse,
2014+
.tp_flags2 = Py_TPFLAGS2_REGION_AWARE,
20132015
};
20142016

20152017
PyObject *

Objects/object.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,14 +1489,17 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
14891489
Py_TYPE(name)->tp_name);
14901490
return -1;
14911491
}
1492+
if (PyRegion_AddLocalRef(name)) {
1493+
return -1;
1494+
}
14921495
Py_INCREF(name);
14931496

14941497
_PyUnicode_InternMortal(tstate->interp, &name);
14951498
if (tp->tp_setattro != NULL) {
14961499
// Check for immutability
14971500
if (!Py_CHECKWRITE(v)) {
14981501
PyErr_WriteToImmutable(v);
1499-
Py_DECREF(name);
1502+
PyRegion_CLEARLOCAL(name);
15001503
return -1;
15011504
}
15021505

@@ -1509,27 +1512,28 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
15091512
// Call the setattro function of the type
15101513
err = (*tp->tp_setattro)(v, name, value);
15111514

1512-
Py_DECREF(name);
1515+
PyRegion_CLEARLOCAL(name);
15131516
return err;
15141517
}
15151518
if (tp->tp_setattr != NULL) {
15161519
const char *name_str = PyUnicode_AsUTF8(name);
15171520
if (name_str == NULL) {
1518-
Py_DECREF(name);
1521+
PyRegion_CLEARLOCAL(name);
15191522
return -1;
15201523
}
15211524

1522-
if(Py_CHECKWRITE(v)){
1523-
err = (*tp->tp_setattr)(v, (char *)name_str, value);
1524-
}else{
1525+
if (!Py_CHECKWRITE(v)){
15251526
PyErr_WriteToImmutable(v);
1526-
err = -1;
1527+
PyRegion_CLEARLOCAL(name);
1528+
return -1;
15271529
}
15281530

1529-
Py_DECREF(name);
1531+
PyRegion_NotifyTypeUse(tp);
1532+
err = (*tp->tp_setattr)(v, (char *)name_str, value);
1533+
1534+
PyRegion_CLEARLOCAL(name);
15301535
return err;
15311536
}
1532-
Py_DECREF(name);
15331537
_PyObject_ASSERT(name, Py_REFCNT(name) >= 1);
15341538
if (tp->tp_getattr == NULL && tp->tp_getattro == NULL)
15351539
PyErr_Format(PyExc_TypeError,
@@ -1545,6 +1549,7 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
15451549
tp->tp_name,
15461550
value==NULL ? "del" : "assign to",
15471551
name);
1552+
PyRegion_CLEARLOCAL(name);
15481553
return -1;
15491554
}
15501555

0 commit comments

Comments
 (0)