Author: travis.oliphant
Date: Tue Aug 14 06:27:32 2007
New Revision: 57004
Modified:
python/branches/py3k-buffer/Modules/_sre.c
python/branches/py3k-buffer/Modules/arraymodule.c
python/branches/py3k-buffer/Objects/bufferobject.c
python/branches/py3k-buffer/Objects/bytesobject.c
python/branches/py3k-buffer/Objects/stringobject.c
Log:
py3k-buffer branch: fix several problems so that test_array.py passes
Modified: python/branches/py3k-buffer/Modules/_sre.c
==============================================================================
--- python/branches/py3k-buffer/Modules/_sre.c (original)
+++ python/branches/py3k-buffer/Modules/_sre.c Tue Aug 14 06:27:32 2007
@@ -1674,45 +1674,35 @@
void* ptr;
PyBuffer view;
-#if defined(HAVE_UNICODE)
- if (PyUnicode_Check(string)) {
- /* unicode strings doesn't always support the buffer interface */
- ptr = (void*) PyUnicode_AS_DATA(string);
- bytes = PyUnicode_GET_DATA_SIZE(string);
- size = PyUnicode_GET_SIZE(string);
- charsize = sizeof(Py_UNICODE);
-
- } else {
-#endif
-
/* get pointer to string buffer */
buffer = Py_Type(string)->tp_as_buffer;
if (!buffer || !buffer->bf_getbuffer ||
- (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) !=0) {
+ (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
return NULL;
}
-
/* determine buffer size */
bytes = view.len;
ptr = view.buf;
+
+ /* Release the buffer immediately --- possibly dangerous
+ but doing something else would require some re-factoring
+ */
+ PyObject_ReleaseBuffer(string, &view);
+
if (bytes < 0) {
PyErr_SetString(PyExc_TypeError, "buffer has negative size");
return NULL;
}
/* determine character size */
-#if PY_VERSION_HEX >= 0x01060000
size = PyObject_Size(string);
-#else
- size = PyObject_Length(string);
-#endif
if (PyString_Check(string) || bytes == size)
charsize = 1;
#if defined(HAVE_UNICODE)
- else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE)))
+ else if (bytes == (Py_ssize_t) (size * sizeof(Py_UNICODE)))
charsize = sizeof(Py_UNICODE);
#endif
else {
@@ -1720,10 +1710,6 @@
return NULL;
}
-#if defined(HAVE_UNICODE)
- }
-#endif
-
*p_length = size;
*p_charsize = charsize;
@@ -1789,6 +1775,7 @@
LOCAL(void)
state_fini(SRE_STATE* state)
{
+
Py_XDECREF(state->string);
data_stack_dealloc(state);
}
Modified: python/branches/py3k-buffer/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-buffer/Modules/arraymodule.c (original)
+++ python/branches/py3k-buffer/Modules/arraymodule.c Tue Aug 14 06:27:32 2007
@@ -42,10 +42,10 @@
#ifdef Py_UNICODE_WIDE
#define PyArr_UNI 'w'
-static const char *PyArr_UNISTR = "w";
+/*static const char *PyArr_UNISTR = "w"; */
#else
#define PyArr_UNI 'u'
-static const char *PyArr_UNISTR = "u";
+/*static const char *PyArr_UNISTR = "u"; */
#endif
#define array_Check(op) PyObject_TypeCheck(op, &Arraytype)
@@ -1735,7 +1735,6 @@
(objobjargproc)array_ass_subscr
};
-static const void *emptybuf = "";
static int
array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
@@ -1748,28 +1747,26 @@
if (view==NULL) goto finish;
view->buf = (void *)self->ob_item;
- view->len = Py_Size(self)*self->ob_descr->itemsize;
+ view->len = (Py_Size(self)) * self->ob_descr->itemsize;
view->readonly = 0;
view->ndim = 1;
view->itemsize = self->ob_descr->itemsize;
view->suboffsets = NULL;
- view->internal = NULL;
+ view->shape = NULL;
if ((flags & PyBUF_ALW_ND)==PyBUF_ALW_ND) {
- view->shape = &(Py_Size(self));
+ view->shape = &((Py_Size(self)));
}
- else
- view->shape = NULL;
+ view->strides = NULL;
if ((flags & PyBUF_ALW_STRIDES)==PyBUF_ALW_STRIDES)
view->strides = &(view->itemsize);
- else
- view->strides = NULL;
+ view->format = NULL;
+ view->internal = NULL;
if ((flags & PyBUF_REQ_FORMAT) == PyBUF_REQ_FORMAT) {
- view->format = malloc(2);
- view->format[0] = (char)self->ob_descr->typecode;
+ view->internal = malloc(3);
+ view->format = view->internal;
+ view->format[0] = (char)(self->ob_descr->typecode);
view->format[1] = '\0';
}
- else
- view->format = NULL;
finish:
self->ob_exports++;
@@ -1779,7 +1776,7 @@
static void
array_buffer_relbuf(arrayobject *self, PyBuffer *view)
{
- free(view->format);
+ free(view->internal);
self->ob_exports--;
}
Modified: python/branches/py3k-buffer/Objects/bufferobject.c
==============================================================================
--- python/branches/py3k-buffer/Objects/bufferobject.c (original)
+++ python/branches/py3k-buffer/Objects/bufferobject.c Tue Aug 14 06:27:32 2007
@@ -25,21 +25,20 @@
else {
Py_ssize_t count, offset;
PyBufferProcs *bp = self->b_base->ob_type->tp_as_buffer;
- PyBuffer view;
- if ((*bp->bf_getbuffer)(self->b_base, &view, PyBUF_SIMPLE) <
0) return 0;
- count = view.len;
+ if ((*bp->bf_getbuffer)(self->b_base, view, PyBUF_SIMPLE) < 0)
return 0;
+ count = view->len;
/* apply constraints to the start/end */
if (self->b_offset > count)
offset = count;
else
offset = self->b_offset;
- view.buf = (char*)view.buf + offset;
+ view->buf = (char*)view->buf + offset;
if (self->b_size == Py_END_OF_BUFFER)
- view.len = count;
+ view->len = count;
else
- view.len = self->b_size;
- if (offset + view.len > count)
- view.len = count - offset;
+ view->len = self->b_size;
+ if (offset + view->len > count)
+ view->len = count - offset;
}
return 1;
}
Modified: python/branches/py3k-buffer/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-buffer/Objects/bytesobject.c (original)
+++ python/branches/py3k-buffer/Objects/bytesobject.c Tue Aug 14 06:27:32 2007
@@ -79,7 +79,9 @@
PyUnicode_Check(obj) ||
buffer->bf_getbuffer == NULL) return -1;
- return buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE);
+ if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
+ return -1;
+ return view->len;
}
/* Direct API functions */
Modified: python/branches/py3k-buffer/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-buffer/Objects/stringobject.c (original)
+++ python/branches/py3k-buffer/Objects/stringobject.c Tue Aug 14 06:27:32 2007
@@ -1239,7 +1239,7 @@
static int
string_buffer_getbuffer(PyStringObject *self, PyBuffer *view, int flags)
{
- return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self),
1, flags);
+ return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self),
0, flags);
}
static PySequenceMethods string_as_sequence = {
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins