summaryrefslogtreecommitdiffstats
path: root/Objects/moduleobject.c
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-08-24 18:34:26 (GMT)
committerBarry Warsaw <barry@python.org>2001-08-24 18:34:26 (GMT)
commit7ce3694a527afe425a2b9df65c049b0ef4e75960 (patch)
tree089937f432c69e85afbfc8308d5ebc86dd2c2c49 /Objects/moduleobject.c
parentdadace004b4b94dcc4437bafc9c8407fbb1bed74 (diff)
downloadcpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.zip
cpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.tar.gz
cpython-7ce3694a527afe425a2b9df65c049b0ef4e75960.tar.bz2
repr's converted to using PyString_FromFormat() instead of sprintf'ing
into a hardcoded char* buffer. Closes patch #454743.
Diffstat (limited to 'Objects/moduleobject.c')
-rw-r--r--Objects/moduleobject.c19
1 files changed, 2 insertions, 17 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 2ccf0bf..ba81593 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -157,13 +157,8 @@ module_dealloc(PyModuleObject *m)
static PyObject *
module_repr(PyModuleObject *m)
{
- static int template1len = sizeof("<module '' (built-in)>") + 1;
- static int template2len = sizeof("<module '' from ''>") + 1;
-
- char *buf;
char *name;
char *filename;
- PyObject *rtn;
name = PyModule_GetName((PyObject *)m);
if (name == NULL) {
@@ -173,19 +168,9 @@ module_repr(PyModuleObject *m)
filename = PyModule_GetFilename((PyObject *)m);
if (filename == NULL) {
PyErr_Clear();
- buf = PyObject_MALLOC(
- sizeof(char) * (strlen(name) + template1len));
- sprintf(buf, "<module '%s' (built-in)>", name);
- }
- else {
- buf = PyObject_MALLOC(
- sizeof(char) * (strlen(name) + strlen(filename) +
- template2len));
- sprintf(buf, "<module '%s' from '%s'>", name, filename);
+ return PyString_FromFormat("<module '%s' (built-in)>", name);
}
- rtn = PyString_FromString(buf);
- PyObject_FREE(buf);
- return rtn;
+ return PyString_FromFormat("<module '%s' from '%s'>", name, filename);
}
/* We only need a traverse function, no clear function: If the module