@@ -1092,7 +1092,7 @@ test_getitem(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1092
1092
1093
1093
1094
1094
static PyObject *
1095
- test_dict_getitemref (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (args ))
1095
+ test_dict_api (PyObject * Py_UNUSED (module ), PyObject * Py_UNUSED (args ))
1096
1096
{
1097
1097
assert (!PyErr_Occurred ());
1098
1098
@@ -1112,12 +1112,18 @@ test_dict_getitemref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1112
1112
if (key == NULL ) {
1113
1113
goto error ;
1114
1114
}
1115
+ invalid_dict = key ; // borrowed reference
1115
1116
1116
1117
missing_key = PyUnicode_FromString ("missing_key" );
1117
1118
if (missing_key == NULL ) {
1118
1119
goto error ;
1119
1120
}
1120
1121
1122
+ invalid_key = PyList_New (0 ); // not hashable key
1123
+ if (invalid_key == NULL ) {
1124
+ goto error ;
1125
+ }
1126
+
1121
1127
value = PyUnicode_FromString ("value" );
1122
1128
if (value == NULL ) {
1123
1129
goto error ;
@@ -1129,6 +1135,17 @@ test_dict_getitemref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1129
1135
}
1130
1136
assert (res == 0 );
1131
1137
1138
+ // test PyDict_Contains()
1139
+ assert (PyDict_Contains (dict , key ) == 1 );
1140
+ assert (PyDict_Contains (dict , missing_key ) == 0 );
1141
+
1142
+ // test PyDict_ContainsString()
1143
+ assert (PyDict_ContainsString (dict , "key" ) == 1 );
1144
+ assert (PyDict_ContainsString (dict , "missing_key" ) == 0 );
1145
+ assert (PyDict_ContainsString (dict , "\xff" ) == -1 );
1146
+ assert (PyErr_ExceptionMatches (PyExc_UnicodeDecodeError ));
1147
+ PyErr_Clear ();
1148
+
1132
1149
// test PyDict_GetItemRef(), key is present
1133
1150
get_value = Py_Ellipsis ; // marker value
1134
1151
assert (PyDict_GetItemRef (dict , key , & get_value ) == 1 );
@@ -1154,7 +1171,6 @@ test_dict_getitemref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1154
1171
assert (get_value == NULL );
1155
1172
1156
1173
// test PyDict_GetItemRef(), invalid dict
1157
- invalid_dict = key ; // borrowed reference
1158
1174
get_value = Py_Ellipsis ; // marker value
1159
1175
assert (PyDict_GetItemRef (invalid_dict , key , & get_value ) == -1 );
1160
1176
assert (PyErr_ExceptionMatches (PyExc_SystemError ));
@@ -1168,11 +1184,6 @@ test_dict_getitemref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
1168
1184
PyErr_Clear ();
1169
1185
assert (get_value == NULL );
1170
1186
1171
- invalid_key = PyList_New (0 ); // not hashable key
1172
- if (invalid_key == NULL ) {
1173
- goto error ;
1174
- }
1175
-
1176
1187
// test PyDict_GetItemRef(), invalid key
1177
1188
get_value = Py_Ellipsis ; // marker value
1178
1189
assert (PyDict_GetItemRef (dict , invalid_key , & get_value ) == -1 );
@@ -1222,7 +1233,7 @@ static struct PyMethodDef methods[] = {
1222
1233
{"test_vectorcall" , test_vectorcall , METH_NOARGS , _Py_NULL },
1223
1234
{"test_getattr" , test_getattr , METH_NOARGS , _Py_NULL },
1224
1235
{"test_getitem" , test_getitem , METH_NOARGS , _Py_NULL },
1225
- {"test_dict_getitemref " , test_dict_getitemref , METH_NOARGS , _Py_NULL },
1236
+ {"test_dict_api " , test_dict_api , METH_NOARGS , _Py_NULL },
1226
1237
{_Py_NULL , _Py_NULL , 0 , _Py_NULL }
1227
1238
};
1228
1239
0 commit comments