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)
return v;
onError:
- Py_DECREF(v);
return NULL;
}
return repr;
onError:
- Py_DECREF(repr);
return NULL;
}
return repr;
onError:
- Py_DECREF(repr);
return NULL;
}
Py_UNICODE ch = *p++;
if (ch >= 256) {
if (latin1_encoding_error(&p, &s, errors,
- "ordinal not in range(256)"))
+ "ordinal not in range(256)")) {
+ Py_DECREF(repr);
goto onError;
+ }
}
else
*s++ = (char)ch;
return repr;
onError:
- Py_DECREF(repr);
return NULL;
}
Py_UNICODE ch = *p++;
if (ch >= 128) {
if (ascii_encoding_error(&p, &s, errors,
- "ordinal not in range(128)"))
+ "ordinal not in range(128)")) {
+ Py_DECREF(repr);
goto onError;
+ }
}
else
*s++ = (char)ch;
return repr;
onError:
- Py_DECREF(repr);
return NULL;
}
/* Get mapping (Unicode ordinal -> string char, integer or None) */
w = PyInt_FromLong((long)ch);
if (w == NULL)
- goto onError;
+ goto onErrorDecref;
x = PyObject_GetItem(mapping, w);
Py_DECREF(w);
if (x == NULL) {
x = Py_None;
Py_INCREF(x);
} else
- goto onError;
+ goto onErrorDecref;
}
/* Apply mapping */
PyErr_SetString(PyExc_TypeError,
"character mapping must be in range(256)");
Py_DECREF(x);
- goto onError;
+ goto onErrorDecref;
}
*s++ = (char)value;
}
if (charmap_encoding_error(&p, &s, errors,
"character maps to <undefined>")) {
Py_DECREF(x);
- goto onError;
+ goto onErrorDecref;
}
}
else if (PyString_Check(x)) {
(targetsize << 2);
extrachars += needed;
if (_PyString_Resize(&v, PyString_GET_SIZE(v) + needed)) {
- Py_DECREF(x);
+ Py_DECREF(x);
goto onError;
}
s = PyString_AS_STRING(v) + oldpos;
PyErr_SetString(PyExc_TypeError,
"character mapping must return integer, None or unicode");
Py_DECREF(x);
- goto onError;
+ goto onErrorDecref;
}
Py_DECREF(x);
}
goto onError;
return v;
- onError:
+ onErrorDecref:
Py_DECREF(v);
+ onError:
return NULL;
}