@@ -127,6 +127,41 @@ set_clear(PyObject *self, PyObject *obj)
127
127
RETURN_INT (PySet_Clear (obj ));
128
128
}
129
129
130
+ static PyObject *
131
+ test_frozenset_add_in_capi (PyObject * self , PyObject * Py_UNUSED (obj ))
132
+ {
133
+ // Test that `frozenset` can be used with `PySet_Add`,
134
+ // when frozenset is just created in CAPI.
135
+ PyObject * fs = PyFrozenSet_New (NULL );
136
+ if (fs == NULL ) {
137
+ return NULL ;
138
+ }
139
+ PyObject * num = PyLong_FromLong (1 );
140
+ if (num == NULL ) {
141
+ goto error ;
142
+ }
143
+ if (PySet_Add (fs , num ) < 0 ) {
144
+ goto error ;
145
+ }
146
+ int contains = PySet_Contains (fs , num );
147
+ if (contains < 0 ) {
148
+ goto error ;
149
+ }
150
+ else if (contains == 0 ) {
151
+ goto unexpected ;
152
+ }
153
+ Py_DECREF (fs );
154
+ Py_DECREF (num );
155
+ Py_RETURN_NONE ;
156
+
157
+ unexpected :
158
+ PyErr_SetString (PyExc_ValueError , "set does not contain expected value" );
159
+ error :
160
+ Py_DECREF (fs );
161
+ Py_XDECREF (num );
162
+ return NULL ;
163
+ }
164
+
130
165
static PyMethodDef test_methods [] = {
131
166
{"set_check" , set_check , METH_O },
132
167
{"set_checkexact" , set_checkexact , METH_O },
@@ -146,6 +181,8 @@ static PyMethodDef test_methods[] = {
146
181
{"set_pop" , set_pop , METH_O },
147
182
{"set_clear" , set_clear , METH_O },
148
183
184
+ {"test_frozenset_add_in_capi" , test_frozenset_add_in_capi , METH_NOARGS },
185
+
149
186
{NULL },
150
187
};
151
188
0 commit comments