Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Unicode warnings



This patch removes some compiler warnings with ZLE_UNICODE_SUPPORT
defined.  A few were related to actual bugs, mostly incorrect lengths of
strings.

It makes no headway whatsoever into the great continent of expansion and
completion, whose mountains provide a forbidding aspect on every side to
approaching explorers.  At two points I have simply erected barriers to
prevent the unwary traveller from entering: if you have magic-space
bound to space, it no longer does arbitrarily incorrect things, simply
inserts a space, and the interface use to add characters to history
expansion simply casts to ZLE_CHAR_T, which removes the warning but does
nothing more useful.

One other remaining warning (apart from the numerous strict aliasing
messages) needs handling: in zle_refresh() at the moment we have no code
to support conversion failures and that results in a "may be used before
defined" warning for vp.  Apart from that, basic editor support looks
pretty much OK.

Index: Src/Zle/zle_hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v
retrieving revision 1.23
diff -u -r1.23 zle_hist.c
--- Src/Zle/zle_hist.c	18 Mar 2005 18:28:19 -0000	1.23
+++ Src/Zle/zle_hist.c	28 Jul 2005 14:19:53 -0000
@@ -1068,7 +1068,8 @@
 	rpt:
 	    if (!sbptr && previous_search_len) {
 		if (previous_search_len > sibuf - FIRST_SEARCH_CHAR - 2) {
-		    ibuf = hrealloc(ibuf, sibuf, (sibuf + previous_search_len)
+		    ibuf = hrealloc((char *)ibuf, sibuf * ZLE_CHAR_SIZE,
+				    (sibuf + previous_search_len)
 				    * ZLE_CHAR_SIZE);
 		    sbuf = ibuf + FIRST_SEARCH_CHAR;
 		    sibuf += previous_search_len;
@@ -1096,7 +1097,7 @@
 	    } else if (cmd == Th(z_selfinsert)) {
 #ifdef ZLE_UNICODE_SUPPORT
 		if (!lastchar_wide_valid)
-		    getfullcharrest(lastchar);
+		    getrestchar(lastchar);
 #else
 		;
 #endif
@@ -1113,7 +1114,8 @@
 	    }
 	    set_isrch_spot(top_spot++, hl, pos, zlecs, sbptr, dir, nomatch);
 	    if (sbptr >= sibuf - FIRST_SEARCH_CHAR - 2) {
-		ibuf = hrealloc(ibuf, sibuf, sibuf * 2 * ZLE_CHAR_SIZE);
+		ibuf = hrealloc((char *)ibuf, sibuf * ZLE_CHAR_SIZE,
+				sibuf * 2 * ZLE_CHAR_SIZE);
 		sbuf = ibuf + FIRST_SEARCH_CHAR;
 		sibuf *= 2;
 	    }
@@ -1298,9 +1300,10 @@
 #endif
 	    }
 	  ins:
-	    if(sptr == ssbuf - 1) {
-		char *newbuf = zhalloc(ssbuf *= 2);
-		strcpy(newbuf, sbuf);
+	    if (sptr == ssbuf - 1) {
+		ZLE_STRING_T newbuf =
+		    (ZLE_STRING_T) zhalloc((ssbuf *= 2) * ZLE_CHAR_SIZE);
+		ZS_strcpy(newbuf, sbuf);
 		statusline = sbuf = newbuf;
 	    }
 	    sbuf[sptr++] = LASTFULLCHAR;
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.70
diff -u -r1.70 zle_main.c
--- Src/Zle/zle_main.c	26 Jul 2005 22:46:10 -0000	1.70
+++ Src/Zle/zle_main.c	28 Jul 2005 14:19:53 -0000
@@ -938,7 +938,7 @@
     zlecontext = context;
     histline = curhist;
     undoing = 1;
-    zleline = (unsigned char *)zalloc(((linesz = 256) + 2) * ZLE_CHAR_SIZE);
+    zleline = (ZLE_STRING_T)zalloc(((linesz = 256) + 2) * ZLE_CHAR_SIZE);
     *zleline = ZWC('\0');
     virangeflag = lastcmd = done = zlecs = zlell = mark = 0;
     vichgflag = 0;
@@ -1518,7 +1518,8 @@
 {
 #ifdef ZLE_UNICODE_SUPPORT
     zrealloc(zle_wordchars, strlen(wordchars)*MB_CUR_MAX);
-    mbsrtowcs(zle_wordchars, &wordchars, strlen(wordchars), NULL);
+    mbsrtowcs(zle_wordchars, (const char **)&wordchars,
+	      strlen(wordchars), NULL);
     /* TODO: error handling here */
 #endif
 }
Index: Src/Zle/zle_misc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v
retrieving revision 1.22
diff -u -r1.22 zle_misc.c
--- Src/Zle/zle_misc.c	11 Mar 2005 10:33:45 -0000	1.22
+++ Src/Zle/zle_misc.c	28 Jul 2005 14:19:53 -0000
@@ -724,7 +724,7 @@
 	if (*l == ZWC('\''))
 	    qtct++;
     *len += 2 + qtct*3;
-    l = ol = (char *)zhalloc(*len * ZLE_CHAR_SIZE);
+    l = ol = (ZLE_STRING_T)zhalloc(*len * ZLE_CHAR_SIZE);
     *l++ = ZWC('\'');
     for (; str < end; str++)
 	if (*str == ZWC('\'')) {
Index: Src/Zle/zle_params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v
retrieving revision 1.24
diff -u -r1.24 zle_params.c
--- Src/Zle/zle_params.c	23 Feb 2005 13:50:45 -0000	1.24
+++ Src/Zle/zle_params.c	28 Jul 2005 14:19:53 -0000
@@ -187,7 +187,7 @@
 static char *
 get_buffer(UNUSED(Param pm))
 {
-    return (char *)zlelineasstring((char *)zleline, zlell, 0, NULL, NULL, 1);
+    return (char *)zlelineasstring(zleline, zlell, 0, NULL, NULL, 1);
 }
 
 /**/
@@ -264,7 +264,7 @@
 static void
 set_rbuffer(UNUSED(Param pm), char *x)
 {
-    char *y;
+    ZLE_STRING_T y;
     int len;
 
     if (x && *x != ZWC('\0'))
@@ -610,7 +610,8 @@
 get_lsearch(UNUSED(Param pm))
 {
     if (previous_search_len)
-	return metafy(previous_search, previous_search_len, META_HEAPDUP);
+	return zlelineasstring(previous_search, previous_search_len, 0,
+			       NULL, NULL, 1);
     else
 	return "";
 }
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.52
diff -u -r1.52 zle_tricky.c
--- Src/Zle/zle_tricky.c	23 May 2005 10:11:28 -0000	1.52
+++ Src/Zle/zle_tricky.c	28 Jul 2005 14:19:53 -0000
@@ -2332,9 +2332,19 @@
 	 bangq += 2)
 	if (bangq[1] == '"' && (bangq == (char *)zleline || bangq[-1] != '\\'))
 	    break;
+#ifdef ZLE_UNICODE_SUPPORT
+    /*
+     * TODO: expansion and completion with Unicode are currently
+     * fundamentally broken.  Most of the code for this hasn't been
+     * commented out, but crashing the shell just because you entered
+     * a space seems to be worth guarding against.
+     */
+    ret = selfinsert(args);
+#else
     if (!(ret = selfinsert(args)) &&
 	(!bangq || bangq + 2 > (char *)zleline + zlecs))
 	doexpandhist();
+#endif
     return ret;
 }
 
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.24
diff -u -r1.24 zle_utils.c
--- Src/Zle/zle_utils.c	26 Feb 2005 07:40:57 -0000	1.24
+++ Src/Zle/zle_utils.c	28 Jul 2005 14:19:53 -0000
@@ -85,10 +85,23 @@
 
 /**/
 mod_export void
-zleaddtoline(ZLE_CHAR_T chr)
+zleaddtoline(int chr)
 {
     spaceinline(1);
+#ifdef ZLE_UNICODE_SUPPORT
+    /*
+     * TODO: the main shell has as yet very little notion of multibyte
+     * characters.  Until this gets fixed we just have to assume
+     * this is a complete character.
+     *
+     * Possibly we could get away with attempting to build up a
+     * multibyte character here, storing partial characters between
+     * calls.
+     */
+    zleline[zlecs++] = (ZLE_CHAR_T)chr;
+#else
     zleline[zlecs++] = chr;
+#endif
 }
 
 /*
@@ -188,7 +201,6 @@
     ZLE_STRING_T outstr;
     int ll, sz;
 #ifdef ZLE_UNICODE_SUPPORT
-    int cll;
     mbstate_t ps;
 #endif
 

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author