@@ -129,6 +129,33 @@ 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
+ return NULL ;
144
+ }
145
+ if (PySet_Add (fs , num ) < 0 ) {
146
+ return NULL ;
147
+ }
148
+ int contains = PySet_Contains (fs , num );
149
+ if (contains < 0 ) {
150
+ return NULL ;
151
+ }
152
+ else if (contains == 0 ) {
153
+ PyErr_SetString (PyExc_ValueError , "set does not contain expected value" );
154
+ return NULL ;
155
+ }
156
+ Py_RETURN_NONE ;
157
+ }
158
+
132
159
static PyMethodDef test_methods [] = {
133
160
{"set_check" , set_check , METH_O },
134
161
{"set_checkexact" , set_checkexact , METH_O },
@@ -148,6 +175,8 @@ static PyMethodDef test_methods[] = {
148
175
{"set_pop" , set_pop , METH_O },
149
176
{"set_clear" , set_clear , METH_O },
150
177
178
+ {"test_frozenset_add_in_capi" , test_frozenset_add_in_capi , METH_NOARGS },
179
+
151
180
{NULL },
152
181
};
153
182
0 commit comments