Port to Python 3.
[pyke] / pyke.c
diff --git a/pyke.c b/pyke.c
index 03f1c1f..330f15c 100644 (file)
--- a/pyke.c
+++ b/pyke.c
@@ -50,11 +50,13 @@ int convulong(PyObject *o, void *pp)
   PyObject *t;
 
   if (!o) VALERR("can't delete");
+#ifdef PY2
   if (PyInt_Check(o)) {
     long i = PyInt_AS_LONG(o);
     if (i < 0) VALERR("must be nonnegative");
     *p = i;
   } else
+#endif
   {
     if ((t = PyNumber_Long(o)) == 0) goto end;
     *p = PyLong_AsUnsignedLong(t);
@@ -110,6 +112,7 @@ int convbin(PyObject *o, void *pp)
     r->sz = BIN_LEN(o);
     return (1);
   }
+#ifdef PY2
   if (PyUnicode_Check(o)) {
     o = _PyUnicode_AsDefaultEncodedString(o, 0);
     if (!o) return (0);
@@ -117,6 +120,7 @@ int convbin(PyObject *o, void *pp)
     r->sz = PyString_GET_SIZE(o);
     return (1);
   }
+#endif
   return (PyObject_AsReadBuffer(o, &r->p, &r->sz) ? 0 : 1);
 }
 
@@ -274,6 +278,9 @@ void *newtype(PyTypeObject *metaty,
   if (ty->ht_name)
     ty->ht_type.tp_name = TEXT_STR(ty->ht_name);
   ty->ht_slots = 0;
+#ifdef PY3
+  ty->ht_qualname = 0;
+#endif
   (void)PyObject_INIT(&ty->ht_type, metaty);
   Py_INCREF(metaty);
   return (ty);
@@ -281,6 +288,10 @@ void *newtype(PyTypeObject *metaty,
 
 void typeready(PyTypeObject *ty)
 {
+#ifdef PY3
+  PyHeapTypeObject *hty = (PyHeapTypeObject *)ty;
+  hty->ht_qualname = hty->ht_name;
+#endif
   PyType_Ready(ty);
   PyDict_SetItemString(ty->tp_dict, "__module__", modname);
 }
@@ -312,7 +323,8 @@ PyObject *mkexc(PyObject *mod, PyObject *base,
     while (mm->ml_name) {
       if ((func = PyCFunction_NewEx((/*unconst*/ PyMethodDef *)mm,
                                    0, mod)) == 0 ||
-         (meth = PyMethod_New(func, 0, exc)) == 0 ||
+         (meth = PY23(PyMethod_New(func, 0, exc),
+                      PyInstanceMethod_New(func))) == 0 ||
          PyDict_SetItemString(dict, mm->ml_name, meth))
        goto fail;
       Py_DECREF(func); func = 0;