Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7bb50277
Commit
7bb50277
authored
Jan 30, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dis(): Simplified stack emulation a bit.
parent
ddc857df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
Lib/pickletools.py
Lib/pickletools.py
+16
-14
No files found.
Lib/pickletools.py
View file @
7bb50277
...
@@ -1898,15 +1898,19 @@ def dis(pickle, out=None, indentlevel=4):
...
@@ -1898,15 +1898,19 @@ def dis(pickle, out=None, indentlevel=4):
opcode
.
name
)
opcode
.
name
)
maxproto
=
max
(
maxproto
,
opcode
.
proto
)
maxproto
=
max
(
maxproto
,
opcode
.
proto
)
# See whether a MARK should be popped.
before
=
opcode
.
stack_before
# don't mutate
before
=
opcode
.
stack_before
# don't mutate
after
=
opcode
.
stack_after
# don't mutate
after
=
opcode
.
stack_after
# don't mutate
numtopop
=
len
(
before
)
# See whether a MARK should be popped.
markmsg
=
None
markmsg
=
None
if
markobject
in
before
or
(
opcode
.
name
==
"POP"
and
if
markobject
in
before
or
(
opcode
.
name
==
"POP"
and
stack
and
stack
and
stack
[
-
1
]
is
markobject
):
stack
[
-
1
]
is
markobject
):
assert
markobject
not
in
after
assert
markobject
not
in
after
if
__debug__
:
if
markobject
in
before
:
assert
before
[
-
1
]
is
stackslice
if
markstack
:
if
markstack
:
markpos
=
markstack
.
pop
()
markpos
=
markstack
.
pop
()
if
markpos
is
None
:
if
markpos
is
None
:
...
@@ -1917,19 +1921,18 @@ def dis(pickle, out=None, indentlevel=4):
...
@@ -1917,19 +1921,18 @@ def dis(pickle, out=None, indentlevel=4):
while
stack
[
-
1
]
is
not
markobject
:
while
stack
[
-
1
]
is
not
markobject
:
stack
.
pop
()
stack
.
pop
()
stack
.
pop
()
stack
.
pop
()
#
Remove markobject stuff from stack_before
.
#
Stop later code from popping too much
.
try
:
try
:
i
=
before
.
index
(
markobject
)
numtopop
=
before
.
index
(
markobject
)
before
=
before
[:
i
]
except
ValueError
:
except
ValueError
:
assert
opcode
.
name
==
"POP"
assert
opcode
.
name
==
"POP"
assert
len
(
before
)
==
1
numtopop
=
0
before
=
[]
# stop code later from popping again
else
:
else
:
errormsg
=
markmsg
=
"no MARK exists on stack"
errormsg
=
markmsg
=
"no MARK exists on stack"
# Check for correct memo usage.
# Check for correct memo usage.
if
opcode
.
name
in
(
"PUT"
,
"BINPUT"
,
"LONG_BINPUT"
):
if
opcode
.
name
in
(
"PUT"
,
"BINPUT"
,
"LONG_BINPUT"
):
assert
arg
is
not
None
if
arg
in
memo
:
if
arg
in
memo
:
errormsg
=
"memo key %r already defined"
%
arg
errormsg
=
"memo key %r already defined"
%
arg
elif
not
stack
:
elif
not
stack
:
...
@@ -1961,14 +1964,13 @@ def dis(pickle, out=None, indentlevel=4):
...
@@ -1961,14 +1964,13 @@ def dis(pickle, out=None, indentlevel=4):
raise
ValueError
(
errormsg
)
raise
ValueError
(
errormsg
)
# Emulate the stack effects.
# Emulate the stack effects.
n
=
len
(
before
)
if
len
(
stack
)
<
numtopop
:
if
len
(
stack
)
<
n
:
raise
ValueError
(
"tries to pop %d items from stack with "
raise
ValueError
(
"tried to pop %d items from stack with "
"only %d items"
%
(
numtopop
,
len
(
stack
)))
"only %d items"
%
(
n
,
len
(
stack
)))
if
numtopop
:
if
n
:
del
stack
[
-
numtopop
:]
del
stack
[
-
n
:]
if
markobject
in
after
:
if
markobject
in
after
:
assert
markobject
not
in
opcode
.
stack_
before
assert
markobject
not
in
before
markstack
.
append
(
pos
)
markstack
.
append
(
pos
)
stack
.
extend
(
after
)
stack
.
extend
(
after
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment