Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-111495: Add tests for PyList C API#111562

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 33 commits intopython:mainfromrawwar:kalyan/test-capi-list
Nov 8, 2023

Conversation

rawwar
Copy link
Contributor

@rawwarrawwar commentedOct 31, 2023
edited by bedevere-appbot
Loading

Adding tests for PyList C API - Issue#111495

@bedevere-appbedevere-appbot mentioned this pull requestOct 31, 2023
10 tasks
Signed-off-by: kalyanr <kalyan.ben10@live.com>
…o kalyan/test-capi-listSigned-off-by: kalyanr <kalyan.ben10@live.com>
…i-listSigned-off-by: kalyanr <kalyan.ben10@live.com>
@rawwar
Copy link
ContributorAuthor

@serhiy-storchaka , Is adding{NULL}, totest_methods[] necessary? yesterday, i was able to runmake without any issues. Today, after taking the pull from main, its been failing. below are the details

static PyMethodDef test_methods[] = {    {"list_check", list_check, METH_O},    {"list_check_exact", list_check_exact, METH_O},    {"list_new", list_new, METH_O},    {"list_size", list_size, METH_O},};

Fails with

(base) kalyan@rawwar:~/oss/python-projects/cpython$ makegcc  -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall    -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal -I./Include/internal/mimalloc  -I. -I./Include    -fPIC -c ./Modules/_testcapi/list.c -o Modules/_testcapi/list.ogcc -shared      Modules/_testcapimodule.o Modules/_testcapi/vectorcall.o Modules/_testcapi/vectorcall_limited.o Modules/_testcapi/heaptype.o Modules/_testcapi/abstract.o Modules/_testcapi/bytearray.o Modules/_testcapi/bytes.o Modules/_testcapi/unicode.o Modules/_testcapi/dict.o Modules/_testcapi/set.o Modules/_testcapi/list.o Modules/_testcapi/tuple.o Modules/_testcapi/getargs.o Modules/_testcapi/datetime.o Modules/_testcapi/docstring.o Modules/_testcapi/mem.o Modules/_testcapi/watchers.o Modules/_testcapi/long.o Modules/_testcapi/float.o Modules/_testcapi/complex.o Modules/_testcapi/numbers.o Modules/_testcapi/structmember.o Modules/_testcapi/exceptions.o Modules/_testcapi/code.o Modules/_testcapi/buffer.o Modules/_testcapi/pyatomic.o Modules/_testcapi/pyos.o Modules/_testcapi/file.o Modules/_testcapi/codec.o Modules/_testcapi/immortal.o Modules/_testcapi/heaptype_relative.o Modules/_testcapi/gc.o Modules/_testcapi/sys.o   -o Modules/_testcapi.cpython-313-x86_64-linux-gnu.so[ERROR] Importing extension '_testcapi' failed!Traceback (most recent call last):  File "/home/kalyan/oss/python-projects/cpython/./Tools/build/check_extension_modules.py", line 412, in check_module_import    bootstrap_load(spec)  File "<frozen importlib._bootstrap>", line 960, in _load  File "<frozen importlib._bootstrap>", line 915, in _load_unlocked  File "<frozen importlib._bootstrap>", line 813, in module_from_spec  File "<frozen importlib._bootstrap_external>", line 1302, in create_module  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removedValueError: module functions cannot set METH_CLASS or METH_STATICTraceback (most recent call last):  File "/home/kalyan/oss/python-projects/cpython/./Tools/build/check_extension_modules.py", line 483, in <module>    main()  File "/home/kalyan/oss/python-projects/cpython/./Tools/build/check_extension_modules.py", line 474, in main    checker.check()  File "/home/kalyan/oss/python-projects/cpython/./Tools/build/check_extension_modules.py", line 171, in check    self.check_module_import(modinfo)  File "/home/kalyan/oss/python-projects/cpython/./Tools/build/check_extension_modules.py", line 412, in check_module_import    bootstrap_load(spec)  File "<frozen importlib._bootstrap>", line 960, in _load  File "<frozen importlib._bootstrap>", line 915, in _load_unlocked  File "<frozen importlib._bootstrap>", line 813, in module_from_spec  File "<frozen importlib._bootstrap_external>", line 1302, in create_module  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removedValueError: module functions cannot set METH_CLASS or METH_STATICmake: *** [Makefile:1177: checksharedmods] Error 1

But, when I include{NULL} like below, I am able to run make without any issues:

static PyMethodDef test_methods[] = {    {"list_check", list_check, METH_O},    {"list_check_exact", list_check_exact, METH_O},    {"list_new", list_new, METH_O},    {"list_size", list_size, METH_O},    {NULL},};

Signed-off-by: kalyanr <kalyan.ben10@live.com>
Signed-off-by: kalyanr <kalyan.ben10@live.com>
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh! I wrote a very similar PR yesterday! I have a few more tests.

rawwar reacted with eyes emoji
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

See also#111582. It would be nice if you with@vstinner unite your works.

lst = [1, 2, NULL]
self.assertEqual(getitem(lst, 0), 1)
self.assertRaises(IndexError, getitem, lst, -1)
self.assertRaises(IndexError, getitem, lst, 10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Add tests for index equal to the size of the list,PY_SSIZE_T_MIN,PY_SSIZE_T_MAX (imported from_testcapi).

All functions that have Py_ssize_t parameter should be tested with the following values: 0, size-1, -1, size,PY_SSIZE_T_MIN,PY_SSIZE_T_MAX.

rawwar reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For methods likeslice, they accept multiplePy_ssize_t parameters. Should each of these parameters be tested with the values you mentioned?

rawwarand others added5 commitsNovember 1, 2023 15:36
Signed-off-by: kalyanr <kalyan.ben10@live.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@rawwar
Copy link
ContributorAuthor

rawwar commentedNov 1, 2023
edited
Loading

@vstinner , What can we do now? I'm not sure If I should continue working on this PR? Although, I also added tests forPy_LIMITED_API ones as well.
I am also planning on contributing tests forPyTuple. let me know if I can go ahead with that

Signed-off-by: kalyanr <kalyan.ben10@live.com>
}
NULLABLE(obj);
NULLABLE(value);
RETURN_INT(PyList_SetSlice(obj, ilow, ihigh, Py_XNewRef(value)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Py_XNewRef() is wrong and causes a reference leak.

}
NULLABLE(obj);
NULLABLE(value);
RETURN_INT(PyList_Append(obj, Py_XNewRef(value)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Py_XNewRef() is wrong and causes a reference leak.

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you@rawwar.

I had too much minor suggestions, so I simply applied them myself.

Now it LGTM.

Comment on lines 116 to 117
self.assertRaises(TypeError, setitem, lst, 1.5, 10)
self.assertRaises(TypeError, setitem, 23, 'a', 5)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It only tests the wrapper, not the C API function.

@vstinner
Copy link
Member

I merged your PR@rawwar, thanks for adding tests for the PyList API!

@serhiy-storchakaserhiy-storchaka added the needs backport to 3.12only security fixes labelNov 8, 2023
@miss-islington-app
Copy link

Thanks@rawwar for the PR, and@vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 8, 2023
(cherry picked from commita3903c8)Co-authored-by: Kalyan <kalyan.ben10@live.com>Signed-off-by: kalyanr <kalyan.ben10@live.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

GH-111861 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelNov 8, 2023
serhiy-storchaka added a commit that referenced this pull requestNov 8, 2023
(cherry picked from commita3903c8)Signed-off-by: kalyanr <kalyan.ben10@live.com>Co-authored-by: Kalyan <kalyan.ben10@live.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
Signed-off-by: kalyanr <kalyan.ben10@live.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
Signed-off-by: kalyanr <kalyan.ben10@live.com>Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@rawwar@vstinner@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp