[Python-checkins] cpython: Issue #22003: When initialized from a bytes object, io.BytesIO() now

Zachary Ware zachary.ware+pydev at gmail.com
Wed Jul 30 22:11:51 CEST 2014


I'd like to point out a couple of compiler warnings on Windows:

On Tue, Jul 29, 2014 at 6:45 PM, antoine.pitrou
<python-checkins at python.org> wrote:
> diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
> --- a/Modules/_io/bytesio.c
> +++ b/Modules/_io/bytesio.c
> @@ -33,6 +37,45 @@
>          return NULL; \
>      }
>
> +/* Ensure we have a buffer suitable for writing, in the case that an initvalue
> + * object was provided, and we're currently borrowing its buffer. `size'
> + * indicates the new buffer size allocated as part of unsharing, to avoid a
> + * redundant reallocation caused by any subsequent mutation. `truncate'
> + * indicates whether truncation should occur if `size` < self->string_size.
> + *
> + * Do nothing if the buffer wasn't shared. Returns 0 on success, or sets an
> + * exception and returns -1 on failure. Existing state is preserved on failure.
> + */
> +static int
> +unshare(bytesio *self, size_t preferred_size, int truncate)
> +{
> +    if (self->initvalue) {
> +        Py_ssize_t copy_size;
> +        char *new_buf;
> +
> +        if((! truncate) && preferred_size < self->string_size) {

..\Modules\_io\bytesio.c(56): warning C4018: '<' : signed/unsigned mismatch

> +            preferred_size = self->string_size;
> +        }
> +
> +        new_buf = (char *)PyMem_Malloc(preferred_size);
> +        if (new_buf == NULL) {
> +            PyErr_NoMemory();
> +            return -1;
> +        }
> +
> +        copy_size = self->string_size;
> +        if (copy_size > preferred_size) {

..\Modules\_io\bytesio.c(67): warning C4018: '>' : signed/unsigned mismatch

> +            copy_size = preferred_size;
> +        }
> +
> +        memcpy(new_buf, self->buf, copy_size);
> +        Py_CLEAR(self->initvalue);
> +        self->buf = new_buf;
> +        self->buf_size = preferred_size;
> +        self->string_size = (Py_ssize_t) copy_size;
> +    }
> +    return 0;
> +}
>
>  /* Internal routine to get a line from the buffer of a BytesIO
>     object. Returns the length between the current position to the

-- 
Zach


More information about the Python-checkins mailing list