From 7e6d6a60598153c2133b1bcae18329be89995782 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 5 Dec 2023 16:20:01 +0100 Subject: [PATCH] Add support for PostgreSQL 15, 16 This requires putting in a replacement for the pg_atoi() function, which was removed in PostgreSQL. fixes #20, fixes #21, fixes #25 --- .cirrus.yml | 2 ++ .gitignore | 1 + inout.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index a8b0c0d..a053227 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -9,6 +9,8 @@ task: image: ubuntu:20.04 env: matrix: + - PGVERSION: 16 + - PGVERSION: 15 - PGVERSION: 14 - PGVERSION: 13 - PGVERSION: 12 diff --git a/.gitignore b/.gitignore index 15a5439..c8f0c88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.dylib *.o *.so /results/ diff --git a/inout.c b/inout.c index 743e1ea..c6c5bab 100644 --- a/inout.c +++ b/inout.c @@ -8,13 +8,65 @@ #include +/* + * Copy of old pg_atoi() from PostgreSQL, cut down to support int8 only. + */ +static int8 +my_pg_atoi8(const char *s) +{ + long result; + char *badp; + + /* + * Some versions of strtol treat the empty string as an error, but some + * seem not to. Make an explicit test to be sure we catch it. + */ + if (s == NULL) + elog(ERROR, "NULL pointer"); + if (*s == 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); + + errno = 0; + result = strtol(s, &badp, 10); + + /* We made no progress parsing the string, so bail out */ + if (s == badp) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); + + if (errno == ERANGE || result < SCHAR_MIN || result > SCHAR_MAX) + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value \"%s\" is out of range for 8-bit integer", s))); + + /* + * Skip any trailing whitespace; if anything but whitespace remains before + * the terminating character, bail out + */ + while (*badp && isspace((unsigned char) *badp)) + badp++; + + if (*badp) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", s))); + + return (int8) result; +} + PG_FUNCTION_INFO_V1(int1in); Datum int1in(PG_FUNCTION_ARGS) { char *s = PG_GETARG_CSTRING(0); - PG_RETURN_INT8(pg_atoi(s, sizeof(int8), '\0')); + PG_RETURN_INT8(my_pg_atoi8(s)); } PG_FUNCTION_INFO_V1(int1out);