Port to Python 3.
[catacomb-python] / bytestring.c
index ced62b4..89f3e4a 100644 (file)
@@ -42,7 +42,9 @@ static PyObject *allocate(PyTypeObject *ty, size_t n)
 #if defined(CACHE_HASH) || PY_VERSION_HEX >= 0x02030000
   x->ob_shash = -1;
 #endif
+#ifdef PY2
   x->ob_sstate = SSTATE_NOT_INTERNED;
+#endif
   return ((PyObject *)x);
 }
 
@@ -172,7 +174,11 @@ static PyObject *bytestring_pyitem(PyObject *me, Py_ssize_t i)
   PyObject *rc = 0;
 
   if (i < 0 || i >= BIN_LEN(me)) IXERR("out of range");
+#ifdef PY3
+  rc = getulong(BIN_PTR(me)[i]&0xff);
+#else
   rc = bytestring_pywrap(BIN_PTR(me) + i, 1);
+#endif
 end:
   return (rc);
 }
@@ -206,8 +212,8 @@ static PyObject *bytestring_pysubscript(PyObject *me, PyObject *ix)
     if (i < 0) i += BIN_LEN(me);
     rc = bytestring_pyitem(me, i);
   } else if (PySlice_Check(ix)) {
-    if (PySlice_GetIndicesEx((PySliceObject *)ix, BIN_LEN(me),
-                            &i, &j, &k, &n))
+    if (PySlice_GetIndicesEx(PY23((PySliceObject *), NOTHING)ix,
+                            BIN_LEN(me), &i, &j, &k, &n))
       return (0);
     if (k == 1) return bytestring_pyslice(me, i, j);
     rc = bytestring_pywrap(0, n);
@@ -266,7 +272,9 @@ static const PyNumberMethods bytestring_pynumber = {
   0,                                   /* @nb_add@ */
   0,                                   /* @nb_subtract@ */
   0,                                   /* @nb_multiply@ */
+#ifdef PY2
   0,                                   /* @nb_divide@ */
+#endif
   0,                                   /* @nb_remainder@ */
   0,                                   /* @nb_divmod@ */
   0,                                   /* @nb_power@ */