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
70f52768
Kaydet (Commit)
70f52768
authored
Haz 28, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
In most cases, the parser will protect True, False, and None from being assign to.
We must check for __debug__ in all cases.
üst
1d180684
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
13 deletions
+38
-13
ast.c
Python/ast.c
+38
-13
No files found.
Python/ast.c
Dosyayı görüntüle @
70f52768
...
@@ -357,19 +357,24 @@ static const char* FORBIDDEN[] = {
...
@@ -357,19 +357,24 @@ static const char* FORBIDDEN[] = {
"None"
,
"None"
,
"True"
,
"True"
,
"False"
,
"False"
,
"__debug__"
,
NULL
,
NULL
,
};
};
static
int
static
int
forbidden_name
(
identifier
name
,
const
node
*
n
)
forbidden_name
(
identifier
name
,
const
node
*
n
,
int
full_checks
)
{
{
const
char
**
p
;
assert
(
PyUnicode_Check
(
name
));
assert
(
PyUnicode_Check
(
name
));
for
(
p
=
FORBIDDEN
;
*
p
;
p
++
)
{
if
(
PyUnicode_CompareWithASCIIString
(
name
,
"__debug__"
)
==
0
)
{
if
(
PyUnicode_CompareWithASCIIString
(
name
,
*
p
)
==
0
)
{
ast_error
(
n
,
"assignment to keyword"
);
ast_error
(
n
,
"assignment to keyword"
);
return
1
;
return
1
;
}
if
(
full_checks
)
{
const
char
**
p
;
for
(
p
=
FORBIDDEN
;
*
p
;
p
++
)
{
if
(
PyUnicode_CompareWithASCIIString
(
name
,
*
p
)
==
0
)
{
ast_error
(
n
,
"assignment to keyword"
);
return
1
;
}
}
}
}
}
return
0
;
return
0
;
...
@@ -403,6 +408,8 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
...
@@ -403,6 +408,8 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
switch
(
e
->
kind
)
{
switch
(
e
->
kind
)
{
case
Attribute_kind
:
case
Attribute_kind
:
e
->
v
.
Attribute
.
ctx
=
ctx
;
e
->
v
.
Attribute
.
ctx
=
ctx
;
if
(
ctx
==
Store
&&
forbidden_name
(
e
->
v
.
Attribute
.
attr
,
n
,
1
))
return
0
;
break
;
break
;
case
Subscript_kind
:
case
Subscript_kind
:
e
->
v
.
Subscript
.
ctx
=
ctx
;
e
->
v
.
Subscript
.
ctx
=
ctx
;
...
@@ -414,7 +421,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
...
@@ -414,7 +421,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n)
break
;
break
;
case
Name_kind
:
case
Name_kind
:
if
(
ctx
==
Store
)
{
if
(
ctx
==
Store
)
{
if
(
forbidden_name
(
e
->
v
.
Name
.
id
,
n
))
if
(
forbidden_name
(
e
->
v
.
Name
.
id
,
n
,
1
))
return
0
;
/* forbidden_name() calls ast_error() */
return
0
;
/* forbidden_name() calls ast_error() */
}
}
e
->
v
.
Name
.
ctx
=
ctx
;
e
->
v
.
Name
.
ctx
=
ctx
;
...
@@ -631,6 +638,8 @@ compiler_arg(struct compiling *c, const node *n)
...
@@ -631,6 +638,8 @@ compiler_arg(struct compiling *c, const node *n)
name
=
NEW_IDENTIFIER
(
ch
);
name
=
NEW_IDENTIFIER
(
ch
);
if
(
!
name
)
if
(
!
name
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
name
,
ch
,
0
))
return
NULL
;
if
(
NCH
(
n
)
==
3
&&
TYPE
(
CHILD
(
n
,
1
))
==
COLON
)
{
if
(
NCH
(
n
)
==
3
&&
TYPE
(
CHILD
(
n
,
1
))
==
COLON
)
{
annotation
=
ast_for_expr
(
c
,
CHILD
(
n
,
2
));
annotation
=
ast_for_expr
(
c
,
CHILD
(
n
,
2
));
...
@@ -697,6 +706,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
...
@@ -697,6 +706,8 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
argname
=
NEW_IDENTIFIER
(
ch
);
argname
=
NEW_IDENTIFIER
(
ch
);
if
(
!
argname
)
if
(
!
argname
)
goto
error
;
goto
error
;
if
(
forbidden_name
(
argname
,
ch
,
0
))
goto
error
;
arg
=
arg
(
argname
,
annotation
,
c
->
c_arena
);
arg
=
arg
(
argname
,
annotation
,
c
->
c_arena
);
if
(
!
arg
)
if
(
!
arg
)
goto
error
;
goto
error
;
...
@@ -855,6 +866,8 @@ ast_for_arguments(struct compiling *c, const node *n)
...
@@ -855,6 +866,8 @@ ast_for_arguments(struct compiling *c, const node *n)
vararg
=
NEW_IDENTIFIER
(
CHILD
(
ch
,
0
));
vararg
=
NEW_IDENTIFIER
(
CHILD
(
ch
,
0
));
if
(
!
vararg
)
if
(
!
vararg
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
vararg
,
CHILD
(
ch
,
0
),
0
))
return
NULL
;
if
(
NCH
(
ch
)
>
1
)
{
if
(
NCH
(
ch
)
>
1
)
{
/* there is an annotation on the vararg */
/* there is an annotation on the vararg */
varargannotation
=
ast_for_expr
(
c
,
CHILD
(
ch
,
2
));
varargannotation
=
ast_for_expr
(
c
,
CHILD
(
ch
,
2
));
...
@@ -880,6 +893,8 @@ ast_for_arguments(struct compiling *c, const node *n)
...
@@ -880,6 +893,8 @@ ast_for_arguments(struct compiling *c, const node *n)
}
}
if
(
!
kwarg
)
if
(
!
kwarg
)
goto
error
;
goto
error
;
if
(
forbidden_name
(
kwarg
,
CHILD
(
ch
,
0
),
0
))
goto
error
;
i
+=
3
;
i
+=
3
;
break
;
break
;
default:
default:
...
@@ -1001,6 +1016,8 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
...
@@ -1001,6 +1016,8 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
name
=
NEW_IDENTIFIER
(
CHILD
(
n
,
name_i
));
name
=
NEW_IDENTIFIER
(
CHILD
(
n
,
name_i
));
if
(
!
name
)
if
(
!
name
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
name
,
CHILD
(
n
,
name_i
),
0
))
return
NULL
;
args
=
ast_for_arguments
(
c
,
CHILD
(
n
,
name_i
+
1
));
args
=
ast_for_arguments
(
c
,
CHILD
(
n
,
name_i
+
1
));
if
(
!
args
)
if
(
!
args
)
return
NULL
;
return
NULL
;
...
@@ -2010,7 +2027,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
...
@@ -2010,7 +2027,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
}
else
if
(
e
->
kind
!=
Name_kind
)
{
}
else
if
(
e
->
kind
!=
Name_kind
)
{
ast_error
(
CHILD
(
ch
,
0
),
"keyword can't be an expression"
);
ast_error
(
CHILD
(
ch
,
0
),
"keyword can't be an expression"
);
return
NULL
;
return
NULL
;
}
else
if
(
forbidden_name
(
e
->
v
.
Name
.
id
,
ch
))
{
}
else
if
(
forbidden_name
(
e
->
v
.
Name
.
id
,
ch
,
1
))
{
return
NULL
;
return
NULL
;
}
}
key
=
e
->
v
.
Name
.
id
;
key
=
e
->
v
.
Name
.
id
;
...
@@ -2279,11 +2296,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
...
@@ -2279,11 +2296,11 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
str
=
NEW_IDENTIFIER
(
str_node
);
str
=
NEW_IDENTIFIER
(
str_node
);
if
(
!
str
)
if
(
!
str
)
return
NULL
;
return
NULL
;
if
(
store
&&
forbidden_name
(
str
,
str_node
))
if
(
store
&&
forbidden_name
(
str
,
str_node
,
0
))
return
NULL
;
return
NULL
;
}
}
else
{
else
{
if
(
forbidden_name
(
name
,
name_node
))
if
(
forbidden_name
(
name
,
name_node
,
0
))
return
NULL
;
return
NULL
;
}
}
return
alias
(
name
,
str
,
c
->
c_arena
);
return
alias
(
name
,
str
,
c
->
c_arena
);
...
@@ -2302,7 +2319,7 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
...
@@ -2302,7 +2319,7 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
a
->
asname
=
NEW_IDENTIFIER
(
asname_node
);
a
->
asname
=
NEW_IDENTIFIER
(
asname_node
);
if
(
!
a
->
asname
)
if
(
!
a
->
asname
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
a
->
asname
,
asname_node
))
if
(
forbidden_name
(
a
->
asname
,
asname_node
,
0
))
return
NULL
;
return
NULL
;
return
a
;
return
a
;
}
}
...
@@ -2313,7 +2330,7 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
...
@@ -2313,7 +2330,7 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
name
=
NEW_IDENTIFIER
(
name_node
);
name
=
NEW_IDENTIFIER
(
name_node
);
if
(
!
name
)
if
(
!
name
)
return
NULL
;
return
NULL
;
if
(
store
&&
forbidden_name
(
name
,
name_node
))
if
(
store
&&
forbidden_name
(
name
,
name_node
,
0
))
return
NULL
;
return
NULL
;
return
alias
(
name
,
NULL
,
c
->
c_arena
);
return
alias
(
name
,
NULL
,
c
->
c_arena
);
}
}
...
@@ -2853,6 +2870,8 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
...
@@ -2853,6 +2870,8 @@ ast_for_except_clause(struct compiling *c, const node *exc, node *body)
identifier
e
=
NEW_IDENTIFIER
(
CHILD
(
exc
,
3
));
identifier
e
=
NEW_IDENTIFIER
(
CHILD
(
exc
,
3
));
if
(
!
e
)
if
(
!
e
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
e
,
CHILD
(
exc
,
3
),
0
))
return
NULL
;
expression
=
ast_for_expr
(
c
,
CHILD
(
exc
,
1
));
expression
=
ast_for_expr
(
c
,
CHILD
(
exc
,
1
));
if
(
!
expression
)
if
(
!
expression
)
return
NULL
;
return
NULL
;
...
@@ -3023,6 +3042,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
...
@@ -3023,6 +3042,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
if
(
!
classname
)
if
(
!
classname
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
classname
,
CHILD
(
n
,
3
),
0
))
return
NULL
;
return
ClassDef
(
classname
,
NULL
,
NULL
,
NULL
,
NULL
,
s
,
decorator_seq
,
return
ClassDef
(
classname
,
NULL
,
NULL
,
NULL
,
NULL
,
s
,
decorator_seq
,
LINENO
(
n
),
n
->
n_col_offset
,
c
->
c_arena
);
LINENO
(
n
),
n
->
n_col_offset
,
c
->
c_arena
);
}
}
...
@@ -3034,6 +3055,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
...
@@ -3034,6 +3055,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
if
(
!
classname
)
if
(
!
classname
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
classname
,
CHILD
(
n
,
3
),
0
))
return
NULL
;
return
ClassDef
(
classname
,
NULL
,
NULL
,
NULL
,
NULL
,
s
,
decorator_seq
,
return
ClassDef
(
classname
,
NULL
,
NULL
,
NULL
,
NULL
,
s
,
decorator_seq
,
LINENO
(
n
),
n
->
n_col_offset
,
c
->
c_arena
);
LINENO
(
n
),
n
->
n_col_offset
,
c
->
c_arena
);
}
}
...
@@ -3057,6 +3080,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
...
@@ -3057,6 +3080,8 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
classname
=
NEW_IDENTIFIER
(
CHILD
(
n
,
1
));
if
(
!
classname
)
if
(
!
classname
)
return
NULL
;
return
NULL
;
if
(
forbidden_name
(
classname
,
CHILD
(
n
,
1
),
0
))
return
NULL
;
return
ClassDef
(
classname
,
call
->
v
.
Call
.
args
,
call
->
v
.
Call
.
keywords
,
return
ClassDef
(
classname
,
call
->
v
.
Call
.
args
,
call
->
v
.
Call
.
keywords
,
call
->
v
.
Call
.
starargs
,
call
->
v
.
Call
.
kwargs
,
s
,
call
->
v
.
Call
.
starargs
,
call
->
v
.
Call
.
kwargs
,
s
,
...
...
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