diff src/bufferproxy.c @ 898:424ef30fa1ea

Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
author marcus
date Sat, 26 Jan 2008 20:13:06 +0000
parents e8926413cb3e
children d971d169536c
line wrap: on
line diff
--- a/src/bufferproxy.c	Sat Jan 26 07:28:29 2008 +0000
+++ b/src/bufferproxy.c	Sat Jan 26 20:13:06 2008 +0000
@@ -39,7 +39,8 @@
                                    PyObject *kwds);
 static void _bufferproxy_dealloc (PyBufferProxy *self);
 static PyObject* _bufferproxy_get_dict (PyBufferProxy *self, void *closure);
-static PyObject* _bufferproxy_get_raw (PyBufferProxy *buffer, void *closure);
+static PyObject* _bufferproxy_get_raw (PyBufferProxy *self, void *closure);
+static PyObject* _bufferproxy_get_length (PyBufferProxy *self, void *closure);
 static PyObject* _bufferproxy_repr (PyBufferProxy *self);
 static PyObject* _bufferproxy_write (PyBufferProxy *buffer, PyObject *args);
 
@@ -75,6 +76,8 @@
     { "__dict__", (getter) _bufferproxy_get_dict, NULL, NULL, NULL },
     { "raw", (getter) _bufferproxy_get_raw, NULL,
       "The raw buffer data as string", NULL },
+    { "length", (getter) _bufferproxy_get_length, NULL,
+      "The size of the buffer data.", NULL },
     { NULL, NULL, NULL, NULL, NULL }
 };
 
@@ -198,9 +201,18 @@
  * Getter for PyBufferProxy.raw.
  */
 static PyObject*
-_bufferproxy_get_raw (PyBufferProxy *buffer, void *closure)
+_bufferproxy_get_raw (PyBufferProxy *self, void *closure)
 {
-    return PyString_FromStringAndSize (buffer->buffer, buffer->length);
+    return PyString_FromStringAndSize (self->buffer, self->length);
+}
+
+/**
+ * Getter for PyBufferProxy.length
+ */
+static PyObject*
+_bufferproxy_get_length (PyBufferProxy *self, void *closure)
+{
+    return PyInt_FromLong (self->length);
 }
 
 /**** Methods ****/
@@ -342,6 +354,4 @@
     apiobj = PyCObject_FromVoidPtr (c_api, NULL);
     PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
     Py_DECREF (apiobj);
-
-
 }