From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13151 invoked from network); 22 Jan 2005 05:28:33 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 22 Jan 2005 05:28:33 -0000 Received: (qmail 68109 invoked from network); 22 Jan 2005 05:28:24 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 22 Jan 2005 05:28:24 -0000 Received: (qmail 14205 invoked by alias); 22 Jan 2005 03:36:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20735 Received: (qmail 14191 invoked from network); 22 Jan 2005 03:36:03 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 22 Jan 2005 03:36:03 -0000 Received: (qmail 32759 invoked from network); 22 Jan 2005 03:36:03 -0000 Received: from acolyte.scowler.net (216.254.112.45) by a.mx.sunsite.dk with SMTP; 22 Jan 2005 03:35:59 -0000 Received: by acolyte.scowler.net (Postfix, from userid 1000) id 899EA7004A; Fri, 21 Jan 2005 22:35:57 -0500 (EST) Date: Fri, 21 Jan 2005 22:35:57 -0500 From: Clint Adams To: Peter Stephenson Cc: zsh-workers@sunsite.dk Subject: Re: PATCH: minor zle_utils fix Message-ID: <20050122033557.GA24905@scowler.net> Mail-Followup-To: Peter Stephenson , zsh-workers@sunsite.dk References: <20050116162247.GA26801@scowler.net> <200501171040.j0HAe6mY003515@news01.csr.com> <20050119012630.GA2463@scowler.net> <200501191049.j0JAn8US032409@news01.csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200501191049.j0JAn8US032409@news01.csr.com> User-Agent: Mutt/1.5.6+20040907i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Addressing these two points: > Your way's probably neater; we probably don't need to lose too much > sleep about the efficiency of the old interface as long as it's not too > gross. So the patch will need matching free()s in all callers. I think > there's just one at the moment. > As discussed previously, this should just be zlell; we are not using > terminating wide nulls. This fits in with current usage where we don't > use terminating ordinary nulls since an ASCII NUL is a valid character > in unsigned char *zleline. M Src/Zle/zle_utils.c M Src/hist.c * modified files --- orig/Src/Zle/zle_utils.c +++ mod/Src/Zle/zle_utils.c @@ -89,10 +89,35 @@ mod_export unsigned char * zlegetline(int *ll, int *cs) { + char *s; +#ifdef ZLE_UNICODE_SUPPORT + char *mb_cursor; + int i, j; + size_t mb_len = 0; + + mb_cursor = s = zalloc(zlell * MB_CUR_MAX); + + for(i=0;i<=zlell;i++) { + if (i == zlecs) + *cs = mb_len; + j = wctomb(mb_cursor, zleline[i]); + if (j == -1) { + /* invalid char; what to do? */ + } else { + mb_len += j; + } + } + + *ll = mb_len; + + return (unsigned char *)s; +#else *ll = zlell; *cs = zlecs; - return zleline; + s = ztrdup(zleline); + return (unsigned char *)s; +#endif } --- orig/Src/hist.c +++ mod/Src/hist.c @@ -2260,7 +2260,7 @@ if (zlegetlineptr) { linein = zlegetlineptr(&ll, &cs); } else { - linein = ""; + linein = ztrdup(""); ll = cs = 0; } zlell = ll + 1; /* length of line plus space added below */ @@ -2287,6 +2287,7 @@ p[zlell] = '\0'; inpush(p, 0, NULL); } + zsfree(linein); } if (zlecs) zlecs--;