Replace tabs by spaces

This commit is contained in:
Victor Stinner 2011-11-04 20:06:39 +01:00
parent 12be46ca84
commit 2fc507fe45

View file

@ -7267,13 +7267,13 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
BOOL *pusedDefaultChar = &usedDefaultChar; BOOL *pusedDefaultChar = &usedDefaultChar;
int outsize; int outsize;
PyObject *exc = NULL; PyObject *exc = NULL;
Py_UNICODE *p; Py_UNICODE *p;
Py_ssize_t size; Py_ssize_t size;
const DWORD flags = encode_code_page_flags(code_page, NULL); const DWORD flags = encode_code_page_flags(code_page, NULL);
char *out; char *out;
/* Create a substring so that we can get the UTF-16 representation /* Create a substring so that we can get the UTF-16 representation
of just the slice under consideration. */ of just the slice under consideration. */
PyObject *substring; PyObject *substring;
assert(len > 0); assert(len > 0);
@ -7282,14 +7282,14 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
else else
pusedDefaultChar = NULL; pusedDefaultChar = NULL;
substring = PyUnicode_Substring(unicode, offset, offset+len); substring = PyUnicode_Substring(unicode, offset, offset+len);
if (substring == NULL) if (substring == NULL)
return -1; return -1;
p = PyUnicode_AsUnicodeAndSize(substring, &size); p = PyUnicode_AsUnicodeAndSize(substring, &size);
if (p == NULL) { if (p == NULL) {
Py_DECREF(substring); Py_DECREF(substring);
return -1; return -1;
} }
/* First get the size of the result */ /* First get the size of the result */
outsize = WideCharToMultiByte(code_page, flags, outsize = WideCharToMultiByte(code_page, flags,
@ -7299,18 +7299,18 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
if (outsize <= 0) if (outsize <= 0)
goto error; goto error;
/* If we used a default char, then we failed! */ /* If we used a default char, then we failed! */
if (pusedDefaultChar && *pusedDefaultChar) { if (pusedDefaultChar && *pusedDefaultChar) {
Py_DECREF(substring); Py_DECREF(substring);
return -2; return -2;
} }
if (*outbytes == NULL) { if (*outbytes == NULL) {
/* Create string object */ /* Create string object */
*outbytes = PyBytes_FromStringAndSize(NULL, outsize); *outbytes = PyBytes_FromStringAndSize(NULL, outsize);
if (*outbytes == NULL) { if (*outbytes == NULL) {
Py_DECREF(substring); Py_DECREF(substring);
return -1; return -1;
} }
out = PyBytes_AS_STRING(*outbytes); out = PyBytes_AS_STRING(*outbytes);
} }
else { else {
@ -7318,13 +7318,13 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
const Py_ssize_t n = PyBytes_Size(*outbytes); const Py_ssize_t n = PyBytes_Size(*outbytes);
if (outsize > PY_SSIZE_T_MAX - n) { if (outsize > PY_SSIZE_T_MAX - n) {
PyErr_NoMemory(); PyErr_NoMemory();
Py_DECREF(substring); Py_DECREF(substring);
return -1; return -1;
} }
if (_PyBytes_Resize(outbytes, n + outsize) < 0) { if (_PyBytes_Resize(outbytes, n + outsize) < 0) {
Py_DECREF(substring); Py_DECREF(substring);
return -1; return -1;
} }
out = PyBytes_AS_STRING(*outbytes) + n; out = PyBytes_AS_STRING(*outbytes) + n;
} }
@ -7333,7 +7333,7 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
p, size, p, size,
out, outsize, out, outsize,
NULL, pusedDefaultChar); NULL, pusedDefaultChar);
Py_CLEAR(substring); Py_CLEAR(substring);
if (outsize <= 0) if (outsize <= 0)
goto error; goto error;
if (pusedDefaultChar && *pusedDefaultChar) if (pusedDefaultChar && *pusedDefaultChar)
@ -7341,7 +7341,7 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
return 0; return 0;
error: error:
Py_XDECREF(substring); Py_XDECREF(substring);
if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION)
return -2; return -2;
PyErr_SetFromWindowsErr(0); PyErr_SetFromWindowsErr(0);
@ -7361,8 +7361,8 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
Py_ssize_t insize, const char* errors) Py_ssize_t insize, const char* errors)
{ {
const DWORD flags = encode_code_page_flags(code_page, errors); const DWORD flags = encode_code_page_flags(code_page, errors);
Py_ssize_t pos = unicode_offset; Py_ssize_t pos = unicode_offset;
Py_ssize_t endin = unicode_offset + insize; Py_ssize_t endin = unicode_offset + insize;
/* Ideally, we should get reason from FormatMessage. This is the Windows /* Ideally, we should get reason from FormatMessage. This is the Windows
2000 English version of the message. */ 2000 English version of the message. */
const char *reason = "invalid character"; const char *reason = "invalid character";
@ -7430,19 +7430,19 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
/* Encode the string character per character */ /* Encode the string character per character */
while (pos < endin) while (pos < endin)
{ {
Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, pos); Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, pos);
wchar_t chars[2]; wchar_t chars[2];
int charsize; int charsize;
if (ch < 0x10000) { if (ch < 0x10000) {
chars[0] = (wchar_t)ch; chars[0] = (wchar_t)ch;
charsize = 1; charsize = 1;
} }
else { else {
ch -= 0x10000; ch -= 0x10000;
chars[0] = 0xd800 + (ch >> 10); chars[0] = 0xd800 + (ch >> 10);
chars[1] = 0xdc00 + (ch & 0x3ff); chars[1] = 0xdc00 + (ch & 0x3ff);
charsize = 2; charsize = 2;
} }
outsize = WideCharToMultiByte(code_page, flags, outsize = WideCharToMultiByte(code_page, flags,
chars, charsize, chars, charsize,
@ -7547,9 +7547,9 @@ encode_code_page(int code_page,
Py_ssize_t offset; Py_ssize_t offset;
int chunk_len, ret, done; int chunk_len, ret, done;
if (PyUnicode_READY(unicode) < 0) if (PyUnicode_READY(unicode) < 0)
return NULL; return NULL;
len = PyUnicode_GET_LENGTH(unicode); len = PyUnicode_GET_LENGTH(unicode);
if (code_page < 0) { if (code_page < 0) {
PyErr_SetString(PyExc_ValueError, "invalid code page number"); PyErr_SetString(PyExc_ValueError, "invalid code page number");
@ -7563,7 +7563,7 @@ encode_code_page(int code_page,
do do
{ {
#ifdef NEED_RETRY #ifdef NEED_RETRY
/* UTF-16 encoding may double the size, so use only INT_MAX/2 /* UTF-16 encoding may double the size, so use only INT_MAX/2
chunks. */ chunks. */
if (len > INT_MAX/2) { if (len > INT_MAX/2) {
chunk_len = INT_MAX/2; chunk_len = INT_MAX/2;