-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-46323: Reduce stack usage of ctypes python callback function. #31224
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
Conversation
bc4d666
to
1bf3c7a
Compare
@@ -16,6 +16,11 @@ | |||
#include <ffi.h> | |||
#include "ctypes.h" | |||
|
|||
#ifdef HAVE_ALLOCA_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same workaroud
cpython/Modules/_ctypes/callproc.c
Lines 80 to 84 in 06e1701
#include "ctypes.h" | |
#ifdef HAVE_ALLOCA_H | |
/* AIX needs alloca.h for alloca() */ | |
#include <alloca.h> | |
#endif |
52f5730
to
dcabd85
Compare
dcabd85
to
3754856
Compare
To clarify, this prevents stackoverflow in situations with repeated calls where argcount is small, but will have roughly the same amount of stack usage when argcount is around 1000 (very rare) , right? |
@sweeneyde Correct and also a little performance issue (See benchmark) |
fef8e28
to
dd5aded
Compare
dd5aded
to
f4a276f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I think the title could be improved: "Reduce stack usage in Ctypes calls" or something. Right now, the mismatch is confusing between the title implying "use less stack" and the NEWS entry implying "use more stack". |
I've changed the title, Looks proper? |
@@ -0,0 +1,3 @@ | |||
:mod:`ctypes` now allocates memory on the stack instead of on the heap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no heap allocation directly before this PR, and there will be no heap allocation after, right? It's just eliminating that dead code path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sweeneyde Yeah but this is the result of bpo-46323
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Victor and I decided to add NEWS entry for all this change at this moment.
Theoretically, we had to add NEWS entry at the first PR, but it's too late.
The change and title LGTM! |
@sweeneyde |
https://bugs.python.org/issue46323