Issue 811294: dis.disassemble_string() broken - Python tracker (original) (raw)

Created on 2003-09-23 17:23 by arigo, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
dis.diff arigo,2003-09-26 10:20 braindead fix
dis-extra.diff arigo,2003-09-26 11:07 adding a nice (offset, lineno) generator
Messages (6)
msg18306 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2003-09-23 17:23
dis.disassemble_string(), called by dis.dis("some-bytecode-string"), still relies on the dead SET_LINENO opcode. I'll propose a patch for this at some later time.
msg18307 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2003-09-26 10:20
Logged In: YES user_id=4771 ah well. I didn't realize that disassemble_string() never tried to *display* line numbers. It only detects SET_LINENO so that it can write a nice blank line before it. Attached a patch that removes this behavior (no longer possible in a function that doesn't have access to a co_lnotab). I'll submit another more constructive patch anyway, in which I try to factor out the subtle decoding algorithm for co_lnotabs into an easy-to-use generator.
msg18308 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2003-09-26 11:07
Logged In: YES user_id=4771 Here is a patch with a separate generator function that enumerates all (offset, lineno) pairs, as they where in the compiler before they got obfuscated into lnotab. For simplicity, disassemble() just turns them into a dict, so it didn't really have to be a generator at all, but it is just nicer this way. Maybe pdb could use it too.
msg18309 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2003-10-16 12:55
Logged In: YES user_id=6656 I think I trust Armin on stuff like this
msg18310 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2003-10-16 13:16
Logged In: YES user_id=4771 Do we want findlinestarts() to be added to the public interface of dis? I think it is a generally useful tool (e.g. it could be used in trace.py too, though I don't understand trace.py well enough to know if the easy patch does exactly what is expected). I can write a doc patch if the answer is yes.
msg18311 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2003-10-28 12:17
Logged In: YES user_id=4771 findlinestarts() not documented. Its docstring should be enough to interest people that want to play with co_lnotab. Checked in: Lib/dis.py (rev: 1.47)
History
Date User Action Args
2022-04-10 16:11:19 admin set github: 39285
2003-09-23 17:23:36 arigo create