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
1c67dd9b
Commit
1c67dd9b
authored
Oct 14, 2011
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
parent
bd928fef
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
200 additions
and
183 deletions
+200
-183
Modules/_cursesmodule.c
Modules/_cursesmodule.c
+7
-4
Modules/_pickle.c
Modules/_pickle.c
+4
-3
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+2
-2
Objects/descrobject.c
Objects/descrobject.c
+1
-1
Objects/dictobject.c
Objects/dictobject.c
+3
-2
Parser/asdl_c.py
Parser/asdl_c.py
+4
-3
Python/Python-ast.c
Python/Python-ast.c
+135
-134
Python/_warnings.c
Python/_warnings.c
+15
-17
Python/ceval.c
Python/ceval.c
+4
-2
Python/errors.c
Python/errors.c
+16
-10
Python/pythonrun.c
Python/pythonrun.c
+6
-3
Python/sysmodule.c
Python/sysmodule.c
+3
-2
No files found.
Modules/_cursesmodule.c
View file @
1c67dd9b
...
...
@@ -2454,6 +2454,8 @@ update_lines_cols(void)
{
PyObject
*
o
;
PyObject
*
m
=
PyImport_ImportModuleNoBlock
(
"curses"
);
_Py_IDENTIFIER
(
LINES
);
_Py_IDENTIFIER
(
COLS
);
if
(
!
m
)
return
0
;
...
...
@@ -2463,12 +2465,13 @@ update_lines_cols(void)
Py_DECREF
(
m
);
return
0
;
}
if
(
PyObject_SetAttrString
(
m
,
"LINES"
,
o
))
{
if
(
_PyObject_SetAttrId
(
m
,
&
PyId_LINES
,
o
))
{
Py_DECREF
(
m
);
Py_DECREF
(
o
);
return
0
;
}
if
(
PyDict_SetItemString
(
ModDict
,
"LINES"
,
o
))
{
/* PyId_LINES.object will be initialized here. */
if
(
PyDict_SetItem
(
ModDict
,
PyId_LINES
.
object
,
o
))
{
Py_DECREF
(
m
);
Py_DECREF
(
o
);
return
0
;
...
...
@@ -2479,12 +2482,12 @@ update_lines_cols(void)
Py_DECREF
(
m
);
return
0
;
}
if
(
PyObject_SetAttrString
(
m
,
"COLS"
,
o
))
{
if
(
_PyObject_SetAttrId
(
m
,
&
PyId_COLS
,
o
))
{
Py_DECREF
(
m
);
Py_DECREF
(
o
);
return
0
;
}
if
(
PyDict_SetItem
String
(
ModDict
,
"COLS"
,
o
))
{
if
(
PyDict_SetItem
(
ModDict
,
PyId_COLS
.
object
,
o
))
{
Py_DECREF
(
m
);
Py_DECREF
(
o
);
return
0
;
...
...
Modules/_pickle.c
View file @
1c67dd9b
...
...
@@ -4388,12 +4388,13 @@ static PyObject *
instantiate
(
PyObject
*
cls
,
PyObject
*
args
)
{
PyObject
*
result
=
NULL
;
_Py_IDENTIFIER
(
__getinitargs__
);
/* Caller must assure args are a tuple. Normally, args come from
Pdata_poptuple which packs objects from the top of the stack
into a newly created tuple. */
assert
(
PyTuple_Check
(
args
));
if
(
Py_SIZE
(
args
)
>
0
||
!
PyType_Check
(
cls
)
||
PyObject_HasAttrString
(
cls
,
"__getinitargs__"
))
{
_PyObject_HasAttrId
(
cls
,
&
PyId___getinitargs__
))
{
result
=
PyObject_CallObject
(
cls
,
args
);
}
else
{
...
...
@@ -5557,6 +5558,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
PyObject
*
fix_imports
=
Py_True
;
char
*
encoding
=
NULL
;
char
*
errors
=
NULL
;
_Py_IDENTIFIER
(
persistent_load
);
/* XXX: That is an horrible error message. But, I don't know how to do
better... */
...
...
@@ -5591,8 +5593,7 @@ Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
if
(
self
->
fix_imports
==
-
1
)
return
-
1
;
if
(
PyObject_HasAttrString
((
PyObject
*
)
self
,
"persistent_load"
))
{
_Py_IDENTIFIER
(
persistent_load
);
if
(
_PyObject_HasAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_load
))
{
self
->
pers_func
=
_PyObject_GetAttrId
((
PyObject
*
)
self
,
&
PyId_persistent_load
);
if
(
self
->
pers_func
==
NULL
)
...
...
Modules/itertoolsmodule.c
View file @
1c67dd9b
...
...
@@ -626,6 +626,7 @@ tee(PyObject *self, PyObject *args)
{
Py_ssize_t
i
,
n
=
2
;
PyObject
*
it
,
*
iterable
,
*
copyable
,
*
result
;
_Py_IDENTIFIER
(
__copy__
);
if
(
!
PyArg_ParseTuple
(
args
,
"O|n"
,
&
iterable
,
&
n
))
return
NULL
;
...
...
@@ -643,7 +644,7 @@ tee(PyObject *self, PyObject *args)
Py_DECREF
(
result
);
return
NULL
;
}
if
(
!
PyObject_HasAttrString
(
it
,
"__copy__"
))
{
if
(
!
_PyObject_HasAttrId
(
it
,
&
PyId___copy__
))
{
copyable
=
tee_fromiterable
(
it
);
Py_DECREF
(
it
);
if
(
copyable
==
NULL
)
{
...
...
@@ -654,7 +655,6 @@ tee(PyObject *self, PyObject *args)
copyable
=
it
;
PyTuple_SET_ITEM
(
result
,
0
,
copyable
);
for
(
i
=
1
;
i
<
n
;
i
++
)
{
_Py_IDENTIFIER
(
__copy__
);
copyable
=
_PyObject_CallMethodId
(
copyable
,
&
PyId___copy__
,
NULL
);
if
(
copyable
==
NULL
)
{
...
...
Objects/descrobject.c
View file @
1c67dd9b
...
...
@@ -1311,7 +1311,7 @@ property_init(PyObject *self, PyObject *args, PyObject *kwds)
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
class's dict. */
int
err
=
PyObject_SetAttrString
(
self
,
"__doc__"
,
get_doc
);
int
err
=
_PyObject_SetAttrId
(
self
,
&
PyId___doc__
,
get_doc
);
Py_DECREF
(
get_doc
);
if
(
err
<
0
)
return
-
1
;
...
...
Objects/dictobject.c
View file @
1c67dd9b
...
...
@@ -1387,7 +1387,8 @@ dict_update_common(PyObject *self, PyObject *args, PyObject *kwds, char *methnam
result
=
-
1
;
else
if
(
arg
!=
NULL
)
{
if
(
PyObject_HasAttrString
(
arg
,
"keys"
))
_Py_IDENTIFIER
(
keys
);
if
(
_PyObject_HasAttrId
(
arg
,
&
PyId_keys
))
result
=
PyDict_Merge
(
self
,
arg
,
1
);
else
result
=
PyDict_MergeFromSeq2
(
self
,
arg
,
1
);
...
...
@@ -2747,7 +2748,7 @@ dictviews_or(PyObject* self, PyObject *other)
{
PyObject
*
result
=
PySet_New
(
self
);
PyObject
*
tmp
;
_Py_
identifier
(
update
);
_Py_
IDENTIFIER
(
update
);
if
(
result
==
NULL
)
return
NULL
;
...
...
Parser/asdl_c.py
View file @
1c67dd9b
...
...
@@ -747,6 +747,7 @@ 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;
...
...
@@ -758,7 +759,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
}
PyTuple_SET_ITEM(l, i, s);
}
result =
PyObject_SetAttrString((PyObject*)type, "_attributes"
, l) >= 0;
result =
_PyObject_SetAttrId((PyObject*)type, &PyId__attributes
, l) >= 0;
Py_DECREF(l);
return result;
}
...
...
@@ -1024,7 +1025,7 @@ class ObjVisitor(PickleVisitor):
for
a
in
sum
.
attributes
:
self
.
emit
(
"value = ast2obj_%s(o->%s);"
%
(
a
.
type
,
a
.
name
),
1
)
self
.
emit
(
"if (!value) goto failed;"
,
1
)
self
.
emit
(
'if (
PyObject_SetAttrString(result, "%s"
, value) < 0)'
%
a
.
name
,
1
)
self
.
emit
(
'if (
_PyObject_SetAttrId(result, &PyId_%s
, value) < 0)'
%
a
.
name
,
1
)
self
.
emit
(
'goto failed;'
,
2
)
self
.
emit
(
'Py_DECREF(value);'
,
1
)
self
.
func_end
()
...
...
@@ -1070,7 +1071,7 @@ class ObjVisitor(PickleVisitor):
value
=
"o->v.%s.%s"
%
(
name
,
field
.
name
)
self
.
set
(
field
,
value
,
depth
)
emit
(
"if (!value) goto failed;"
,
0
)
emit
(
'if (
PyObject_SetAttrString(result, "%s"
, value) == -1)'
%
field
.
name
,
0
)
emit
(
'if (
_PyObject_SetAttrId(result, &PyId_%s
, value) == -1)'
%
field
.
name
,
0
)
emit
(
"goto failed;"
,
1
)
emit
(
"Py_DECREF(value);"
,
0
)
...
...
Python/Python-ast.c
View file @
1c67dd9b
This diff is collapsed.
Click to expand it.
Python/_warnings.c
View file @
1c67dd9b
...
...
@@ -654,8 +654,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
return
NULL
;
if
(
module_globals
)
{
static
PyObject
*
get_source_name
=
NULL
;
static
PyObject
*
splitlines_name
=
NULL
;
_Py_IDENTIFIER
(
get_source
);
_Py_IDENTIFIER
(
splitlines
);
PyObject
*
tmp
;
PyObject
*
loader
;
PyObject
*
module_name
;
PyObject
*
source
;
...
...
@@ -663,16 +664,12 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
PyObject
*
source_line
;
PyObject
*
returned
;
if
(
get_source_name
==
NULL
)
{
get_source_name
=
PyUnicode_InternFromString
(
"get_source"
);
if
(
!
get_source_name
)
return
NULL
;
}
if
(
splitlines_name
==
NULL
)
{
splitlines_name
=
PyUnicode_InternFromString
(
"splitlines"
);
if
(
!
splitlines_name
)
return
NULL
;
}
if
((
tmp
=
_PyUnicode_FromId
(
&
PyId_get_source
))
==
NULL
)
return
NULL
;
Py_DECREF
(
tmp
);
if
((
tmp
=
_PyUnicode_FromId
(
&
PyId_splitlines
))
==
NULL
)
return
NULL
;
Py_DECREF
(
tmp
);
/* Check/get the requisite pieces needed for the loader. */
loader
=
PyDict_GetItemString
(
module_globals
,
"__loader__"
);
...
...
@@ -682,11 +679,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
goto
standard_call
;
/* Make sure the loader implements the optional get_source() method. */
if
(
!
PyObject_HasAttrString
(
loader
,
"get_source"
))
if
(
!
_PyObject_HasAttrId
(
loader
,
&
PyId_get_source
))
goto
standard_call
;
/* Call get_source() to get the source code. */
source
=
PyObject_CallMethodObjArgs
(
loader
,
get_source_name
,
module_name
,
NULL
);
source
=
PyObject_CallMethodObjArgs
(
loader
,
PyId_get_source
.
object
,
module_name
,
NULL
);
if
(
!
source
)
return
NULL
;
else
if
(
source
==
Py_None
)
{
...
...
@@ -695,8 +692,9 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
}
/* Split the source into lines. */
source_list
=
PyObject_CallMethodObjArgs
(
source
,
splitlines_name
,
NULL
);
source_list
=
PyObject_CallMethodObjArgs
(
source
,
PyId_splitlines
.
object
,
NULL
);
Py_DECREF
(
source
);
if
(
!
source_list
)
return
NULL
;
...
...
Python/ceval.c
View file @
1c67dd9b
...
...
@@ -4422,7 +4422,9 @@ import_from(PyObject *v, PyObject *name)
static
int
import_all_from
(
PyObject
*
locals
,
PyObject
*
v
)
{
PyObject
*
all
=
PyObject_GetAttrString
(
v
,
"__all__"
);
_Py_IDENTIFIER
(
__all__
);
_Py_IDENTIFIER
(
__dict__
);
PyObject
*
all
=
_PyObject_GetAttrId
(
v
,
&
PyId___all__
);
PyObject
*
dict
,
*
name
,
*
value
;
int
skip_leading_underscores
=
0
;
int
pos
,
err
;
...
...
@@ -4431,7 +4433,7 @@ import_all_from(PyObject *locals, PyObject *v)
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
-
1
;
/* Unexpected error */
PyErr_Clear
();
dict
=
PyObject_GetAttrString
(
v
,
"__dict__"
);
dict
=
_PyObject_GetAttrId
(
v
,
&
PyId___dict__
);
if
(
dict
==
NULL
)
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
return
-
1
;
...
...
Python/errors.c
View file @
1c67dd9b
...
...
@@ -780,6 +780,12 @@ void
PyErr_SyntaxLocationEx
(
const
char
*
filename
,
int
lineno
,
int
col_offset
)
{
PyObject
*
exc
,
*
v
,
*
tb
,
*
tmp
;
_Py_IDENTIFIER
(
filename
);
_Py_IDENTIFIER
(
lineno
);
_Py_IDENTIFIER
(
msg
);
_Py_IDENTIFIER
(
offset
);
_Py_IDENTIFIER
(
print_file_and_line
);
_Py_IDENTIFIER
(
text
);
/* add attributes for the line number and filename for the error */
PyErr_Fetch
(
&
exc
,
&
v
,
&
tb
);
...
...
@@ -790,7 +796,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if
(
tmp
==
NULL
)
PyErr_Clear
();
else
{
if
(
PyObject_SetAttrString
(
v
,
"lineno"
,
tmp
))
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_lineno
,
tmp
))
PyErr_Clear
();
Py_DECREF
(
tmp
);
}
...
...
@@ -799,7 +805,7 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if
(
tmp
==
NULL
)
PyErr_Clear
();
else
{
if
(
PyObject_SetAttrString
(
v
,
"offset"
,
tmp
))
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_offset
,
tmp
))
PyErr_Clear
();
Py_DECREF
(
tmp
);
}
...
...
@@ -809,35 +815,35 @@ PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
if
(
tmp
==
NULL
)
PyErr_Clear
();
else
{
if
(
PyObject_SetAttrString
(
v
,
"filename"
,
tmp
))
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_filename
,
tmp
))
PyErr_Clear
();
Py_DECREF
(
tmp
);
}
tmp
=
PyErr_ProgramText
(
filename
,
lineno
);
if
(
tmp
)
{
if
(
PyObject_SetAttrString
(
v
,
"text"
,
tmp
))
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_text
,
tmp
))
PyErr_Clear
();
Py_DECREF
(
tmp
);
}
}
if
(
PyObject_SetAttrString
(
v
,
"offset"
,
Py_None
))
{
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_offset
,
Py_None
))
{
PyErr_Clear
();
}
if
(
exc
!=
PyExc_SyntaxError
)
{
if
(
!
PyObject_HasAttrString
(
v
,
"msg"
))
{
if
(
!
_PyObject_HasAttrId
(
v
,
&
PyId_msg
))
{
tmp
=
PyObject_Str
(
v
);
if
(
tmp
)
{
if
(
PyObject_SetAttrString
(
v
,
"msg"
,
tmp
))
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_msg
,
tmp
))
PyErr_Clear
();
Py_DECREF
(
tmp
);
}
else
{
PyErr_Clear
();
}
}
if
(
!
PyObject_HasAttrString
(
v
,
"print_file_and_line"
))
{
if
(
PyObject_SetAttrString
(
v
,
"print_file_and_line"
,
Py_None
))
if
(
!
_PyObject_HasAttrId
(
v
,
&
PyId_print_file_and_line
))
{
if
(
_PyObject_SetAttrId
(
v
,
&
PyId_print_file_and_line
,
Py_None
))
PyErr_Clear
();
}
}
...
...
Python/pythonrun.c
View file @
1c67dd9b
...
...
@@ -810,6 +810,8 @@ create_stdio(PyObject* io,
_Py_IDENTIFIER
(
open
);
_Py_IDENTIFIER
(
isatty
);
_Py_IDENTIFIER
(
TextIOWrapper
);
_Py_IDENTIFIER
(
name
);
_Py_IDENTIFIER
(
mode
);
/* stdin is always opened in buffered mode, first because it shouldn't
make a difference in common use cases, second because TextIOWrapper
...
...
@@ -842,7 +844,7 @@ create_stdio(PyObject* io,
}
text
=
PyUnicode_FromString
(
name
);
if
(
text
==
NULL
||
PyObject_SetAttrString
(
raw
,
"name"
,
text
)
<
0
)
if
(
text
==
NULL
||
_PyObject_SetAttrId
(
raw
,
&
PyId_name
,
text
)
<
0
)
goto
error
;
res
=
_PyObject_CallMethodId
(
raw
,
&
PyId_isatty
,
""
);
if
(
res
==
NULL
)
...
...
@@ -879,7 +881,7 @@ create_stdio(PyObject* io,
else
mode
=
"r"
;
text
=
PyUnicode_FromString
(
mode
);
if
(
!
text
||
PyObject_SetAttrString
(
stream
,
"mode"
,
text
)
<
0
)
if
(
!
text
||
_PyObject_SetAttrId
(
stream
,
&
PyId_mode
,
text
)
<
0
)
goto
error
;
Py_CLEAR
(
text
);
return
stream
;
...
...
@@ -1547,6 +1549,7 @@ print_exception(PyObject *f, PyObject *value)
{
int
err
=
0
;
PyObject
*
type
,
*
tb
;
_Py_IDENTIFIER
(
print_file_and_line
);
if
(
!
PyExceptionInstance_Check
(
value
))
{
PyFile_WriteString
(
"TypeError: print_exception(): Exception expected for value, "
,
f
);
...
...
@@ -1562,7 +1565,7 @@ print_exception(PyObject *f, PyObject *value)
if
(
tb
&&
tb
!=
Py_None
)
err
=
PyTraceBack_Print
(
tb
,
f
);
if
(
err
==
0
&&
PyObject_HasAttrString
(
value
,
"print_file_and_line"
))
_PyObject_HasAttrId
(
value
,
&
PyId_print_file_and_line
))
{
PyObject
*
message
;
const
char
*
filename
,
*
text
;
...
...
Python/sysmodule.c
View file @
1c67dd9b
...
...
@@ -139,6 +139,7 @@ sys_displayhook(PyObject *self, PyObject *o)
PyObject
*
modules
=
interp
->
modules
;
PyObject
*
builtins
=
PyDict_GetItemString
(
modules
,
"builtins"
);
int
err
;
_Py_IDENTIFIER
(
_
);
if
(
builtins
==
NULL
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"lost builtins module"
);
...
...
@@ -152,7 +153,7 @@ sys_displayhook(PyObject *self, PyObject *o)
Py_INCREF
(
Py_None
);
return
Py_None
;
}
if
(
PyObject_SetAttrString
(
builtins
,
"_"
,
Py_None
)
!=
0
)
if
(
_PyObject_SetAttrId
(
builtins
,
&
PyId__
,
Py_None
)
!=
0
)
return
NULL
;
outf
=
PySys_GetObject
(
"stdout"
);
if
(
outf
==
NULL
||
outf
==
Py_None
)
{
...
...
@@ -174,7 +175,7 @@ sys_displayhook(PyObject *self, PyObject *o)
}
if
(
PyFile_WriteString
(
"
\n
"
,
outf
)
!=
0
)
return
NULL
;
if
(
PyObject_SetAttrString
(
builtins
,
"_"
,
o
)
!=
0
)
if
(
_PyObject_SetAttrId
(
builtins
,
&
PyId__
,
o
)
!=
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
...
...
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