diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 3a8ce51..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: CI - -on: - push: - branches: ['*'] - pull_request: - branches: ['*'] - -jobs: - test: - strategy: - fail-fast: false - matrix: - pg: [14, 13, 12, 11, 10, 9.6, 9.5] - name: PostgreSQL ${{ matrix.pg }} - runs-on: ubuntu-latest - container: zilder/pg-ext-check - steps: - - run: pg-setup ${{ matrix.pg }} - - uses: actions/checkout@v2 - - run: build-check diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..aca8b0d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + test: + strategy: + matrix: + pg: [15, 14, 13, 12, 11, 10] + name: 🐘 PostgreSQL ${{ matrix.pg }} + runs-on: ubuntu-latest + container: pgxn/pgxn-tools + steps: + - run: pg-start ${{ matrix.pg }} + - uses: actions/checkout@v2 + - run: pg-build-test + diff --git a/.gitignore b/.gitignore index a7cb72e..a384c72 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ sha*.sql.in sha*.sql sha*.c -sql/hashtypes--0.1.2--0.1.3.sql \ No newline at end of file +sql/hashtypes--0.1.2--0.1.3.sql +sql/*.sql.in + +results/ \ No newline at end of file diff --git a/META.json b/META.json index 1367185..4f85aa9 100644 --- a/META.json +++ b/META.json @@ -1,19 +1,32 @@ { "name": "hashtypes", "abstract": "data types for sha{1,256,512}, md5 and crc32", - "version": "0.1.4", - "maintainer": ["Chris Travers ", "Manuel Kniep "], - "license": "postgresql", - "meta-spec": { - "version": "1.0.0", - "url": "http://pgxn.org/meta/spec.txt" - }, + "version": "0.1.5", + "maintainer" : [ + "adjustgmbh" + ], + "license": { + "PostgreSQL": "http://www.postgresql.org/about/licence" + }, "provides": { "hashtypes": { - "file": "sql/hashtypes--0.1.4.sql", - "version": "0.1.4" + "file": "sql/hashtypes--0.1.5.sql", + "version": "0.1.5", + "abstract": "data types for sha{1,256,512}, md5 and crc32" } }, + "meta-spec": { + "version": "1.0.0", + "url": "http://pgxn.org/meta/spec.txt" + }, + "description": "data types for sha{1,256,512}, md5 and crc32", + "prereqs": { + "runtime": { + "requires": { + "PostgreSQL": "10.0.0" + } + } + }, "resources": { "bugtracker": { "web": "http://github.com/adjust/hashtypes/issues/" diff --git a/Makefile b/Makefile index 8d4f722..1106c1e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ HASHTYPESVERSION = 0.1.5 EXTENSION = hashtypes -DOCS = README.hashtypes MODULE_big = hashtypes OBJS = src/common.o src/md5.o src/crc32.o $(LN_OBJS) DATA_built = sql/hashtypes--$(HASHTYPESVERSION).sql sql/hashtypes--0.1.2--0.1.3.sql diff --git a/README.hashtypes b/README.md similarity index 75% rename from README.hashtypes rename to README.md index 047cd8f..0f38ce5 100644 --- a/README.hashtypes +++ b/README.md @@ -1,3 +1,5 @@ +[![CI](https://github.com/adjust/hashtypes/actions/workflows/main.yml/badge.svg)](https://github.com/adjust/hashtypes/actions/workflows/main.yml) + This extension is actually a fork of shatypes[1] which adds some other data types as crc32 and provides some fixes to original implementations. diff --git a/expected/regress_sha.out b/expected/regress_sha.out index 039159f..f150546 100644 --- a/expected/regress_sha.out +++ b/expected/regress_sha.out @@ -70,3 +70,17 @@ SELECT * FROM md5test_after; 5e8862cd73694287ff341e75c95e3c6a (2 rows) +CREATE TABLE crc32test (val crc32); +INSERT INTO crc32test VALUES ('ab1'::crc32), ('ab2'::crc32); +SELECT val FROM crc32test WHERE val <> 'ab2'::crc32; + val +---------- + 00000ab1 +(1 row) + +SELECT val FROM crc32test WHERE val = 'ab2'::crc32; + val +---------- + 00000ab2 +(1 row) + diff --git a/sql/regress_sha.sql b/sql/regress_sha.sql index 5538659..c66816d 100644 --- a/sql/regress_sha.sql +++ b/sql/regress_sha.sql @@ -37,3 +37,9 @@ COPY md5test TO '/tmp/tst' WITH (FORMAT binary); COPY md5test_after FROM '/tmp/tst' WITH (FORMAT binary); SELECT * FROM md5test; SELECT * FROM md5test_after; + +CREATE TABLE crc32test (val crc32); +INSERT INTO crc32test VALUES ('ab1'::crc32), ('ab2'::crc32); + +SELECT val FROM crc32test WHERE val <> 'ab2'::crc32; +SELECT val FROM crc32test WHERE val = 'ab2'::crc32; diff --git a/src/crc32.c b/src/crc32.c index da8cc19..3adac76 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -11,6 +11,8 @@ Datum crc32_in(PG_FUNCTION_ARGS) { char *in = PG_GETARG_CSTRING(0); + char *p; + long int pout; if (strlen(in) > 8) { @@ -19,12 +21,9 @@ crc32_in(PG_FUNCTION_ARGS) errmsg("crc32 value cannot exceed 32 bits"))); } - crc32 *out = palloc(sizeof(crc32)); - - - char *p; errno = 0; - long int pout = strtol(in, &p, 16); + pout = strtol(in, &p, 16); + if (errno != 0 || *p != 0 || p == in) { ereport(ERROR, ( @@ -35,17 +34,16 @@ crc32_in(PG_FUNCTION_ARGS) /* I don't check if pout overflows uint32 because it's restricted by string * length check above. */ - out = (uint32_t)pout; - - PG_RETURN_CRC32(out); + PG_RETURN_CRC32(pout); } PG_FUNCTION_INFO_V1(crc32_out); Datum crc32_out(PG_FUNCTION_ARGS) { - crc32 *in = PG_GETARG_CRC32(0); + crc32 in = PG_GETARG_CRC32(0); char *out = (char *) palloc(10); + snprintf(out, 10, "%08x", in); PG_RETURN_CSTRING(out); } diff --git a/src/md5.c b/src/md5.c index e106cf1..dd97d58 100644 --- a/src/md5.c +++ b/src/md5.c @@ -8,6 +8,16 @@ */ #include "postgres.h" +// pg16-compability +#ifndef SET_VARSIZE +/* + * pg >= 16 reorganized the toastable header files + * https://github.com/postgres/postgres/commit/d952373a987bad331c0e499463159dd142ced1ef + * to ensure cross version compatibility we do a bit of a hack here + */ +#include "varatt.h" +#endif + #include "access/hash.h" #include "common.h" #include "fmgr.h" @@ -52,7 +62,7 @@ md5_in(PG_FUNCTION_ARGS) { char *arg = PG_GETARG_CSTRING(0); Md5 *output; - + output = (Md5 *) cstring_to_hexarr(arg, MD5_LENGTH, "MD5"); PG_RETURN_MD5(output); @@ -63,7 +73,7 @@ Datum md5_recv(PG_FUNCTION_ARGS) { StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); - Md5 *result; + Md5 *result; int nbytes; nbytes = buf->len - buf->cursor; @@ -75,7 +85,7 @@ md5_recv(PG_FUNCTION_ARGS) result = palloc(sizeof(Md5)); - pq_copymsgbytes(buf, result->bytes, nbytes); + pq_copymsgbytes(buf, (char *) result->bytes, nbytes); PG_RETURN_MD5(result); } @@ -123,7 +133,7 @@ md5_to_text(PG_FUNCTION_ARGS) cstring = hexarr_to_cstring(value->bytes, MD5_LENGTH); textval = DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(cstring))); - + PG_RETURN_TEXT_P(textval); }