return input_obj;
}
/* Fix the size of the resulting string */
- if (inlen > 0 &&_PyString_Resize(&result, output-output_start))
- return NULL;
+ if (inlen > 0)
+ _PyString_Resize(&result, output - output_start);
return result;
}
is only one module referencing the object. You can also think of it
as creating a new string object and destroying the old one, only
more efficiently. In any case, don't use this if the string may
- already be known to some other part of the code... */
+ already be known to some other part of the code...
+ Note that if there's not enough memory to resize the string, the original
+ string object at *pv is deallocated, *pv is set to NULL, an "out of
+ memory" exception is set, and -1 is returned. Else (on success) 0 is
+ returned, and the value in *pv may or may not be the same as on input.
+ As always, an extra byte is allocated for a trailing \0 byte (newsize
+ does *not* include that), and a trailing \0 byte is stored.
+*/
int
_PyString_Resize(PyObject **pv, int newsize)
*out++ = '-';
}
- if (_PyString_Resize(&v, out - start)) {
- Py_DECREF(v);
- return NULL;
- }
+ _PyString_Resize(&v, out - start);
return v;
}
/* Resize the string if necessary */
if (offset + 12 > PyString_GET_SIZE(repr)) {
if (_PyString_Resize(&repr, PyString_GET_SIZE(repr) + 100))
- goto onError;
+ return NULL;
p = PyString_AS_STRING(repr) + offset;
}
*p++ = PyString_AS_STRING(repr)[1];
*p = '\0';
- if (_PyString_Resize(&repr, p - PyString_AS_STRING(repr)))
- goto onError;
-
+ _PyString_Resize(&repr, p - PyString_AS_STRING(repr));
return repr;
-
- onError:
- Py_DECREF(repr);
- return NULL;
}
PyObject *PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
*p++ = (char) ch;
}
*p = '\0';
- if (_PyString_Resize(&repr, p - q))
- goto onError;
-
+ _PyString_Resize(&repr, p - q);
return repr;
-
- onError:
- Py_DECREF(repr);
- return NULL;
}
PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
}
/* Resize if error handling skipped some characters */
if (s - start < PyString_GET_SIZE(repr))
- if (_PyString_Resize(&repr, s - start))
- goto onError;
+ _PyString_Resize(&repr, s - start);
return repr;
onError:
}
/* Resize if error handling skipped some characters */
if (s - start < PyString_GET_SIZE(repr))
- if (_PyString_Resize(&repr, s - start))
- goto onError;
+ _PyString_Resize(&repr, s - start);
return repr;
onError:
Py_DECREF(x);
}
if (s - PyString_AS_STRING(v) < PyString_GET_SIZE(v))
- if (_PyString_Resize(&v, (int)(s - PyString_AS_STRING(v))))
- goto onError;
+ _PyString_Resize(&v, (int)(s - PyString_AS_STRING(v)));
return v;
onError:
- Py_DECREF(v);
+ Py_XDECREF(v);
return NULL;
}