Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Re: RFC: region_highlight inter-plugin interoperability: echo service?
- X-seq: zsh-workers 46070
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] Re: RFC: region_highlight inter-plugin interoperability: echo service?
- Date: Thu, 18 Jun 2020 11:16:26 +0000
- In-reply-to: <20200618103311.62307eb5@tarpaulin.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20200606072018.GA14049@tarpaulin.shahaf.local2> <20200618103311.62307eb5@tarpaulin.shahaf.local2>
Daniel Shahaf wrote on Thu, 18 Jun 2020 10:33 +0000:
> +++ b/Src/Zle/zle_refresh.c
> @@ -414,16 +414,19 @@ get_region_highlight(UNUSED(Param pm))
> arrsize--;
> rhp++, arrp++) {
> char digbuf1[DIGBUFSIZE], digbuf2[DIGBUFSIZE];
> - int atrlen = 0, alloclen;
> + int atrlen, alloclen;
> + const char memo_equals[] = "memo=";
>
> sprintf(digbuf1, "%d", rhp->start);
> sprintf(digbuf2, "%d", rhp->end);
>
> atrlen = output_highlight(rhp->atr, NULL);
> alloclen = atrlen + strlen(digbuf1) + strlen(digbuf2) +
> - 3; /* 2 spaces, 1 0 */
> + 3; /* 2 spaces, 1 terminating NUL */
> if (rhp->flags & ZRH_PREDISPLAY)
> alloclen += 2; /* "P " */
> + if (rhp->memo)
> + alloclen += 1 /* space */ + strlen(memo_equals) + strlen(rhp->memo);
> *arrp = (char *)zhalloc(alloclen * sizeof(char));
> /*
> * On input we allow a space after the flags.
> @@ -436,6 +439,12 @@ get_region_highlight(UNUSED(Param pm))
> (rhp->flags & ZRH_PREDISPLAY) ? "P" : "",
> digbuf1, digbuf2);
> (void)output_highlight(rhp->atr, *arrp + strlen(*arrp));
> +
> + if (rhp->memo) {
> + strcat(*arrp, " ");
> + strcat(*arrp, memo_equals);
> + strcat(*arrp, rhp->memo);
> + }
> }
> *arrp = NULL;
> return retarr;
> +++ b/Src/Zle/zle_utils.c
> @@ -557,6 +557,22 @@ zlegetline(int *ll, int *cs)
> +/*
> + * free() the 'memo' elements of region_highlights.
> + */
> +
> +/**/
> +void
> +free_region_highlights_memos(void)
> +{
> + struct region_highlight *rhp;
> + for (rhp = region_highlights;
> + rhp < region_highlights + n_region_highlights;
> + rhp++) {
> + zsfree(rhp->memo);
s/zsfree/zfree/
since the calculation of alloclen in get_region_highlight() can result
in an alloclen that's different to strlen(rhp->memo)+1 — at least when
the ZRH_PREDISPLAY bit is set.
(This only matters for --enable-zsh-mem builds, and even then only if
alloclen happens to be exactly the one value that will cause zfree()'s
fr_rec condition's truth value to flip, but still.)
Cheers,
Daniel
> + }
> +}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author