mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-33334: Support NOP and EXTENDED_ARG in dis.stack_effect(). (#6566)
Added tests to ensure that all defined opcodes are supported.
This commit is contained in:
parent
e9d9494d6b
commit
57faf34887
3 changed files with 21 additions and 0 deletions
|
@ -15,6 +15,21 @@ class OpcodeTests(unittest.TestCase):
|
||||||
self.assertRaises(ValueError, _opcode.stack_effect, 30000)
|
self.assertRaises(ValueError, _opcode.stack_effect, 30000)
|
||||||
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE'])
|
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['BUILD_SLICE'])
|
||||||
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0)
|
self.assertRaises(ValueError, _opcode.stack_effect, dis.opmap['POP_TOP'], 0)
|
||||||
|
# All defined opcodes
|
||||||
|
for name, code in dis.opmap.items():
|
||||||
|
with self.subTest(opname=name):
|
||||||
|
if code < dis.HAVE_ARGUMENT:
|
||||||
|
_opcode.stack_effect(code)
|
||||||
|
self.assertRaises(ValueError, _opcode.stack_effect, code, 0)
|
||||||
|
else:
|
||||||
|
_opcode.stack_effect(code, 0)
|
||||||
|
self.assertRaises(ValueError, _opcode.stack_effect, code)
|
||||||
|
# All not defined opcodes
|
||||||
|
for code in set(range(256)) - set(dis.opmap.values()):
|
||||||
|
with self.subTest(opcode=code):
|
||||||
|
self.assertRaises(ValueError, _opcode.stack_effect, code)
|
||||||
|
self.assertRaises(ValueError, _opcode.stack_effect, code, 0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
:func:`dis.stack_effect` now supports all defined opcodes including NOP and
|
||||||
|
EXTENDED_ARG.
|
|
@ -859,6 +859,10 @@ static int
|
||||||
stack_effect(int opcode, int oparg, int jump)
|
stack_effect(int opcode, int oparg, int jump)
|
||||||
{
|
{
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
case NOP:
|
||||||
|
case EXTENDED_ARG:
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Stack manipulation */
|
/* Stack manipulation */
|
||||||
case POP_TOP:
|
case POP_TOP:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue