@@ -3676,10 +3676,39 @@ subtype_dict(PyObject *obj, void *context)
3676
3676
return PyObject_GenericGetDict (obj , context );
3677
3677
}
3678
3678
3679
+ int
3680
+ _PyObject_SetDict (PyObject * obj , PyObject * value )
3681
+ {
3682
+ if (value != NULL && !PyDict_Check (value )) {
3683
+ PyErr_Format (PyExc_TypeError ,
3684
+ "__dict__ must be set to a dictionary, "
3685
+ "not a '%.200s'" , Py_TYPE (value )-> tp_name );
3686
+ return -1 ;
3687
+ }
3688
+ if (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
3689
+ return _PyObject_SetManagedDict (obj , value );
3690
+ }
3691
+ PyObject * * dictptr = _PyObject_ComputedDictPointer (obj );
3692
+ if (dictptr == NULL ) {
3693
+ PyErr_SetString (PyExc_AttributeError ,
3694
+ "This object has no __dict__" );
3695
+ return -1 ;
3696
+ }
3697
+ Py_BEGIN_CRITICAL_SECTION (obj );
3698
+ PyObject * olddict = * dictptr ;
3699
+ FT_ATOMIC_STORE_PTR_RELEASE (* dictptr , Py_NewRef (value ));
3700
+ #ifdef Py_GIL_DISABLED
3701
+ _PyObject_XDecRefDelayed (olddict );
3702
+ #else
3703
+ Py_XDECREF (olddict );
3704
+ #endif
3705
+ Py_END_CRITICAL_SECTION ();
3706
+ return 0 ;
3707
+ }
3708
+
3679
3709
static int
3680
3710
subtype_setdict (PyObject * obj , PyObject * value , void * context )
3681
3711
{
3682
- PyObject * * dictptr ;
3683
3712
PyTypeObject * base ;
3684
3713
3685
3714
base = get_builtin_base_with_dict (Py_TYPE (obj ));
@@ -3697,28 +3726,7 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
3697
3726
}
3698
3727
return func (descr , obj , value );
3699
3728
}
3700
- /* Almost like PyObject_GenericSetDict, but allow __dict__ to be deleted. */
3701
- if (value != NULL && !PyDict_Check (value )) {
3702
- PyErr_Format (PyExc_TypeError ,
3703
- "__dict__ must be set to a dictionary, "
3704
- "not a '%.200s'" , Py_TYPE (value )-> tp_name );
3705
- return -1 ;
3706
- }
3707
-
3708
- if (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
3709
- return _PyObject_SetManagedDict (obj , value );
3710
- }
3711
- else {
3712
- dictptr = _PyObject_ComputedDictPointer (obj );
3713
- if (dictptr == NULL ) {
3714
- PyErr_SetString (PyExc_AttributeError ,
3715
- "This object has no __dict__" );
3716
- return -1 ;
3717
- }
3718
- Py_CLEAR (* dictptr );
3719
- * dictptr = Py_XNewRef (value );
3720
- }
3721
- return 0 ;
3729
+ return _PyObject_SetDict (obj , value );
3722
3730
}
3723
3731
3724
3732
static PyObject *
0 commit comments