FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-143191: Use _PyOS_MIN_STACK_SIZE in _thread.stack_size() by vstinner · Pull Request #143601 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 8 additions & 0 deletions Lib/test/test_thread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def test_stack_size(self):
thread.stack_size(0)
self.assertEqual(thread.stack_size(), 0, "stack_size not reset to default")

with self.assertRaises(ValueError):
# 123 bytes is too small
thread.stack_size(123)

with self.assertRaises(ValueError):
# size must be positive
thread.stack_size(-4096)

@unittest.skipIf(os.name not in ("nt", "posix"), 'test meant for nt and posix')
def test_nt_and_posix_stack_size(self):
try:
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`_thread.stack_size` now raises :exc:`ValueError` if the stack size is
too small. Patch by Victor Stinner.
7 changes: 4 additions & 3 deletions Modules/_threadmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2200,9 +2200,10 @@ thread_stack_size(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|n:stack_size", &new_size))
return NULL;

if (new_size < 0) {
PyErr_SetString(PyExc_ValueError,
"size must be 0 or a positive value");
Py_ssize_t min_size = _PyOS_MIN_STACK_SIZE + SYSTEM_PAGE_SIZE;
if (new_size != 0 && new_size < min_size) {
PyErr_Format(PyExc_ValueError,
"size must be at least %zi bytes", min_size);
return NULL;
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL