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