diff --git a/BUILD b/BUILD index 5092c961f2..9a03f366ec 100644 --- a/BUILD +++ b/BUILD @@ -28,9 +28,7 @@ ZLIB_DEPS = ["@zlib//:zlib"] ################################################################################ MSVC_COPTS = [ - "/wd4018", # -Wno-sign-compare "/wd4065", # switch statement contains 'default' but no 'case' labels - "/wd4146", # unary minus operator applied to unsigned type, result still unsigned "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ebdc85bed5..da366b8b12 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -41,6 +41,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES Intel) endif() # Options +option(protobuf_INSTALL "Install protobuf binaries and files" ON) if(WITH_PROTOC) set(protobuf_PROTOC_EXE ${WITH_PROTOC} CACHE FILEPATH "Protocol Buffer Compiler executable" FORCE) endif() @@ -214,9 +215,7 @@ if (MSVC) add_definitions(/utf-8) # MSVC warning suppressions add_definitions( - /wd4018 # 'expression' : signed/unsigned mismatch /wd4065 # switch statement contains 'default' but no 'case' labels - /wd4146 # unary minus operator applied to unsigned type, result still unsigned /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data @@ -305,7 +304,9 @@ if (protobuf_BUILD_CONFORMANCE) include(conformance.cmake) endif (protobuf_BUILD_CONFORMANCE) -include(install.cmake) +if (protobuf_INSTALL) + include(install.cmake) +endif (protobuf_INSTALL) if (protobuf_BUILD_EXAMPLES) include(examples.cmake) diff --git a/cmake/README.md b/cmake/README.md index 89d00c1b6f..d75012cff0 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -320,8 +320,6 @@ The following warnings have been disabled while building the protobuf libraries and compiler. You may have to disable some of them in your own project as well, or live with them. -* C4018 - 'expression' : signed/unsigned mismatch -* C4146 - unary minus operator applied to unsigned type, result still unsigned * C4244 - Conversion from 'type1' to 'type2', possible loss of data. * C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake index 1f5ae5ab04..ac37f41147 100644 --- a/cmake/libprotobuf.cmake +++ b/cmake/libprotobuf.cmake @@ -125,6 +125,8 @@ if(MSVC AND protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf PROPERTIES VERSION ${protobuf_VERSION} + # Use only the first SO version component for compatibility with Makefile emitted SONAME. + SOVERSION 30 OUTPUT_NAME ${LIB_PREFIX}protobuf DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotobuf ALIAS libprotobuf) diff --git a/cmake/tests.cmake b/cmake/tests.cmake index aa069febd2..e66ff93435 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -224,6 +224,11 @@ if(MINGW) endif() add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files}) +if (MSVC) + target_compile_options(tests PRIVATE + /wd4146 # unary minus operator applied to unsigned type, result still unsigned + ) +endif() target_link_libraries(tests libprotoc libprotobuf gmock_main) set(test_plugin_files diff --git a/kokoro/linux/dockerfile/test/php80/Dockerfile b/kokoro/linux/dockerfile/test/php80/Dockerfile index 8093eae16c..5b382d0a10 100644 --- a/kokoro/linux/dockerfile/test/php80/Dockerfile +++ b/kokoro/linux/dockerfile/test/php80/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM debian:stretch # Install dependencies. We start with the basic ones require to build protoc # and the C++ build @@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y \ # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - php5 \ + php \ libcurl4-openssl-dev \ libgmp-dev \ libgmp3-dev \ @@ -90,6 +90,34 @@ RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar \ && cp phpunit /usr/local/php-8.0/bin \ && mv phpunit /usr/local/php-8.0-zts/bin +# php 8.1 +RUN cd php-src \ + && git checkout php-8.1.2 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1-zts \ + && make \ + && make install \ + && make clean + # Install php dependencies RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ valgrind \ diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 2c9a7108b9..9c290f7dd9 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -287,7 +287,7 @@ PHP_METHOD(RepeatedField, append) { } /** - * RepeatedField::offsetExists() + * RepeatedField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -309,7 +309,7 @@ PHP_METHOD(RepeatedField, offsetExists) { } /** - * RepeatedField::offsetGet() + * RepeatedField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -341,7 +341,7 @@ PHP_METHOD(RepeatedField, offsetGet) { } /** - * RepeatedField::offsetSet() + * RepeatedField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -386,7 +386,7 @@ PHP_METHOD(RepeatedField, offsetSet) { } /** - * RepeatedField::offsetUnset() + * RepeatedField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -416,7 +416,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { } /** - * RepeatedField::count() + * RepeatedField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -436,7 +436,7 @@ PHP_METHOD(RepeatedField, count) { } /** - * RepeatedField::getIterator() + * RepeatedField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -459,24 +459,38 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_append, 0, 0, 1) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + static zend_function_entry repeated_field_methods[] = { - PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, append, arginfo_append, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -550,7 +564,7 @@ static void RepeatedFieldIter_make(zval *val, zval *repeated_field) { */ /** - * RepeatedFieldIter::rewind() + * RepeatedFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -560,7 +574,7 @@ PHP_METHOD(RepeatedFieldIter, rewind) { } /** - * RepeatedFieldIter::current() + * RepeatedFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -583,7 +597,7 @@ PHP_METHOD(RepeatedFieldIter, current) { } /** - * RepeatedFieldIter::key() + * RepeatedFieldIter::key(): mixed * * Implements the Iterator interface. Returns the current key. */ @@ -593,7 +607,7 @@ PHP_METHOD(RepeatedFieldIter, key) { } /** - * RepeatedFieldIter::next() + * RepeatedFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -603,7 +617,7 @@ PHP_METHOD(RepeatedFieldIter, next) { } /** - * RepeatedFieldIter::valid() + * RepeatedFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -613,12 +627,27 @@ PHP_METHOD(RepeatedFieldIter, valid) { RETURN_BOOL(intern->position < upb_array_size(field->array)); } +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + static zend_function_entry repeated_field_iter_methods[] = { - PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index bbdfe29c5d..252b1f5b3c 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -305,7 +305,7 @@ PHP_METHOD(MapField, __construct) { } /** - * MapField::offsetExists() + * MapField::offsetExists(): bool * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -329,7 +329,7 @@ PHP_METHOD(MapField, offsetExists) { } /** - * MapField::offsetGet() + * MapField::offsetGet(): mixed * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -361,7 +361,7 @@ PHP_METHOD(MapField, offsetGet) { } /** - * MapField::offsetSet() + * MapField::offsetSet(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -389,7 +389,7 @@ PHP_METHOD(MapField, offsetSet) { } /** - * MapField::offsetUnset() + * MapField::offsetUnset(): void * * Implements the ArrayAccess interface. Invoked when PHP code calls: * @@ -413,7 +413,7 @@ PHP_METHOD(MapField, offsetUnset) { } /** - * MapField::count() + * MapField::count(): int * * Implements the Countable interface. Invoked when PHP code calls: * @@ -433,7 +433,7 @@ PHP_METHOD(MapField, count) { } /** - * MapField::getIterator() + * MapField::getIterator(): Traversable * * Implements the IteratorAggregate interface. Invoked when PHP code calls: * @@ -453,23 +453,38 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_construct, 0, 0, 2) ZEND_ARG_INFO(0, value_class) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_offsetGet, 0, 0, IS_MIXED, 1) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2) +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetSet, 0, 2, IS_VOID, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, newval) ZEND_END_ARG_INFO() +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetUnset, 0, 0, IS_VOID, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_offsetExists, 0, 0, _IS_BOOL, 0) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIterator, 0, 0, Traversable, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_count, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + static zend_function_entry MapField_methods[] = { - PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) - PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapField, __construct, arginfo_construct, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetExists, arginfo_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(MapField, offsetUnset, arginfo_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(MapField, count, arginfo_count, ZEND_ACC_PUBLIC) + PHP_ME(MapField, getIterator, arginfo_getIterator, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -547,7 +562,7 @@ static void MapFieldIter_make(zval *val, zval *map_field) { */ /** - * MapFieldIter::rewind() + * MapFieldIter::rewind(): void * * Implements the Iterator interface. Sets the iterator to the first element. */ @@ -559,7 +574,7 @@ PHP_METHOD(MapFieldIter, rewind) { } /** - * MapFieldIter::current() + * MapFieldIter::current(): mixed * * Implements the Iterator interface. Returns the current value. */ @@ -587,7 +602,7 @@ PHP_METHOD(MapFieldIter, key) { } /** - * MapFieldIter::next() + * MapFieldIter::next(): void * * Implements the Iterator interface. Advances to the next element. */ @@ -598,7 +613,7 @@ PHP_METHOD(MapFieldIter, next) { } /** - * MapFieldIter::valid() + * MapFieldIter::valid(): bool * * Implements the Iterator interface. Returns true if this is a valid element. */ @@ -609,12 +624,27 @@ PHP_METHOD(MapFieldIter, valid) { RETURN_BOOL(!done); } +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_rewind, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_current, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_key, 0, 0, IS_MIXED, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_next, 0, 0, IS_VOID, 0) +ZEND_END_ARG_INFO() + +PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_valid, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + static zend_function_entry map_field_iter_methods[] = { - PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) - PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, rewind, arginfo_rewind, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, current, arginfo_current, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, key, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, next, arginfo_next, ZEND_ACC_PUBLIC) + PHP_ME(MapFieldIter, valid, arginfo_valid, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 41ae2718b4..fdee1170a6 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -82,6 +82,42 @@ const zval *get_generated_pool(); // PHP 7.2.0. #if PHP_VERSION_ID < 70200 #define zend_ce_countable spl_ce_Countable +#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) +#endif + +// polyfill for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX, which changes between 7.1 and 7.2 +#if PHP_VERSION_ID < 70200 +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, /*class_name*/ 0, allow_null) +#else +#define PROTOBUF_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) +#endif + +// In PHP 8.1, mismatched tentative return types emit a deprecation notice. +// https://wiki.php.net/rfc/internal_method_return_types +// +// When compiling for earlier php versions, the return type is dropped. +#if PHP_VERSION_ID < 80100 +#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ + ZEND_BEGIN_ARG_INFO_EX(name, return_reference, required_num_args, allow_null) +#endif + +#ifndef IS_VOID +#define IS_VOID 99 +#endif + +#ifndef IS_MIXED +#define IS_MIXED 99 +#endif + +#ifndef _IS_BOOL +#define _IS_BOOL 99 +#endif + +#ifndef IS_LONG +#define IS_LONG 99 #endif ZEND_BEGIN_ARG_INFO(arginfo_void, 0) diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 1dd6645bcd..b71246e81d 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -37,6 +37,7 @@ use Google\Protobuf\FieldMask; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\RepeatedField; use Google\Protobuf\Internal\MapField; +use function bccomp; function camel2underscore($input) { preg_match_all( diff --git a/php/src/Google/Protobuf/Internal/GPBWire.php b/php/src/Google/Protobuf/Internal/GPBWire.php index 29569530fd..034f5df92e 100644 --- a/php/src/Google/Protobuf/Internal/GPBWire.php +++ b/php/src/Google/Protobuf/Internal/GPBWire.php @@ -146,7 +146,7 @@ class GPBWire return bcsub(bcmul(bcsub(0, $int64), 2), 1); } } else { - return ($int64 << 1) ^ ($int64 >> 63); + return ((int)$int64 << 1) ^ ((int)$int64 >> 63); } } diff --git a/php/src/Google/Protobuf/Internal/MapField.php b/php/src/Google/Protobuf/Internal/MapField.php index 719fb350bd..86463a9a47 100644 --- a/php/src/Google/Protobuf/Internal/MapField.php +++ b/php/src/Google/Protobuf/Internal/MapField.php @@ -37,6 +37,8 @@ namespace Google\Protobuf\Internal; +use Traversable; + /** * MapField is used by generated protocol message classes to manipulate map * fields. It can be used like native PHP array. @@ -134,6 +136,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($key) { return $this->container[$key]; @@ -151,6 +154,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for value. * @throws \ErrorException Non-existing key. */ + #[\ReturnTypeWillChange] public function offsetSet($key, $value) { $this->checkKey($this->key_type, $key); @@ -209,6 +213,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @return void * @throws \ErrorException Invalid type for key. */ + #[\ReturnTypeWillChange] public function offsetUnset($key) { $this->checkKey($this->key_type, $key); @@ -224,7 +229,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * @return bool True if the element at the given key exists. * @throws \ErrorException Invalid type for key. */ - public function offsetExists($key) + public function offsetExists($key): bool { $this->checkKey($this->key_type, $key); return isset($this->container[$key]); @@ -233,7 +238,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new MapFieldIter($this->container, $this->key_type); } @@ -245,7 +250,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/MapFieldIter.php b/php/src/Google/Protobuf/Internal/MapFieldIter.php index 4e18005ea8..a3c834bd2c 100644 --- a/php/src/Google/Protobuf/Internal/MapFieldIter.php +++ b/php/src/Google/Protobuf/Internal/MapFieldIter.php @@ -68,9 +68,10 @@ class MapFieldIter implements \Iterator * * @return void */ + #[\ReturnTypeWillChange] public function rewind() { - return reset($this->container); + reset($this->container); } /** @@ -78,6 +79,7 @@ class MapFieldIter implements \Iterator * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return current($this->container); @@ -88,6 +90,7 @@ class MapFieldIter implements \Iterator * * @return object The current key. */ + #[\ReturnTypeWillChange] public function key() { $key = key($this->container); @@ -117,9 +120,10 @@ class MapFieldIter implements \Iterator * * @return void */ + #[\ReturnTypeWillChange] public function next() { - return next($this->container); + next($this->container); } /** @@ -127,7 +131,7 @@ class MapFieldIter implements \Iterator * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return key($this->container) !== null; } diff --git a/php/src/Google/Protobuf/Internal/RepeatedField.php b/php/src/Google/Protobuf/Internal/RepeatedField.php index c0331ff38e..704123ad15 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedField.php +++ b/php/src/Google/Protobuf/Internal/RepeatedField.php @@ -39,6 +39,7 @@ namespace Google\Protobuf\Internal; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBUtil; +use Traversable; /** * RepeatedField is used by generated protocol message classes to manipulate @@ -121,6 +122,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Invalid type for index. * @throws \ErrorException Non-existing index. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->container[$offset]; @@ -138,6 +140,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException Non-existing index. * @throws \ErrorException Incorrect type of the element. */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { switch ($this->type) { @@ -209,6 +212,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @throws \ErrorException The element to be removed is not at the end of the * RepeatedField. */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { $count = count($this->container); @@ -230,7 +234,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * @return bool True if the element at the given offset exists. * @throws \ErrorException Invalid type for index. */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->container[$offset]); } @@ -238,7 +242,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable /** * @ignore */ - public function getIterator() + public function getIterator(): Traversable { return new RepeatedFieldIter($this->container); } @@ -250,7 +254,7 @@ class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable * * @return integer The number of stored elements. */ - public function count() + public function count(): int { return count($this->container); } diff --git a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php index 2b6f82309b..3c85869989 100644 --- a/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php +++ b/php/src/Google/Protobuf/Internal/RepeatedFieldIter.php @@ -71,6 +71,7 @@ class RepeatedFieldIter implements \Iterator * * @return void */ + #[\ReturnTypeWillChange] public function rewind() { $this->position = 0; @@ -81,6 +82,7 @@ class RepeatedFieldIter implements \Iterator * * @return object The element at the current position. */ + #[\ReturnTypeWillChange] public function current() { return $this->container[$this->position]; @@ -91,6 +93,7 @@ class RepeatedFieldIter implements \Iterator * * @return integer The current position. */ + #[\ReturnTypeWillChange] public function key() { return $this->position; @@ -101,6 +104,7 @@ class RepeatedFieldIter implements \Iterator * * @return void */ + #[\ReturnTypeWillChange] public function next() { ++$this->position; @@ -111,7 +115,7 @@ class RepeatedFieldIter implements \Iterator * * @return bool True if there are more elements to iterate. */ - public function valid() + public function valid(): bool { return isset($this->container[$this->position]); } diff --git a/src/google/protobuf/io/io_win32_unittest.cc b/src/google/protobuf/io/io_win32_unittest.cc index c50f68d6a9..e8f378fcac 100644 --- a/src/google/protobuf/io/io_win32_unittest.cc +++ b/src/google/protobuf/io/io_win32_unittest.cc @@ -164,8 +164,8 @@ void IoWin32Test::SetUp() { test_tmpdir.clear(); wtest_tmpdir.clear(); DWORD size = ::GetCurrentDirectoryW(MAX_PATH, working_directory); - EXPECT_GT(size, 0); - EXPECT_LT(size, MAX_PATH); + EXPECT_GT(size, 0U); + EXPECT_LT(size, static_cast(MAX_PATH)); string tmp; bool ok = false; @@ -581,7 +581,7 @@ TEST_F(IoWin32Test, ExpandWildcardsFailsIfNoFileMatchesTest) { TEST_F(IoWin32Test, AsWindowsPathTest) { DWORD size = GetCurrentDirectoryW(0, nullptr); std::unique_ptr cwd_str(new wchar_t[size]); - EXPECT_GT(GetCurrentDirectoryW(size, cwd_str.get()), 0); + EXPECT_GT(GetCurrentDirectoryW(size, cwd_str.get()), 0U); wstring cwd = wstring(L"\\\\?\\") + cwd_str.get(); ASSERT_EQ(testonly_utf8_to_winpath("relative_mkdirtest"), diff --git a/src/google/protobuf/io/zero_copy_stream_unittest.cc b/src/google/protobuf/io/zero_copy_stream_unittest.cc index fe9b6a191e..d4e5b54514 100644 --- a/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -49,7 +49,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #include #endif @@ -764,7 +764,7 @@ TEST_F(IoTest, FileIo) { } } -#ifndef _MSC_VER +#ifndef _WIN32 // This tests the FileInputStream with a non blocking file. It opens a pipe in // non blocking mode, then starts reading it. The writing thread starts writing // 100ms after that. diff --git a/src/google/protobuf/stubs/int128.cc b/src/google/protobuf/stubs/int128.cc index e5e159e1f8..36ead7e015 100644 --- a/src/google/protobuf/stubs/int128.cc +++ b/src/google/protobuf/stubs/int128.cc @@ -173,12 +173,13 @@ std::ostream& operator<<(std::ostream& o, const uint128& b) { // Add the requisite padding. std::streamsize width = o.width(0); - if (width > rep.size()) { + auto repSize = static_cast(rep.size()); + if (width > repSize) { if ((flags & std::ios::adjustfield) == std::ios::left) { - rep.append(width - rep.size(), o.fill()); + rep.append(width - repSize, o.fill()); } else { rep.insert(static_cast(0), - width - rep.size(), o.fill()); + width - repSize, o.fill()); } } diff --git a/tests.sh b/tests.sh index 290f110a8c..13bf034da6 100755 --- a/tests.sh +++ b/tests.sh @@ -496,6 +496,8 @@ build_php() { use_php $1 pushd php rm -rf vendor + php -v + php -m composer update composer test popd @@ -505,6 +507,8 @@ build_php() { test_php_c() { pushd php rm -rf vendor + php -v + php -m composer update composer test_c popd @@ -572,7 +576,9 @@ build_php_multirequest() { build_php8.0_all() { build_php 8.0 + build_php 8.1 build_php_c 8.0 + build_php_c 8.1 } build_php_all_32() { diff --git a/update_version.py b/update_version.py index 2c2b4890eb..6e89555c87 100755 --- a/update_version.py +++ b/update_version.py @@ -61,6 +61,19 @@ def GetFullVersion(rc_suffix = '-rc-'): return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION) +def GetSharedObjectVersion(): + protobuf_version_offset = 11 + expected_major_version = 3 + if NEW_VERSION_INFO[0] != expected_major_version: + print("""[ERROR] Major protobuf version has changed. Please update +update_version.py to readjust the protobuf_version_offset and +expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is +always increasing. + """) + exit(1) + return [NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2], 0] + + def RewriteXml(filename, rewriter, add_xml_prefix=True): document = minidom.parse(filename) rewriter(document) @@ -89,6 +102,14 @@ def RewriteTextFile(filename, line_rewriter): f.close() +def UpdateCMake(): + RewriteTextFile('cmake/libprotobuf.cmake', + lambda line : re.sub( + r'SOVERSION [0-9]+\.[0-9]+(\.[0-9]+)?', + 'SOVERSION %s' % GetSharedObjectVersion()[0], + line)) + + def UpdateConfigure(): RewriteTextFile('configure.ac', lambda line : re.sub( @@ -270,22 +291,10 @@ def UpdateJavaScript(): def UpdateMakefile(): - protobuf_version_offset = 11 - expected_major_version = 3 - if NEW_VERSION_INFO[0] != expected_major_version: - print("""[ERROR] Major protobuf version has changed. Please update -update_version.py to readjust the protobuf_version_offset and -expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is -always increasing. - """) - exit(1) - - protobuf_version_info = '%d:%d:0' % ( - NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2]) RewriteTextFile('src/Makefile.am', lambda line : re.sub( r'^PROTOBUF_VERSION = .*$', - 'PROTOBUF_VERSION = %s' % protobuf_version_info, + 'PROTOBUF_VERSION = %s' % ":".join(map(str,GetSharedObjectVersion())), line)) @@ -397,6 +406,7 @@ def UpdateBazel(): line)) +UpdateCMake() UpdateConfigure() UpdateCsharp() UpdateCpp()