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
a5fe3ef8
Kaydet (Commit)
a5fe3ef8
authored
Eki 08, 2006
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix #1569998: no break inside try statement (outside loop) allowed.
(backport from rev. 52129)
üst
74284b96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
test_syntax.py
Lib/test/test_syntax.py
+14
-0
NEWS
Misc/NEWS
+3
-0
compile.c
Python/compile.c
+13
-1
No files found.
Lib/test/test_syntax.py
Dosyayı görüntüle @
a5fe3ef8
...
...
@@ -319,6 +319,20 @@ This is essentially a continue in a finally which should not be allowed.
...
SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[41]>, line 8)
There is one test for a break that is not in a loop. The compiler
uses a single data structure to keep track of try-finally and loops,
so we need to be sure that a break is actually inside a loop. If it
isn't, there should be a syntax error.
>>> try:
... print 1
... break
... print 2
... finally:
... print 3
Traceback (most recent call last):
...
SyntaxError: 'break' outside loop (<doctest test.test_syntax[42]>, line 3)
"""
import
re
...
...
Misc/NEWS
Dosyayı görüntüle @
a5fe3ef8
...
...
@@ -12,6 +12,9 @@ What's New in Python 2.5.1c1?
Core and builtins
-----------------
- Bug #1569998: break inside a try statement (outside a loop) is now
recognized and rejected.
- Patch #1542451: disallow continue anywhere under a finally.
- list.pop(x) accepts any object x following the __index__ protocol.
...
...
Python/compile.c
Dosyayı görüntüle @
a5fe3ef8
...
...
@@ -187,6 +187,8 @@ static int compiler_push_fblock(struct compiler *, enum fblocktype,
basicblock
*
);
static
void
compiler_pop_fblock
(
struct
compiler
*
,
enum
fblocktype
,
basicblock
*
);
/* Returns true if there is a loop on the fblock stack. */
static
int
compiler_in_loop
(
struct
compiler
*
);
static
int
inplace_binop
(
struct
compiler
*
,
operator_ty
);
static
int
expr_constant
(
expr_ty
e
);
...
...
@@ -2764,7 +2766,7 @@ compiler_visit_stmt(struct compiler *c, stmt_ty s)
case
Pass_kind
:
break
;
case
Break_kind
:
if
(
!
c
->
u
->
u_nfblocks
)
if
(
!
compiler_in_loop
(
c
)
)
return
compiler_error
(
c
,
"'break' outside loop"
);
ADDOP
(
c
,
BREAK_LOOP
);
break
;
...
...
@@ -3754,6 +3756,16 @@ compiler_pop_fblock(struct compiler *c, enum fblocktype t, basicblock *b)
assert
(
u
->
u_fblock
[
u
->
u_nfblocks
].
fb_block
==
b
);
}
static
int
compiler_in_loop
(
struct
compiler
*
c
)
{
int
i
;
struct
compiler_unit
*
u
=
c
->
u
;
for
(
i
=
0
;
i
<
u
->
u_nfblocks
;
++
i
)
{
if
(
u
->
u_fblock
[
i
].
fb_type
==
LOOP
)
return
1
;
}
return
0
;
}
/* Raises a SyntaxError and returns 0.
If something goes wrong, a different exception may be raised.
*/
...
...
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