summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-03-21 17:15:42 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-03-21 17:15:42 (GMT)
commit6ced7c433353208e5b9d4dc25018937f1c9ae87d (patch)
tree61efdd2c527ab2eeeff1dd306218b91efbe1b91d /Modules
parent44afe2b35a3f82f26d35a2cec507ec6d59e6d6d3 (diff)
downloadcpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.zip
cpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.tar.gz
cpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.tar.bz2
Issue #10833: Use PyErr_Format() and PyUnicode_FromFormat() instead of
PyOS_snprintf() to avoid temporary buffer allocated on the stack and a conversion from bytes to Unicode.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c9
-rw-r--r--Modules/_testcapimodule.c9
-rw-r--r--Modules/_tkinter.c8
-rw-r--r--Modules/readline.c13
4 files changed, 13 insertions, 26 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index cd44471..f50cae0 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -766,7 +766,7 @@ typedef struct
PyObject *name;
} PyDateTime_TimeZone;
-/* The interned UTC timezone instance */
+/* The interned UTC timezone instance */
static PyObject *PyDateTime_TimeZone_UTC;
/* Create new timezone instance checking offset range. This
@@ -3287,7 +3287,6 @@ timezone_repr(PyDateTime_TimeZone *self)
static PyObject *
timezone_str(PyDateTime_TimeZone *self)
{
- char buf[10];
int hours, minutes, seconds;
PyObject *offset;
char sign;
@@ -3313,11 +3312,9 @@ timezone_str(PyDateTime_TimeZone *self)
Py_DECREF(offset);
minutes = divmod(seconds, 60, &seconds);
hours = divmod(minutes, 60, &minutes);
- assert(seconds == 0);
/* XXX ignore sub-minute data, curently not allowed. */
- PyOS_snprintf(buf, sizeof(buf), "UTC%c%02d:%02d", sign, hours, minutes);
-
- return PyUnicode_FromString(buf);
+ assert(seconds == 0);
+ return PyUnicode_FromFormat("UTC%c%02d:%02d", sign, hours, minutes);
}
static PyObject *
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 75dbe57..35d25e6 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -22,14 +22,7 @@ static PyObject *TestError; /* set to exception object in init */
static PyObject *
raiseTestError(const char* test_name, const char* msg)
{
- char buf[2048];
-
- if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
- PyErr_SetString(TestError, "internal error msg too large");
- else {
- PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
- PyErr_SetString(TestError, buf);
- }
+ PyErr_Format(TestError, "%s: %s", test_name, msg);
return NULL;
}
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 5939357..91b1b53 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -2400,11 +2400,9 @@ static PyObject *
Tktt_Repr(PyObject *self)
{
TkttObject *v = (TkttObject *)self;
- char buf[100];
-
- PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v,
- v->func == NULL ? ", handler deleted" : "");
- return PyUnicode_FromString(buf);
+ return PyUnicode_FromFormat("<tktimertoken at %p%s>",
+ v,
+ v->func == NULL ? ", handler deleted" : "");
}
static PyTypeObject Tktt_Type =
diff --git a/Modules/readline.c b/Modules/readline.c
index 8337956..a5e48ab 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -233,10 +233,9 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
Py_XDECREF(tmp);
}
else {
- PyOS_snprintf(buf, sizeof(buf),
- "set_%.50s(func): argument not callable",
- funcname);
- PyErr_SetString(PyExc_TypeError, buf);
+ PyErr_Format(PyExc_TypeError,
+ "set_%.50s(func): argument not callable",
+ funcname);
return NULL;
}
Py_RETURN_NONE;
@@ -890,7 +889,7 @@ setup_readline(void)
#endif
#ifdef __APPLE__
- /* the libedit readline emulation resets key bindings etc
+ /* the libedit readline emulation resets key bindings etc
* when calling rl_initialize. So call it upfront
*/
if (using_libedit_emulation)
@@ -930,11 +929,11 @@ setup_readline(void)
*/
#ifdef __APPLE__
if (using_libedit_emulation)
- rl_read_init_file(NULL);
+ rl_read_init_file(NULL);
else
#endif /* __APPLE__ */
rl_initialize();
-
+
RESTORE_LOCALE(saved_locale)
}