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

bob.ippolito python-checkins at python.org
Fri May 26 20:06:40 CEST 2006


Author: bob.ippolito
Date: Fri May 26 20:06:40 2006
New Revision: 46374

Modified:
   sandbox/trunk/hotbuffer/Modules/_hotbuf.c
Log:
ssize_t fixes

Modified: sandbox/trunk/hotbuffer/Modules/_hotbuf.c
==============================================================================
--- sandbox/trunk/hotbuffer/Modules/_hotbuf.c	(original)
+++ sandbox/trunk/hotbuffer/Modules/_hotbuf.c	Fri May 26 20:06:40 2006
@@ -3,10 +3,18 @@
  * network I/O.
  */
 
+#define PY_SSIZE_T_CLEAN
+
 #include "Python.h"
 #include "structmember.h"
 #include <string.h> /* for memmove */
 
+#if PY_VERSION_HEX < 0x02050000
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
 static PyTypeObject PyHotbuf_Type;
 
 #define PyHotbuf_Check(op) PyObject_TypeCheck((op), &PyHotbuf_Type)
@@ -235,7 +243,7 @@
 {
     Py_ssize_t newposition;
 
-    newposition = PyInt_AsLong(arg);
+    newposition = PyInt_AsSsize_t(arg);
     if (newposition == -1 && PyErr_Occurred())
         return NULL;
 
@@ -262,7 +270,7 @@
 static PyObject*
 hotbuf_advance(PyHotbufObject *self, PyObject* arg)
 {
-    Py_ssize_t nbytes = PyInt_AsLong(arg);
+    Py_ssize_t nbytes = PyInt_AsSsize_t(arg);
     if (nbytes == -1 && PyErr_Occurred())
         return NULL;
 
@@ -286,7 +294,7 @@
 {
     Py_ssize_t newlimit;
 
-    newlimit = PyInt_AsLong(arg);
+    newlimit = PyInt_AsSsize_t(arg);
     if (newlimit == -1 && PyErr_Occurred())
         return NULL;
 
@@ -321,7 +329,7 @@
     Py_ssize_t window;
     Py_ssize_t newlimit;
 
-    window = PyInt_AsLong(arg);
+    window = PyInt_AsSsize_t(arg);
     if (window == -1 && PyErr_Occurred())
         return NULL;
 
@@ -486,7 +494,7 @@
 static PyObject*
 hotbuf_remaining(PyHotbufObject *self)
 {
-    return PyInt_FromLong(self->b_limit - self->b_position);
+    return PyInt_FromSsize_t(self->b_limit - self->b_position);
 }
 
 
@@ -722,7 +730,7 @@
                         "unpack requires a single struct argument");
     }
     
-    len = PyInt_AsLong(size_obj);
+    len = PyInt_AsSsize_t(size_obj);
     if (len < 0)
         PyErr_SetString(PyExc_TypeError,
                         "unpack requires a single struct argument");


More information about the Python-checkins mailing list