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);
r->sz = BIN_LEN(o);
return (1);
}
+#ifdef PY2
if (PyUnicode_Check(o)) {
o = _PyUnicode_AsDefaultEncodedString(o, 0);
if (!o) return (0);
r->sz = PyString_GET_SIZE(o);
return (1);
}
+#endif
return (PyObject_AsReadBuffer(o, &r->p, &r->sz) ? 0 : 1);
}
return (0);
}
+PyObject *enrich_compare(int op, int cmp)
+{
+ int r = -1;
+
+ switch (op) {
+ case Py_LT: r = cmp < 0; break;
+ case Py_LE: r = cmp <= 0; break;
+ case Py_EQ: r = cmp == 0; break;
+ case Py_NE: r = cmp != 0; break;
+ case Py_GE: r = cmp >= 0; break;
+ case Py_GT: r = cmp > 0; break;
+ default: assert(0);
+ }
+ return (getbool(r));
+}
+
/*----- Saving and restoring exceptions ----------------------------------*/
void report_lost_exception_v(struct excinfo *exc,
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);
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);
}
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;