summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/params.c73
-rw-r--r--Test/C01arith.ztst6
3 files changed, 43 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 30fa6e7a0..fdbe5e16e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-11  Peter Stephenson  <pws@csr.com>
+
+	* 22686: Src/params.c: unset array if assigning numeric
+	parameter to it.
+
 2006-09-10  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 22685: Src/builtin.c: printf "%d" \'X should handle multibyte
diff --git a/Src/params.c b/Src/params.c
index 2a4a7a745..e60c8c740 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2495,46 +2495,9 @@ sethparam(char *s, char **val)
     return v->pm;
 }
 
-/**/
-mod_export Param
-setiparam(char *s, zlong val)
-{
-    struct value vbuf;
-    Value v;
-    char *t = s, *ss;
-    Param pm;
-    mnumber mnval;
-
-    if (!isident(s)) {
-	zerr("not an identifier: %s", s);
-	errflag = 1;
-	return NULL;
-    }
-    queue_signals();
-    if (!(v = getvalue(&vbuf, &s, 1))) {
-	if ((ss = strchr(s, '[')))
-	    *ss = '\0';
-	if (!(pm = createparam(t, ss ? PM_ARRAY : PM_INTEGER)))
-	    pm = (Param) paramtab->getnode(paramtab, t);
-	DPUTS(!pm, "BUG: parameter not created");
-	if (ss) {
-	    *ss = '[';
-	} else {
-	    pm->base = outputradix;
-	}
-	v = getvalue(&vbuf, &t, 1);
-	DPUTS(!v, "BUG: value not found for new parameter");
-    }
-    mnval.type = MN_INTEGER;
-    mnval.u.l = val;
-    setnumvalue(v, mnval);
-    unqueue_signals();
-    return v->pm;
-}
 
 /*
- * Like setiparam(), but can take an mnumber which can be integer or
- * floating.
+ * Set a generic shell number, floating point or integer.
  */
 
 /**/
@@ -2543,7 +2506,7 @@ setnparam(char *s, mnumber val)
 {
     struct value vbuf;
     Value v;
-    char *t = s, *ss = NULL;
+    char *t = s, *ss;
     Param pm;
 
     if (!isident(s)) {
@@ -2552,8 +2515,23 @@ setnparam(char *s, mnumber val)
 	return NULL;
     }
     queue_signals();
-    if (!(v = getvalue(&vbuf, &s, 1))) {
-	if ((ss = strchr(s, '[')))
+    ss = strchr(s, '[');
+    v = getvalue(&vbuf, &s, 1);
+    if (v && (v->pm->node.flags & (PM_ARRAY|PM_HASHED)) &&
+	!(v->pm->node.flags & (PM_SPECIAL|PM_TIED)) &&
+	/*
+	 * not sure what KSHARRAYS has got to do with this...
+	 * copied this from assignsparam().
+	 */
+	unset(KSHARRAYS) && !ss) {
+	unsetparam_pm(v->pm, 0, 1);
+	s = t;
+	v = NULL;
+    }
+    if (!v) {
+	/* s has been updated by getvalue, so check again */
+	ss = strchr(s, '[');
+	if (ss)
 	    *ss = '\0';
 	pm = createparam(t, ss ? PM_ARRAY :
 			 (val.type & MN_INTEGER) ? PM_INTEGER : PM_FFLOAT);
@@ -2573,6 +2551,19 @@ setnparam(char *s, mnumber val)
     return v->pm;
 }
 
+/* Simplified interface to setnparam */
+
+/**/
+mod_export Param
+setiparam(char *s, zlong val)
+{
+    mnumber mnval;
+    mnval.type = MN_INTEGER;
+    mnval.u.l = val;
+    return setnparam(s, mnval);
+}
+
+
 /* Unset a parameter */
 
 /**/
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 9bab48244..9867b5d9a 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -97,6 +97,12 @@
 0:setting array elements in math context
 >array 1 2
 
+  xarr=()
+  (( xarr = 3 ))
+  print ${(t)xarr} $xarr
+0:converting type from array
+>integer 3
+
   print $(( 13 = 42 ))
 1:bad lvalue
 ?(eval):1: lvalue required