Skip to content

util.c: mark internal symbols 'static' - #24137

Merged
mauke merged 3 commits into
Perl:bleadfrom
mauke:util-static-internal-functions
Jan 31, 2026
Merged

util.c: mark internal symbols 'static'#24137
mauke merged 3 commits into
Perl:bleadfrom
mauke:util-static-internal-functions

Conversation

@mauke

@mauke mauke commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

As a general rule, our symbols are either public API (with a Perl_ prefix) or internal (often with an S_ prefix) and declared as static. A few symbols in util.c have been overlooked: They are clearly intended to be internal (no prefix, only used within this file), but not declared static, so they were visible to the linker. These patches add the missing static keyword to those symbols.


  • This set of changes does not require a perldelta entry.

mauke added 3 commits January 30, 2026 00:16
It was already declared 'static' in proto.h/embed.fnc, but for
consistency, make the definition in util.c 'static' as well.
This is purely an internal helper function.
These are internal variables not intended to be part of our API, so make
them static.
Comment thread util.c
* Examples: https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64
*/
U64
static U64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR #24105 uses it, so it may need to be public.

Though I think it should be flagged "C" rather than "A".

That PR puts everything in a header and has similar visibility problems to this function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Technically not a problem because the proposed prng.h file (which is not really a header) is only getting included in util.c anyway, so it is still the same translation unit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not uppercase STATIC?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why randomly capitalize language keywords?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency. Maybe it's no longer a concern, in which case should we change all STATICs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't know why STATIC exists. It is hardcoded in perl.h as #define STATIC static. We already have many uses of plain static in core (a naive rg '^\s*static\b' *.c *.h | wc -l reports 615 matches), so there is no consistency to be had anyway.

...digging...

The first occurrence of STATIC I can find is in perl-2.0's regexp.c (where it already expands to plain static). In perl-3.000 its definition was copied into both regcomp.c and regexec.c, and the former moved to regcomp_internal.h in 85900e2. These definitions still exist.

All non-regex uses of STATIC began in commit 76e3520, which changed some (but not all) occurrences of static to STATIC and added a conditional definition to perl.h: If PERL_OBJECT is defined, STATIC expands to nothing instead. PERL_OBJECT (a feature to let you define an interpreter as a C++ class CPerlObj, not a C struct or a collection of global variables) was removed in acfe0ab (5.7.x), but for some reason the STATIC declarations were not changed back to static. Since then, STATIC has always been hardcoded as static.

So to answer your questions:

  • Under PERL_OBJECT, making splitmix64 STATIC would not have made sense: It does not need access to any member functions or variables of CPerlObj.
  • Yes, all uses of STATIC in the core should have been ripped out in 5.8.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See also PR #24141.

@mauke
mauke merged commit 53f78c4 into Perl:blead Jan 31, 2026
34 checks passed
@mauke
mauke deleted the util-static-internal-functions branch January 31, 2026 09:04
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.

3 participants