-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-110525: Add tests for internal set
CAPI
#110630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||||||||
#include "parts.h" | ||||||||||||||||||||||||||||||||||||
#include "../_testcapi/util.h" // NULLABLE, RETURN_INT | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
#include "pycore_setobject.h" | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static PyObject * | ||||||||||||||||||||||||||||||||||||
set_update(PyObject *self, PyObject *args) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
PyObject *set, *iterable; | ||||||||||||||||||||||||||||||||||||
if (!PyArg_ParseTuple(args, "OO", &set, &iterable)) { | ||||||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
NULLABLE(set); | ||||||||||||||||||||||||||||||||||||
NULLABLE(iterable); | ||||||||||||||||||||||||||||||||||||
RETURN_INT(_PySet_Update(set, iterable)); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static PyObject * | ||||||||||||||||||||||||||||||||||||
set_next_entry(PyObject *self, PyObject *args) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
int rc; | ||||||||||||||||||||||||||||||||||||
Py_ssize_t pos; | ||||||||||||||||||||||||||||||||||||
Py_hash_t hash = (Py_hash_t)UNINITIALIZED_SIZE; | ||||||||||||||||||||||||||||||||||||
PyObject *set, *item = UNINITIALIZED_PTR; | ||||||||||||||||||||||||||||||||||||
if (!PyArg_ParseTuple(args, "On", &set, &pos)) { | ||||||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
NULLABLE(set); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
rc = _PySet_NextEntry(set, &pos, &item, &hash); | ||||||||||||||||||||||||||||||||||||
if (rc == 1) { | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it returns 2 or -2?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand this one. Right now it is defined as: Lines 2332 to 2346 in 66a9b10
It cannot return anything except This function is not documented currently. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of the test is to verify our assumptions (that it cannot return anything except [-1, 0, 1]). Otherwise there would not be need of tests. In future a new return can be added in the code, or refactoring can lead to returning non-initialized variable in rare case. The wrapper will successfully return None. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, I used an assertion, which is more readable in my opinion 👍 |
||||||||||||||||||||||||||||||||||||
return Py_BuildValue("innO", rc, pos, hash, item); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
assert(item == UNINITIALIZED_PTR); | ||||||||||||||||||||||||||||||||||||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
assert(hash == (Py_hash_t)UNINITIALIZED_SIZE); | ||||||||||||||||||||||||||||||||||||
if (rc == -1) { | ||||||||||||||||||||||||||||||||||||
return NULL; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
assert(rc == 0); | ||||||||||||||||||||||||||||||||||||
Py_RETURN_NONE; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
static PyMethodDef TestMethods[] = { | ||||||||||||||||||||||||||||||||||||
{"set_update", set_update, METH_VARARGS}, | ||||||||||||||||||||||||||||||||||||
{"set_next_entry", set_next_entry, METH_VARARGS}, | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
{NULL}, | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
int | ||||||||||||||||||||||||||||||||||||
_PyTestInternalCapi_Init_Set(PyObject *m) | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
if (PyModule_AddFunctions(m, TestMethods) < 0) { | ||||||||||||||||||||||||||||||||||||
return -1; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
return 0; | ||||||||||||||||||||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.