From d118856049e514dd413112ee6e2d03713c68df9d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 9 Jun 2010 16:38:55 +0000 Subject: [PATCH] Merged revisions 81860 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r81860 | antoine.pitrou | 2010-06-09 18:24:00 +0200 (mer., 09 juin 2010) | 3 lines Issue #8930: fix some C code indentation ........ --- Modules/_codecsmodule.c | 194 +++++++++++++++++++------------------- Objects/bytearrayobject.c | 60 ++++++------ Objects/bytesobject.c | 38 ++++---- 3 files changed, 146 insertions(+), 146 deletions(-) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index cabe600ee8e..eb740f95fdc 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -162,62 +162,62 @@ static PyObject * escape_encode(PyObject *self, PyObject *args) { - static const char *hexdigits = "0123456789abcdef"; - PyObject *str; - Py_ssize_t size; - Py_ssize_t newsize; - const char *errors = NULL; - PyObject *v; + static const char *hexdigits = "0123456789abcdef"; + PyObject *str; + Py_ssize_t size; + Py_ssize_t newsize; + const char *errors = NULL; + PyObject *v; - if (!PyArg_ParseTuple(args, "O!|z:escape_encode", - &PyBytes_Type, &str, &errors)) - return NULL; + if (!PyArg_ParseTuple(args, "O!|z:escape_encode", + &PyBytes_Type, &str, &errors)) + return NULL; - size = PyBytes_GET_SIZE(str); - newsize = 4*size; - if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) { - PyErr_SetString(PyExc_OverflowError, - "string is too large to encode"); - return NULL; + size = PyBytes_GET_SIZE(str); + newsize = 4*size; + if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) { + PyErr_SetString(PyExc_OverflowError, + "string is too large to encode"); + return NULL; + } + v = PyBytes_FromStringAndSize(NULL, newsize); + + if (v == NULL) { + return NULL; + } + else { + register Py_ssize_t i; + register char c; + register char *p = PyBytes_AS_STRING(v); + + for (i = 0; i < size; i++) { + /* There's at least enough room for a hex escape */ + assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); + c = PyBytes_AS_STRING(str)[i]; + if (c == '\'' || c == '\\') + *p++ = '\\', *p++ = c; + else if (c == '\t') + *p++ = '\\', *p++ = 't'; + else if (c == '\n') + *p++ = '\\', *p++ = 'n'; + else if (c == '\r') + *p++ = '\\', *p++ = 'r'; + else if (c < ' ' || c >= 0x7f) { + *p++ = '\\'; + *p++ = 'x'; + *p++ = hexdigits[(c & 0xf0) >> 4]; + *p++ = hexdigits[c & 0xf]; + } + else + *p++ = c; } - v = PyBytes_FromStringAndSize(NULL, newsize); - - if (v == NULL) { - return NULL; + *p = '\0'; + if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) { + return NULL; } - else { - register Py_ssize_t i; - register char c; - register char *p = PyBytes_AS_STRING(v); + } - for (i = 0; i < size; i++) { - /* There's at least enough room for a hex escape */ - assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); - c = PyBytes_AS_STRING(str)[i]; - if (c == '\'' || c == '\\') - *p++ = '\\', *p++ = c; - else if (c == '\t') - *p++ = '\\', *p++ = 't'; - else if (c == '\n') - *p++ = '\\', *p++ = 'n'; - else if (c == '\r') - *p++ = '\\', *p++ = 'r'; - else if (c < ' ' || c >= 0x7f) { - *p++ = '\\'; - *p++ = 'x'; - *p++ = hexdigits[(c & 0xf0) >> 4]; - *p++ = hexdigits[c & 0xf]; - } - else - *p++ = c; - } - *p = '\0'; - if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) { - return NULL; - } - } - - return codec_tuple(v, size); + return codec_tuple(v, size); } /* --- Decoder ------------------------------------------------------------ */ @@ -252,7 +252,7 @@ static PyObject * utf_7_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int final = 0; Py_ssize_t consumed; @@ -265,7 +265,7 @@ utf_7_decode(PyObject *self, decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -275,7 +275,7 @@ static PyObject * utf_8_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int final = 0; Py_ssize_t consumed; @@ -288,7 +288,7 @@ utf_8_decode(PyObject *self, decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -298,7 +298,7 @@ static PyObject * utf_16_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 0; int final = 0; @@ -311,7 +311,7 @@ utf_16_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -321,7 +321,7 @@ static PyObject * utf_16_le_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = -1; int final = 0; @@ -335,7 +335,7 @@ utf_16_le_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -345,7 +345,7 @@ static PyObject * utf_16_be_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 1; int final = 0; @@ -359,7 +359,7 @@ utf_16_be_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -377,7 +377,7 @@ static PyObject * utf_16_ex_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 0; PyObject *unicode, *tuple; @@ -390,7 +390,7 @@ utf_16_ex_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (unicode == NULL) return NULL; tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); @@ -402,7 +402,7 @@ static PyObject * utf_32_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 0; int final = 0; @@ -415,7 +415,7 @@ utf_32_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -425,7 +425,7 @@ static PyObject * utf_32_le_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = -1; int final = 0; @@ -438,7 +438,7 @@ utf_32_le_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -448,7 +448,7 @@ static PyObject * utf_32_be_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 1; int final = 0; @@ -461,7 +461,7 @@ utf_32_be_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); @@ -479,7 +479,7 @@ static PyObject * utf_32_ex_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int byteorder = 0; PyObject *unicode, *tuple; @@ -492,7 +492,7 @@ utf_32_ex_decode(PyObject *self, consumed = pbuf.len; /* This is overwritten unless final is true. */ unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (unicode == NULL) return NULL; tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); @@ -504,7 +504,7 @@ static PyObject * unicode_escape_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; PyObject *unicode; @@ -512,68 +512,68 @@ unicode_escape_decode(PyObject *self, &pbuf, &errors)) return NULL; - unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors); + PyBuffer_Release(&pbuf); + return codec_tuple(unicode, pbuf.len); } static PyObject * raw_unicode_escape_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; - PyObject *unicode; + PyObject *unicode; if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode", &pbuf, &errors)) return NULL; - unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors); + PyBuffer_Release(&pbuf); + return codec_tuple(unicode, pbuf.len); } static PyObject * latin_1_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; - PyObject *unicode; + Py_buffer pbuf; + PyObject *unicode; const char *errors = NULL; if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode", &pbuf, &errors)) return NULL; - unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors); + PyBuffer_Release(&pbuf); + return codec_tuple(unicode, pbuf.len); } static PyObject * ascii_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; - PyObject *unicode; + Py_buffer pbuf; + PyObject *unicode; const char *errors = NULL; if (!PyArg_ParseTuple(args, "y*|z:ascii_decode", &pbuf, &errors)) return NULL; - unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors); + PyBuffer_Release(&pbuf); + return codec_tuple(unicode, pbuf.len); } static PyObject * charmap_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; - PyObject *unicode; + Py_buffer pbuf; + PyObject *unicode; const char *errors = NULL; PyObject *mapping = NULL; @@ -583,9 +583,9 @@ charmap_decode(PyObject *self, if (mapping == Py_None) mapping = NULL; - unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors); + PyBuffer_Release(&pbuf); + return codec_tuple(unicode, pbuf.len); } #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) @@ -594,7 +594,7 @@ static PyObject * mbcs_decode(PyObject *self, PyObject *args) { - Py_buffer pbuf; + Py_buffer pbuf; const char *errors = NULL; int final = 0; Py_ssize_t consumed; @@ -607,7 +607,7 @@ mbcs_decode(PyObject *self, decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyBuffer_Release(&pbuf); if (decoded == NULL) return NULL; return codec_tuple(decoded, consumed); diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 165ccae9f42..16350ff8c02 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1650,43 +1650,43 @@ replace_single_character_in_place(PyByteArrayObject *self, char from_c, char to_c, Py_ssize_t maxcount) { - char *self_s, *result_s, *start, *end, *next; - Py_ssize_t self_len; - PyByteArrayObject *result; + char *self_s, *result_s, *start, *end, *next; + Py_ssize_t self_len; + PyByteArrayObject *result; - /* The result string will be the same size */ - self_s = PyByteArray_AS_STRING(self); - self_len = PyByteArray_GET_SIZE(self); + /* The result string will be the same size */ + self_s = PyByteArray_AS_STRING(self); + self_len = PyByteArray_GET_SIZE(self); - next = findchar(self_s, self_len, from_c); + next = findchar(self_s, self_len, from_c); - if (next == NULL) { - /* No matches; return the original bytes */ - return return_self(self); - } + if (next == NULL) { + /* No matches; return the original bytes */ + return return_self(self); + } - /* Need to make a new bytes */ - result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len); - if (result == NULL) - return NULL; - result_s = PyByteArray_AS_STRING(result); - Py_MEMCPY(result_s, self_s, self_len); + /* Need to make a new bytes */ + result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len); + if (result == NULL) + return NULL; + result_s = PyByteArray_AS_STRING(result); + Py_MEMCPY(result_s, self_s, self_len); - /* change everything in-place, starting with this one */ - start = result_s + (next-self_s); - *start = to_c; - start++; - end = result_s + self_len; + /* change everything in-place, starting with this one */ + start = result_s + (next-self_s); + *start = to_c; + start++; + end = result_s + self_len; - while (--maxcount > 0) { - next = findchar(start, end-start, from_c); - if (next == NULL) - break; - *next = to_c; - start = next+1; - } + while (--maxcount > 0) { + next = findchar(start, end-start, from_c); + if (next == NULL) + break; + *next = to_c; + start = next+1; + } - return result; + return result; } /* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */ diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 8a15e89c9b3..fa31a8090f2 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -14,10 +14,10 @@ _getbuffer(PyObject *obj, Py_buffer *view) if (buffer == NULL || buffer->bf_getbuffer == NULL) { - PyErr_Format(PyExc_TypeError, - "Type %.100s doesn't support the buffer API", - Py_TYPE(obj)->tp_name); - return -1; + PyErr_Format(PyExc_TypeError, + "Type %.100s doesn't support the buffer API", + Py_TYPE(obj)->tp_name); + return -1; } if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0) @@ -776,19 +776,19 @@ bytes_contains(PyObject *self, PyObject *arg) { Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError); if (ival == -1 && PyErr_Occurred()) { - Py_buffer varg; - int pos; - PyErr_Clear(); - if (_getbuffer(arg, &varg) < 0) - return -1; - pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self), - varg.buf, varg.len, 0); - PyBuffer_Release(&varg); - return pos >= 0; + Py_buffer varg; + int pos; + PyErr_Clear(); + if (_getbuffer(arg, &varg) < 0) + return -1; + pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self), + varg.buf, varg.len, 0); + PyBuffer_Release(&varg); + return pos >= 0; } if (ival < 0 || ival >= 256) { - PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); - return -1; + PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); + return -1; } return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL; @@ -2345,12 +2345,12 @@ bytes_splitlines(PyObject *self, PyObject *args) int keepends = 0; if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) - return NULL; + return NULL; return stringlib_splitlines( - (PyObject*) self, PyBytes_AS_STRING(self), - PyBytes_GET_SIZE(self), keepends - ); + (PyObject*) self, PyBytes_AS_STRING(self), + PyBytes_GET_SIZE(self), keepends + ); }