Skip to content

Convert JS magic numbers to struct_info symbols (Part 9/9): libopenal. NFC - #28267

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:magic_numbers_9_libopenal
Open

sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:magic_numbers_9_libopenal

Conversation

@sbc100

@sbc100 sbc100 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Replace hardcoded magic numbers in the OpenAL library with symbolic constants exposed via struct_info, adding 82 defines and rebaselining the affected dylink codesize expectation (+2 bytes from FLT_MAX formatting).

This is part 9 of a 9-part series replacing hardcoded numeric constants across JS libraries and runtime code. Across the full series, 938 new defines are added to struct_info (534 -> 1,472), adding ~22 ms (~2.7%) to an uncached hello-world link (0 ms on cached builds).

Split out from #28199

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces numerous hardcoded magic numbers and hex values with symbolic AL and ALC constants throughout src/lib/libopenal.js to improve code readability and maintainability. To support this, the corresponding definitions were added to src/struct_info.json, and the generated metadata files were updated. Feedback on the changes suggests referencing ALC_NO_ERROR directly as a global constant instead of cDefs.ALC_NO_ERROR for consistency with other constants in the file.

Comment thread src/lib/libopenal.js
// ------------------------------------------------------

_alcErr: 0,
_alcErr: cDefs.ALC_NO_ERROR,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other AL_ and ALC_ constants in this file (such as AL_NO_ERROR on line 2205), ALC_NO_ERROR should be referenced directly as a global constant rather than via cDefs.ALC_NO_ERROR. Since ALC_NO_ERROR is exposed as a global variable by the Emscripten compiler, the cDefs. prefix is redundant.

    _alcErr: ALC_NO_ERROR,

…. NFC

Replace hardcoded magic numbers in the OpenAL library with symbolic
constants exposed via `struct_info`, adding 82 defines and rebaselining
the affected dylink codesize expectation (+2 bytes from `FLT_MAX`
formatting).

This is part 9 of a 9-part series replacing hardcoded numeric constants
across JS libraries and runtime code. Across the full series, 938 new
defines are added to `struct_info` (534 -> 1,472), adding ~22 ms (~2.7%)
to an uncached hello-world link (0 ms on cached builds).

Split out from emscripten-core#28199
@sbc100
sbc100 force-pushed the magic_numbers_9_libopenal branch from 6ff1e5b to 3457d52 Compare November 14, 2026 07:03

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant