From 6ede0aa1dffb36bce6e4b3d773aaaeae367389ca Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 15 Nov 2024 09:20:55 -0500 Subject: [PATCH 1/2] PHPC-2473: Bump to libmongoc 1.29.0 (#1748) * PHPC-2473: Bump to libmongoc 1.29.0 Update sources and paths for libmongoc 1.29.0. Update libmongoc CI builds and re-enable "latest". Also updates the file paths in comment. The test-variants.yml file was moved in e128d2e182524709376e2cb2aa3b0d265670795f * PHPC-2475: bson_as_legacy_extended_json replaces bson_as_json * PHPC-2470: Vendor bson-atomic as phongo_atomic libmongoc 1.29.0 deprecated bson-atomic.h, so this vendors the necessary functionality into PHPC. Also applied clang-format to the new sources. --- .../generated/build/build-libmongoc.yml | 26 +- .../generated/test-variant/libmongoc.yml | 60 +-- .../templates/build/build-libmongoc.yml | 26 +- .../templates/test-variant/libmongoc.yml | 60 +-- bin/prep-release.php | 2 +- config.m4 | 19 +- config.w32 | 12 +- php_phongo.c | 5 +- sbom.json | 16 +- scripts/update-submodule-sources.php | 2 +- src/LIBMONGOC_VERSION_CURRENT | 2 +- src/libmongoc | 2 +- src/phongo_atomic.c | 119 ++++++ src/phongo_atomic.h | 363 ++++++++++++++++++ src/phongo_bson.c | 2 +- 15 files changed, 598 insertions(+), 118 deletions(-) create mode 100644 src/phongo_atomic.c create mode 100644 src/phongo_atomic.h diff --git a/.evergreen/config/generated/build/build-libmongoc.yml b/.evergreen/config/generated/build/build-libmongoc.yml index 7317e94e6..dd915b927 100644 --- a/.evergreen/config/generated/build/build-libmongoc.yml +++ b/.evergreen/config/generated/build/build-libmongoc.yml @@ -3,16 +3,16 @@ tasks: # The following tasks are used to build with different libmongoc versions. # If libmongoc is not set to a stable version, disable the first two builds and only leave the last one enabled. # When updating libmongoc to a stable release, make sure all builds are enabled. -# These tasks are used in the build task group "build-php-libmongoc" defined in .evergreen/config/build-task-groups.yml, +# These tasks are used in the build task group "build-php-libmongoc" defined in .evergreen/config/templates/build-task-groups.yml, # where the "max_hosts" setting must be set to the number of enabled tasks. -# Last but not least, make sure the corresponding test variants are enabled in .evergreen/config/test-variants.yml +# Last but not least, make sure the corresponding test variants are enabled in .evergreen/config/templates/test-variant/libmongoc.yml - name: "build-php-8.3-libmongoc-lowest-supported" tags: ["build-libmongoc", "php8.3"] commands: - func: "compile driver" vars: PHP_VERSION: "8.3" - LIBMONGOC_VERSION: "1.28.1" + LIBMONGOC_VERSION: "1.29.0" - func: "upload build" - name: "build-php-8.3-libmongoc-next-stable" @@ -21,16 +21,14 @@ tasks: - func: "compile driver" vars: PHP_VERSION: "8.3" - LIBMONGOC_VERSION: "r1.28" + LIBMONGOC_VERSION: "r1.29" - func: "upload build" -# TODO: this currently fails as libmongoc master needs changes to build directories -# We can re-enable this after switching to 1.29-dev -# - name: "build-php-8.3-libmongoc-latest" -# tags: ["build-libmongoc", "php8.3"] -# commands: -# - func: "compile driver" -# vars: -# PHP_VERSION: "8.3" -# LIBMONGOC_VERSION: "master" -# - func: "upload build" + - name: "build-php-8.3-libmongoc-latest" + tags: ["build-libmongoc", "php8.3"] + commands: + - func: "compile driver" + vars: + PHP_VERSION: "8.3" + LIBMONGOC_VERSION: "master" + - func: "upload build" diff --git a/.evergreen/config/generated/test-variant/libmongoc.yml b/.evergreen/config/generated/test-variant/libmongoc.yml index c7c9db90a..85b41e617 100644 --- a/.evergreen/config/generated/test-variant/libmongoc.yml +++ b/.evergreen/config/generated/test-variant/libmongoc.yml @@ -63,33 +63,33 @@ buildvariants: execution_tasks: - ".ocsp .7.0" -# - name: test-debian12-php-8.3-libmongoc-latest -# tags: ["test", "libmongoc", "debian", "x64", "php8.3"] -# display_name: "Test: Debian 12, PHP 8.3, libmongoc latest" -# run_on: debian12-small -# expansions: -# FETCH_BUILD_VARIANT: "build-debian12" -# FETCH_BUILD_TASK: "build-php-8.3-libmongoc-latest" -# depends_on: -# - variant: "build-debian12" -# name: "build-php-8.3-libmongoc-latest" -# tasks: -# - ".standalone .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".replicaset .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".sharded .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".loadbalanced .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - "test-atlas-connectivity" -# - ".ocsp !.4.4 !.5.0 !.6.0" -# display_tasks: -# - name: "test-ocsp-latest" -# execution_tasks: -# - ".ocsp .latest" -# - name: "test-ocsp-rapid" -# execution_tasks: -# - ".ocsp .rapid" -# - name: "test-ocsp-8.0" -# execution_tasks: -# - ".ocsp .8.0" -# - name: "test-ocsp-7.0" -# execution_tasks: -# - ".ocsp .7.0" + - name: test-debian12-php-8.3-libmongoc-latest + tags: ["test", "libmongoc", "debian", "x64", "php8.3"] + display_name: "Test: Debian 12, PHP 8.3, libmongoc latest" + run_on: debian12-small + expansions: + FETCH_BUILD_VARIANT: "build-debian12" + FETCH_BUILD_TASK: "build-php-8.3-libmongoc-latest" + depends_on: + - variant: "build-debian12" + name: "build-php-8.3-libmongoc-latest" + tasks: + - ".standalone .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".replicaset .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".sharded .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".loadbalanced .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - "test-atlas-connectivity" + - ".ocsp !.4.4 !.5.0 !.6.0" + display_tasks: + - name: "test-ocsp-latest" + execution_tasks: + - ".ocsp .latest" + - name: "test-ocsp-rapid" + execution_tasks: + - ".ocsp .rapid" + - name: "test-ocsp-8.0" + execution_tasks: + - ".ocsp .8.0" + - name: "test-ocsp-7.0" + execution_tasks: + - ".ocsp .7.0" diff --git a/.evergreen/config/templates/build/build-libmongoc.yml b/.evergreen/config/templates/build/build-libmongoc.yml index 4f268ce66..606fb24c0 100644 --- a/.evergreen/config/templates/build/build-libmongoc.yml +++ b/.evergreen/config/templates/build/build-libmongoc.yml @@ -1,16 +1,16 @@ # The following tasks are used to build with different libmongoc versions. # If libmongoc is not set to a stable version, disable the first two builds and only leave the last one enabled. # When updating libmongoc to a stable release, make sure all builds are enabled. -# These tasks are used in the build task group "build-php-libmongoc" defined in .evergreen/config/build-task-groups.yml, +# These tasks are used in the build task group "build-php-libmongoc" defined in .evergreen/config/templates/build-task-groups.yml, # where the "max_hosts" setting must be set to the number of enabled tasks. -# Last but not least, make sure the corresponding test variants are enabled in .evergreen/config/test-variants.yml +# Last but not least, make sure the corresponding test variants are enabled in .evergreen/config/templates/test-variant/libmongoc.yml - name: "build-php-%phpVersion%-libmongoc-lowest-supported" tags: ["build-libmongoc", "php%phpVersion%"] commands: - func: "compile driver" vars: PHP_VERSION: "%phpVersion%" - LIBMONGOC_VERSION: "1.28.1" + LIBMONGOC_VERSION: "1.29.0" - func: "upload build" - name: "build-php-%phpVersion%-libmongoc-next-stable" @@ -19,16 +19,14 @@ - func: "compile driver" vars: PHP_VERSION: "%phpVersion%" - LIBMONGOC_VERSION: "r1.28" + LIBMONGOC_VERSION: "r1.29" - func: "upload build" -# TODO: this currently fails as libmongoc master needs changes to build directories -# We can re-enable this after switching to 1.29-dev -# - name: "build-php-%phpVersion%-libmongoc-latest" -# tags: ["build-libmongoc", "php%phpVersion%"] -# commands: -# - func: "compile driver" -# vars: -# PHP_VERSION: "%phpVersion%" -# LIBMONGOC_VERSION: "master" -# - func: "upload build" + - name: "build-php-%phpVersion%-libmongoc-latest" + tags: ["build-libmongoc", "php%phpVersion%"] + commands: + - func: "compile driver" + vars: + PHP_VERSION: "%phpVersion%" + LIBMONGOC_VERSION: "master" + - func: "upload build" diff --git a/.evergreen/config/templates/test-variant/libmongoc.yml b/.evergreen/config/templates/test-variant/libmongoc.yml index e84365ca0..90099c6bf 100644 --- a/.evergreen/config/templates/test-variant/libmongoc.yml +++ b/.evergreen/config/templates/test-variant/libmongoc.yml @@ -61,33 +61,33 @@ execution_tasks: - ".ocsp .7.0" -# - name: test-debian12-php-%phpVersion%-libmongoc-latest -# tags: ["test", "libmongoc", "debian", "x64", "php%phpVersion%"] -# display_name: "Test: Debian 12, PHP %phpVersion%, libmongoc latest" -# run_on: debian12-small -# expansions: -# FETCH_BUILD_VARIANT: "build-debian12" -# FETCH_BUILD_TASK: "build-php-%phpVersion%-libmongoc-latest" -# depends_on: -# - variant: "build-debian12" -# name: "build-php-%phpVersion%-libmongoc-latest" -# tasks: -# - ".standalone .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".replicaset .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".sharded .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - ".loadbalanced .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" -# - "test-atlas-connectivity" -# - ".ocsp !.4.4 !.5.0 !.6.0" -# display_tasks: -# - name: "test-ocsp-latest" -# execution_tasks: -# - ".ocsp .latest" -# - name: "test-ocsp-rapid" -# execution_tasks: -# - ".ocsp .rapid" -# - name: "test-ocsp-8.0" -# execution_tasks: -# - ".ocsp .8.0" -# - name: "test-ocsp-7.0" -# execution_tasks: -# - ".ocsp .7.0" + - name: test-debian12-php-%phpVersion%-libmongoc-latest + tags: ["test", "libmongoc", "debian", "x64", "php%phpVersion%"] + display_name: "Test: Debian 12, PHP %phpVersion%, libmongoc latest" + run_on: debian12-small + expansions: + FETCH_BUILD_VARIANT: "build-debian12" + FETCH_BUILD_TASK: "build-php-%phpVersion%-libmongoc-latest" + depends_on: + - variant: "build-debian12" + name: "build-php-%phpVersion%-libmongoc-latest" + tasks: + - ".standalone .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".replicaset .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".sharded .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - ".loadbalanced .local !.4.0 !.4.2 !.4.4 !.5.0 !.6.0" + - "test-atlas-connectivity" + - ".ocsp !.4.4 !.5.0 !.6.0" + display_tasks: + - name: "test-ocsp-latest" + execution_tasks: + - ".ocsp .latest" + - name: "test-ocsp-rapid" + execution_tasks: + - ".ocsp .rapid" + - name: "test-ocsp-8.0" + execution_tasks: + - ".ocsp .8.0" + - name: "test-ocsp-7.0" + execution_tasks: + - ".ocsp .7.0" diff --git a/bin/prep-release.php b/bin/prep-release.php index aa9882e3c..963794e94 100644 --- a/bin/prep-release.php +++ b/bin/prep-release.php @@ -48,7 +48,7 @@ function get_files() { "src/BSON/*.{c,h}", "src/contrib/*.{c,h}", - "src/libmongoc/src/common/*.{c,h,h.in}", + "src/libmongoc/src/common/src/*.{c,h,h.in}", "src/libmongoc/src/kms-message/src/*.{c,h}", "src/libmongoc/src/kms-message/src/kms_message/*.{c,h}", "src/libmongoc/src/libbson/src/bson/*.{c,h,h.in}", diff --git a/config.m4 b/config.m4 index 8e77673a0..28998f5e8 100644 --- a/config.m4 +++ b/config.m4 @@ -127,6 +127,7 @@ if test "$PHP_MONGODB" != "no"; then PHP_MONGODB_SOURCES="\ php_phongo.c \ src/phongo_apm.c \ + src/phongo_atomic.c \ src/phongo_bson.c \ src/phongo_bson_encode.c \ src/phongo_client.c \ @@ -276,7 +277,7 @@ if test "$PHP_MONGODB" != "no"; then PHP_MONGODB_MONGOCRYPT_VERSION_STRING="None" if test "$PHP_MONGODB_SYSTEM_LIBS" != "no"; then - PKG_CHECK_MODULES([PHP_MONGODB_BSON], [libbson-1.0 >= 1.28.1], [ + PKG_CHECK_MODULES([PHP_MONGODB_BSON], [libbson-1.0 >= 1.29.0], [ PHP_MONGODB_BSON_VERSION=`$PKG_CONFIG libbson-1.0 --modversion` PHP_MONGODB_BSON_VERSION_STRING="System ($PHP_MONGODB_BSON_VERSION)" @@ -284,10 +285,10 @@ if test "$PHP_MONGODB" != "no"; then PHP_EVAL_LIBLINE($PHP_MONGODB_BSON_LIBS, MONGODB_SHARED_LIBADD) AC_DEFINE(HAVE_SYSTEM_LIBBSON, 1, [Use system libbson]) ],[ - AC_MSG_ERROR([Could not find system library for libbson >= 1.28.1]) + AC_MSG_ERROR([Could not find system library for libbson >= 1.29.0]) ]) - PKG_CHECK_MODULES([PHP_MONGODB_MONGOC], [libmongoc-1.0 >= 1.28.1], [ + PKG_CHECK_MODULES([PHP_MONGODB_MONGOC], [libmongoc-1.0 >= 1.29.0], [ PHP_MONGODB_BSON_VERSION=`$PKG_CONFIG libbson-1.0 --modversion` PHP_MONGODB_BSON_VERSION_STRING="System ($PHP_MONGODB_BSON_VERSION)" @@ -295,7 +296,7 @@ if test "$PHP_MONGODB" != "no"; then PHP_EVAL_LIBLINE($PHP_MONGODB_MONGOC_LIBS, MONGODB_SHARED_LIBADD) AC_DEFINE(HAVE_SYSTEM_LIBMONGOC, 1, [Use system libmongoc]) ],[ - AC_MSG_ERROR(Could not find system library for libmongoc >= 1.28.1) + AC_MSG_ERROR(Could not find system library for libmongoc >= 1.29.0) ]) if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" != "no"; then @@ -394,7 +395,7 @@ if test "$PHP_MONGODB" != "no"; then fi dnl Sources below are updated by scripts/update-submodule-sources.php - PHP_MONGODB_COMMON_SOURCES="common-b64.c common-md5.c common-thread.c" + PHP_MONGODB_COMMON_SOURCES="common-atomic.c common-b64.c common-md5.c common-thread.c" PHP_MONGODB_KMS_MESSAGE_SOURCES="hexlify.c kms_azure_request.c kms_b64.c kms_caller_identity_request.c kms_crypto_apple.c kms_crypto_libcrypto.c kms_crypto_none.c kms_crypto_windows.c kms_decrypt_request.c kms_encrypt_request.c kms_gcp_request.c kms_kmip_reader_writer.c kms_kmip_request.c kms_kmip_response.c kms_kmip_response_parser.c kms_kv_list.c kms_message.c kms_port.c kms_request.c kms_request_opt.c kms_request_str.c kms_response.c kms_response_parser.c sort.c" PHP_MONGODB_BSON_SOURCES="bcon.c bson-atomic.c bson.c bson-clock.c bson-context.c bson-decimal128.c bson-error.c bson-iso8601.c bson-iter.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version-functions.c bson-writer.c" PHP_MONGODB_JSONSL_SOURCES="jsonsl.c" @@ -402,18 +403,18 @@ if test "$PHP_MONGODB" != "no"; then PHP_MONGODB_UTF8PROC_SOURCES="utf8proc.c" PHP_MONGODB_ZLIB_SOURCES="adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c" - PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/common/], $PHP_MONGODB_COMMON_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS) + PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/common/src/], $PHP_MONGODB_COMMON_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS) PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/libbson/src/bson/], $PHP_MONGODB_BSON_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS) PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/libbson/src/jsonsl/], $PHP_MONGODB_JSONSL_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS) PHP_MONGODB_ADD_SOURCES([src/libmongoc/src/libmongoc/src/mongoc/], $PHP_MONGODB_MONGOC_SOURCES, $PHP_MONGODB_BUNDLED_CFLAGS) - PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/common/]) + PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/common/src/]) PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/uthash/]) PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/libbson/src/]) PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/libbson/src/jsonsl/]) PHP_MONGODB_ADD_INCLUDE([src/libmongoc/src/libmongoc/src/]) - PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/common/]) + PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/common/src/]) PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/libbson/src/bson/]) PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/libbson/src/jsonsl/]) PHP_MONGODB_ADD_BUILD_DIR([src/libmongoc/src/libmongoc/src/mongoc/]) @@ -431,7 +432,7 @@ if test "$PHP_MONGODB" != "no"; then ac_config_dir=PHP_EXT_SRCDIR(mongodb) AC_CONFIG_FILES([ - ${ac_config_dir}/src/libmongoc/src/common/common-config.h + ${ac_config_dir}/src/libmongoc/src/common/src/common-config.h ${ac_config_dir}/src/libmongoc/src/libbson/src/bson/bson-config.h ${ac_config_dir}/src/libmongoc/src/libbson/src/bson/bson-version.h ${ac_config_dir}/src/libmongoc/src/libmongoc/src/mongoc/mongoc-config.h diff --git a/config.w32 b/config.w32 index f83c4127b..dbded6599 100644 --- a/config.w32 +++ b/config.w32 @@ -93,7 +93,7 @@ if (PHP_MONGODB != "no") { /I" + configure_module_dirname + "/src/MongoDB/Exception \ /I" + configure_module_dirname + "/src/MongoDB/Monitoring \ /I" + configure_module_dirname + "/src/contrib \ - /I" + configure_module_dirname + "/src/libmongoc/src/common \ + /I" + configure_module_dirname + "/src/libmongoc/src/common/src \ /I" + configure_module_dirname + "/src/libmongoc/src/uthash \ /I" + configure_module_dirname + "/src/libmongoc/src/libbson/src \ /I" + configure_module_dirname + "/src/libmongoc/src/libbson/src/jsonsl \ @@ -106,7 +106,7 @@ if (PHP_MONGODB != "no") { PHP_MONGODB_CFLAGS = PHP_MONGODB_CFLAGS.replace(/\s+/g, ' '); // Sources below are updated by scripts/update-submodule-sources.php - var PHP_MONGODB_COMMON_SOURCES="common-b64.c common-md5.c common-thread.c" + var PHP_MONGODB_COMMON_SOURCES="common-atomic.c common-b64.c common-md5.c common-thread.c" var PHP_MONGODB_KMS_MESSAGE_SOURCES="hexlify.c kms_azure_request.c kms_b64.c kms_caller_identity_request.c kms_crypto_apple.c kms_crypto_libcrypto.c kms_crypto_none.c kms_crypto_windows.c kms_decrypt_request.c kms_encrypt_request.c kms_gcp_request.c kms_kmip_reader_writer.c kms_kmip_request.c kms_kmip_response.c kms_kmip_response_parser.c kms_kv_list.c kms_message.c kms_port.c kms_request.c kms_request_opt.c kms_request_str.c kms_response.c kms_response_parser.c sort.c"; var PHP_MONGODB_BSON_SOURCES="bcon.c bson-atomic.c bson.c bson-clock.c bson-context.c bson-decimal128.c bson-error.c bson-iso8601.c bson-iter.c bson-json.c bson-keys.c bson-md5.c bson-memory.c bson-oid.c bson-reader.c bson-string.c bson-timegm.c bson-utf8.c bson-value.c bson-version-functions.c bson-writer.c"; var PHP_MONGODB_JSONSL_SOURCES="jsonsl.c"; @@ -114,12 +114,12 @@ if (PHP_MONGODB != "no") { var PHP_MONGODB_UTF8PROC_SOURCES="utf8proc.c"; EXTENSION("mongodb", "php_phongo.c", null, PHP_MONGODB_CFLAGS); - MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c"); + MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_atomic.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c"); MONGODB_ADD_SOURCES("/src/BSON", "Binary.c BinaryInterface.c Document.c Iterator.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c PackedArray.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c functions.c"); MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorId.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c"); MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c"); MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c LogSubscriber.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c"); - MONGODB_ADD_SOURCES("/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES); + MONGODB_ADD_SOURCES("/src/libmongoc/src/common/src", PHP_MONGODB_COMMON_SOURCES); MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/bson", PHP_MONGODB_BSON_SOURCES); MONGODB_ADD_SOURCES("/src/libmongoc/src/libbson/src/jsonsl", PHP_MONGODB_JSONSL_SOURCES); MONGODB_ADD_SOURCES("/src/libmongoc/src/libmongoc/src/mongoc", PHP_MONGODB_MONGOC_SOURCES); @@ -333,8 +333,8 @@ if (PHP_MONGODB != "no") { ); mongodb_generate_header( - configure_module_dirname + "/src/libmongoc/src/common/common-config.h.in", - configure_module_dirname + "/src/libmongoc/src/common/common-config.h", + configure_module_dirname + "/src/libmongoc/src/common/src/common-config.h.in", + configure_module_dirname + "/src/libmongoc/src/common/src/common-config.h", mongoc_opts ); diff --git a/php_phongo.c b/php_phongo.c index e44eb3b19..ad93ff75e 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -25,6 +25,7 @@ #include #include "php_phongo.h" +#include "src/phongo_atomic.h" #include "src/phongo_client.h" #include "src/phongo_error.h" #include "src/phongo_ini.h" @@ -130,7 +131,7 @@ PHP_GINIT_FUNCTION(mongodb) /* {{{ */ #endif /* Increment the thread counter. */ - bson_atomic_int32_fetch_add(&phongo_num_threads, 1, bson_memory_order_seq_cst); + phongo_atomic_int32_fetch_add(&phongo_num_threads, 1, phongo_memory_order_seq_cst); /* Clear extension globals */ memset(mongodb_globals, 0, sizeof(zend_mongodb_globals)); @@ -375,7 +376,7 @@ PHP_GSHUTDOWN_FUNCTION(mongodb) /* {{{ */ * is the last thread, MSHUTDOWN has been called, persistent clients from * all threads have been destroyed, and it is now safe to shutdown libmongoc * and restore libbson's original vtable. */ - if (bson_atomic_int32_fetch_sub(&phongo_num_threads, 1, bson_memory_order_seq_cst) - 1 == 0) { + if (phongo_atomic_int32_fetch_sub(&phongo_num_threads, 1, phongo_memory_order_seq_cst) - 1 == 0) { mongoc_cleanup(); bson_mem_restore_vtable(); } diff --git a/sbom.json b/sbom.json index 6be25fdae..fb98f7605 100644 --- a/sbom.json +++ b/sbom.json @@ -19,22 +19,22 @@ "version": "1.12.0" }, { - "bom-ref": "pkg:github/mongodb/mongo-c-driver@1.28.1", + "bom-ref": "pkg:github/mongodb/mongo-c-driver@1.29.0", "externalReferences": [ { "type": "distribution", - "url": "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/1.28.1.tar.gz" + "url": "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/1.29.0.tar.gz" }, { "type": "website", - "url": "https://github.com/mongodb/mongo-c-driver/tree/1.28.1" + "url": "https://github.com/mongodb/mongo-c-driver/tree/1.29.0" } ], "group": "mongodb", "name": "mongo-c-driver", - "purl": "pkg:github/mongodb/mongo-c-driver@1.28.1", + "purl": "pkg:github/mongodb/mongo-c-driver@1.29.0", "type": "library", - "version": "1.28.1" + "version": "1.29.0" } ], "dependencies": [ @@ -42,11 +42,11 @@ "ref": "pkg:github/mongodb/libmongocrypt@1.12.0" }, { - "ref": "pkg:github/mongodb/mongo-c-driver@1.28.1" + "ref": "pkg:github/mongodb/mongo-c-driver@1.29.0" } ], "metadata": { - "timestamp": "2024-11-12T17:58:27.805097+00:00", + "timestamp": "2024-11-12T18:00:38.546484+00:00", "tools": [ { "externalReferences": [ @@ -90,7 +90,7 @@ ] }, "serialNumber": "urn:uuid:acb30d08-ee47-4ff0-b301-d66ef1f54082", - "version": 6, + "version": 7, "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json", "bomFormat": "CycloneDX", "specVersion": "1.5", diff --git a/scripts/update-submodule-sources.php b/scripts/update-submodule-sources.php index 124d04616..8240fd9e3 100644 --- a/scripts/update-submodule-sources.php +++ b/scripts/update-submodule-sources.php @@ -8,7 +8,7 @@ } $vars = [ - 'PHP_MONGODB_COMMON_SOURCES' => 'src/libmongoc/src/common', + 'PHP_MONGODB_COMMON_SOURCES' => 'src/libmongoc/src/common/src', 'PHP_MONGODB_KMS_MESSAGE_SOURCES' => 'src/libmongoc/src/kms-message/src', 'PHP_MONGODB_BSON_SOURCES' => 'src/libmongoc/src/libbson/src/bson', 'PHP_MONGODB_JSONSL_SOURCES' => 'src/libmongoc/src/libbson/src/jsonsl', diff --git a/src/LIBMONGOC_VERSION_CURRENT b/src/LIBMONGOC_VERSION_CURRENT index 450a687b2..5e57fb895 100644 --- a/src/LIBMONGOC_VERSION_CURRENT +++ b/src/LIBMONGOC_VERSION_CURRENT @@ -1 +1 @@ -1.28.1 +1.29.0 diff --git a/src/libmongoc b/src/libmongoc index 97f166d8d..fc82e03cb 160000 --- a/src/libmongoc +++ b/src/libmongoc @@ -1 +1 @@ -Subproject commit 97f166d8d784d6096d48ba288f98b48028cdfe8b +Subproject commit fc82e03cbea13abf276b5abb3736249e97c7ee0f diff --git a/src/phongo_atomic.c b/src/phongo_atomic.c new file mode 100644 index 000000000..dcd332412 --- /dev/null +++ b/src/phongo_atomic.c @@ -0,0 +1,119 @@ +/* + * Copyright 2024-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Note: this file was derived from libbson's bson-atomic.c */ + +#include "bson/bson.h" + +#include "phongo_atomic.h" + +#ifdef BSON_OS_UNIX +/* For sched_yield() */ +#include +#endif + +static void _thrd_yield(void) +{ + BSON_IF_WINDOWS(SwitchToThread();) + BSON_IF_POSIX(sched_yield();) +} + +/** + * Some platforms do not support compiler intrinsics for atomic operations. + * We emulate that here using a spin lock and regular arithmetic operations + */ +static int8_t gEmulAtomicLock = 0; + +static void _lock_emul_atomic(void) +{ + int i; + if (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) { + /* Successfully took the spinlock */ + return; + } + /* Failed. Try taking ten more times, then begin sleeping. */ + for (i = 0; i < 10; ++i) { + if (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) == 0) { + /* Succeeded in taking the lock */ + return; + } + } + /* Still don't have the lock. Spin and yield */ + while (phongo_atomic_int8_compare_exchange_weak(&gEmulAtomicLock, 0, 1, phongo_memory_order_acquire) != 0) { + _thrd_yield(); + } +} + +static void _unlock_emul_atomic(void) +{ + int64_t rv = phongo_atomic_int8_exchange(&gEmulAtomicLock, 0, phongo_memory_order_release); + BSON_ASSERT(rv == 1 && "Released atomic lock while not holding it"); +} + +int32_t _phongo_emul_atomic_int32_fetch_add(volatile int32_t* p, int32_t n, enum phongo_memory_order _unused) +{ + int32_t ret; + + BSON_UNUSED(_unused); + + _lock_emul_atomic(); + ret = *p; + *p += n; + _unlock_emul_atomic(); + return ret; +} + +int32_t _phongo_emul_atomic_int32_exchange(volatile int32_t* p, int32_t n, enum phongo_memory_order _unused) +{ + int32_t ret; + + BSON_UNUSED(_unused); + + _lock_emul_atomic(); + ret = *p; + *p = n; + _unlock_emul_atomic(); + return ret; +} + +int32_t _phongo_emul_atomic_int32_compare_exchange_strong( + volatile int32_t* p, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order _unused) +{ + int32_t ret; + + BSON_UNUSED(_unused); + + _lock_emul_atomic(); + ret = *p; + if (ret == expect_value) { + *p = new_value; + } + _unlock_emul_atomic(); + return ret; +} + +int32_t _phongo_emul_atomic_int32_compare_exchange_weak( + volatile int32_t* p, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order order) +{ + /* We're emulating. We can't do a weak version. */ + return _phongo_emul_atomic_int32_compare_exchange_strong(p, expect_value, new_value, order); +} diff --git a/src/phongo_atomic.h b/src/phongo_atomic.h new file mode 100644 index 000000000..463d0d057 --- /dev/null +++ b/src/phongo_atomic.h @@ -0,0 +1,363 @@ +/* + * Copyright 2024-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Note: this file was derived from libbson's bson-atomic.h */ + +#ifndef PHONGO_ATOMIC_H +#define PHONGO_ATOMIC_H + +#include "bson/bson.h" + +#ifdef _MSC_VER +#include +#endif + +enum phongo_memory_order { + phongo_memory_order_seq_cst, + phongo_memory_order_acquire, + phongo_memory_order_release, + phongo_memory_order_relaxed, + phongo_memory_order_acq_rel, + phongo_memory_order_consume, +}; + +#if defined(_M_ARM) /* MSVC memorder atomics are only avail on ARM */ +#define MSVC_MEMORDER_SUFFIX(X) X +#else +#define MSVC_MEMORDER_SUFFIX(X) +#endif + +#if defined(USE_LEGACY_GCC_ATOMICS) || (!defined(__clang__) && __GNUC__ == 4) || defined(__xlC__) +#define PHONGO_USE_LEGACY_GCC_ATOMICS +#else +#undef PHONGO_USE_LEGACY_GCC_ATOMICS +#endif + +/* Not all GCC-like compilers support the current __atomic built-ins. Older + * GCC (pre-5) used different built-ins named with the __sync prefix. When + * compiling with such older GCC versions, it is necessary to use the applicable + * functions, which requires redefining BSON_IF_GNU_LIKE and defining the + * additional PHONGO_IF_GNU_LEGACY_ATOMICS macro here. */ +#ifdef PHONGO_USE_LEGACY_GCC_ATOMICS +#undef BSON_IF_GNU_LIKE +#define BSON_IF_GNU_LIKE(...) +#define BSON_IF_MSVC(...) +#define PHONGO_IF_GNU_LEGACY_ATOMICS(...) __VA_ARGS__ +#else +#define PHONGO_IF_GNU_LEGACY_ATOMICS(...) +#endif + +/* CDRIVER-4229 zSeries with gcc 4.8.4 produces illegal instructions for int and + * int32 atomic intrinsics. */ +#if defined(__s390__) || defined(__s390x__) || defined(__zarch__) +#define PHONGO_EMULATE_INT32 +#endif + +/* clang-format off */ + +#define DEF_ATOMIC_OP(MSVC_Intrinsic, GNU_Intrinsic, GNU_Legacy_Intrinsic, Order, ...) \ + do { \ + switch (Order) { \ + case phongo_memory_order_acq_rel: \ + BSON_IF_MSVC(return MSVC_Intrinsic(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_ACQ_REL);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + case phongo_memory_order_seq_cst: \ + BSON_IF_MSVC(return MSVC_Intrinsic(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_SEQ_CST);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + case phongo_memory_order_acquire: \ + BSON_IF_MSVC(return BSON_CONCAT(MSVC_Intrinsic, MSVC_MEMORDER_SUFFIX(_acq))(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_ACQUIRE);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + case phongo_memory_order_consume: \ + BSON_IF_MSVC(return BSON_CONCAT(MSVC_Intrinsic, MSVC_MEMORDER_SUFFIX(_acq))(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_CONSUME);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + case phongo_memory_order_release: \ + BSON_IF_MSVC(return BSON_CONCAT(MSVC_Intrinsic, MSVC_MEMORDER_SUFFIX(_rel))(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_RELEASE);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + case phongo_memory_order_relaxed: \ + BSON_IF_MSVC(return BSON_CONCAT(MSVC_Intrinsic, MSVC_MEMORDER_SUFFIX(_nf))(__VA_ARGS__);) \ + BSON_IF_GNU_LIKE(return GNU_Intrinsic(__VA_ARGS__, __ATOMIC_RELAXED);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(return GNU_Legacy_Intrinsic(__VA_ARGS__);) \ + default: \ + BSON_UNREACHABLE("Invalid phongo_memory_order value"); \ + } \ + } while (0) + +#define DEF_ATOMIC_CMPEXCH_STRONG(VCSuffix1, VCSuffix2, GNU_MemOrder, Ptr, ExpectActualVar, NewValue) \ + do { \ + BSON_IF_MSVC(ExpectActualVar = BSON_CONCAT3(_InterlockedCompareExchange, VCSuffix1, VCSuffix2)( \ + Ptr, NewValue, ExpectActualVar);) \ + BSON_IF_GNU_LIKE((void) __atomic_compare_exchange_n(Ptr, \ + &ExpectActualVar, \ + NewValue, \ + false, /* Not weak */ \ + GNU_MemOrder, \ + GNU_MemOrder);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(__typeof__(ExpectActualVar) _val; \ + _val = __sync_val_compare_and_swap(Ptr, ExpectActualVar, NewValue); \ + ExpectActualVar = _val;) \ + } while (0) + +#define DEF_ATOMIC_CMPEXCH_WEAK(VCSuffix1, VCSuffix2, GNU_MemOrder, Ptr, ExpectActualVar, NewValue) \ + do { \ + BSON_IF_MSVC(ExpectActualVar = BSON_CONCAT3(_InterlockedCompareExchange, VCSuffix1, VCSuffix2)( \ + Ptr, NewValue, ExpectActualVar);) \ + BSON_IF_GNU_LIKE((void) __atomic_compare_exchange_n(Ptr, \ + &ExpectActualVar, \ + NewValue, \ + true, /* Yes weak */ \ + GNU_MemOrder, \ + GNU_MemOrder);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(__typeof__(ExpectActualVar) _val; \ + _val = __sync_val_compare_and_swap(Ptr, ExpectActualVar, NewValue); \ + ExpectActualVar = _val;) \ + } while (0) + +#define DECL_ATOMIC_INTEGRAL(NamePart, Type, VCIntrinSuffix) \ + static BSON_INLINE Type phongo_atomic_##NamePart##_fetch_add( \ + Type volatile* a, Type addend, enum phongo_memory_order ord) \ + { \ + DEF_ATOMIC_OP(BSON_CONCAT(_InterlockedExchangeAdd, VCIntrinSuffix), \ + __atomic_fetch_add, \ + __sync_fetch_and_add, \ + ord, \ + a, \ + addend); \ + } \ + \ + static BSON_INLINE Type phongo_atomic_##NamePart##_fetch_sub( \ + Type volatile* a, Type subtrahend, enum phongo_memory_order ord) \ + { \ + /* MSVC doesn't have a subtract intrinsic, so just reuse addition */ \ + BSON_IF_MSVC(return phongo_atomic_##NamePart##_fetch_add(a, -subtrahend, ord);) \ + BSON_IF_GNU_LIKE(DEF_ATOMIC_OP(~, __atomic_fetch_sub, ~, ord, a, subtrahend);) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(DEF_ATOMIC_OP(~, ~, __sync_fetch_and_sub, ord, a, subtrahend);) \ + } \ + \ + static BSON_INLINE Type phongo_atomic_##NamePart##_fetch(Type volatile const* a, enum phongo_memory_order order) \ + { \ + /* MSVC doesn't have a load intrinsic, so just add zero */ \ + BSON_IF_MSVC(return phongo_atomic_##NamePart##_fetch_add((Type volatile*) a, 0, order);) \ + /* GNU doesn't want RELEASE order for the fetch operation, so we can't \ + * just use DEF_ATOMIC_OP. */ \ + BSON_IF_GNU_LIKE(switch (order) { \ + case phongo_memory_order_release: /* Fall back to seqcst */ \ + case phongo_memory_order_acq_rel: /* Fall back to seqcst */ \ + case phongo_memory_order_seq_cst: \ + return __atomic_load_n(a, __ATOMIC_SEQ_CST); \ + case phongo_memory_order_acquire: \ + return __atomic_load_n(a, __ATOMIC_ACQUIRE); \ + case phongo_memory_order_consume: \ + return __atomic_load_n(a, __ATOMIC_CONSUME); \ + case phongo_memory_order_relaxed: \ + return __atomic_load_n(a, __ATOMIC_RELAXED); \ + default: \ + BSON_UNREACHABLE("Invalid phongo_memory_order value"); \ + }) \ + PHONGO_IF_GNU_LEGACY_ATOMICS({ \ + BSON_UNUSED(order); \ + __sync_synchronize(); \ + return *a; \ + }) \ + } \ + \ + static BSON_INLINE Type phongo_atomic_##NamePart##_exchange( \ + Type volatile* a, Type value, enum phongo_memory_order ord) \ + { \ + BSON_IF_MSVC(DEF_ATOMIC_OP(BSON_CONCAT(_InterlockedExchange, VCIntrinSuffix), ~, ~, ord, a, value);) \ + /* GNU doesn't want CONSUME order for the exchange operation, so we \ + * cannot use DEF_ATOMIC_OP. */ \ + BSON_IF_GNU_LIKE(switch (ord) { \ + case phongo_memory_order_acq_rel: \ + return __atomic_exchange_n(a, value, __ATOMIC_ACQ_REL); \ + case phongo_memory_order_release: \ + return __atomic_exchange_n(a, value, __ATOMIC_RELEASE); \ + case phongo_memory_order_seq_cst: \ + return __atomic_exchange_n(a, value, __ATOMIC_SEQ_CST); \ + case phongo_memory_order_consume: /* Fall back to acquire */ \ + case phongo_memory_order_acquire: \ + return __atomic_exchange_n(a, value, __ATOMIC_ACQUIRE); \ + case phongo_memory_order_relaxed: \ + return __atomic_exchange_n(a, value, __ATOMIC_RELAXED); \ + default: \ + BSON_UNREACHABLE("Invalid phongo_memory_order value"); \ + }) \ + PHONGO_IF_GNU_LEGACY_ATOMICS(BSON_UNUSED(ord); return __sync_val_compare_and_swap(a, *a, value);) \ + } \ + \ + static BSON_INLINE Type phongo_atomic_##NamePart##_compare_exchange_strong( \ + Type volatile* a, Type expect, Type new_value, enum phongo_memory_order ord) \ + { \ + Type actual = expect; \ + switch (ord) { \ + case phongo_memory_order_release: \ + case phongo_memory_order_acq_rel: \ + case phongo_memory_order_seq_cst: \ + DEF_ATOMIC_CMPEXCH_STRONG(VCIntrinSuffix, , __ATOMIC_SEQ_CST, a, actual, new_value); \ + break; \ + case phongo_memory_order_acquire: \ + DEF_ATOMIC_CMPEXCH_STRONG( \ + VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_acq), __ATOMIC_ACQUIRE, a, actual, new_value); \ + break; \ + case phongo_memory_order_consume: \ + DEF_ATOMIC_CMPEXCH_STRONG( \ + VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_acq), __ATOMIC_CONSUME, a, actual, new_value); \ + break; \ + case phongo_memory_order_relaxed: \ + DEF_ATOMIC_CMPEXCH_STRONG( \ + VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_nf), __ATOMIC_RELAXED, a, actual, new_value); \ + break; \ + default: \ + BSON_UNREACHABLE("Invalid phongo_memory_order value"); \ + } \ + return actual; \ + } \ + \ + static BSON_INLINE Type phongo_atomic_##NamePart##_compare_exchange_weak( \ + Type volatile* a, Type expect, Type new_value, enum phongo_memory_order ord) \ + { \ + Type actual = expect; \ + switch (ord) { \ + case phongo_memory_order_release: \ + case phongo_memory_order_acq_rel: \ + case phongo_memory_order_seq_cst: \ + DEF_ATOMIC_CMPEXCH_WEAK(VCIntrinSuffix, , __ATOMIC_SEQ_CST, a, actual, new_value); \ + break; \ + case phongo_memory_order_acquire: \ + DEF_ATOMIC_CMPEXCH_WEAK( \ + VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_acq), __ATOMIC_ACQUIRE, a, actual, new_value); \ + break; \ + case phongo_memory_order_consume: \ + DEF_ATOMIC_CMPEXCH_WEAK( \ + VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_acq), __ATOMIC_CONSUME, a, actual, new_value); \ + break; \ + case phongo_memory_order_relaxed: \ + DEF_ATOMIC_CMPEXCH_WEAK(VCIntrinSuffix, MSVC_MEMORDER_SUFFIX(_nf), __ATOMIC_RELAXED, a, actual, new_value); \ + break; \ + default: \ + BSON_UNREACHABLE("Invalid phongo_memory_order value"); \ + } \ + return actual; \ + } + +/* clang-format on */ + +#define DECL_ATOMIC_STDINT(Name, VCSuffix) DECL_ATOMIC_INTEGRAL(Name, Name##_t, VCSuffix) + +#if defined(_MSC_VER) || defined(PHONGO_USE_LEGACY_GCC_ATOMICS) +/* MSVC and GCC require built-in types (not typedefs) for their atomic + * intrinsics. */ +#if defined(_MSC_VER) +#define DECL_ATOMIC_INTEGRAL_INT8 char +#define DECL_ATOMIC_INTEGRAL_INT32 long +#else +#define DECL_ATOMIC_INTEGRAL_INT8 signed char +#define DECL_ATOMIC_INTEGRAL_INT32 int +#endif +DECL_ATOMIC_INTEGRAL(int8, DECL_ATOMIC_INTEGRAL_INT8, 8) +#if !defined(PHONGO_EMULATE_INT32) +DECL_ATOMIC_INTEGRAL(int32, DECL_ATOMIC_INTEGRAL_INT32, ) +#endif +#else +/* Other compilers that we support provide generic intrinsics */ +DECL_ATOMIC_STDINT(int8, 8) +#if !defined(PHONGO_EMULATE_INT32) +DECL_ATOMIC_STDINT(int32, ) +#endif +#endif + +#ifndef DECL_ATOMIC_INTEGRAL_INT32 +#define DECL_ATOMIC_INTEGRAL_INT32 int32_t +#endif + +int32_t _phongo_emul_atomic_int32_fetch_add(int32_t volatile* val, int32_t v, enum phongo_memory_order); + +int32_t _phongo_emul_atomic_int32_exchange(int32_t volatile* val, int32_t v, enum phongo_memory_order); + +int32_t _phongo_emul_atomic_int32_compare_exchange_strong( + int32_t volatile* val, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order); + +int32_t _phongo_emul_atomic_int32_compare_exchange_weak( + int32_t volatile* val, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order); + +#if defined(PHONGO_EMULATE_INT32) +static BSON_INLINE int32_t phongo_atomic_int32_fetch(const int32_t volatile* val, enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_fetch_add((int32_t volatile*) val, 0, order); +} + +static BSON_INLINE int32_t phongo_atomic_int32_fetch_add(int32_t volatile* val, int32_t v, enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_fetch_add(val, v, order); +} + +static BSON_INLINE int32_t phongo_atomic_int32_fetch_sub(int32_t volatile* val, int32_t v, enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_fetch_add(val, -v, order); +} + +static BSON_INLINE int32_t phongo_atomic_int32_exchange(int32_t volatile* val, int32_t v, enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_exchange(val, v, order); +} + +static BSON_INLINE int32_t phongo_atomic_int32_compare_exchange_strong( + int32_t volatile* val, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_compare_exchange_strong(val, expect_value, new_value, order); +} + +static BSON_INLINE int32_t phongo_atomic_int32_compare_exchange_weak( + int32_t volatile* val, + int32_t expect_value, + int32_t new_value, + enum phongo_memory_order order) +{ + return _phongo_emul_atomic_int32_compare_exchange_weak(val, expect_value, new_value, order); +} +#endif /* PHONGO_EMULATE_INT32 */ + +#undef DECL_ATOMIC_STDINT +#undef DECL_ATOMIC_INTEGRAL +#undef DEF_ATOMIC_OP +#undef DEF_ATOMIC_CMPEXCH_STRONG +#undef DEF_ATOMIC_CMPEXCH_WEAK +#undef MSVC_MEMORDER_SUFFIX + +/* TODO: Redefine BSON_IF_MSVC is necessary (see: CDRIVER-5813) */ +#ifdef PHONGO_USE_LEGACY_GCC_ATOMICS +#undef BSON_IF_GNU_LIKE +#define BSON_IF_GNU_LIKE(...) __VA_ARGS__ +#endif +#undef PHONGO_IF_GNU_LEGACY_ATOMICS +#undef PHONGO_USE_LEGACY_GCC_ATOMICS + +#undef PHONGO_EMULATE_INT32 + +#endif /* PHONGO_ATOMIC_H */ diff --git a/src/phongo_bson.c b/src/phongo_bson.c index 62b9cdceb..92b14e568 100644 --- a/src/phongo_bson.c +++ b/src/phongo_bson.c @@ -1446,7 +1446,7 @@ bool php_phongo_bson_to_json(zval* return_value, const bson_t* bson, php_phongo_ size_t json_len; if (mode == PHONGO_JSON_MODE_LEGACY) { - json = bson_as_json(bson, &json_len); + json = bson_as_legacy_extended_json(bson, &json_len); } else if (mode == PHONGO_JSON_MODE_CANONICAL) { json = bson_as_canonical_extended_json(bson, &json_len); } else if (mode == PHONGO_JSON_MODE_RELAXED) { From c879aec9f9830ac799df3e497757a00343fef6f7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Nahan <814683+macintoshplus@users.noreply.github.com> Date: Thu, 21 Nov 2024 21:19:13 +0100 Subject: [PATCH 2/2] Remove ext prefix from extension name in composer.json (#1752) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 42c103c1e..b19c23aa6 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "ext-json": "*" }, "php-ext": { - "extension-name": "ext-mongodb", + "extension-name": "mongodb", "configure-options": [ { "name": "enable-mongodb-developer-flags",