diff --git a/src/runtime/python/compat.h b/src/runtime/python/compat.h index 2824575d7..1c5483844 100644 --- a/src/runtime/python/compat.h +++ b/src/runtime/python/compat.h @@ -20,8 +20,9 @@ #define PyStringObject PyUnicodeObject #define PyString_Check PyUnicode_Check #define PyString_FromStringAndSize PyUnicode_FromStringAndSize - // #define PyString_FromFormat PyUnicode_FromFormat + #define PyString_FromFormat PyUnicode_FromFormat // #define PyString_Concat(ps,s) {PyObject* tmp = *(ps); *(ps) = PyUnicode_Concat(tmp,s); Py_DECREF(tmp);} + #define PyString_Concat PyUnicode_Concat #define PyString_Compare PyUnicode_Compare #endif diff --git a/src/runtime/python/expr.c b/src/runtime/python/expr.c index 6eb719f54..f7d1c9a5e 100644 --- a/src/runtime/python/expr.c +++ b/src/runtime/python/expr.c @@ -130,7 +130,10 @@ ExprLit_richcompare(ExprLitObject *t1, ExprLitObject *t2, int op) if (t1->type != t2->type) goto done; if (t1->type == 0) { - if (PyLong_AsLong(t1->value) != PyLong_AsLong(t2->value)) goto done; + int o1, o2; + int l1 = PyLong_AsLongAndOverflow(t1->value, &o1); + int l2 = PyLong_AsLongAndOverflow(t2->value, &o2); + if (!(l1 == l2 && o1 == o2)) goto done; } else if (t1->type == 1) { if (PyFloat_AsDouble(t1->value) != PyFloat_AsDouble(t2->value)) goto done; } else if (t1->type == 2) { diff --git a/src/runtime/python/marshaller.c b/src/runtime/python/marshaller.c index 8c364f5e4..c5f575a9c 100644 --- a/src/runtime/python/marshaller.c +++ b/src/runtime/python/marshaller.c @@ -80,12 +80,22 @@ PgfExpr eimplarg(PgfUnmarshaller *this, PgfExpr expr) PgfLiteral lint(PgfUnmarshaller *this, size_t size, uintmax_t *v) { intmax_t *v0 = (intmax_t *)v; - if (size > 1) { - PyErr_SetString(PyExc_NotImplementedError, "multi-part integers not implemented"); // TODO - Py_RETURN_NOTIMPLEMENTED; + if (size == 0) { + return (PgfLiteral) 0; + } else if (size > 1) { + // TODO: string concatenation works but probably not optimal + PyObject *sb = PyString_FromFormat("%ld", *v0); + for (size_t n = 1; n < size; n++) { + uintmax_t *vn = v + n; + PyObject *t = PyString_FromFormat("%lu", *vn); + sb = PyString_Concat(sb, t); + } + PyObject *i = PyLong_FromUnicodeObject(sb, 10); + return (PgfLiteral) i; + } else { + PyObject *i = PyLong_FromLong(*v0); + return (PgfLiteral) i; } - PyObject *i = PyLong_FromLong(*v0); - return (PgfLiteral) i; } PgfLiteral lflt(PgfUnmarshaller *this, double v) diff --git a/src/runtime/python/setup.py b/src/runtime/python/setup.py index 940ae8f50..4a5b8f882 100644 --- a/src/runtime/python/setup.py +++ b/src/runtime/python/setup.py @@ -10,7 +10,7 @@ if libraries==['']: pgf_module = Extension('pgf', sources = ['pypgf.c', 'marshaller.c', 'expr.c'], - extra_compile_args = ['-std=c99', '-Werror', '-Wno-error=int-conversion', '-Wno-comment'], + extra_compile_args = ['-std=c99', '-Werror', '-Wno-error=int-conversion', '-Wno-error=unused-variable', '-Wno-comment'], include_dirs = includes, library_dirs = libraries, libraries = ['pgf']) diff --git a/src/runtime/python/test_suite.py b/src/runtime/python/test_suite.py index b3c0070f7..2a7a6fc17 100644 --- a/src/runtime/python/test_suite.py +++ b/src/runtime/python/test_suite.py @@ -139,11 +139,11 @@ def test_readExpr_equality_int(): def test_readExpr_equality_int_neg(): assert pgf.readExpr("-123") == pgf.readExpr("-123") -# def test_readExpr_equality_int_big(): -# assert pgf.readExpr("774763251095801167872") == pgf.readExpr("774763251095801167872") +def test_readExpr_equality_int_big(): + assert pgf.readExpr("774763251095801167872") == pgf.readExpr("774763251095801167872") -# def test_readExpr_equality_int_big_neg(): -# assert pgf.readExpr("-774763251095801167872") == pgf.readExpr("-774763251095801167872") +def test_readExpr_equality_int_big_neg(): + assert pgf.readExpr("-774763251095801167872") == pgf.readExpr("-774763251095801167872") def test_readExpr_inequality_int(): assert pgf.readExpr("123") != pgf.readExpr("456")