[Python-3000-checkins] r57198 - python/branches/py3k/Objects/memoryobject.c

neal.norwitz python-3000-checkins at python.org
Sun Aug 19 20:39:16 CEST 2007


Author: neal.norwitz
Date: Sun Aug 19 20:38:46 2007
New Revision: 57198

Modified:
   python/branches/py3k/Objects/memoryobject.c
Log:
SF #1777057, fix memoryview('test') so it works in debug mode too.

Also return a boolean for the readonly flag.

Other cleanup: make sure to set an exception when returning NULL and
reformat the getsets to be shorter by putting them all on one line.


Modified: python/branches/py3k/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k/Objects/memoryobject.c	(original)
+++ python/branches/py3k/Objects/memoryobject.c	Sun Aug 19 20:38:46 2007
@@ -27,6 +27,7 @@
 PyMemoryView_FromMemory(PyBuffer *info)
 {
 	/* XXX(nnorwitz): need to implement something here? */
+        PyErr_SetString(PyExc_NotImplementedError, "need to implement");
         return NULL;
 }
 
@@ -46,8 +47,9 @@
                                                    &PyMemoryView_Type);
         if (mview == NULL) return NULL;
         
+        mview->base = NULL;
         if (PyObject_GetBuffer(base, &(mview->view), PyBUF_FULL) < 0) {
-                PyObject_DEL(mview);
+                Py_DECREF(mview);
                 return NULL;
         }
 
@@ -337,7 +339,7 @@
 static PyObject *
 memory_readonly_get(PyMemoryViewObject *self)
 {
-        return PyInt_FromLong(self->view.readonly);
+        return PyBool_FromLong(self->view.readonly);
 }
 
 static PyObject *
@@ -347,30 +349,14 @@
 }
 
 static PyGetSetDef memory_getsetlist[] ={ 
-        {"format",
-         (getter)memory_format_get,
-         NULL, NULL},
-        {"itemsize",
-         (getter)memory_itemsize_get,
-         NULL, NULL},
-        {"shape",
-         (getter)memory_shape_get,
-         NULL, NULL},
-        {"strides",
-         (getter)memory_strides_get,
-         NULL, NULL},
-        {"suboffsets",
-         (getter)memory_suboffsets_get,
-         NULL, NULL},
-        {"size",
-         (getter)memory_size_get,
-         NULL, NULL},
-        {"readonly",
-         (getter)memory_readonly_get,
-         NULL, NULL},
-        {"ndim",
-         (getter)memory_ndim_get,
-         NULL, NULL},
+        {"format",	(getter)memory_format_get,	NULL, NULL},
+        {"itemsize",	(getter)memory_itemsize_get,	NULL, NULL},
+        {"shape",	(getter)memory_shape_get,	NULL, NULL},
+        {"strides",	(getter)memory_strides_get,	NULL, NULL},
+        {"suboffsets",	(getter)memory_suboffsets_get,	NULL, NULL},
+        {"size",	(getter)memory_size_get,	NULL, NULL},
+        {"readonly",	(getter)memory_readonly_get,	NULL, NULL},
+        {"ndim",	(getter)memory_ndim_get,	NULL, NULL},
         {NULL, NULL, NULL, NULL},
 };
 
@@ -401,7 +387,8 @@
 static void
 memory_dealloc(PyMemoryViewObject *self)
 {
-        if (PyTuple_Check(self->base)) {
+        if (self->base != NULL) {
+            if (PyTuple_Check(self->base)) {
                 /* Special case when first element is generic object
                    with buffer interface and the second element is a
                    contiguous "shadow" that must be copied back into
@@ -419,11 +406,12 @@
                 */
                 PyObject_ReleaseBuffer(PyTuple_GET_ITEM(self->base,0),
                                        &(self->view));
-        }
-        else {
+            }
+            else {
                 PyObject_ReleaseBuffer(self->base, &(self->view));
+            }
+            Py_CLEAR(self->base);
         }
-        Py_CLEAR(self->base);
         PyObject_DEL(self);
 }
 


More information about the Python-3000-checkins mailing list