mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Little stuff.
Add a missing DECREF in an obscure corner. If the str() or repr() of an object passed to a string interpolation -- e.g. "%s" % obj -- returns a non-string, the returned object was leaked. Repair an indentation glitch. Replace a bunch of PyString_AsString() calls (and their ilk) with macros.
This commit is contained in:
parent
2554dd993a
commit
7802a53e38
1 changed files with 9 additions and 8 deletions
|
@ -3146,15 +3146,15 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
orig_args = args;
|
orig_args = args;
|
||||||
fmt = PyString_AsString(format);
|
fmt = PyString_AS_STRING(format);
|
||||||
fmtcnt = PyString_Size(format);
|
fmtcnt = PyString_GET_SIZE(format);
|
||||||
reslen = rescnt = fmtcnt + 100;
|
reslen = rescnt = fmtcnt + 100;
|
||||||
result = PyString_FromStringAndSize((char *)NULL, reslen);
|
result = PyString_FromStringAndSize((char *)NULL, reslen);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
res = PyString_AsString(result);
|
res = PyString_AsString(result);
|
||||||
if (PyTuple_Check(args)) {
|
if (PyTuple_Check(args)) {
|
||||||
arglen = PyTuple_Size(args);
|
arglen = PyTuple_GET_SIZE(args);
|
||||||
argidx = 0;
|
argidx = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3170,7 +3170,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
reslen += rescnt;
|
reslen += rescnt;
|
||||||
if (_PyString_Resize(&result, reslen) < 0)
|
if (_PyString_Resize(&result, reslen) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
res = PyString_AsString(result)
|
res = PyString_AS_STRING(result)
|
||||||
+ reslen - rescnt;
|
+ reslen - rescnt;
|
||||||
--rescnt;
|
--rescnt;
|
||||||
}
|
}
|
||||||
|
@ -3351,7 +3351,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (c == 's')
|
if (c == 's')
|
||||||
temp = PyObject_Str(v);
|
temp = PyObject_Str(v);
|
||||||
else
|
else
|
||||||
temp = PyObject_Repr(v);
|
temp = PyObject_Repr(v);
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
|
@ -3359,10 +3359,11 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
if (!PyString_Check(temp)) {
|
if (!PyString_Check(temp)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"%s argument has non-string str()");
|
"%s argument has non-string str()");
|
||||||
|
Py_DECREF(temp);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pbuf = PyString_AsString(temp);
|
pbuf = PyString_AS_STRING(temp);
|
||||||
len = PyString_Size(temp);
|
len = PyString_GET_SIZE(temp);
|
||||||
if (prec >= 0 && len > prec)
|
if (prec >= 0 && len > prec)
|
||||||
len = prec;
|
len = prec;
|
||||||
break;
|
break;
|
||||||
|
@ -3441,7 +3442,7 @@ PyString_Format(PyObject *format, PyObject *args)
|
||||||
reslen += rescnt;
|
reslen += rescnt;
|
||||||
if (_PyString_Resize(&result, reslen) < 0)
|
if (_PyString_Resize(&result, reslen) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
res = PyString_AsString(result)
|
res = PyString_AS_STRING(result)
|
||||||
+ reslen - rescnt;
|
+ reslen - rescnt;
|
||||||
}
|
}
|
||||||
if (sign) {
|
if (sign) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue