#include "catacomb-python.h"
+/* #undef HAVE_LONG_LONG */
+
/*----- External values ---------------------------------------------------*/
static PyObject *modname = 0;
return (PyLong_FromUnsignedLong(w));
}
+#ifndef HAVE_LONG_LONG
static PyObject *i32 = 0;
static int init_i32(void)
{ if (!i32 && (i32 = PyInt_FromLong(32)) == 0) return (-1); return (0); }
+#endif
PyObject *getk64(kludge64 u)
{
+#ifdef HAVE_LONG_LONG
+ return (PyLong_FromUnsignedLongLong(GET64(unsigned PY_LONG_LONG, u)));
+#else
PyObject *i = 0, *j = 0, *t;
PyObject *rc = 0;
if (i) Py_DECREF(i);
if (j) Py_DECREF(j);
return (rc);
+#endif
}
PyObject *getbool(int b)
unsigned long *p = pp;
PyObject *t;
+ if (!o) VALERR("can't delete");
if (PyInt_Check(o)) {
i = PyInt_AS_LONG(o);
if (i < 0) VALERR("must be nonnegative");
return (0);
}
+#ifdef HAVE_UINT64
+# define CONVu64(n) do { \
+ kludge64 k; \
+ uint64 t; \
+ if (!convk64(o, &k)) goto end; \
+ t = GET64(uint64, k); \
+ if (t > MASK##n) VALERR("out of range"); \
+ *p = t; \
+ } while (0)
+#else
+# define CONVu64(n) assert(!"shouldn't be possible")
+#endif
+
#define CONVU_(n) \
int convu##n(PyObject *o, void *pp) \
{ \
unsigned long u; \
uint##n *p = pp; \
\
- if (!convulong(o, &u)) goto end; \
- if (u > MASK##n) VALERR("out of range"); \
- *p = u; \
+ if (MASK##n > ULONG_MAX) \
+ CONVu64(n); \
+ else { \
+ if (!convulong(o, &u)) goto end; \
+ if (u > MASK##n) VALERR("out of range"); \
+ *p = u; \
+ } \
return (1); \
end: \
return (0); \
int convk64(PyObject *o, void *pp)
{
- PyObject *i = 0, *t;
+ PyObject *i = 0;
int rc = 0;
+#if HAVE_LONG_LONG
+ unsigned PY_LONG_LONG t;
+#else
+ PyObject *t;
uint32 lo, hi;
-
+#endif
+
+ if (!o) VALERR("can't delete");
+#if HAVE_LONG_LONG
+ if ((i = PyNumber_Long(o)) == 0) goto end;
+ t = PyLong_AsUnsignedLongLong(i);
+ if (t == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) goto end;
+ ASSIGN64(*(kludge64 *)pp, t);
+#else
if (init_i32()) goto end;
if ((i = PyNumber_Int(o)) == 0) goto end;
lo = PyInt_AsUnsignedLongMask(i);
Py_DECREF(i); i = t;
if (PyObject_IsTrue(i)) VALERR("out of range");
SET64(*(kludge64 *)pp, hi, lo);
+#endif
rc = 1;
+
end:
if (i) Py_DECREF(i);
return (rc);
int convbool(PyObject *o, void *pp)
{
+ if (!o) VALERR("can't delete");
*(int *)pp = PyObject_IsTrue(o);
return (1);
+end:
+ return (0);
}
/*----- Type messing ------------------------------------------------------*/
PyDict_SetItemString(ty->tp_dict, "__module__", modname);
}
-PyTypeObject *inittype(PyTypeObject *tyskel)
+PyTypeObject *inittype(PyTypeObject *tyskel, PyTypeObject *meta)
{
- PyTypeObject *ty = newtype(&PyType_Type, tyskel, 0);
+ PyTypeObject *ty = newtype(meta, tyskel, 0);
ty->tp_flags |= Py_TPFLAGS_HEAPTYPE;
typeready(ty);
return (ty);
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Iterates over the items of a mapping.",
+"Iterates over the keys of a mapping.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Iterates over the items of a mapping.",
+"Iterates over the values of a mapping.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
Py_ssize_t gmap_pysize(PyObject *me)
{
PyObject *i = 0, *x = 0;
- int rc = -1;
- int n = 0;
+ Py_ssize_t rc = -1, n = 0;
if ((i = PyObject_GetIter(me)) == 0) goto done;
while ((x = PyIter_Next(i)) != 0) { n++; Py_DECREF(x); x = 0; }