@@ -2437,60 +2437,23 @@ test_critical_sections(PyObject *module, PyObject *Py_UNUSED(args))
24372437
24382438
24392439static PyObject *
2440- test_pyset_add (PyObject * self , PyObject * Py_UNUSED (args ))
2440+ // Interface to pyset_add, returning the set
2441+ pyset_add (PyObject * self , PyObject * const * args , Py_ssize_t nargsf )
24412442{
2442-
2443- PyObject * set = NULL , * empty_tuple = NULL , * tracked_object ;
2444- int return_value ;
2445-
2446- tracked_object = PyImport_ImportModule ("sys" );
2447- if (tracked_object == NULL ) {
2448- goto failed ;
2449- }
2450- if (!PyObject_GC_IsTracked (tracked_object )) {
2451- PyErr_SetString (PyExc_ValueError , "Test item is not tracked by GC" );
2452- goto failed ;
2453- }
2454-
2455- empty_tuple = PyTuple_New (0 );
2456- if (empty_tuple == NULL ) {
2457- goto failed ;
2458- }
2459- set = PyFrozenSet_New (empty_tuple );
2460- if (set == NULL ) {
2461- goto failed ;
2462- }
2463-
2464- if (PyObject_GC_IsTracked (set )) {
2465- PyErr_SetString (PyExc_ValueError , "Empty frozenset object is tracked by GC" );
2466- goto failed ;
2467- }
2468- return_value = PySet_Add (set , empty_tuple );
2469- if (return_value < 0 ) {
2470- goto failed ;
2471- }
2472- if (PyObject_GC_IsTracked (set )) {
2473- PyErr_SetString (PyExc_ValueError , "Frozenset object with immutable is tracked by GC" );
2474- goto failed ;
2443+ Py_ssize_t nargs = _PyVectorcall_NARGS (nargsf );
2444+ if (nargs != 2 ) {
2445+ PyErr_SetString (PyExc_ValueError , "pyset_add requires exactly two arguments" );
2446+ return NULL ;
24752447 }
2448+ PyObject * set = args [0 ];
2449+ PyObject * item = args [1 ];
24762450
2477- PySet_Add (set , tracked_object );
2478- if (return_value < 0 ) {
2479- goto failed ;
2480- }
2481- if (!PyObject_GC_IsTracked (set )) {
2482- PyErr_SetString (PyExc_ValueError , "Frozenset object with tracked objects is not tracked by GC" );
2483- goto failed ;
2451+ int return_value = PySet_Add (set , item );
2452+ if (return_value < 0 ) {
2453+ return NULL ;
24842454 }
24852455
2486- Py_RETURN_NONE ;
2487-
2488- failed :
2489- Py_XDECREF (tracked_object );
2490- Py_XDECREF (empty_tuple );
2491- Py_XDECREF (set );
2492- return NULL ;
2493-
2456+ return Py_NewRef (set );
24942457}
24952458
24962459// Used by `finalize_thread_hang`.
@@ -2704,7 +2667,7 @@ static PyMethodDef TestMethods[] = {
27042667 {"gen_get_code" , gen_get_code , METH_O , NULL },
27052668 {"get_feature_macros" , get_feature_macros , METH_NOARGS , NULL },
27062669 {"test_code_api" , test_code_api , METH_NOARGS , NULL },
2707- {"test_pyset_add " , test_pyset_add , METH_NOARGS , NULL },
2670+ {"pyset_add " , _PyCFunction_CAST ( pyset_add ), METH_FASTCALL , NULL },
27082671 {"settrace_to_error" , settrace_to_error , METH_O , NULL },
27092672 {"settrace_to_record" , settrace_to_record , METH_O , NULL },
27102673 {"test_macros" , test_macros , METH_NOARGS , NULL },
0 commit comments