Conversation
This commit is a compilation of many old patches of mine.
It removes obsolete code and enforces C99 as a build
requirement.
Changes:
- Remove many unused tests and useless feature tests.
(This was a bit more involved for <sys/types.h>, which
had annoying special casing.) This included the
'check for global headers' in the iffe script.
- Assume fchmod is present and use it instead of chmod in
shcomp for slightly better performance.
- dotpaths_lib(): Use fstat rather than stat for the PWD
for better performance.
- Scrap pre-C99 fallbacks for iswblank(3).
- Replaced usage of the obsolescent timeofday() macro with the
more portable tvgettime() function in libast, which itself uses
the modern clock_gettime internally.
- Replaced usage of strcopy with either strcpy or stpcpy in
cases where no buffer overlap occurs. There are perhaps
more places where replacement is possible (ksh93v- and ksh2020
do this far more liberally), but I'm trying to be conservative
with these changes to avoid accidentally introducing bugs.
- Replaced an instance of strncopy with strlcpy in keytrap()
because the buffers don't overlap.
- Also replaced some instances of strncpy with strlcpy
(vide ksh2020 commit f63ebd0 and associated issue).
- Add pertinent documentation as it relates to str*copy's
usage with overlapping buffers.
- Backported a modified version of ksh93v-'s stpcpy fallback.
- Introduced usage of C99 restrict, primarily for standards
compliance in compatibility functions (though some regular
functions like sfopen() do also use restrict now).
- Assume C99 __func__ is available and drop now unneeded
C90 feature tests.
- Added a few casts to fix some compiler warnings.
- Remove basic iffe probes for various C99 multibyte functions
(excluding those that still need tests due to platform-specific
bugs). Also removed other unnecessary probes for C99 and POSIX
functionality.
- Remove unnecessary mktime.c, wc.c and wordexp.c compat files
(the operating system should provide these functions).
- Switched to using C99-style struct init throughout the codebase.
- Removed usage of bzero, bcopy and memzero in favor of standard
memset.
I have additional changes for using C99-style for loops and bools,
but those have been excluded because this patch is big enough as it is.
This merely moves some logic out of sh_init(), though there is one minor change in behavior: - Initialize sh.pwdfd to -1 because it shouldn't default to stdin.
GCC and Clang may not necessarily use the latest C standard available, so enable e.g. C23 with the help of make.probe. If the user wants to use something else, it can be overridden with CCFLAGS.
This was probably inadvertently brought over from other unrelated branches (i.e. thickfold and co.).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit is a compilation of many old patches of mine. It removes obsolete code and enforces C99 as a build requirement.
Changes:
<sys/types.h>, which had annoying special casing.) This included the "check for global headers" in the iffe script.fchmodis present and use it instead ofchmodin shcomp for very slightly better performance.dotpaths_lib(): Usefstatrather than stat for the PWD for better performance.iswblank(3).timeofday()macro with the more portabletvgettime()function in libast, which itself uses the modernclock_gettimeinternally when it's available.strcopywith eitherstrcpyorstpcpyin cases where no buffer overlap occurs. There are perhaps more places where replacement is possible (ksh93v- and ksh2020 do this far more liberally), but I'm trying to be conservative with these changes to avoid accidentally introducing bugs.strncopywithstrlcpyinkeytrap()because the buffers don't overlap.strncpywithstrlcpy(vide ksh2020 commit f63ebd0 and associated issue Replace uses ofstrncpy()withstrlcpy()att/ast#266).str*copy's usage with overlapping buffers.stpcpyfallback.restrict, primarily for standards compliance in compatibility functions (though some regular functions likesfopen()will also use restrict now).__func__is available and drop now unnecessary C90 feature tests.iffeprobes for various C99 multibyte functions (excluding those that still need tests due to platform-specific bugs). Also removed other unnecessary probes for C99 and POSIX functionality.bzero,bcopy,memclearandmemzeroin favor of standardmemsetandmemcpy.getaddrinfoin io.c because that violates the POSIX standard.I have additional changes for using C99-style for loops and bools, but those have been excluded because this patch is big enough as it is. I also encountered crashing bugs when I attempted to remove widespread usage of the struct hack, so the struct hack was only removed if it was already disabled by a preexisting
__STDC_VERSION__check.Progresses #777 (this commit doesn't include or fix the removed
_c99_in_the_wildcode).