Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c740e4fe
Kaydet (Commit)
c740e4fe
authored
Eyl 26, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Eyl 26, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (#1557)
üst
114454e9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
36 deletions
+56
-36
test_itertools.py
Lib/test/test_itertools.py
+24
-0
2017-09-25-14-04-30.bpo-30347.B4--_D.rst
...S.d/next/Library/2017-09-25-14-04-30.bpo-30347.B4--_D.rst
+1
-0
itertoolsmodule.c
Modules/itertoolsmodule.c
+31
-36
No files found.
Lib/test/test_itertools.py
Dosyayı görüntüle @
c740e4fe
...
...
@@ -2017,6 +2017,30 @@ class RegressionTests(unittest.TestCase):
with
self
.
assertRaises
(
StopIteration
):
next
(
it
)
def
test_issue30347_1
(
self
):
def
f
(
n
):
if
n
==
5
:
list
(
b
)
return
n
!=
6
for
(
k
,
b
)
in
groupby
(
range
(
10
),
f
):
list
(
b
)
# shouldn't crash
def
test_issue30347_2
(
self
):
class
K
:
def
__init__
(
self
,
v
):
pass
def
__eq__
(
self
,
other
):
nonlocal
i
i
+=
1
if
i
==
1
:
next
(
g
,
None
)
return
True
i
=
0
g
=
next
(
groupby
(
range
(
10
),
K
))[
1
]
for
j
in
range
(
2
):
next
(
g
,
None
)
# shouldn't crash
class
SubclassWithKwargsTest
(
unittest
.
TestCase
):
def
test_keywords_in_subclass
(
self
):
# count is not subclassable...
...
...
Misc/NEWS.d/next/Library/2017-09-25-14-04-30.bpo-30347.B4--_D.rst
0 → 100644
Dosyayı görüntüle @
c740e4fe
Stop crashes when concurrently iterate over itertools.groupby() iterators.
Modules/itertoolsmodule.c
Dosyayı görüntüle @
c740e4fe
...
...
@@ -73,10 +73,37 @@ groupby_traverse(groupbyobject *gbo, visitproc visit, void *arg)
return
0
;
}
Py_LOCAL_INLINE
(
int
)
groupby_step
(
groupbyobject
*
gbo
)
{
PyObject
*
newvalue
,
*
newkey
,
*
oldvalue
;
newvalue
=
PyIter_Next
(
gbo
->
it
);
if
(
newvalue
==
NULL
)
return
-
1
;
if
(
gbo
->
keyfunc
==
Py_None
)
{
newkey
=
newvalue
;
Py_INCREF
(
newvalue
);
}
else
{
newkey
=
PyObject_CallFunctionObjArgs
(
gbo
->
keyfunc
,
newvalue
,
NULL
);
if
(
newkey
==
NULL
)
{
Py_DECREF
(
newvalue
);
return
-
1
;
}
}
oldvalue
=
gbo
->
currvalue
;
gbo
->
currvalue
=
newvalue
;
Py_XSETREF
(
gbo
->
currkey
,
newkey
);
Py_XDECREF
(
oldvalue
);
return
0
;
}
static
PyObject
*
groupby_next
(
groupbyobject
*
gbo
)
{
PyObject
*
newvalue
,
*
newkey
,
*
r
,
*
grouper
;
PyObject
*
r
,
*
grouper
;
gbo
->
currgrouper
=
NULL
;
/* skip to next iteration group */
...
...
@@ -95,25 +122,9 @@ groupby_next(groupbyobject *gbo)
break
;
}
newvalue
=
PyIter_Next
(
gbo
->
it
);
if
(
newvalue
==
NULL
)
if
(
groupby_step
(
gbo
)
<
0
)
return
NULL
;
if
(
gbo
->
keyfunc
==
Py_None
)
{
newkey
=
newvalue
;
Py_INCREF
(
newvalue
);
}
else
{
newkey
=
PyObject_CallFunctionObjArgs
(
gbo
->
keyfunc
,
newvalue
,
NULL
);
if
(
newkey
==
NULL
)
{
Py_DECREF
(
newvalue
);
return
NULL
;
}
}
Py_XSETREF
(
gbo
->
currkey
,
newkey
);
Py_XSETREF
(
gbo
->
currvalue
,
newvalue
);
}
Py_INCREF
(
gbo
->
currkey
);
Py_XSETREF
(
gbo
->
tgtkey
,
gbo
->
currkey
);
...
...
@@ -285,30 +296,14 @@ static PyObject *
_grouper_next
(
_grouperobject
*
igo
)
{
groupbyobject
*
gbo
=
(
groupbyobject
*
)
igo
->
parent
;
PyObject
*
newvalue
,
*
newkey
,
*
r
;
PyObject
*
r
;
int
rcmp
;
if
(
gbo
->
currgrouper
!=
igo
)
return
NULL
;
if
(
gbo
->
currvalue
==
NULL
)
{
newvalue
=
PyIter_Next
(
gbo
->
it
);
if
(
newvalue
==
NULL
)
if
(
groupby_step
(
gbo
)
<
0
)
return
NULL
;
if
(
gbo
->
keyfunc
==
Py_None
)
{
newkey
=
newvalue
;
Py_INCREF
(
newvalue
);
}
else
{
newkey
=
PyObject_CallFunctionObjArgs
(
gbo
->
keyfunc
,
newvalue
,
NULL
);
if
(
newkey
==
NULL
)
{
Py_DECREF
(
newvalue
);
return
NULL
;
}
}
assert
(
gbo
->
currkey
==
NULL
);
gbo
->
currkey
=
newkey
;
gbo
->
currvalue
=
newvalue
;
}
assert
(
gbo
->
currkey
!=
NULL
);
...
...
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