[Python-checkins] r46375 - sandbox/trunk/hotbuffer/Modules/_hotbuf.c

"Martin v. Löwis" martin at v.loewis.de
Fri May 26 21:05:55 CEST 2006


bob.ippolito wrote:
> +#define lenfunc inquiry
> +#define readbufferproc getreadbufferproc
> +#define writebufferproc getwritebufferproc
> +#define charbufferproc getcharbufferproc
> +#define segcountproc getsegcountproc

I would like to advise against these. Instead, I would write the
patch below.

Regards,
Martin

Index: _hotbuf.c
===================================================================
--- _hotbuf.c   (Revision 46387)
+++ _hotbuf.c   (Arbeitskopie)
@@ -15,11 +15,6 @@
 #define PY_SSIZE_T_MIN INT_MIN
 #define PyInt_FromSsize_t PyInt_FromLong
 #define PyInt_AsSsize_t PyInt_AsLong
-#define lenfunc inquiry
-#define readbufferproc getreadbufferproc
-#define writebufferproc getwritebufferproc
-#define charbufferproc getcharbufferproc
-#define segcountproc getsegcountproc
 #endif

 static PyTypeObject PyHotbuf_Type;
@@ -769,8 +764,9 @@
  * deliver the portion in the active window.
  */
 static Py_ssize_t
-hotbuf_getwritebuf(PyHotbufObject *self, Py_ssize_t idx, void **pp)
+hotbuf_getwritebuf(PyObject *self, Py_ssize_t idx, void **pp)
 {
+    PyyHotbufObject *self = (yHotbufObject*)self;
     if ( idx != 0 ) {
         PyErr_SetString(PyExc_SystemError,
                         "accessing non-existent hotbuf segment");
@@ -782,15 +778,16 @@
 }

 static Py_ssize_t
-hotbuf_getsegcount(PyHotbufObject *self, Py_ssize_t *lenp)
+hotbuf_getsegcount(PyObject *self, Py_ssize_t *lenp)
 {
+    PyHotbufObject *self = (PyHotbufObject*)self;
     if (lenp)
         *lenp = self->b_capacity;
     return 1;
 }

 static Py_ssize_t
-hotbuf_getcharbuf(PyHotbufObject *self, Py_ssize_t idx, const char **pp)
+hotbuf_getcharbuf(PyObject *self, Py_ssize_t idx, const char **pp)
 {
     return hotbuf_getwritebuf(self, idx, (void**)pp);
 }
@@ -802,8 +799,9 @@
  */

 static Py_ssize_t
-hotbuf_length(PyHotbufObject *self)
+hotbuf_length(PyObject *_self)
 {
+    PyHotbufObject *self = (PyHotbufObject*)_self;
     /* Note: this is the same as 'remaining'. */
     assert(self->b_position <= self->b_limit);
     return self->b_limit - self->b_position;
@@ -945,7 +943,7 @@
 };

 static PySequenceMethods hotbuf_as_sequence = {
-    (lenfunc)hotbuf_length,                 /*sq_length*/
+    hotbuf_length,                 /*sq_length*/
     0 /* (binaryfunc)hotbuf_concat */,              /*sq_concat*/
     0 /* (ssizeargfunc)hotbuf_repeat */,            /*sq_repeat*/
     0 /* (ssizeargfunc)hotbuf_item */,              /*sq_item*/
@@ -955,10 +953,10 @@
 };

 static PyBufferProcs hotbuf_as_buffer = {
-    (readbufferproc)hotbuf_getwritebuf,
-    (writebufferproc)hotbuf_getwritebuf,
-    (segcountproc)hotbuf_getsegcount,
-    (charbufferproc)hotbuf_getcharbuf,
+    hotbuf_getwritebuf,
+    hotbuf_getwritebuf,
+    hotbuf_getsegcount,
+    hotbuf_getcharbuf,
 };

 static PyTypeObject PyHotbuf_Type = {


More information about the Python-checkins mailing list