Skip to content

Conversation

@khwilliamson
Copy link
Contributor

Some header files in the Perl core have guards to keep a recursive #include from compiling them again. This is standard practice in C coding, and I was surprised at how many headers don't have it. These seem to rely on only being included from perl.h, which does have its own guard.

Most of the guards use a common naming convention. If the file is named foo.h, the guard is named 'PERL_FOO_H'. Often, though, a trailing underscore is added, 'PERL_FOO_H_', making the convention slightly fuzzy. The 'PERL_' is not added if the file 'foo' already includes 'perl' in its name,

Those rules are enough to describe all the guards in the core, except for the outliers in this commit, plus perl.h.

There are occasions in various Perl scripts that examine our source that we want to create a pattern that matches the header guard name for a particular file. In spite of the slight fuzziness, that's easy using the above rules, except for the ones in this commit, and perl.h. It would be better for that code to not have to worry about the outliers, and since these are arbitrary names, we can just change them to follow the rules that already apply to most.

This commit changes the names of the outliers so that the only file the rules don't apply to is perl.h. Its guard is named H_PERL. That spelling is used in Encode, so it's not so easy to change it seamlessly. I'm willing to live with it continuing to be an outlier for the code I write.

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

Some header files in the Perl core have guards to keep a
recursive #include from compiling them again.  This is standard practice
in C coding, and I was surprised at how many headers don't have
it.  These seem to rely on only being included from perl.h, which does
have its own guard.

Most of the guards use a common naming convention.  If the file is named
foo.h, the guard is named 'PERL_FOO_H'.  Often, though, a trailing
underscore is added,  'PERL_FOO_H_', making the convention slightly
fuzzy.  The 'PERL_' is not added if the file 'foo' already includes
'perl' in its name,

Those rules are enough to describe all the guards in the core, except
for the outliers in this commit, plus perl.h.

There are occasions in various Perl scripts that examine our source that
we want to create a pattern that matches the header guard name for a
particular file.  In spite of the slight fuzziness, that's easy using
the above rules, except for the ones in this commit, and perl.h.
It would be better for that code to not have to worry about the
outliers, and since these are arbitrary names, we can just change them
to follow the rules that already apply to most.

This commit changes the names of the outliers so that the only file the
rules don't apply to is perl.h.  Its guard is named H_PERL.  That
spelling is used in Encode, so it's not so easy to change it seamlessly.
I'm willing to live with it continuing to be an outlier for the code I
write.
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