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

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->stringsize. + * + * 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, sizet preferredsize, int truncate) +{ + if (self->initvalue) { + Pyssizet copysize; + char *newbuf; + + if((! truncate) && preferredsize < self->stringsize) {

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

+ preferredsize = self->stringsize; + } + + newbuf = (char *)PyMemMalloc(preferredsize); + if (newbuf == NULL) { + PyErrNoMemory(); + return -1; + } + + copysize = self->stringsize; + if (copysize > preferredsize) {

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

+ copysize = preferredsize; + } + + memcpy(newbuf, self->buf, copysize); + PyCLEAR(self->initvalue); + self->buf = newbuf; + self->bufsize = preferredsize; + self->stringsize = (Pyssizet) copysize; + } + 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-Dev mailing list