@@ -5399,6 +5399,85 @@ static PyTypeObject MyList_Type = {
53995399 MyList_new , /* tp_new */
54005400};
54015401
5402+ /* Test bpo-35983: trashcan backwards compatibility macros */
5403+
5404+ typedef struct {
5405+ PyObject_HEAD
5406+ PyObject * item ;
5407+ } SingleContainerObject ;
5408+
5409+ static PyObject *
5410+ SingleContainer_new (PyTypeObject * type , PyObject * args , PyObject * kwargs )
5411+ {
5412+ PyObject * obj ;
5413+ if (!_PyArg_NoKeywords ("SingleContainer" , kwargs )) {
5414+ return NULL ;
5415+ }
5416+ if (!PyArg_UnpackTuple (args , "SingleContainer" , 1 , 1 , & obj )) {
5417+ return NULL ;
5418+ }
5419+ SingleContainerObject * op = PyObject_GC_New (SingleContainerObject , type );
5420+ if (op ) {
5421+ Py_INCREF (obj );
5422+ op -> item = obj ;
5423+ }
5424+ return (PyObject * )op ;
5425+ }
5426+
5427+ void
5428+ SingleContainer_dealloc (SingleContainerObject * op )
5429+ {
5430+ /* Intentionally use the old
5431+ * Py_TRASHCAN_SAFE_BEGIN/Py_TRASHCAN_SAFE_END macros */
5432+ PyObject_GC_UnTrack (op );
5433+ Py_TRASHCAN_SAFE_BEGIN (op );
5434+ Py_DECREF (op -> item );
5435+ PyObject_GC_Del (op );
5436+ Py_TRASHCAN_SAFE_END (op );
5437+ }
5438+
5439+ static PyTypeObject SingleContainer_Type = {
5440+ PyVarObject_HEAD_INIT (NULL , 0 )
5441+ "SingleContainer" ,
5442+ sizeof (SingleContainerObject ),
5443+ 0 ,
5444+ (destructor )SingleContainer_dealloc , /* tp_dealloc */
5445+ 0 , /* tp_print */
5446+ 0 , /* tp_getattr */
5447+ 0 , /* tp_setattr */
5448+ 0 , /* tp_reserved */
5449+ 0 , /* tp_repr */
5450+ 0 , /* tp_as_number */
5451+ 0 , /* tp_as_sequence */
5452+ 0 , /* tp_as_mapping */
5453+ 0 , /* tp_hash */
5454+ 0 , /* tp_call */
5455+ 0 , /* tp_str */
5456+ 0 , /* tp_getattro */
5457+ 0 , /* tp_setattro */
5458+ 0 , /* tp_as_buffer */
5459+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
5460+ Py_TPFLAGS_HAVE_GC , /* tp_flags */
5461+ 0 , /* tp_doc */
5462+ 0 , /* tp_traverse */
5463+ 0 , /* tp_clear */
5464+ 0 , /* tp_richcompare */
5465+ 0 , /* tp_weaklistoffset */
5466+ 0 , /* tp_iter */
5467+ 0 , /* tp_iternext */
5468+ 0 , /* tp_methods */
5469+ 0 , /* tp_members */
5470+ 0 , /* tp_getset */
5471+ 0 , /* tp_base */
5472+ 0 , /* tp_dict */
5473+ 0 , /* tp_descr_get */
5474+ 0 , /* tp_descr_set */
5475+ 0 , /* tp_dictoffset */
5476+ 0 , /* tp_init */
5477+ 0 , /* tp_alloc */
5478+ SingleContainer_new /* tp_new */
5479+ };
5480+
54025481
54035482/* Test PEP 560 */
54045483
@@ -5519,6 +5598,11 @@ PyInit__testcapi(void)
55195598 Py_INCREF (& MyList_Type );
55205599 PyModule_AddObject (m , "MyList" , (PyObject * )& MyList_Type );
55215600
5601+ if (PyType_Ready (& SingleContainer_Type ) < 0 )
5602+ return NULL ;
5603+ Py_INCREF (& SingleContainer_Type );
5604+ PyModule_AddObject (m , "SingleContainer" , (PyObject * )& SingleContainer_Type );
5605+
55225606 if (PyType_Ready (& GenericAlias_Type ) < 0 )
55235607 return NULL ;
55245608 Py_INCREF (& GenericAlias_Type );
0 commit comments