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
ae7bf1a5
Commit
ae7bf1a5
authored
Jan 17, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix reentrancy bug in slice assignment
parent
ba0b6aed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
Objects/listobject.c
Objects/listobject.c
+20
-4
No files found.
Objects/listobject.c
View file @
ae7bf1a5
...
...
@@ -368,6 +368,13 @@ list_ass_slice(a, ilow, ihigh, v)
int
ilow
,
ihigh
;
object
*
v
;
{
/* Because [X]DECREF can recursively invoke list operations on
this list, we must postpone all [X]DECREF activity until
after the list is back in its canonical shape. Therefore
we must allocate an additional array, 'recycle', into which
we temporarily copy the items that are deleted from the
list. :-( */
object
**
recycle
,
**
p
;
object
**
item
;
int
n
;
/* Size of replacement list */
int
d
;
/* Change in size */
...
...
@@ -402,9 +409,13 @@ list_ass_slice(a, ilow, ihigh, v)
ihigh
=
a
->
ob_size
;
item
=
a
->
ob_item
;
d
=
n
-
(
ihigh
-
ilow
);
if
(
d
<=
0
)
{
/* Delete -d items; XDECREF ihigh-ilow items */
if
(
ihigh
>
ilow
)
p
=
recycle
=
NEW
(
object
*
,
(
ihigh
-
ilow
));
else
p
=
recycle
=
NULL
;
if
(
d
<=
0
)
{
/* Delete -d items; recycle ihigh-ilow items */
for
(
k
=
ilow
;
k
<
ihigh
;
k
++
)
XDECREF
(
item
[
k
]);
/* bug: reentrant side effects */
*
p
++
=
item
[
k
];
if
(
d
<
0
)
{
for
(
/*k = ihigh*/
;
k
<
a
->
ob_size
;
k
++
)
item
[
k
+
d
]
=
item
[
k
];
...
...
@@ -413,7 +424,7 @@ list_ass_slice(a, ilow, ihigh, v)
a
->
ob_item
=
item
;
}
}
else
{
/* Insert d items;
XDECREF
ihigh-ilow items */
else
{
/* Insert d items;
recycle
ihigh-ilow items */
RESIZE
(
item
,
object
*
,
a
->
ob_size
+
d
);
if
(
item
==
NULL
)
{
err_nomem
();
...
...
@@ -422,7 +433,7 @@ list_ass_slice(a, ilow, ihigh, v)
for
(
k
=
a
->
ob_size
;
--
k
>=
ihigh
;
)
item
[
k
+
d
]
=
item
[
k
];
for
(
/*k = ihigh-1*/
;
k
>=
ilow
;
--
k
)
XDECREF
(
item
[
k
]);
/* bug: side effects :-( */
*
p
++
=
item
[
k
];
a
->
ob_item
=
item
;
a
->
ob_size
+=
d
;
}
...
...
@@ -431,6 +442,11 @@ list_ass_slice(a, ilow, ihigh, v)
XINCREF
(
w
);
item
[
ilow
]
=
w
;
}
if
(
recycle
)
{
while
(
--
p
>=
recycle
)
XDECREF
(
*
p
);
DEL
(
recycle
);
}
return
0
;
#undef b
}
...
...
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