hydroflask <hydrofl...@yqxmail.com> added the comment:

Two things, one is a nit pick the other is more serious. I think vstinner 
mentioned this in his review of your patch but on this line:

https://github.com/python/cpython/commit/b5527688aae11d0b5af58176267a9943576e71e5#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139dR180

Instead of using PySequence_Fast_ITEMS(), you can just use PyTuple_GET_ITEM() 
since you know the converters are a tuple. In terms of runtime efficiency it 
doesn't change anything but is consistent with this line: 
https://github.com/python/cpython/commit/b5527688aae11d0b5af58176267a9943576e71e5#diff-706e65ee28911740bf638707e19578b8182e57c6a8a9a4a91105d825f95a139dR157

Though on second thought I think PySequence_Fast_ITEMS() is probably a better 
API overall in terms of efficiency if PyTuple_GET_ITEM() would eventually 
become a real function call given the long term push toward a stable API.

The other issue is more serious, you are always allocating an array of 
CTYPES_MAX_ARGCOUNT pointers on the stack on every C callback. This could cause 
stack overflows in situations where a relatively deep set of callbacks are 
invoked. This usage of CTYPES_MAX_ARGCOUNT differs its usage in callproc.c, 
where in that case `alloca()` is used to allocate the specific number of array 
entries on the stack. To avoid an unintended stack overflow I would use 
alloca() or if you don't like alloca() I would only allocate a relatively small 
constant number on the stack.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46323>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to