begriffs / pg_rational

Precise fractional arithmetic for PostgreSQL
MIT License
233 stars 14 forks source link

Add .travis.yml #19

Closed df7cb closed 4 years ago

df7cb commented 4 years ago

Enable continuous integration tests on travis-ci.org.

To actually run the tests, you need to enable the repository on travis-ci.org first, and then push some change. (Enable first, then merge this.)

begriffs commented 4 years ago

This is great, thanks a lot! I think Travis is enabled, so I'll see what it says when I merge this pr.

begriffs commented 4 years ago

Well, travis detects the build failure for earlier versions of postgres.

I wanted to create a shim for the missing overflow testing functions that we could use on older versions, but looks like the postgres source [0] uses autotools to provide the HAVE__BUILTIN_OP_OVERFLOW flag. I don't want to clutter our source with GNU crap, either autotools or the gcc builtins I used before.

Perhaps for the ifdef shim we could could try detecting overflow in a slow -- but portable -- C way.

0: https://github.com/postgres/postgres/commit/4d6ad31257adaf8a51e1c4377d96afa656d9165f

df7cb commented 4 years ago

Why autotools?

#if PG_VERSION_NUM < 100000
...
#endif
begriffs commented 4 years ago

Christoph Berg wrote:

Why autotools?

#if PG_VERSION_NUM < 100000
...
#endif

Good point, we can just check the pg version, and for old pg provide our own modified copy of e.g. pg_mul_s32_overflow() that has the conditional compilation part removed, like:

static inline bool
pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
{
    int64       res = (int64) a * (int64) b;

    if (res > PG_INT32_MAX || res < PG_INT32_MIN)
    {
        *result = 0x5EED;       /* to avoid spurious warnings */
        return true;
    }
    *result = (int32) res;
    return false;
}

No need for us to try to get fancy by trying to conditionally use GCC builtins like builtin_mul_overflow. Postgres detects the presence of the builtins with config/c-compiler.m4 (which I assume uses autoconf), and sets HAVEBUILTIN_OP_OVERFLOW.