Skip to content

Commit a59d6db

Browse files
committed
Safer implementation of move_gens_to_heap()
1 parent b980e64 commit a59d6db

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cypari2/stack.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,20 @@ cdef int move_gens_to_heap(pari_sp lim) except -1:
118118
avma <= lim.
119119
"""
120120
while avma <= lim and stackbottom is not <PyObject*>top_of_stack:
121-
sig_on()
122121
current = <Gen>stackbottom
123-
h = gclone(current.g)
122+
sig_on()
123+
current.g = gclone(current.g)
124124
sig_off()
125125
remove_from_pari_stack(current)
126-
current.g = current.address = h
126+
# The .address attribute can only be updated now because it is
127+
# needed in remove_from_pari_stack(). This means that the object
128+
# is temporarily in an inconsistent state but this does not
129+
# matter since .address is normally not used.
130+
#
131+
# The more important .g attribute is updated correctly before
132+
# remove_from_pari_stack(). Therefore, the object can be used
133+
# normally regardless of what happens to the PARI stack.
134+
current.address = current.g
127135

128136

129137
cdef Gen new_gen(GEN x):

0 commit comments

Comments
 (0)