diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-08-13 15:53:07 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-08-13 15:53:07 (GMT) |
commit | 423be95dcf55b0b8737207beb7b30eb549430dba (patch) | |
tree | b23453f2dc43d809aca931203a9580a81bd938fe /Objects/bytearrayobject.c | |
parent | 688356f59f3b0fe2412a5f66b79f0f9fdc4a98d2 (diff) | |
download | cpython-423be95dcf55b0b8737207beb7b30eb549430dba.zip cpython-423be95dcf55b0b8737207beb7b30eb549430dba.tar.gz cpython-423be95dcf55b0b8737207beb7b30eb549430dba.tar.bz2 |
Merged revisions 65654 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r65654 | martin.v.loewis | 2008-08-12 16:49:50 +0200 (Tue, 12 Aug 2008) | 6 lines
Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
by denying s# to parse objects that have a releasebuffer procedure,
and introducing s*.
More module might need to get converted to use s*.
........
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index a76f827..dfe0a86 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -69,7 +69,7 @@ bytes_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags) ptr = ""; else ptr = obj->ob_bytes; - ret = PyBuffer_FillInfo(view, ptr, Py_SIZE(obj), 0, flags); + ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags); if (ret >= 0) { obj->ob_exports++; } @@ -248,9 +248,9 @@ PyByteArray_Concat(PyObject *a, PyObject *b) done: if (va.len != -1) - PyObject_ReleaseBuffer(a, &va); + PyBuffer_Release(&va); if (vb.len != -1) - PyObject_ReleaseBuffer(b, &vb); + PyBuffer_Release(&vb); return (PyObject *)result; } @@ -278,7 +278,7 @@ bytes_iconcat(PyByteArrayObject *self, PyObject *other) mysize = Py_SIZE(self); size = mysize + vo.len; if (size < 0) { - PyObject_ReleaseBuffer(other, &vo); + PyBuffer_Release(&vo); return PyErr_NoMemory(); } if (size < self->ob_alloc) { @@ -286,11 +286,11 @@ bytes_iconcat(PyByteArrayObject *self, PyObject *other) self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */ } else if (PyByteArray_Resize((PyObject *)self, size) < 0) { - PyObject_ReleaseBuffer(other, &vo); + PyBuffer_Release(&vo); return NULL; } memcpy(self->ob_bytes + mysize, vo.buf, vo.len); - PyObject_ReleaseBuffer(other, &vo); + PyBuffer_Release(&vo); Py_INCREF(self); return (PyObject *)self; } @@ -501,7 +501,7 @@ bytes_setslice(PyByteArrayObject *self, Py_ssize_t lo, Py_ssize_t hi, finish: if (vbytes.len != -1) - PyObject_ReleaseBuffer(values, &vbytes); + PyBuffer_Release(&vbytes); return res; } @@ -767,10 +767,10 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds) if (PyByteArray_Resize((PyObject *)self, size) < 0) goto fail; if (PyBuffer_ToContiguous(self->ob_bytes, &view, size, 'C') < 0) goto fail; - PyObject_ReleaseBuffer(arg, &view); + PyBuffer_Release(&view); return 0; fail: - PyObject_ReleaseBuffer(arg, &view); + PyBuffer_Release(&view); return -1; } @@ -954,7 +954,7 @@ bytes_richcompare(PyObject *self, PyObject *other, int op) other_size = _getbuffer(other, &other_bytes); if (other_size < 0) { PyErr_Clear(); - PyObject_ReleaseBuffer(self, &self_bytes); + PyBuffer_Release(&self_bytes); Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } @@ -989,8 +989,8 @@ bytes_richcompare(PyObject *self, PyObject *other, int op) } res = cmp ? Py_True : Py_False; - PyObject_ReleaseBuffer(self, &self_bytes); - PyObject_ReleaseBuffer(other, &other_bytes); + PyBuffer_Release(&self_bytes); + PyBuffer_Release(&other_bytes); Py_INCREF(res); return res; } @@ -998,6 +998,11 @@ bytes_richcompare(PyObject *self, PyObject *other, int op) static void bytes_dealloc(PyByteArrayObject *self) { + if (self->ob_exports > 0) { + PyErr_SetString(PyExc_SystemError, + "deallocated bytearray object has exported buffers"); + PyErr_Print(); + } if (self->ob_bytes != 0) { PyMem_Free(self->ob_bytes); } @@ -1065,7 +1070,7 @@ bytes_find_internal(PyByteArrayObject *self, PyObject *args, int dir) res = stringlib_rfind_slice( PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), subbuf.buf, subbuf.len, start, end); - PyObject_ReleaseBuffer(subobj, &subbuf); + PyBuffer_Release(&subbuf); return res; } @@ -1115,7 +1120,7 @@ bytes_count(PyByteArrayObject *self, PyObject *args) count_obj = PyLong_FromSsize_t( stringlib_count(str + start, end - start, vsub.buf, vsub.len) ); - PyObject_ReleaseBuffer(sub_obj, &vsub); + PyBuffer_Release(&vsub); return count_obj; } @@ -1191,7 +1196,7 @@ bytes_contains(PyObject *self, PyObject *arg) return -1; pos = stringlib_find(PyByteArray_AS_STRING(self), Py_SIZE(self), varg.buf, varg.len, 0); - PyObject_ReleaseBuffer(arg, &varg); + PyBuffer_Release(&varg); return pos >= 0; } if (ival < 0 || ival >= 256) { @@ -1241,7 +1246,7 @@ _bytes_tailmatch(PyByteArrayObject *self, PyObject *substr, Py_ssize_t start, rv = ! memcmp(str+start, vsubstr.buf, vsubstr.len); done: - PyObject_ReleaseBuffer(substr, &vsubstr); + PyBuffer_Release(&vsubstr); return rv; } @@ -1421,9 +1426,9 @@ bytes_translate(PyByteArrayObject *self, PyObject *args) PyByteArray_Resize(result, output - output_start); done: - PyObject_ReleaseBuffer(tableobj, &vtable); + PyBuffer_Release(&vtable); if (delobj != NULL) - PyObject_ReleaseBuffer(delobj, &vdel); + PyBuffer_Release(&vdel); return result; } @@ -2042,7 +2047,7 @@ bytes_replace(PyByteArrayObject *self, PyObject *args) if (_getbuffer(from, &vfrom) < 0) return NULL; if (_getbuffer(to, &vto) < 0) { - PyObject_ReleaseBuffer(from, &vfrom); + PyBuffer_Release(&vfrom); return NULL; } @@ -2050,8 +2055,8 @@ bytes_replace(PyByteArrayObject *self, PyObject *args) vfrom.buf, vfrom.len, vto.buf, vto.len, count); - PyObject_ReleaseBuffer(from, &vfrom); - PyObject_ReleaseBuffer(to, &vto); + PyBuffer_Release(&vfrom); + PyBuffer_Release(&vto); return res; } @@ -2207,7 +2212,7 @@ bytes_split(PyByteArrayObject *self, PyObject *args) if (n == 0) { PyErr_SetString(PyExc_ValueError, "empty separator"); - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } if (n == 1) @@ -2215,7 +2220,7 @@ bytes_split(PyByteArrayObject *self, PyObject *args) list = PyList_New(PREALLOC_SIZE(maxsplit)); if (list == NULL) { - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } @@ -2243,12 +2248,12 @@ bytes_split(PyByteArrayObject *self, PyObject *args) #endif SPLIT_ADD(s, i, len); FIX_PREALLOC_SIZE(list); - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return list; onError: Py_DECREF(list); - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } @@ -2439,7 +2444,7 @@ bytes_rsplit(PyByteArrayObject *self, PyObject *args) if (n == 0) { PyErr_SetString(PyExc_ValueError, "empty separator"); - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } else if (n == 1) @@ -2447,7 +2452,7 @@ bytes_rsplit(PyByteArrayObject *self, PyObject *args) list = PyList_New(PREALLOC_SIZE(maxsplit)); if (list == NULL) { - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } @@ -2468,12 +2473,12 @@ bytes_rsplit(PyByteArrayObject *self, PyObject *args) FIX_PREALLOC_SIZE(list); if (PyList_Reverse(list) < 0) goto onError; - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return list; onError: Py_DECREF(list); - PyObject_ReleaseBuffer(subobj, &vsub); + PyBuffer_Release(&vsub); return NULL; } @@ -2749,7 +2754,7 @@ bytes_strip(PyByteArrayObject *self, PyObject *args) else right = rstrip_helper(myptr, mysize, argptr, argsize); if (arg != Py_None) - PyObject_ReleaseBuffer(arg, &varg); + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left); } @@ -2783,7 +2788,7 @@ bytes_lstrip(PyByteArrayObject *self, PyObject *args) left = lstrip_helper(myptr, mysize, argptr, argsize); right = mysize; if (arg != Py_None) - PyObject_ReleaseBuffer(arg, &varg); + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left); } @@ -2817,7 +2822,7 @@ bytes_rstrip(PyByteArrayObject *self, PyObject *args) left = 0; right = rstrip_helper(myptr, mysize, argptr, argsize); if (arg != Py_None) - PyObject_ReleaseBuffer(arg, &varg); + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(self->ob_bytes + left, right - left); } |