Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash 2.05a compatibility #70

Merged
merged 10 commits into from
Aug 30, 2024
Merged

Conversation

laurenthuberdeau
Copy link
Collaborator

@laurenthuberdeau laurenthuberdeau commented Aug 29, 2024

Context

In #69, it looked like compatibility with bash version 1.14 was easily attainable. Unfortunately, the workaround to emit characters using %b doesn't work for \0 meaning more work is required to bootstrap pnut-exe using pnut.sh on bash 1.14.

This PR makes pnut compatible with bash version 2.05a, and adds the necessary CI checks to ensure we don't break compatibility by accident. The main problem was with unset which fails when unsetting a variable that was not set. This bug was fixed in version 2.05b, explaining why version 2.05a was failing but not 2.05b. Fortunately, unset is only used in the free function which is not important to Pnut and is only called in 1 place and the existing RT_FREE_UNSETS_VARS macro controls the behavior of free (unset vs no-op).

The earliest bash version with which Pnut can bootstrap itself is 2.05b.
Version 2.05a fails when pnut gets to the end of an #included file
because free is called and the `unset` builtin fails (and then pnut
because of set -e). We already have an option that toggle free between a
no-op and using unset, so let's disable it since it doesn't make much of
a difference for pnut.

From bash's `CHANGES` file:

  h.  The `unset' builtin no longer returns a failure status when asked to
      unset a previously-unset variable or function.
@laurenthuberdeau laurenthuberdeau changed the title Bash 2 compatibility Bash 2.05a compatibility Aug 29, 2024
@laurenthuberdeau laurenthuberdeau force-pushed the laurent/bash-2-compatibility branch 8 times, most recently from 5df6b4e to 982bcce Compare August 30, 2024 17:38
brew install coreutils
else
sudo apt-get update
sudo apt-get install -y coreutils
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The timeout utility lives in coreutils. It's usually preinstalled but let's just make sure it is.

@@ -4,8 +4,10 @@ set -e -u

TEMP_DIR="bootstrap-results"

PNUT_EXE_OPTIONS= # Set by the backend option
PNUT_SH_OPTIONS="-DRT_NO_INIT_GLOBALS -Dsh"
: ${PNUT_OPTIONS:=} # Default to empty options
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The bootstrap-pnut*.sh and run-tests.sh scripts now passes the PNUT_OPTIONS environment to pnut. This allows us to enable certain options (by defining macros) from outside the script.

@@ -46,7 +46,7 @@ unpack_escaped_string() {
__buf="${__buf#?}" # Remove the current char from $__buf
;;
*)
__c=$(LC_CTYPE=C printf "%d" "'${__buf%"${__buf#?}"}")
__c=$(LC_CTYPE=C printf "%d" "'${__buf%"${__buf#?}"}"); __c=$((__c > 0 ? __c : 256 + __c))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bash-2.05a uses signed char so everything in the extended range gets encoded as a negative number. We could remove this line if we choose to not support early versions of bash, but it worth the extract few characters so we can say we support a version of bash from 2001.

if [ "$backend" = "sh" ]; then
bash "./$1" $2 # Default to bash for sh backend
# Use a 30s timeout to prevent infinite loops
timeout ${2:-30} $shell "./$1" $3
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This script used to ignore the --shell option and would always use bash. I fixed the issue, but this meant I had to disable a failing few tests for yash.

@laurenthuberdeau laurenthuberdeau merged commit 0348374 into main Aug 30, 2024
53 checks passed
@laurenthuberdeau laurenthuberdeau deleted the laurent/bash-2-compatibility branch August 30, 2024 19:09
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