Skip to content

zlib: use macro list for brotli error constants - #66932

Open
Suryanshpandey07 wants to merge 1 commit into
nodejs:mainfrom
Suryanshpandey07:fix-shared-brotli
Open

Suryanshpandey07 wants to merge 1 commit into
nodejs:mainfrom
Suryanshpandey07:fix-shared-brotli

Conversation

@Suryanshpandey07

Copy link
Copy Markdown

Expose Brotli decoder error constants using BROTLI_DECODER_ERROR_CODES_LIST instead of manually listing each constant. This avoids compilation errors when building against older shared Brotli libraries (such as Brotli <= 1.2.0) where BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH is not yet defined.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies. labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Expose Brotli decoder error constants using
BROTLI_DECODER_ERROR_CODES_LIST instead of manually listing each
constant. This avoids compilation errors when building against older
shared Brotli libraries (such as Brotli <= 1.2.0) where
BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH is not yet defined.

Signed-off-by: Suryanshpandey07 <diyanshpandey1234@gmail.com>
@Suryanshpandey07 Suryanshpandey07 changed the title zlib: define brotli error constants using macro list zlib: use macro list for brotli error constants Oct 22, 2026
@Suryanshpandey07

Copy link
Copy Markdown
Author

Context

When building Node.js configured with --shared-brotli against shared Brotli libraries (such as Brotli <= 1.2.0 found in many distributions), the build fails with:

../../src/node_zlib.cc:2271:32: error: use of undeclared identifier 'BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH'
 2271 |   NODE_DEFINE_CONSTANT(target, BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Solution

Brotli's public header <brotli/decode.h> defines BROTLI_DECODER_ERROR_CODES_LIST as an X-macro intended for iterating over all decoder error codes defined by that header version.

By switching to this macro list:

  • The error constants present in whichever Brotli version is included (bundled or shared) are automatically exposed.
  • Building against Brotli <= 1.2.0 succeeds without undeclared identifier errors.
  • Any future error codes added upstream in Brotli will be exposed automatically.
  • The block switch test in test/parallel/test-zlib-invalid-input.js is guarded with a check on zlib.constants.BROTLI_DECODER_ERROR_FORMAT_BLOCK_SWITCH !== undefined so test suites run cleanly across shared library versions.

@MikeMcC399

Copy link
Copy Markdown
Contributor

There are conflicts in this PR. If you would like to keep this PR active, please rebase the branch in this PR according to the Pull requests documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. zlib Issues and PRs related to the zlib module and its compression dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants