Skip to content

Conversation

kalpitha-ibm
Copy link

@kalpitha-ibm kalpitha-ibm commented Jul 7, 2025

Adding fix on behalf on IBM AIX
This is related assignment of compound_variables.

Below is the example test case to assign compond_variable
using set-x to display the values.

set -x

complex=( real=1 img=2 )

  • complex.real=1
  • complex.img=2

complex=( real1=3 img1=4 )

  • complex.real1=3
  • complex.img1=4

RC=$?

  • RC=0

real=echo "${complex.real}"

  • echo ''
  • real='' >> here the variable should be 1

img=echo "${complex.img}"

  • echo ''
  • img='' >> here the variable should be 2

real1=echo "${complex.real1}"

  • echo 3
  • real1=3

img1=echo "${complex.img1}"

  • echo 4
  • img1=4

The goal of the test was to ensure all parts of the complex compound variable were preserved after setting additional fields. The fix ensures that the variable isn't overwritten and that all expected values (1, 2, 3, 4) are correctly retained and verified.

 compond_variable is not assigned properly
@JohnoKing
Copy link

I was able to reproduce the bug on all current ksh93 releases. It appears to be a regression introduced in ksh93u- 2010-08-11. This PR has some problems though:

- The PR doesn't compile because of 93u+m's changes to np->nvalue (was the patch was originally written against 2012-08-01 93u+?). Compiler error output:

/home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/name.c:515:26: error: member reference base type 'void *' is not a structure or union
  515 |                                         else if(((np->nvalue.cp && np->nvalue.cp!=Empty)) && !nv_type(np))
      |                                                   ~~~~~~~~~~^~~
/home/johno/GitRepos/KornShell/ksh/src/cmd/ksh93/sh/name.c:515:43: error: member reference base type 'void *' is not a structure or union
  515 |                                         else if(((np->nvalue.cp && np->nvalue.cp!=Empty)) && !nv_type(np))
      |                                                                    ~~~~~~~~~~^~~

- The PR does not include a regression test.

These problems can be fixed with a patch:

diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c
index b35624a62..52185d717 100644
--- a/src/cmd/ksh93/sh/name.c
+++ b/src/cmd/ksh93/sh/name.c
@@ -512,7 +512,7 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ)
 						if(!nv_isnull(np) && np->nvalue!=Empty && !nv_isvtree(np))
 							sub=1;
 					}
-					else if(((np->nvalue && np->nvalue!=Empty)||nv_isvtree(np)|| nv_arrayptr(np)) && !nv_type(np))
+					else if(np->nvalue && np->nvalue!=Empty && !nv_type(np))
 					{
 						int was_assoc_array = ap && ap->fun;
 						nv_unset(np,NV_EXPORT);  /* this can free ap */
diff --git a/src/cmd/ksh93/tests/comvar.sh b/src/cmd/ksh93/tests/comvar.sh
index 27bd77f4b..2d5aca417 100755
--- a/src/cmd/ksh93/tests/comvar.sh
+++ b/src/cmd/ksh93/tests/comvar.sh
@@ -733,5 +733,22 @@ exp=$'(\n\ttypeset -C -a c\n)'
 [[ $got == "$exp" ]] || err_exit 'setting compound array c.c=() does not preserve -C attribute' \
 	"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
 
+# ======
+# github.com/ksh93/ksh/pull/889
+unset complex real img img1 real1
+complex=( real=1 img=2 )
+complex=( real1=3 img1=4 )
+real=$(echo "${complex.real}")
+img=$(echo "${complex.img}")
+real1=$(echo "${complex.real1}")
+img1=$(echo "${complex.img1}")
+exp='real=1
+img=2
+real1=3
+img1=4'
+got=$(typeset -p real img real1 img1)
+[[ $exp == "$got" ]] || err_exit 'previous fields of complex compound variable are lost when adding additional fields' \
+	"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
+
 # ======
 exit $((Errors<125?Errors:125))

After patching the pull request to make it compile, another problem is evident; the bugfix causes some regression test failures:

# Run the regression tests with './bin/shtests' at the root of the repository
test arrays begins at 2025-07-07+14:55:56
	arrays.sh[606]: FAIL: setting element 1 of array to compound variable failed (expected 'typeset -a foo=((11 22) (x=3))', got 'typeset -a foo=((11 22) (44 55) )')
test arrays failed at 2025-07-07+14:55:56 with exit code 1 [ 186 tests 1 error ]
test comvar begins at 2025-07-07+14:56:03
	comvar.sh[659]: FAIL: assignment of compound variable to compound array element not working
test comvar failed at 2025-07-07+14:56:03 with exit code 1 [ 105 tests 1 error ]
test subshell begins at 2025-07-07+14:56:43
	subshell.sh[100]: FAIL: compound variable changes after unset leaves
test subshell failed at 2025-07-07+14:56:54 with exit code 1 [ 154 tests 1 error ]
Total errors: 3

The regression this PR attempts to fix was introduced via the following vague and nondescript patch to name.c in 93u- 2010-08-11:

--- a/src/cmd/ksh93/sh/name.c
+++ b/src/cmd/ksh93/sh/name.c
@@ -488,7 +488,7 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
 						if(!nv_isnull(np) && np->nvalue.cp!=Empty && !nv_isvtree(np))
 							sub=1;
 					}
-					else if(np->nvalue.cp && np->nvalue.cp!=Empty && !nv_type(np))
+					else if(((np->nvalue.cp && np->nvalue.cp!=Empty)||nv_isvtree(np)) && !nv_type(np))
 						_nv_unset(np,NV_EXPORT);
 				}
 				else

This pull request blindly reverts the 2010-08-11 change without trying to ascertain the code's intent or purpose, and consequently introduces regressions that manifest as three regression test failures. The bugfix will need some work.

@kalpitha-ibm
Copy link
Author

Thanks for your comments and suggestions!
I will check on these lines and regression caused by the fix and try to come up with wholesome fix for the issue.
Yes, The initial fix originally was written against 2012-08-01 93u+ code on AIX IBM. So now we will come up with fix for the latest community code.

@kalpitha-ibm
Copy link
Author

@JohnoKing Hello !!
Need your help on running test suite complete bucket on AIX.
On AIX we are not able to run the entire test bucket at once just like you have run in the above comment.
We are running script by script replacing err_exit with echo which is consuming more time for testing. Is there any possible suggestion you can provide us with how to run the complete test bucket at once on AIX.
Thanks in Advance!!!

@JohnoKing
Copy link

You can use an older version of the shtests wrapper script circa f811482: https://github.com/ksh93/ksh/blob/f8114823/bin/shtests

Copy it to the bin folder of the repository, build ksh, then run it with bin/shtests (you also really shouldn't replace err_exit with echo). For ancient 93u+ you should define the KSH variable manually to avoid bugs in the bin/package script.

So, e.g.:

$ cd path/to/ksh93u+m
$ git checkout f8114823 -- bin/shtests
$ cd path/to/93u+
$ cp path/to/ksh93u+m/bin/shtests ./bin
$ KSH=$(echo $PWD/arch/*/bin/ksh) bin/shtests

@kalpitha-ibm
Copy link
Author

kalpitha-ibm commented Jul 28, 2025

Thank You @JohnoKing for your suggestion on testing.
We see few tests failing both on RHEL and AIX which are part of test suite only
Below are few issues that we see :
RHEL:

ksh --version

version sh (AT&T Research) 93u+m/1.0.10 2024-08-01

AIX ksh93
ksh93 --version
version sh (AT&T Research) 93u+m/1.0.10

https://github.com/ksh93/ksh/blob/dev/src/cmd/ksh93/tests/heredoc.sh

got=$(
	IFS=/
	set ONE TWO THREE
	cat <<-EOF
		start$@end
		start$*end
	EOF
)
exp=$'startONE TWO THREEend&#10;startONE/TWO/THREEend'
[[ $got == "$exp" ]] || err_exit '$@ and $* in here-document'
	"(expected $(printf %q "$exp"), got $(printf %q "$got"))"


# exp=$'startONE TWO THREEend&#10;startONE/TWO/THREEend'


# echo $got
startONE TWO THREEend startONE TWO THREEend
=============================================

# got=$(set +x; eval 'typeset -a a1=((demo) (select) (if) (case) (while))' 2>&1 && typeset -p a1)
# exp='typeset -a a1=((demo) (select) (if) (case) (while) )'
# echo $exp
typeset -a a1=((demo) (select) (if) (case) (while) )
# echo $got
-ksh93: eval: syntax error at line 1: `select' unexpected
#

========================
```======================


> echo "Hello, World!"
Hello, World!

> set -o histexpand
> echo "Hello, World!"
ksh93: !": event not found

==============================================
there are few other issues in arrays2.sh ,  attributes.sh and functions.sh 
Are we missing anything while testing or all these test cases from test suite are expected failures in the latest ksh on RHEL also ? 
Please guide with these issues from test suite.
Thank You so much in Advance!

@kalpitha-ibm
Copy link
Author

@JohnoKing Can you please guide me out here for the above issues to understand failures in test suite.

@JohnoKing
Copy link

Are you running the RHEL ksh package against the latest git commit for the regression tests? The v1.0.10 release is aging, having been released in August of last year. All of these problems (except that histexpand issue) can only be reproduced when running v1.0.10 against the tests from the latest commit. In such a case failures are expected because the regression tests on the dev branch test for the presence of bugs that were fixed after the v1.0.10 release.
Please run the regression tests against a ksh built from the same commit as the regression tests. For v1.0.10, run that release against the regression tests in f0999ab. For the dev branch, rebuild ksh while on the latest commit (at the time of writing, that's currently 11981f5), then run that rebuilt version (which should be version 1.1.0-alpha+11981f5f) against the regression tests from commit 11981f5.

@kalpitha-ibm
Copy link
Author

Thank You JohnKing!!
I used latest test suite against v1.0.10 released code base seems like that's why we saw issues.

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.

2 participants