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
499dfcf2
Commit
499dfcf2
authored
Mar 21, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
PyOS_snprintf().
parent
bfc7bf06
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
68 deletions
+54
-68
Modules/_elementtree.c
Modules/_elementtree.c
+7
-5
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+2
-4
Modules/gcmodule.c
Modules/gcmodule.c
+2
-2
Modules/pyexpat.c
Modules/pyexpat.c
+7
-6
Modules/timemodule.c
Modules/timemodule.c
+9
-20
Objects/weakrefobject.c
Objects/weakrefobject.c
+27
-31
No files found.
Modules/_elementtree.c
View file @
499dfcf2
...
...
@@ -2138,13 +2138,15 @@ makeuniversal(XMLParserObject* self, const char* string)
static
void
expat_set_error
(
const
char
*
message
,
int
line
,
int
column
)
{
PyObject
*
error
;
PyObject
*
position
;
char
buffer
[
256
];
PyObject
*
errmsg
,
*
error
,
*
position
;
sprintf
(
buffer
,
"%.100s: line %d, column %d"
,
message
,
line
,
column
);
errmsg
=
PyUnicode_FromFormat
(
"%s: line %d, column %d"
,
message
,
line
,
column
);
if
(
errmsg
==
NULL
)
return
;
error
=
PyObject_CallFunction
(
elementtree_parseerror_obj
,
"s"
,
buffer
);
error
=
PyObject_CallFunction
(
elementtree_parseerror_obj
,
"O"
,
errmsg
);
Py_DECREF
(
errmsg
);
if
(
!
error
)
return
;
...
...
Modules/_testcapimodule.c
View file @
499dfcf2
...
...
@@ -43,11 +43,9 @@ static PyObject*
sizeof_error
(
const
char
*
fatname
,
const
char
*
typname
,
int
expected
,
int
got
)
{
char
buf
[
1024
];
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"%.200s #define == %d but sizeof(%.200s) == %d"
,
PyErr_Format
(
TestError
,
"%s #define == %d but sizeof(%s) == %d"
,
fatname
,
expected
,
typname
,
got
);
PyErr_SetString
(
TestError
,
buf
);
return
(
PyObject
*
)
NULL
;
}
...
...
Modules/gcmodule.c
View file @
499dfcf2
...
...
@@ -680,8 +680,8 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
static
void
debug_cycle
(
char
*
msg
,
PyObject
*
op
)
{
PySys_
WriteStderr
(
"gc: %.100s <%.100
s %p>
\n
"
,
msg
,
Py_TYPE
(
op
)
->
tp_name
,
op
);
PySys_
FormatStderr
(
"gc: %s <%
s %p>
\n
"
,
msg
,
Py_TYPE
(
op
)
->
tp_name
,
op
);
}
/* Handle uncollectable garbage (cycles with finalizers, and stuff reachable
...
...
Modules/pyexpat.c
View file @
499dfcf2
...
...
@@ -100,16 +100,17 @@ static PyObject *
set_error
(
xmlparseobject
*
self
,
enum
XML_Error
code
)
{
PyObject
*
err
;
char
buffer
[
256
]
;
PyObject
*
buffer
;
XML_Parser
parser
=
self
->
itself
;
int
lineno
=
XML_GetErrorLineNumber
(
parser
);
int
column
=
XML_GetErrorColumnNumber
(
parser
);
/* There is no risk of overflowing this buffer, since
even for 64-bit integers, there is sufficient space. */
sprintf
(
buffer
,
"%.200s: line %i, column %i"
,
XML_ErrorString
(
code
),
lineno
,
column
);
err
=
PyObject_CallFunction
(
ErrorObject
,
"s"
,
buffer
);
buffer
=
PyUnicode_FromFormat
(
"%s: line %i, column %i"
,
XML_ErrorString
(
code
),
lineno
,
column
);
if
(
buffer
==
NULL
)
return
NULL
;
err
=
PyObject_CallFunction
(
ErrorObject
,
"O"
,
buffer
);
Py_DECREF
(
buffer
);
if
(
err
!=
NULL
&&
set_error_attr
(
err
,
"code"
,
code
)
&&
set_error_attr
(
err
,
"offset"
,
column
)
...
...
Modules/timemodule.c
View file @
499dfcf2
...
...
@@ -601,31 +601,20 @@ _asctime(struct tm *timeptr)
{
/* Inspired by Open Group reference implementation available at
* http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */
static
char
wday_name
[
7
][
3
]
=
{
static
char
wday_name
[
7
][
4
]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
char
mon_name
[
12
][
3
]
=
{
static
char
mon_name
[
12
][
4
]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
char
buf
[
20
];
/* 'Sun Sep 16 01:03:52\0' */
int
n
;
n
=
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"%.3s %.3s%3d %.2d:%.2d:%.2d"
,
wday_name
[
timeptr
->
tm_wday
],
mon_name
[
timeptr
->
tm_mon
],
timeptr
->
tm_mday
,
timeptr
->
tm_hour
,
timeptr
->
tm_min
,
timeptr
->
tm_sec
);
/* XXX: since the fields used by snprintf above are validated in checktm,
* the following condition should never trigger. We keep the check because
* historically fixed size buffer used in asctime was the source of
* crashes. */
if
(
n
+
1
!=
sizeof
(
buf
))
{
PyErr_SetString
(
PyExc_ValueError
,
"unconvertible time"
);
return
NULL
;
}
return
PyUnicode_FromFormat
(
"%s %d"
,
buf
,
1900
+
timeptr
->
tm_year
);
return
PyUnicode_FromFormat
(
"%s %s%3d %.2d:%.2d:%.2d %d"
,
wday_name
[
timeptr
->
tm_wday
],
mon_name
[
timeptr
->
tm_mon
],
timeptr
->
tm_mday
,
timeptr
->
tm_hour
,
timeptr
->
tm_min
,
timeptr
->
tm_sec
,
1900
+
timeptr
->
tm_year
);
}
static
PyObject
*
...
...
Objects/weakrefobject.c
View file @
499dfcf2
...
...
@@ -157,34 +157,31 @@ static PyObject *
weakref_repr
(
PyWeakReference
*
self
)
{
char
buffer
[
256
];
if
(
PyWeakref_GET_OBJECT
(
self
)
==
Py_None
)
{
PyOS_snprintf
(
buffer
,
sizeof
(
buffer
),
"<weakref at %p; dead>"
,
self
);
PyObject
*
name
,
*
repr
;
if
(
PyWeakref_GET_OBJECT
(
self
)
==
Py_None
)
return
PyUnicode_FromFormat
(
"<weakref at %p; dead>"
,
self
);
name
=
PyObject_GetAttrString
(
PyWeakref_GET_OBJECT
(
self
),
"__name__"
);
if
(
name
==
NULL
||
!
PyUnicode_Check
(
name
))
{
if
(
name
==
NULL
)
PyErr_Clear
();
repr
=
PyUnicode_FromFormat
(
"<weakref at %p; to '%s' at %p>"
,
self
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
self
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
self
));
}
else
{
char
*
name
=
NULL
;
PyObject
*
nameobj
=
PyObject_GetAttrString
(
PyWeakref_GET_OBJECT
(
self
),
"__name__"
);
if
(
nameobj
==
NULL
)
PyErr_Clear
();
else
if
(
PyUnicode_Check
(
nameobj
))
name
=
_PyUnicode_AsString
(
nameobj
);
if
(
name
)
PyOS_snprintf
(
buffer
,
sizeof
(
buffer
),
"<weakref at %p; to '%.50s' at %p (%s)>"
,
self
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
self
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
self
),
name
);
else
PyOS_snprintf
(
buffer
,
sizeof
(
buffer
),
"<weakref at %p; to '%.50s' at %p>"
,
self
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
self
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
self
));
Py_XDECREF
(
nameobj
);
repr
=
PyUnicode_FromFormat
(
"<weakref at %p; to '%s' at %p (%U)>"
,
self
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
self
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
self
),
name
);
}
return
PyUnicode_FromString
(
buffer
);
Py_XDECREF
(
name
);
return
repr
;
}
/* Weak references only support equality, not ordering. Two weak references
...
...
@@ -459,12 +456,11 @@ WRAP_TERNARY(proxy_call, PyEval_CallObjectWithKeywords)
static
PyObject
*
proxy_repr
(
PyWeakReference
*
proxy
)
{
char
buf
[
160
];
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"<weakproxy at %p to %.100s at %p>"
,
proxy
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
proxy
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
proxy
));
return
PyUnicode_FromString
(
buf
);
return
PyUnicode_FromFormat
(
"<weakproxy at %p to %s at %p>"
,
proxy
,
Py_TYPE
(
PyWeakref_GET_OBJECT
(
proxy
))
->
tp_name
,
PyWeakref_GET_OBJECT
(
proxy
));
}
...
...
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