@@ -244,42 +244,6 @@ static PyMemberDef func_memberlist[] = {
244244 {NULL } /* Sentinel */
245245};
246246
247- static PyObject *
248- func_get_dict (PyFunctionObject * op )
249- {
250- if (op -> func_dict == NULL ) {
251- op -> func_dict = PyDict_New ();
252- if (op -> func_dict == NULL )
253- return NULL ;
254- }
255- Py_INCREF (op -> func_dict );
256- return op -> func_dict ;
257- }
258-
259- static int
260- func_set_dict (PyFunctionObject * op , PyObject * value )
261- {
262- PyObject * tmp ;
263-
264- /* It is illegal to del f.func_dict */
265- if (value == NULL ) {
266- PyErr_SetString (PyExc_TypeError ,
267- "function's dictionary may not be deleted" );
268- return -1 ;
269- }
270- /* Can only set func_dict to a dictionary */
271- if (!PyDict_Check (value )) {
272- PyErr_SetString (PyExc_TypeError ,
273- "setting function's dictionary to a non-dict" );
274- return -1 ;
275- }
276- tmp = op -> func_dict ;
277- Py_INCREF (value );
278- op -> func_dict = value ;
279- Py_XDECREF (tmp );
280- return 0 ;
281- }
282-
283247static PyObject *
284248func_get_code (PyFunctionObject * op )
285249{
@@ -476,7 +440,7 @@ static PyGetSetDef func_getsetlist[] = {
476440 (setter )func_set_kwdefaults },
477441 {"__annotations__" , (getter )func_get_annotations ,
478442 (setter )func_set_annotations },
479- {"__dict__" , ( getter ) func_get_dict , ( setter ) func_set_dict },
443+ {"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict },
480444 {"__name__" , (getter )func_get_name , (setter )func_set_name },
481445 {"__qualname__" , (getter )func_get_qualname , (setter )func_set_qualname },
482446 {NULL } /* Sentinel */
@@ -831,22 +795,12 @@ cm_get___isabstractmethod__(classmethod *cm, void *closure)
831795 Py_RETURN_FALSE ;
832796}
833797
834- static PyObject *
835- cm_get___dict__ (PyObject * cm , void * closure )
836- {
837- PyObject * * dictptr = _PyObject_GetDictPtr (cm );
838- if (* dictptr == NULL )
839- * dictptr = PyDict_New ();
840- Py_XINCREF (* dictptr );
841- return * dictptr ;
842- }
843-
844798static PyGetSetDef cm_getsetlist [] = {
845799 {"__isabstractmethod__" ,
846800 (getter )cm_get___isabstractmethod__ , NULL ,
847801 NULL ,
848802 NULL },
849- {"__dict__" , ( getter ) cm_get___dict__ , NULL , NULL , NULL },
803+ {"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict , NULL , NULL },
850804 {NULL } /* Sentinel */
851805};
852806
@@ -1020,22 +974,12 @@ sm_get___isabstractmethod__(staticmethod *sm, void *closure)
1020974 Py_RETURN_FALSE ;
1021975}
1022976
1023- static PyObject *
1024- sm_get___dict__ (PyObject * sm , void * closure )
1025- {
1026- PyObject * * dictptr = _PyObject_GetDictPtr (sm );
1027- if (* dictptr == NULL )
1028- * dictptr = PyDict_New ();
1029- Py_XINCREF (* dictptr );
1030- return * dictptr ;
1031- }
1032-
1033977static PyGetSetDef sm_getsetlist [] = {
1034978 {"__isabstractmethod__" ,
1035979 (getter )sm_get___isabstractmethod__ , NULL ,
1036980 NULL ,
1037981 NULL },
1038- {"__dict__" , ( getter ) sm_get___dict__ , NULL , NULL , NULL },
982+ {"__dict__" , PyObject_GenericGetDict , PyObject_GenericSetDict , NULL , NULL },
1039983 {NULL } /* Sentinel */
1040984};
1041985
0 commit comments