chiark
/
gitweb
/
~mdw
/
pyke
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a6b5c54
)
util.c: Use Python's machinery for handling 64-bit integers.
author
Mark Wooding
<mdw@distorted.org.uk>
Sat, 19 Oct 2019 19:02:08 +0000
(20:02 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Sun, 17 Nov 2019 01:43:05 +0000
(
01:43
+0000)
Where available.
util.c
patch
|
blob
|
blame
|
history
diff --git
a/util.c
b/util.c
index cfd411571a71af0c0b06061cba327872b061fbac..027033ef59fadada2fe11ad500aa48fada457d2e 100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-28,6
+28,8
@@
#include "catacomb-python.h"
#include "catacomb-python.h"
+/* #undef HAVE_LONG_LONG */
+
/*----- External values ---------------------------------------------------*/
static PyObject *modname = 0;
/*----- External values ---------------------------------------------------*/
static PyObject *modname = 0;
@@
-42,12
+44,17
@@
PyObject *getulong(unsigned long w)
return (PyLong_FromUnsignedLong(w));
}
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); }
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)
{
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;
PyObject *i = 0, *j = 0, *t;
PyObject *rc = 0;
@@
-63,6
+70,7
@@
end:
if (i) Py_DECREF(i);
if (j) Py_DECREF(j);
return (rc);
if (i) Py_DECREF(i);
if (j) Py_DECREF(j);
return (rc);
+#endif
}
PyObject *getbool(int b)
}
PyObject *getbool(int b)
@@
-146,11
+154,22
@@
end:
int convk64(PyObject *o, void *pp)
{
int convk64(PyObject *o, void *pp)
{
- PyObject *i = 0
, *t
;
+ PyObject *i = 0;
int rc = 0;
int rc = 0;
+#if HAVE_LONG_LONG
+ unsigned PY_LONG_LONG t;
+#else
+ PyObject *t;
uint32 lo, hi;
uint32 lo, hi;
+#endif
if (!o) VALERR("can't delete");
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);
if (init_i32()) goto end;
if ((i = PyNumber_Int(o)) == 0) goto end;
lo = PyInt_AsUnsignedLongMask(i);
@@
-161,7
+180,9
@@
int convk64(PyObject *o, void *pp)
Py_DECREF(i); i = t;
if (PyObject_IsTrue(i)) VALERR("out of range");
SET64(*(kludge64 *)pp, hi, lo);
Py_DECREF(i); i = t;
if (PyObject_IsTrue(i)) VALERR("out of range");
SET64(*(kludge64 *)pp, hi, lo);
+#endif
rc = 1;
rc = 1;
+
end:
if (i) Py_DECREF(i);
return (rc);
end:
if (i) Py_DECREF(i);
return (rc);