[Python-checkins] r68068 - sandbox/trunk/io-c/_bufferedio.c
antoine.pitrou
python-checkins at python.org
Tue Dec 30 16:45:20 CET 2008
Author: antoine.pitrou
Date: Tue Dec 30 16:45:20 2008
New Revision: 68068
Log:
a few fixes by Amaury
Modified:
sandbox/trunk/io-c/_bufferedio.c
Modified: sandbox/trunk/io-c/_bufferedio.c
==============================================================================
--- sandbox/trunk/io-c/_bufferedio.c (original)
+++ sandbox/trunk/io-c/_bufferedio.c Tue Dec 30 16:45:20 2008
@@ -135,7 +135,7 @@
#define ENTER_BUFFERED_READER(self) \
Py_BEGIN_ALLOW_THREADS \
PyThread_acquire_lock(self->read_lock, 1); \
- Py_END_ALLOW_THREADS \
+ Py_END_ALLOW_THREADS
#define LEAVE_BUFFERED_READER(self) \
PyThread_release_lock(self->read_lock);
@@ -143,7 +143,7 @@
#define ENTER_BUFFERED_WRITER(self) \
Py_BEGIN_ALLOW_THREADS \
PyThread_acquire_lock(self->write_lock, 1); \
- Py_END_ALLOW_THREADS \
+ Py_END_ALLOW_THREADS
#define LEAVE_BUFFERED_WRITER(self) \
PyThread_release_lock(self->write_lock);
@@ -155,6 +155,13 @@
return NULL; \
}
+#define CHECK_INITIALIZED_INT(self) \
+ if (self->ok <= 0) { \
+ PyErr_SetString(PyExc_ValueError, \
+ "I/O operation on uninitialized object"); \
+ return -1; \
+ }
+
static void
BufferedObject_dealloc(BufferedObject *self)
{
@@ -234,7 +241,7 @@
{
int closed;
PyObject *res;
- CHECK_INITIALIZED(self)
+ CHECK_INITIALIZED_INT(self)
res = PyObject_GetAttr(self->raw, _PyIO_str_closed);
if (res == NULL)
return -1;
@@ -1041,7 +1048,7 @@
written = 0;
while (remaining > self->buffer_size) {
n = _BufferedWriter_raw_write(
- self, buf.buf + written, buf.len - written);
+ self, (char *) buf.buf + written, buf.len - written);
if (n == -1) {
Py_ssize_t *w = _Buffered_check_blocking_error();
if (w == NULL)
@@ -1050,7 +1057,8 @@
remaining -= *w;
if (remaining > self->buffer_size) {
/* Can't buffer everything, still buffer as much as possible */
- memcpy(self->write_buf, buf.buf + written, self->buffer_size);
+ memcpy(self->write_buf,
+ (char *) buf.buf + written, self->buffer_size);
self->write_end = self->buffer_size;
*w = written + self->buffer_size;
/* Already re-raised */
@@ -1063,7 +1071,7 @@
remaining -= n;
}
if (remaining > 0) {
- memcpy(self->write_buf, buf.buf + written, remaining);
+ memcpy(self->write_buf, (char *) buf.buf + written, remaining);
written += remaining;
}
self->write_pos = 0;
@@ -1075,7 +1083,6 @@
error:
LEAVE_BUFFERED_WRITER(self)
-error_unlocked:
PyBuffer_Release(&buf);
return res;
}
More information about the Python-checkins
mailing list