From 3e3dd9eb0be2fca3224177e2c8ab9b254c24d4a7 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 22:38:12 +0000 Subject: [PATCH 01/13] Run the test job without a container The container was added in f2009ea to run i386 builds. 7095078 replaced i386 with arm64 on the native ubuntu-24.04-arm runner, so both entries now run on a native runner and the container only wraps them. Without it, the job can also run on macOS and Windows, which do not support job containers. The runner's PHP loads gmp by default, and the decoder uses gmp when it is loaded. The bcmath jobs now disable gmp, so they still test the bcmath path. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27425dc..ed2244e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,26 +10,25 @@ permissions: {} jobs: run: - runs-on: ${{ matrix.runner }} - container: shivammathur/node:latest-${{ matrix.arch }} + runs-on: ${{ matrix.os }} strategy: matrix: - arch: ["amd64", "arm64v8"] + os: [ubuntu-latest, ubuntu-24.04-arm] php-version: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] php-extension: ['bcmath', 'gmp'] include: - - arch: amd64 - runner: ubuntu-latest - - arch: arm64v8 - runner: ubuntu-24.04-arm + # The runner's PHP loads gmp by default, and the decoder uses gmp + # when it is loaded. Disable gmp so that the bcmath path runs. + - php-extension: bcmath + disabled-extensions: ':gmp' - name: "PHP ${{ matrix.php-version }} (with ${{ matrix.php-extension }}) test on ${{ matrix.runner }}" + name: "PHP ${{ matrix.php-version }} (with ${{ matrix.php-extension }}) test on ${{ matrix.os }}" steps: - name: Install PHP uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 with: php-version: ${{ matrix.php-version }} - extensions: "mbstring, intl, ${{ matrix.php-extension }}" + extensions: "mbstring, intl, ${{ matrix.php-extension }}, ${{ matrix.disabled-extensions }}" tools: "composer, phpize" - name: Checkout From de98958deefa6a3051a4d425ecfe450f9661793c Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 23:11:42 +0000 Subject: [PATCH 02/13] Check the math extension in each test job Without gmp or bcmath, ReaderTest marks its uint128 value checks incomplete, and the run still passes. If gmp is loaded, the decoder uses it, so a bcmath job does not test bcmath. A new step checks that each job has the extension it names, and that bcmath jobs do not have gmp. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed2244e..fbb96c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,25 @@ jobs: extensions: "mbstring, intl, ${{ matrix.php-extension }}, ${{ matrix.disabled-extensions }}" tools: "composer, phpize" + # Without gmp or bcmath, ReaderTest marks its uint128 value checks + # incomplete, and the run still passes. If gmp is loaded, the decoder + # uses it, and a bcmath job does not test bcmath. + - name: Check the math extension + env: + MATH_EXTENSION: ${{ matrix.php-extension }} + run: | + php -r ' + $ext = getenv("MATH_EXTENSION"); + if (!extension_loaded($ext)) { + echo "::error::$ext is not loaded\n"; + exit(1); + } + if ($ext === "bcmath" && extension_loaded("gmp")) { + echo "::error::gmp is loaded, so the decoder does not use bcmath\n"; + exit(1); + } + ' + - name: Checkout # We use v1 due to https://github.com/actions/checkout/issues/334 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 From e5a50128e738e2e510831560ae2f988452e6a186 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 22:38:35 +0000 Subject: [PATCH 03/13] Run tests on macOS and Windows The test job now also runs PHP 8.1 and 8.5 with gmp on macos-latest and windows-latest. Both run PHPUnit with the pure-PHP reader. On macOS, the job also builds the extension against Homebrew's libmaxminddb, runs the phpt suite, and runs PHPUnit with the extension. Windows can only build the bundled extension, so test-bundled.yml tests it there. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbb96c1..fabc248 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,8 +21,16 @@ jobs: # when it is loaded. Disable gmp so that the bcmath path runs. - php-extension: bcmath disabled-extensions: ':gmp' + # Two PHP versions on each OS are enough to find platform problems. + - { os: macos-latest, php-version: '8.1', php-extension: gmp } + - { os: macos-latest, php-version: '8.5', php-extension: gmp } + - { os: windows-latest, php-version: '8.1', php-extension: gmp } + - { os: windows-latest, php-version: '8.5', php-extension: gmp } name: "PHP ${{ matrix.php-version }} (with ${{ matrix.php-extension }}) test on ${{ matrix.os }}" + defaults: + run: + shell: bash steps: - name: Install PHP uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 @@ -57,7 +65,8 @@ jobs: submodules: true persist-credentials: false - - name: Install libmaxminddb + - name: Install libmaxminddb from git + if: runner.os == 'Linux' run: | mkdir -p "$HOME/libmaxminddb" git clone --recursive https://github.com/maxmind/libmaxminddb.git @@ -66,11 +75,19 @@ jobs: ./configure --prefix="$HOME/libmaxminddb" make make install + echo "CFLAGS=-L$HOME/libmaxminddb/lib" >> "$GITHUB_ENV" + echo "CPPFLAGS=-I$HOME/libmaxminddb/include" >> "$GITHUB_ENV" + # configure finds the Homebrew libmaxminddb through pkg-config. + - name: Install libmaxminddb from Homebrew + if: runner.os == 'macOS' + run: brew install libmaxminddb pkgconf + + # Windows can only build the bundled extension. test-bundled.yml tests + # that DLL. - name: Build extension + if: runner.os != 'Windows' run: | - export CFLAGS="-L$HOME/libmaxminddb/lib" - export CPPFLAGS="-I$HOME/libmaxminddb/include" cd ext phpize ./configure --with-maxminddb --enable-maxminddb-debug @@ -83,7 +100,8 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Test with phpunit without extension - run: vendor/bin/phpunit + run: php vendor/bin/phpunit - name: Test with phpunit using extension + if: runner.os != 'Windows' run: php -d extension=ext/modules/maxminddb.so vendor/bin/phpunit From 2eef8866bd189ba41b0957069238bffa0ce37bb1 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 22:51:11 +0000 Subject: [PATCH 04/13] Compare extension integers to the PHP integer limit handle_uint32() and handle_uint64() compared values to the C LONG_MAX to decide if a value fits in a PHP integer. On 64-bit Windows, a C long is 32 bits but zend_long is 64 bits. The extension therefore returned uint32 and uint64 values above 2^31 - 1 as strings. ZEND_LONG_MAX is the PHP integer limit on every platform. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ ext/maxminddb.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e47a6c..38aa3c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ CHANGELOG cannot throw. * `MaxMind\Db\Reader\Decoder::decode()` and `MaxMind\Db\Reader\Util::read()` declare their exceptions. +* On 64-bit Windows, the extension returned `uint32` and `uint64` values + from 2^31 to `PHP_INT_MAX` as strings. It now returns them as integers. 1.14.0 (2026-09-10) ------------------- diff --git a/ext/maxminddb.c b/ext/maxminddb.c index 5c5d35b..0488bd0 100644 --- a/ext/maxminddb.c +++ b/ext/maxminddb.c @@ -528,11 +528,11 @@ static void handle_uint32(const MMDB_entry_data_list_s *entry_data_list, zval *z_value TSRMLS_DC) { uint32_t val = entry_data_list->entry_data.uint32; -#if LONG_MAX >= UINT32_MAX +#if ZEND_LONG_MAX >= UINT32_MAX ZVAL_LONG(z_value, val); return; #else - if (val <= LONG_MAX) { + if (val <= ZEND_LONG_MAX) { ZVAL_LONG(z_value, val); return; } @@ -550,11 +550,11 @@ static void handle_uint64(const MMDB_entry_data_list_s *entry_data_list, zval *z_value TSRMLS_DC) { uint64_t val = entry_data_list->entry_data.uint64; -#if LONG_MAX >= UINT64_MAX +#if ZEND_LONG_MAX >= UINT64_MAX ZVAL_LONG(z_value, val); return; #else - if (val <= LONG_MAX) { + if (val <= ZEND_LONG_MAX) { ZVAL_LONG(z_value, val); return; } From 0cbbd237cb12426e8d911b05cba470d64419f63f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 23:12:21 +0000 Subject: [PATCH 05/13] Build the Windows DLL from the commit the job checks out For a pull request, the checkout uses the merge commit, but the action built the DLL from the head commit. The job then checked a head-built DLL with the merge commit's files, and a change to ext/ on main was not in the DLL. github.sha is the commit the checkout uses for every event. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index e23bd30..0587b9a 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -233,11 +233,15 @@ jobs: # One job is enough. config.w32 does not vary by PHP version, arch or # thread safety in any way this exercises, and PHP <= 7.4 needs a # toolchain windows-latest no longer carries. + # + # github.sha is the commit the checkout above uses. For a pull request, + # that is the merge commit, which the action can fetch through + # refs/pull//merge. - name: Build the extension uses: php/php-windows-builder/extension@29352c0ef9e8ce65264ea9e287881a6f7758a953 # 1.9.0 with: extension-url: https://github.com/${{ github.repository }} - extension-ref: ${{ github.event.pull_request.head.sha || github.sha }} + extension-ref: ${{ github.sha }} build-directory: winbuild php-version: '8.4' arch: x64 From e957c5c1aa7306dbf58d2887896c52d5bb7c4e2c Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 4 Nov 2026 22:39:19 +0000 Subject: [PATCH 06/13] Run PHPUnit against the Windows bundled DLL The phpt files decode nothing, so until now no job ran the decoding tests against the Windows DLL. The windows-bundled job now runs PHPUnit with the DLL, gmp and mbstring loaded into the php.exe the build downloaded. Composer runs with the runner's PHP 8.4. The job checks that the DLL and gmp are loaded before it runs PHPUnit. A failed extension= load is only a warning, so PHPUnit could otherwise pass with the pure-PHP reader. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index 0587b9a..142631c 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -256,7 +256,8 @@ jobs: # # Uses the php.exe the build downloaded, not the runner's: version, arch, # thread safety and toolset all have to match. Neither is on PATH in a - # later step, so both are located by search. + # later step, so both are located by search and saved for the PHPUnit + # step. - name: Gate the built DLL shell: pwsh run: | @@ -265,6 +266,8 @@ jobs: Where-Object { $_.Directory.Name -eq 'php-bin' }) if ($dll.Count -ne 1) { throw "expected one php_maxminddb.dll, found $($dll.Count)" } if ($php.Count -ne 1) { throw "expected one php-bin\php.exe, found $($php.Count)" } + "BUILD_PHP=$($php[0].FullName)" >> $env:GITHUB_ENV + "BUILD_DLL=$($dll[0].FullName)" >> $env:GITHUB_ENV $ac = Get-Content ext/libmaxminddb/configure.ac -Raw if ($ac -notmatch 'AC_INIT\(\[libmaxminddb\], \[([^\]]+)\]') { @@ -279,3 +282,38 @@ jobs: dev-bin/verify-extension.php ` tests/data/test-data/GeoIP2-City-Test.mmdb $version if ($LASTEXITCODE -ne 0) { throw "the DLL did not load and query cleanly" } + + # The phpt files decode nothing, so this is the only run of the decoding + # tests against the DLL. See the bundled job above for why it matters. + # The runner's PHP only runs Composer. The tests use the downloaded + # php.exe, for the reason the gate step gives. + - name: Install PHP for Composer + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.4' + tools: composer + env: + fail-fast: true + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + # -n ignores the php.ini the build wrote, so extension_dir is set here. + # A failed extension= load is only a warning. Without the check, PHPUnit + # could pass with the pure-PHP reader, or with the uint128 value checks + # marked incomplete. + - name: Test with phpunit using the DLL + shell: pwsh + run: | + $extDir = Join-Path (Split-Path $env:BUILD_PHP) ext + $phpArgs = @( + '-n', + '-d', "extension_dir=$extDir", + '-d', 'extension=gmp', + '-d', 'extension=mbstring', + '-d', "extension=$env:BUILD_DLL" + ) + & $env:BUILD_PHP @phpArgs -r "exit(extension_loaded('maxminddb') && extension_loaded('gmp') ? 0 : 1);" + if ($LASTEXITCODE -ne 0) { throw "the DLL or gmp did not load" } + & $env:BUILD_PHP @phpArgs vendor/bin/phpunit + if ($LASTEXITCODE -ne 0) { throw "PHPUnit failed" } From 56063c760cb89779cade7bb00612b87c7ca94d92 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:56:46 +0000 Subject: [PATCH 07/13] Check the uint128 values without gmp ReaderTest used gmp to turn the uint128 value into a decimal string, and marked the check incomplete without gmp. So the bcmath jobs never checked the uint128 values. The tests now compare the extension's hexadecimal string or the pure-PHP decimal value directly, as testGetWithPrefixLen already does. Co-Authored-By: Claude Opus 5.5 --- tests/MaxMind/Db/Test/ReaderTest.php | 36 +++++++++------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/tests/MaxMind/Db/Test/ReaderTest.php b/tests/MaxMind/Db/Test/ReaderTest.php index 1430d51..665a7ed 100644 --- a/tests/MaxMind/Db/Test/ReaderTest.php +++ b/tests/MaxMind/Db/Test/ReaderTest.php @@ -65,18 +65,10 @@ public function testDecoder(): void $this->assertSame(268435456, $record['uint32']); $this->assertSame(\PHP_INT_MAX > 1152921504606846976 ? 1152921504606846976 : '1152921504606846976', $record['uint64']); - $uint128 = $record['uint128']; - - // For the C extension, which returns a hexadecimal - if (\extension_loaded('gmp')) { - $uint128 = gmp_strval($uint128); - } else { - $this->markTestIncomplete('Requires gmp extension to check value of uint128'); - } - + // The C extension returns uint128 values as hexadecimal strings. $this->assertSame( - '1329227995784915872903807060280344576', - $uint128 + \extension_loaded('maxminddb') ? '0x01000000000000000000000000000000' : '1329227995784915872903807060280344576', + $record['uint128'] ); } @@ -99,13 +91,10 @@ public function testZeros(): void $this->assertSame(0, $record['uint32']); $this->assertSame('0', $record['uint64'] . ''); - $uint128 = $record['uint128']; - if (\extension_loaded('gmp')) { - $uint128 = gmp_strval($uint128); - } else { - $this->markTestIncomplete('Requires gmp extension to check value of uint128'); - } - $this->assertSame('0', $uint128); + $this->assertSame( + \extension_loaded('maxminddb') ? '0x00000000000000000000000000000000' : 0, + $record['uint128'] + ); } public function testMax(): void @@ -120,13 +109,10 @@ public function testMax(): void $this->assertSame(\PHP_INT_MAX < 0xFFFFFFFF ? '4294967295' : 0xFFFFFFFF, $record['uint32']); $this->assertSame('18446744073709551615', $record['uint64'] . ''); - $uint128 = $record['uint128']; - if (\extension_loaded('gmp')) { - $uint128 = gmp_strval($uint128); - } else { - $this->markTestIncomplete('Requires gmp extension to check value of uint128'); - } - $this->assertSame('340282366920938463463374607431768211455', $uint128); + $this->assertSame( + \extension_loaded('maxminddb') ? '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' : '340282366920938463463374607431768211455', + $record['uint128'] + ); } public function testInvalidMetadataType(): void From 95a3b636b1c96136f81ebce167b396e2304bca42 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:57:05 +0000 Subject: [PATCH 08/13] Stop loading gmp for the extension test runs ReaderTest no longer needs gmp to check uint128 values, and the extension does not use gmp. The bundled jobs no longer install or load gmp, or check that it is loaded. This also removes a comment that cited ReaderTest.php:162, a line that no longer holds the uint128 case. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index 142631c..18ed188 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -47,10 +47,7 @@ jobs: uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 with: php-version: ${{ matrix.php-version }} - # gmp so ReaderTest's uint128 boundary cases run rather than skip; - # they are gated on it, and uint128 is the branch this job is the - # only one to compile. - extensions: "mbstring, intl, gmp" + extensions: "mbstring, intl" tools: "composer, phpize" - name: Checkout @@ -138,29 +135,17 @@ jobs: - name: Install dependencies run: composer install --no-progress --prefer-dist --optimize-autoloader - # Both preconditions are load-bearing, and neither failure is loud on its - # own. - # # A failed `extension=` load is a warning, not a fatal, and PHP carries # on. phpunit.xml.dist bootstraps vendor/autoload.php, whose PSR-4 map # resolves MaxMind\Db\Reader to the pure-PHP implementation, and the # suite is written to pass either way -- so an extension that does not # load leaves every assertion above testing src/ rather than the object # this job built. - # - # gmp is what turns ReaderTest's decimal uint128 case from - # markTestIncomplete into a real assertion, and markTestIncomplete does - # not fail a run. (The hex form at ReaderTest.php:162 is gated on - # extension_loaded('maxminddb'), not on gmp, so only half the uint128 - # coverage depends on this -- but it is the half that checks the value - # rather than the format.) - - name: Check the extension and gmp are actually loaded + - name: Check the extension is actually loaded run: | php -d extension="$PWD/ext/modules/maxminddb.so" -r \ 'exit(extension_loaded("maxminddb") ? 0 : 1);' || { echo "::error::the bundled extension did not load; PHPUnit would silently test the pure-PHP reader"; exit 1; } - php -r 'exit(extension_loaded("gmp") ? 0 : 1);' || - { echo "::error::gmp is not loaded; ReaderTest's uint128 value assertions would be skipped, not run"; exit 1; } - name: Test with phpunit using the bundled extension run: php -d extension="$PWD/ext/modules/maxminddb.so" vendor/bin/phpunit @@ -300,8 +285,7 @@ jobs: # -n ignores the php.ini the build wrote, so extension_dir is set here. # A failed extension= load is only a warning. Without the check, PHPUnit - # could pass with the pure-PHP reader, or with the uint128 value checks - # marked incomplete. + # could pass with the pure-PHP reader. - name: Test with phpunit using the DLL shell: pwsh run: | @@ -309,11 +293,10 @@ jobs: $phpArgs = @( '-n', '-d', "extension_dir=$extDir", - '-d', 'extension=gmp', '-d', 'extension=mbstring', '-d', "extension=$env:BUILD_DLL" ) - & $env:BUILD_PHP @phpArgs -r "exit(extension_loaded('maxminddb') && extension_loaded('gmp') ? 0 : 1);" - if ($LASTEXITCODE -ne 0) { throw "the DLL or gmp did not load" } + & $env:BUILD_PHP @phpArgs -r "exit(extension_loaded('maxminddb') ? 0 : 1);" + if ($LASTEXITCODE -ne 0) { throw "the DLL did not load" } & $env:BUILD_PHP @phpArgs vendor/bin/phpunit if ($LASTEXITCODE -ne 0) { throw "PHPUnit failed" } From 6f3f5d32a9d5c5c0d3da18e71039d2b06113eeba Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:57:34 +0000 Subject: [PATCH 09/13] Share the extension checks in a dev-bin script The check that an extension is loaded had a copy in test.yml and two in test-bundled.yml, each with its own error text. dev-bin/ check-extensions.php replaces them. A name that starts with ":" must not be loaded, which is the syntax setup-php uses, so the bcmath jobs pass their disabled-extensions value through. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 7 ++---- .github/workflows/test.yml | 27 +++++++----------------- dev-bin/check-extensions.php | 34 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 dev-bin/check-extensions.php diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index 18ed188..cea1cc4 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -142,10 +142,7 @@ jobs: # load leaves every assertion above testing src/ rather than the object # this job built. - name: Check the extension is actually loaded - run: | - php -d extension="$PWD/ext/modules/maxminddb.so" -r \ - 'exit(extension_loaded("maxminddb") ? 0 : 1);' || - { echo "::error::the bundled extension did not load; PHPUnit would silently test the pure-PHP reader"; exit 1; } + run: php -d extension="$PWD/ext/modules/maxminddb.so" dev-bin/check-extensions.php maxminddb - name: Test with phpunit using the bundled extension run: php -d extension="$PWD/ext/modules/maxminddb.so" vendor/bin/phpunit @@ -296,7 +293,7 @@ jobs: '-d', 'extension=mbstring', '-d', "extension=$env:BUILD_DLL" ) - & $env:BUILD_PHP @phpArgs -r "exit(extension_loaded('maxminddb') ? 0 : 1);" + & $env:BUILD_PHP @phpArgs dev-bin/check-extensions.php maxminddb if ($LASTEXITCODE -ne 0) { throw "the DLL did not load" } & $env:BUILD_PHP @phpArgs vendor/bin/phpunit if ($LASTEXITCODE -ne 0) { throw "PHPUnit failed" } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fabc248..24b4cbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,25 +39,6 @@ jobs: extensions: "mbstring, intl, ${{ matrix.php-extension }}, ${{ matrix.disabled-extensions }}" tools: "composer, phpize" - # Without gmp or bcmath, ReaderTest marks its uint128 value checks - # incomplete, and the run still passes. If gmp is loaded, the decoder - # uses it, and a bcmath job does not test bcmath. - - name: Check the math extension - env: - MATH_EXTENSION: ${{ matrix.php-extension }} - run: | - php -r ' - $ext = getenv("MATH_EXTENSION"); - if (!extension_loaded($ext)) { - echo "::error::$ext is not loaded\n"; - exit(1); - } - if ($ext === "bcmath" && extension_loaded("gmp")) { - echo "::error::gmp is loaded, so the decoder does not use bcmath\n"; - exit(1); - } - ' - - name: Checkout # We use v1 due to https://github.com/actions/checkout/issues/334 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -65,6 +46,14 @@ jobs: submodules: true persist-credentials: false + # The decoder uses gmp if it is loaded, and bcmath otherwise. Check that + # each job uses the extension it names. + - name: Check the math extension + env: + MATH_EXTENSION: ${{ matrix.php-extension }} + DISABLED_EXTENSIONS: ${{ matrix.disabled-extensions }} + run: php dev-bin/check-extensions.php "$MATH_EXTENSION" $DISABLED_EXTENSIONS + - name: Install libmaxminddb from git if: runner.os == 'Linux' run: | diff --git a/dev-bin/check-extensions.php b/dev-bin/check-extensions.php new file mode 100644 index 0000000..b6616cc --- /dev/null +++ b/dev-bin/check-extensions.php @@ -0,0 +1,34 @@ +... +// +// A name that starts with ":" must not be loaded. This is the syntax that +// setup-php uses to disable an extension. + +if ($argc < 2) { + fwrite(\STDERR, "usage: check-extensions.php ...\n"); + + exit(1); +} + +$failed = false; +foreach (array_slice($argv, 1) as $arg) { + if (substr($arg, 0, 1) === ':') { + $name = substr($arg, 1); + if (extension_loaded($name)) { + echo "::error::{$name} is loaded, but this job must not load it\n"; + $failed = true; + } + } elseif (!extension_loaded($arg)) { + echo "::error::{$arg} is not loaded\n"; + $failed = true; + } +} + +exit($failed ? 1 : 0); From 5015c8c48097e2d793505dca6959002380c1d1e6 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:57:40 +0000 Subject: [PATCH 10/13] Check that the extension loads before PHPUnit in test.yml A failed extension= load is only a warning, so PHPUnit can pass with the pure-PHP reader. run-ext-tests.sh does not cover this: make test uses the PHP from php-config, not the php on PATH. On macOS, the two can differ. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24b4cbf..1179b68 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -91,6 +91,10 @@ jobs: - name: Test with phpunit without extension run: php vendor/bin/phpunit + # make test runs the phpt suite with the PHP from php-config, so it does + # not show that the php on PATH can load the extension. - name: Test with phpunit using extension if: runner.os != 'Windows' - run: php -d extension=ext/modules/maxminddb.so vendor/bin/phpunit + run: | + php -d extension=ext/modules/maxminddb.so dev-bin/check-extensions.php maxminddb + php -d extension=ext/modules/maxminddb.so vendor/bin/phpunit From 3d26b5082679f55f250cd54e5009fb3bd7af2ac0 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:57:46 +0000 Subject: [PATCH 11/13] Remove the dead #if in handle_uint64 zend_long is signed, so ZEND_LONG_MAX is at most INT64_MAX, and "#if ZEND_LONG_MAX >= UINT64_MAX" is never true. Only the runtime check was ever compiled. Co-Authored-By: Claude Opus 5.5 --- ext/maxminddb.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ext/maxminddb.c b/ext/maxminddb.c index 0488bd0..cf4226e 100644 --- a/ext/maxminddb.c +++ b/ext/maxminddb.c @@ -550,10 +550,6 @@ static void handle_uint64(const MMDB_entry_data_list_s *entry_data_list, zval *z_value TSRMLS_DC) { uint64_t val = entry_data_list->entry_data.uint64; -#if ZEND_LONG_MAX >= UINT64_MAX - ZVAL_LONG(z_value, val); - return; -#else if (val <= ZEND_LONG_MAX) { ZVAL_LONG(z_value, val); return; @@ -565,7 +561,6 @@ static void handle_uint64(const MMDB_entry_data_list_s *entry_data_list, ZVAL_STRING(z_value, int_str); efree(int_str); -#endif } static void maxminddb_free_storage(free_obj_t *object TSRMLS_DC) { From 419c4e51870410cf1c9687747fcbaa0dde031504 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:57:53 +0000 Subject: [PATCH 12/13] Correct two workflow comments test.yml said that Windows can only build the bundled extension, but ext/config.w32 can also link a system libmaxminddb. The comment on the windows-bundled checkout did not list composer.json and the PHPUnit suite, which the job now also uses. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 6 +++--- .github/workflows/test.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index cea1cc4..9a40dc5 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -195,9 +195,9 @@ jobs: runs-on: windows-latest name: "Windows bundled build (x64, nts, PHP 8.4)" steps: - # The action clones and initialises its own copy to build from; this - # checkout supplies dev-bin/verify-extension.php and the tests/data - # database the gate below queries. + # The action clones and initialises its own copy to build from. This + # checkout supplies the dev-bin scripts, the tests/data databases, + # composer.json and the PHPUnit suite that the steps below use. - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1179b68..85489ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,8 +72,8 @@ jobs: if: runner.os == 'macOS' run: brew install libmaxminddb pkgconf - # Windows can only build the bundled extension. test-bundled.yml tests - # that DLL. + # This job does not build the extension on Windows. test-bundled.yml + # tests the bundled DLL. - name: Build extension if: runner.os != 'Windows' run: | From 4c7090dbd99e9501f30afc68f87ed16e756b5f3f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 5 Nov 2026 17:58:04 +0000 Subject: [PATCH 13/13] Install Composer before the Windows build The windows-bundled job installed PHP and ran Composer after the build, so a failed install lost the build. Both steps now run before the build. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test-bundled.yml | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-bundled.yml b/.github/workflows/test-bundled.yml index 9a40dc5..c313416 100644 --- a/.github/workflows/test-bundled.yml +++ b/.github/workflows/test-bundled.yml @@ -204,6 +204,22 @@ jobs: submodules: recursive persist-credentials: false + # The phpt files decode nothing, so the PHPUnit step below is the only + # run of the decoding tests against the DLL. See the bundled job above + # for why it matters. The runner's PHP only runs Composer. The tests use + # the downloaded php.exe, for the reason the gate step gives. These steps + # run before the build, so a failed install does not lose the build. + - name: Install PHP for Composer + uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 + with: + php-version: '8.4' + tools: composer + env: + fail-fast: true + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + # extension-url rather than the action's local mode, which cannot be used # here: local mode selects itself by finding a config.w32 anywhere in the # tree, but Get-ExtensionName then reads "config.w32" relative to the @@ -265,21 +281,6 @@ jobs: tests/data/test-data/GeoIP2-City-Test.mmdb $version if ($LASTEXITCODE -ne 0) { throw "the DLL did not load and query cleanly" } - # The phpt files decode nothing, so this is the only run of the decoding - # tests against the DLL. See the bundled job above for why it matters. - # The runner's PHP only runs Composer. The tests use the downloaded - # php.exe, for the reason the gate step gives. - - name: Install PHP for Composer - uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0 - with: - php-version: '8.4' - tools: composer - env: - fail-fast: true - - - name: Install dependencies - run: composer install --no-progress --prefer-dist --optimize-autoloader - # -n ignores the php.ini the build wrote, so extension_dir is set here. # A failed extension= load is only a warning. Without the check, PHPUnit # could pass with the pure-PHP reader.