Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14796 > unrolled thread

Re: [mapfile]: problem reentrance with normal file

Started byChet Ramey <chet.ramey@case.edu>
First post2018-11-12 09:43 -0500
Last post2018-11-12 09:43 -0500
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [mapfile]: problem reentrance with normal file Chet Ramey <chet.ramey@case.edu> - 2018-11-12 09:43 -0500

#14796 — Re: [mapfile]: problem reentrance with normal file

FromChet Ramey <chet.ramey@case.edu>
Date2018-11-12 09:43 -0500
SubjectRe: [mapfile]: problem reentrance with normal file
Message-ID<mailman.3919.1542033850.1284.bug-bash@gnu.org>
On 11/11/18 3:32 PM, Didou Serge wrote:

> Bash Version: 4.4
> Patch Level: 7
> Release Status: release
> 
> Description:
> When use mapfile from normal file that call function that use mapfile, the
> first mapfile lost data.
> 
> Repeat-By:
> I create 3 functions:
> ww(){ echo "$@" | mapfile -C yy -c 1 -t TT ; }
> xx(){ mapfile -C yy -c 1 -t TT < <(echo "$@") ; }
> yy(){ echo "$@" ;}
> 
> I create 1 normal file:
> echo -e "Premiere ligne" A{1..45} "\nDeuxieme ligne" B{1..45} "\nTroisieme
> ligne" C{1..45} >fic.txt
> 
	[...]
> This not work (lost data in second line and after) :
> mapfile -C xx -c 1 UU <fic.txt
> 0 0 Premiere ligne A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16
> A17 A18 A19 A20 A21 A22 A23 A24 A25 A26 A27 A28 A29 A30 A31 A32 A33 A34 A35
> A36 A37 A38 A39 A40 A41 A42 A43 A44 A45
> 0 1  B17 B18 B19 B20 B21 B22 B23 B24 B25 B26 B27 B28 B29 B30 B31 B32 B33
> B34 B35 B36 B37 B38 B39 B40 B41 B42 B43 B44 B45
> 0 2 ligne C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18
> C19 C20 C21 C22 C23 C24 C25 C26 C27 C28 C29 C30 C31 C32 C33 C34 C35 C36 C37
> C38 C39 C40 C41 C42 C43 C44 C45

This is a buffering issue caused by nested calls to mapfile in the same
process. The first call to mapfile reads a bufferful of data from the
input file, and the second mapfile (the one executed as part of the
callback) reads data into that same buffer. When the second call finishes,
and the first mapfile is called again, the remaining characters in the
buffer have already been discarded. It's not safe to call mapfile as part
of a callback to a mapfile invocation.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web