Author: christian.heimes
Date: Thu Nov  8 03:28:11 2007
New Revision: 58907

Added:
   python/branches/py3k/Lib/test/test_memoryview.py   (contents, props changed)
Modified:
   python/branches/py3k/Objects/memoryobject.c
Log:
Fixed memoryview constructor. It allowed arbitrary keyword arguments. The bug 
was found by mykhal from #python. I've also added a small test case in the new 
test_memoryview.py

Added: python/branches/py3k/Lib/test/test_memoryview.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_memoryview.py    Thu Nov  8 03:28:11 2007
@@ -0,0 +1,25 @@
+"""Unit tests for the memoryview
+
+XXX We need more tests! Some tests are in test_bytes
+"""
+
+import unittest
+import test.test_support
+
+class MemoryviewTest(unittest.TestCase):
+
+    def test_constructor(self):
+        ob = b'test'
+        self.assert_(memoryview(ob))
+        self.assert_(memoryview(object=ob))
+        self.assertRaises(TypeError, memoryview)
+        self.assertRaises(TypeError, memoryview, ob, ob)
+        self.assertRaises(TypeError, memoryview, argument=ob)
+        self.assertRaises(TypeError, memoryview, ob, argument=True)
+
+def test_main():
+    test.test_support.run_unittest(MemoryviewTest)
+
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k/Objects/memoryobject.c
==============================================================================
--- python/branches/py3k/Objects/memoryobject.c (original)
+++ python/branches/py3k/Objects/memoryobject.c Thu Nov  8 03:28:11 2007
@@ -69,10 +69,15 @@
 static PyObject *
 memory_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
 {
-        PyObject *obj;
-        if (!PyArg_UnpackTuple(args, "memoryview", 1, 1, &obj)) return NULL;
+       PyObject *obj;
+       static char *kwlist[] = {"object", 0};
 
-        return PyMemoryView_FromObject(obj);
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:memoryview", kwlist,
+                                        &obj)) {
+               return NULL;
+       }
+
+       return PyMemoryView_FromObject(obj);
 }
 
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to