Kaydet (Commit) a57aae7d authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 81862 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r81862 | antoine.pitrou | 2010-06-09 18:38:55 +0200 (mer., 09 juin 2010) | 9 lines

  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
  ........
................
üst 839d5f99
This diff is collapsed.
...@@ -1756,43 +1756,43 @@ replace_single_character_in_place(PyByteArrayObject *self, ...@@ -1756,43 +1756,43 @@ replace_single_character_in_place(PyByteArrayObject *self,
char from_c, char to_c, char from_c, char to_c,
Py_ssize_t maxcount) Py_ssize_t maxcount)
{ {
char *self_s, *result_s, *start, *end, *next; char *self_s, *result_s, *start, *end, *next;
Py_ssize_t self_len; Py_ssize_t self_len;
PyByteArrayObject *result; PyByteArrayObject *result;
/* The result string will be the same size */ /* The result string will be the same size */
self_s = PyByteArray_AS_STRING(self); self_s = PyByteArray_AS_STRING(self);
self_len = PyByteArray_GET_SIZE(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) { if (next == NULL) {
/* No matches; return the original bytes */ /* No matches; return the original bytes */
return return_self(self); return return_self(self);
} }
/* Need to make a new bytes */ /* Need to make a new bytes */
result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len); result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
if (result == NULL) if (result == NULL)
return NULL; return NULL;
result_s = PyByteArray_AS_STRING(result); result_s = PyByteArray_AS_STRING(result);
Py_MEMCPY(result_s, self_s, self_len); Py_MEMCPY(result_s, self_s, self_len);
/* change everything in-place, starting with this one */ /* change everything in-place, starting with this one */
start = result_s + (next-self_s); start = result_s + (next-self_s);
*start = to_c; *start = to_c;
start++; start++;
end = result_s + self_len; end = result_s + self_len;
while (--maxcount > 0) { while (--maxcount > 0) {
next = findchar(start, end-start, from_c); next = findchar(start, end-start, from_c);
if (next == NULL) if (next == NULL)
break; break;
*next = to_c; *next = to_c;
start = next+1; start = next+1;
} }
return result; return result;
} }
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */ /* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
......
...@@ -14,10 +14,10 @@ _getbuffer(PyObject *obj, Py_buffer *view) ...@@ -14,10 +14,10 @@ _getbuffer(PyObject *obj, Py_buffer *view)
if (buffer == NULL || buffer->bf_getbuffer == NULL) if (buffer == NULL || buffer->bf_getbuffer == NULL)
{ {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Type %.100s doesn't support the buffer API", "Type %.100s doesn't support the buffer API",
Py_TYPE(obj)->tp_name); Py_TYPE(obj)->tp_name);
return -1; return -1;
} }
if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0) if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
...@@ -790,19 +790,19 @@ bytes_contains(PyObject *self, PyObject *arg) ...@@ -790,19 +790,19 @@ bytes_contains(PyObject *self, PyObject *arg)
{ {
Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError); Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (ival == -1 && PyErr_Occurred()) { if (ival == -1 && PyErr_Occurred()) {
Py_buffer varg; Py_buffer varg;
int pos; int pos;
PyErr_Clear(); PyErr_Clear();
if (_getbuffer(arg, &varg) < 0) if (_getbuffer(arg, &varg) < 0)
return -1; return -1;
pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self), pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self),
varg.buf, varg.len, 0); varg.buf, varg.len, 0);
PyBuffer_Release(&varg); PyBuffer_Release(&varg);
return pos >= 0; return pos >= 0;
} }
if (ival < 0 || ival >= 256) { if (ival < 0 || ival >= 256) {
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
return -1; return -1;
} }
return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL; return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment