From 7031dfeb7641242b46b44e8aa28c96f0b847406d Mon Sep 17 00:00:00 2001 From: Carl-Christian Sautter Date: Wed, 28 Apr 2021 17:58:32 +0200 Subject: [PATCH 1/2] PHP-225 Compile Warnings with PHP7.3 - Docker Test Environment --- .dockerignore | 2 ++ Dockerfile | 58 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 7 ++++++ 3 files changed, 67 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..58d58a3bf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +docker-compose.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f22aa4e4b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +FROM debian:buster-slim AS cassandra_cpp_driver + +# Datastax/Cassandra CPP Driver +WORKDIR /tmp + +RUN echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/backports.list +RUN apt-get update + +RUN apt-get -y install g++ +RUN apt-get -y install make +RUN apt-get -y install cmake +RUN apt-get -y install libuv1-dev +RUN apt-get -y install libssl-dev +RUN apt-get -y install libgmp-dev +RUN apt-get -y install openssl +RUN apt-get -y install libpcre3-dev +RUN apt-get -y install git +RUN apt-get -y install checkinstall +RUN apt-get -y install libz-dev + +RUN git clone https://github.com/datastax/cpp-driver.git \ + && cd cpp-driver \ + && git checkout tags/2.16.0 \ + && mkdir build \ + && cd build \ + && cmake .. \ + && make + +RUN cd /tmp/cpp-driver/build \ + && checkinstall -y -D --install=no --pkgname=cassandra-cpp-driver --pkgversion=2.16.0 --pkgarch=amd64 + +FROM debian:buster-slim + +COPY --from=cassandra_cpp_driver /tmp/cpp-driver/build/cassandra-cpp-driver_2.16.0-1_amd64.deb /tmp/cpp-driver/build/cassandra-cpp-driver_2.16.0-1_amd64.deb +RUN dpkg -i /tmp/cpp-driver/build/cassandra-cpp-driver_2.16.0-1_amd64.deb + +WORKDIR /tmp +RUN apt-get update +# PHP +RUN apt-get install -y php php-fpm +RUN apt-get install -y php-pear +RUN apt-get install -y php-dev + +# Cassandra PHP Driver - PECL Installation +RUN apt-get install -y git +RUN mkdir -p /tmp/php-driver +COPY . /tmp/php-driver/ + +# Install from git source +#RUN git clone https://github.com/datastax/php-driver.git \ +# && cd /tmp/php-driver \ +# && rm -R /tmp/php-driver/.git + +RUN apt-get install -y libgmp-dev +RUN apt-get install -y libuv1-dev +RUN cd /tmp/php-driver \ + && pecl install ext/package.xml \ + && rm -R /tmp/* \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..1589e0ce0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +version: "3.5" + +services: + php-driver: + build: + context: . + image: cassandra-php-driver \ No newline at end of file From c923682751bbfb6b93808d00e42eba4f6a017653 Mon Sep 17 00:00:00 2001 From: Carl-Christian Sautter Date: Wed, 28 Apr 2021 18:00:11 +0200 Subject: [PATCH 2/2] PHP-225 Compile Warnings with PHP7.3 - Fixes --- ext/config.m4 | 4 ++-- ext/php_driver.c | 18 ++++++++++++++++++ ext/src/Bigint.c | 2 +- ext/src/Date.c | 4 ++-- ext/src/Decimal.c | 2 +- ext/src/Duration.c | 12 ++++++------ ext/src/Timeuuid.c | 4 ++-- ext/src/Uuid.c | 2 +- ext/util/inet.c | 1 + ext/util/math.c | 2 +- 10 files changed, 35 insertions(+), 16 deletions(-) diff --git a/ext/config.m4 b/ext/config.m4 index d479d9044..758e4bab8 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -161,10 +161,10 @@ if test "$PHP_CASSANDRA" != "no"; then case $(uname -s) in Linux) - CASSANDRA_CFLAGS="-Wall -Wextra -Wno-long-long -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -Wno-extra-semi -pthread" + CASSANDRA_CFLAGS="-Wall -Wextra -Wno-long-long -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -pthread" ;; Darwin) - CASSANDRA_CFLAGS="-Wall -Wextra -Wno-long-long -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros -Wno-extra-semi" + CASSANDRA_CFLAGS="-Wall -Wextra -Wno-long-long -Wno-deprecated-declarations -Wno-unused-parameter -Wno-unused-result -Wno-variadic-macros" ;; esac diff --git a/ext/php_driver.c b/ext/php_driver.c index 14b7a31dc..f45734ee1 100644 --- a/ext/php_driver.c +++ b/ext/php_driver.c @@ -337,13 +337,31 @@ throw_invalid_argument(zval *object, object_name, expected_type); } } else if (Z_TYPE_P(object) == IS_STRING) { + // remember current diagnostic state + #pragma GCC diagnostic push + // suppress warnings relating %Z + #pragma GCC diagnostic ignored "-Wformat" + #pragma GCC diagnostic ignored "-Wformat-extra-args" + zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be %s, '%Z' given", object_name, expected_type, object); + + // restore diagnostic state + #pragma GCC diagnostic pop } else { + // remember current diagnostic state + #pragma GCC diagnostic push + // suppress warnings relating %Z + #pragma GCC diagnostic ignored "-Wformat" + #pragma GCC diagnostic ignored "-Wformat-extra-args" + zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be %s, %Z given", object_name, expected_type, object); + + // restore diagnostic state + #pragma GCC diagnostic pop } } diff --git a/ext/src/Bigint.c b/ext/src/Bigint.c index bb542cd56..1c8ecc2e3 100644 --- a/ext/src/Bigint.c +++ b/ext/src/Bigint.c @@ -85,7 +85,7 @@ php_driver_bigint_init(INTERNAL_FUNCTION_PARAMETERS) if (double_value > INT64_MAX || double_value < INT64_MIN) { zend_throw_exception_ex(php_driver_range_exception_ce, 0 TSRMLS_CC, - "value must be between " LL_FORMAT " and " LL_FORMAT ", %g given", + "value must be between %+" PRId64 " and %+" PRId64 ", %g given", INT64_MIN, INT64_MAX, double_value); return; } diff --git a/ext/src/Date.c b/ext/src/Date.c index 91dce9eae..afab4f369 100644 --- a/ext/src/Date.c +++ b/ext/src/Date.c @@ -104,7 +104,7 @@ PHP_METHOD(Date, toDateTime) #endif str_len = spprintf(&str, 0, "%lld", - cass_date_time_to_epoch(self->date, + (long long int) cass_date_time_to_epoch(self->date, time_obj != NULL ? time_obj->time : 0)); php_date_initialize(datetime_obj, str, str_len, "U", NULL, 0 TSRMLS_CC); efree(str); @@ -154,7 +154,7 @@ PHP_METHOD(Date, __toString) self = PHP_DRIVER_GET_DATE(getThis()); - spprintf(&ret, 0, PHP_DRIVER_NAMESPACE "\\Date(seconds=%lld)", cass_date_time_to_epoch(self->date, 0)); + spprintf(&ret, 0, PHP_DRIVER_NAMESPACE "\\Date(seconds=%lld)", (long long int) cass_date_time_to_epoch(self->date, 0)); PHP5TO7_RETVAL_STRING(ret); efree(ret); } diff --git a/ext/src/Decimal.c b/ext/src/Decimal.c index 916afc148..14eabb54a 100644 --- a/ext/src/Decimal.c +++ b/ext/src/Decimal.c @@ -116,7 +116,7 @@ from_double(php_driver_numeric *result, double value) #ifdef _WIN32 sprintf(mantissa_str, "%I64d", mantissa); #else - sprintf(mantissa_str, "%lld", mantissa); + sprintf(mantissa_str, "%lld", (long long int) mantissa); #endif mpz_set_str(result->data.decimal.value, mantissa_str, 10); diff --git a/ext/src/Duration.c b/ext/src/Duration.c index efa574d89..ecf599e63 100644 --- a/ext/src/Duration.c +++ b/ext/src/Duration.c @@ -18,7 +18,7 @@ zend_class_entry *php_driver_duration_ce = NULL; static void to_string(zval *result, cass_int64_t value) { char *string; - spprintf(&string, 0, LL_FORMAT, value); + spprintf(&string, 0, LL_FORMAT, (long long int) value); PHP5TO7_ZVAL_STRING(result, string); efree(string); } @@ -35,7 +35,7 @@ static int get_param(zval* value, if (long_value > max || long_value < min) { zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be between " LL_FORMAT " and " LL_FORMAT ", " LL_FORMAT " given", - param_name, min, max, long_value); + param_name, (long long int) min, (long long int) max, (long long int) long_value); return 0; } @@ -46,7 +46,7 @@ static int get_param(zval* value, if (double_value > max || double_value < min) { zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be between " LL_FORMAT " and " LL_FORMAT ", %g given", - param_name, min, max, double_value); + param_name, (long long int) min, (long long int) max, double_value); return 0; } *destination = (cass_int64_t) double_value; @@ -59,7 +59,7 @@ static int get_param(zval* value, if (parsed_big_int > max || parsed_big_int < min) { zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be between " LL_FORMAT " and " LL_FORMAT ", " LL_FORMAT " given", - param_name, min, max, parsed_big_int); + param_name, (long long int) min, (long long int) max, (long long int) parsed_big_int); return 0; } *destination = parsed_big_int; @@ -71,7 +71,7 @@ static int get_param(zval* value, if (bigint_value > max || bigint_value < min) { zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "%s must be between " LL_FORMAT " and " LL_FORMAT ", " LL_FORMAT " given", - param_name, min, max, bigint_value); + param_name, (long long int) min, (long long int) max, (long long int) bigint_value); return 0; } @@ -104,7 +104,7 @@ char *php_driver_duration_to_string(php_driver_duration *duration) if (final_nanos < 0) final_nanos = -final_nanos; - spprintf(&rep, 0, "%s%dmo%dd" LL_FORMAT "ns", is_negative ? "-" : "", final_months, final_days, final_nanos); + spprintf(&rep, 0, "%s%dmo%dd" LL_FORMAT "ns", is_negative ? "-" : "", final_months, final_days, (long long int) final_nanos); return rep; } diff --git a/ext/src/Timeuuid.c b/ext/src/Timeuuid.c index 0b4832fae..88badcc31 100644 --- a/ext/src/Timeuuid.c +++ b/ext/src/Timeuuid.c @@ -50,14 +50,14 @@ php_driver_timeuuid_init(INTERNAL_FUNCTION_PARAMETERS) switch (Z_TYPE_P(param)) { case IS_LONG: if (Z_LVAL_P(param) < 0) { - zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "Timestamp must be a positive integer, %d given", Z_LVAL_P(param)); + zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "Timestamp must be a positive integer, %li given", (long int) Z_LVAL_P(param)); return; } php_driver_uuid_generate_from_time(Z_LVAL_P(param), &self->uuid TSRMLS_CC); break; case IS_STRING: if (cass_uuid_from_string(Z_STRVAL_P(param), &self->uuid) != CASS_OK) { - zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "Invalid UUID: '%.*s'", Z_STRLEN_P(param), Z_STRVAL_P(param)); + zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, "Invalid UUID: '%.*s'", (int) Z_STRLEN_P(param), Z_STRVAL_P(param)); return; } diff --git a/ext/src/Uuid.c b/ext/src/Uuid.c index af37360f2..6655396fa 100644 --- a/ext/src/Uuid.c +++ b/ext/src/Uuid.c @@ -45,7 +45,7 @@ php_driver_uuid_init(INTERNAL_FUNCTION_PARAMETERS) } else { if (cass_uuid_from_string(value, &self->uuid) != CASS_OK) { zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, - "Invalid UUID: '%.*s'", value_len, value); + "Invalid UUID: '%.*s'", (int) value_len, value); return; } } diff --git a/ext/util/inet.c b/ext/util/inet.c index 4a379a5e8..6c2ce6f7e 100644 --- a/ext/util/inet.c +++ b/ext/util/inet.c @@ -24,6 +24,7 @@ #define IPV6 2 #define TOKEN_MAX_LEN 4 #define IP_MAX_ADDRLEN 50 +#pragma GCC diagnostic ignored "-Wmultistatement-macros" #define EXPECTING_TOKEN(expected) \ zend_throw_exception_ex(php_driver_invalid_argument_exception_ce, 0 TSRMLS_CC, \ "Unexpected %s at position %d in address \"%s\", expected " expected, \ diff --git a/ext/util/math.c b/ext/util/math.c index f503b9fa0..2e8fcc48e 100644 --- a/ext/util/math.c +++ b/ext/util/math.c @@ -198,7 +198,7 @@ php_driver_parse_bigint(char *in, int in_len, cass_int64_t *number TSRMLS_DC) if (errno == ERANGE) { zend_throw_exception_ex(php_driver_range_exception_ce, 0 TSRMLS_CC, - "value must be between " LL_FORMAT " and " LL_FORMAT ", %s given", INT64_MIN, INT64_MAX, in); + "value must be between " LL_FORMAT " and " LL_FORMAT ", %s given", (long long int) INT64_MIN, (long long int) INT64_MAX, in); return 0; }