New submission from Matthieu Dartiailh <m.dartia...@gmail.com>:

When constructing bytecode object manually as can be done using the bytecode 
library (https://github.com/MatthieuDartiailh/bytecode which was first 
developed by V Stinner), one can use dis.stack_effect to compute the required 
stack size, thus avoiding stack overflows.

However it can be interesting for those manually built bytecode object to also 
check that no underflow can occur. This computation is straightforward once one 
knows the number of element on the stack a specific opcode expects. 

This works has been done manually in the bytecode project, but it may 
interesting to provide a way in the dis module to access this information with 
an interface similar to dis.stack_effect.

If there is an interest in such a feature I would be happy to contribute it. I 
would however like some opinion on how to do that in an optimal manner. I 
assume it would require to add the implementation in 
https://github.com/python/cpython/blob/master/Python/compile.c and expose it in 
a similar manner to stack_effect.

----------
components: Library (Lib)
messages: 386494
nosy: mdartiailh
priority: normal
severity: normal
status: open
title: Number of object on stack required by opcode
type: enhancement
versions: Python 3.10

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

Reply via email to