X-Git-Url: https://git.distorted.org.uk/~mdw/pyke/blobdiff_plain/1c0e9c88b06e3422c7afa0cf4bd3fbe166b401da..HEAD:/pyke.c diff --git a/pyke.c b/pyke.c index 1d4458b..330f15c 100644 --- a/pyke.c +++ b/pyke.c @@ -46,16 +46,18 @@ PyObject *getbool(int b) int convulong(PyObject *o, void *pp) { - long i; unsigned long *p = pp; PyObject *t; if (!o) VALERR("can't delete"); +#ifdef PY2 if (PyInt_Check(o)) { - i = PyInt_AS_LONG(o); + long i = PyInt_AS_LONG(o); if (i < 0) VALERR("must be nonnegative"); *p = i; - } else { + } else +#endif + { if ((t = PyNumber_Long(o)) == 0) goto end; *p = PyLong_AsUnsignedLong(t); Py_DECREF(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;