Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More checks in foreach
  • Loading branch information
vstinner committed May 14, 2020
commit d0ada2d471f2652f3f311dff9908e2110f4e1d0b
10 changes: 7 additions & 3 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test_bswap(PyObject *self, PyObject *Py_UNUSED(args))

#define TO_PTR(ch) ((void*)(uintptr_t)ch)
#define FROM_PTR(ptr) ((uintptr_t)ptr)
#define VALUE(key) (1 + ((int)(key) - 'a'))

static Py_uhash_t
hash_char(const void *key)
Expand All @@ -75,9 +76,14 @@ hash_char(const void *key)


static int
hashtable_cb(_Py_hashtable_t *table, const void *key, const void *value, void *user_data)
hashtable_cb(_Py_hashtable_t *table,
const void *key_ptr, const void *value_ptr,
void *user_data)
{
int *count = (int *)user_data;
char key = (char)FROM_PTR(key_ptr);
int value = (int)FROM_PTR(value_ptr);
assert(value == VALUE(key));
*count += 1;
return 0;
}
Expand All @@ -92,8 +98,6 @@ test_hashtable(PyObject *self, PyObject *Py_UNUSED(args))
return PyErr_NoMemory();
}

#define VALUE(key) (1 + ((int)(key) - 'a'))

// Test _Py_hashtable_set()
char key;
for (key='a'; key <= 'z'; key++) {
Expand Down