@@ -3948,10 +3948,39 @@ subtype_dict(PyObject *obj, void *context)
3948
3948
return PyObject_GenericGetDict (obj , context );
3949
3949
}
3950
3950
3951
+ int
3952
+ _PyObject_SetDict (PyObject * obj , PyObject * value )
3953
+ {
3954
+ if (value != NULL && !PyDict_Check (value )) {
3955
+ PyErr_Format (PyExc_TypeError ,
3956
+ "__dict__ must be set to a dictionary, "
3957
+ "not a '%.200s'" , Py_TYPE (value )-> tp_name );
3958
+ return -1 ;
3959
+ }
3960
+ if (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
3961
+ return _PyObject_SetManagedDict (obj , value );
3962
+ }
3963
+ PyObject * * dictptr = _PyObject_ComputedDictPointer (obj );
3964
+ if (dictptr == NULL ) {
3965
+ PyErr_SetString (PyExc_AttributeError ,
3966
+ "This object has no __dict__" );
3967
+ return -1 ;
3968
+ }
3969
+ Py_BEGIN_CRITICAL_SECTION (obj );
3970
+ PyObject * olddict = * dictptr ;
3971
+ FT_ATOMIC_STORE_PTR_RELEASE (* dictptr , Py_NewRef (value ));
3972
+ #ifdef Py_GIL_DISABLED
3973
+ _PyObject_XDecRefDelayed (olddict );
3974
+ #else
3975
+ Py_XDECREF (olddict );
3976
+ #endif
3977
+ Py_END_CRITICAL_SECTION ();
3978
+ return 0 ;
3979
+ }
3980
+
3951
3981
static int
3952
3982
subtype_setdict (PyObject * obj , PyObject * value , void * context )
3953
3983
{
3954
- PyObject * * dictptr ;
3955
3984
PyTypeObject * base ;
3956
3985
3957
3986
base = get_builtin_base_with_dict (Py_TYPE (obj ));
@@ -3969,28 +3998,7 @@ subtype_setdict(PyObject *obj, PyObject *value, void *context)
3969
3998
}
3970
3999
return func (descr , obj , value );
3971
4000
}
3972
- /* Almost like PyObject_GenericSetDict, but allow __dict__ to be deleted. */
3973
- if (value != NULL && !PyDict_Check (value )) {
3974
- PyErr_Format (PyExc_TypeError ,
3975
- "__dict__ must be set to a dictionary, "
3976
- "not a '%.200s'" , Py_TYPE (value )-> tp_name );
3977
- return -1 ;
3978
- }
3979
-
3980
- if (Py_TYPE (obj )-> tp_flags & Py_TPFLAGS_MANAGED_DICT ) {
3981
- return _PyObject_SetManagedDict (obj , value );
3982
- }
3983
- else {
3984
- dictptr = _PyObject_ComputedDictPointer (obj );
3985
- if (dictptr == NULL ) {
3986
- PyErr_SetString (PyExc_AttributeError ,
3987
- "This object has no __dict__" );
3988
- return -1 ;
3989
- }
3990
- Py_CLEAR (* dictptr );
3991
- * dictptr = Py_XNewRef (value );
3992
- }
3993
- return 0 ;
4001
+ return _PyObject_SetDict (obj , value );
3994
4002
}
3995
4003
3996
4004
static PyObject *
0 commit comments