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
fc489082
Commit
fc489082
authored
Jan 25, 2017
by
INADA Naoki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #29369: Use Py_IDENTIFIER in Python-ast.c
parent
6e08baf1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
14 deletions
+25
-14
Parser/asdl_c.py
Parser/asdl_c.py
+13
-8
Python/Python-ast.c
Python/Python-ast.c
+12
-6
No files found.
Parser/asdl_c.py
View file @
fc489082
...
...
@@ -622,6 +622,9 @@ class PyTypesVisitor(PickleVisitor):
def
visitModule
(
self
,
mod
):
self
.
emit
(
"""
_Py_IDENTIFIER(_fields);
_Py_IDENTIFIER(_attributes);
typedef struct {
PyObject_HEAD
PyObject *dict;
...
...
@@ -650,7 +653,6 @@ ast_clear(AST_object *self)
static int
ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
{
_Py_IDENTIFIER(_fields);
Py_ssize_t i, numfields = 0;
int res = -1;
PyObject *key, *value, *fields;
...
...
@@ -775,6 +777,8 @@ static PyTypeObject AST_type = {
static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields)
{
_Py_IDENTIFIER(__module__);
_Py_IDENTIFIER(_ast);
PyObject *fnames, *result;
int i;
fnames = PyTuple_New(num_fields);
...
...
@@ -787,8 +791,11 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
}
PyTuple_SET_ITEM(fnames, i, field);
}
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){sOss}",
type, base, "_fields", fnames, "__module__", "_ast");
result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
type, base,
_PyUnicode_FromId(&PyId__fields), fnames,
_PyUnicode_FromId(&PyId___module__),
_PyUnicode_FromId(&PyId__ast));
Py_DECREF(fnames);
return (PyTypeObject*)result;
}
...
...
@@ -796,7 +803,6 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
{
int i, result;
_Py_IDENTIFIER(_attributes);
PyObject *s, *l = PyTuple_New(num_fields);
if (!l)
return 0;
...
...
@@ -942,8 +948,8 @@ static int add_ast_fields(void)
d = AST_type.tp_dict;
empty_tuple = PyTuple_New(0);
if (!empty_tuple ||
PyDict_SetItemString(d, "_fields"
, empty_tuple) < 0 ||
PyDict_SetItemString(d, "_attributes"
, empty_tuple) < 0) {
_PyDict_SetItemId(d, &PyId__fields
, empty_tuple) < 0 ||
_PyDict_SetItemId(d, &PyId__attributes
, empty_tuple) < 0) {
Py_XDECREF(empty_tuple);
return -1;
}
...
...
@@ -1091,8 +1097,7 @@ class ObjVisitor(PickleVisitor):
self
.
emit
(
"%s o = (%s)_o;"
%
(
ctype
,
ctype
),
1
)
self
.
emit
(
"PyObject *result = NULL, *value = NULL;"
,
1
)
self
.
emit
(
'if (!o) {'
,
1
)
self
.
emit
(
"Py_INCREF(Py_None);"
,
2
)
self
.
emit
(
'return Py_None;'
,
2
)
self
.
emit
(
"Py_RETURN_NONE;"
,
2
)
self
.
emit
(
"}"
,
1
)
self
.
emit
(
''
,
0
)
...
...
Python/Python-ast.c
View file @
fc489082
...
...
@@ -504,6 +504,9 @@ static char *withitem_fields[]={
};
_Py_IDENTIFIER
(
_fields
);
_Py_IDENTIFIER
(
_attributes
);
typedef
struct
{
PyObject_HEAD
PyObject
*
dict
;
...
...
@@ -532,7 +535,6 @@ ast_clear(AST_object *self)
static
int
ast_type_init
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
{
_Py_IDENTIFIER
(
_fields
);
Py_ssize_t
i
,
numfields
=
0
;
int
res
=
-
1
;
PyObject
*
key
,
*
value
,
*
fields
;
...
...
@@ -657,6 +659,8 @@ static PyTypeObject AST_type = {
static
PyTypeObject
*
make_type
(
char
*
type
,
PyTypeObject
*
base
,
char
**
fields
,
int
num_fields
)
{
_Py_IDENTIFIER
(
__module__
);
_Py_IDENTIFIER
(
_ast
);
PyObject
*
fnames
,
*
result
;
int
i
;
fnames
=
PyTuple_New
(
num_fields
);
...
...
@@ -669,8 +673,11 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
}
PyTuple_SET_ITEM
(
fnames
,
i
,
field
);
}
result
=
PyObject_CallFunction
((
PyObject
*
)
&
PyType_Type
,
"s(O){sOss}"
,
type
,
base
,
"_fields"
,
fnames
,
"__module__"
,
"_ast"
);
result
=
PyObject_CallFunction
((
PyObject
*
)
&
PyType_Type
,
"s(O){OOOO}"
,
type
,
base
,
_PyUnicode_FromId
(
&
PyId__fields
),
fnames
,
_PyUnicode_FromId
(
&
PyId___module__
),
_PyUnicode_FromId
(
&
PyId__ast
));
Py_DECREF
(
fnames
);
return
(
PyTypeObject
*
)
result
;
}
...
...
@@ -678,7 +685,6 @@ static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int
static
int
add_attributes
(
PyTypeObject
*
type
,
char
**
attrs
,
int
num_fields
)
{
int
i
,
result
;
_Py_IDENTIFIER
(
_attributes
);
PyObject
*
s
,
*
l
=
PyTuple_New
(
num_fields
);
if
(
!
l
)
return
0
;
...
...
@@ -824,8 +830,8 @@ static int add_ast_fields(void)
d
=
AST_type
.
tp_dict
;
empty_tuple
=
PyTuple_New
(
0
);
if
(
!
empty_tuple
||
PyDict_SetItemString
(
d
,
"_fields"
,
empty_tuple
)
<
0
||
PyDict_SetItemString
(
d
,
"_attributes"
,
empty_tuple
)
<
0
)
{
_PyDict_SetItemId
(
d
,
&
PyId__fields
,
empty_tuple
)
<
0
||
_PyDict_SetItemId
(
d
,
&
PyId__attributes
,
empty_tuple
)
<
0
)
{
Py_XDECREF
(
empty_tuple
);
return
-
1
;
}
...
...
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