[phobos] stdin.byChunk seems broken

Andrei Alexandrescu andrei at erdani.com
Sat Jun 5 10:09:08 PDT 2010


Are duper/iduper frequent enough to warrant dedicated symbols as opposed 
to map!"a.dup" and map!"a.idup" respectively?

Andrei

On 06/05/2010 10:04 AM, Steven Schveighoffer wrote:
> I suggested having a range called duper on the ng to solve a similar problem with byLine. This range would call dup on each element. iduper probably be good too...
>
> Sent from my new iPhone
>
> On Jun 4, 2010, at 7:02 PM, Andrei Alexandrescu<andrei at erdani.com>  wrote:
>
> The reason is very simple - byChunk reuses the buffer for each chunk. That's why you are getting garbled data, and that's why you can't use immutable with byChunk.
>
> There are two issues now:
>
> 1. send() should NEVER accept const(ubyte)[]. So you have a bug. The program as written shouldn't compile.
>
> 2. We need a sort of byImmutableChunk or something that creates a new buffer every pass, or simply recommend that people use .idup when they want to send stuff over.
>
>
> Andrei
>
> On 06/04/2010 05:48 PM, Sean Kelly wrote:
> Given the sample:
>
>      import std.algorithm, std.concurrency, std.stdio;
>
>
>      void main()
>      {
>          enum bufferSize = 1;
>          auto tid = spawn(&fileWriter );
>          // Read loop
>          /+ BUG: stdio can't handle the immutable buffer
>          foreach( immutable(ubyte)[] buffer; stdin.byChunk( bufferSize ) )
>              send( tid, buffer );
>          +/
>          foreach( const(ubyte)[] buffer; stdin.byChunk( bufferSize ) )
>              send( tid, buffer );
>      }
>
>
>      void fileWriter()
>      {
>          // Write loop
>          for( ; ; )
>          {
>              // BUG: stdio can't handle the immutable buffer
>              //auto buffer = receiveOnly!(immutable(ubyte)[])();
>              auto buffer = receiveOnly!(const(ubyte)[])();
>              writeln( "rx: ", buffer.field[0] );
>          }
>      }
>
> The output I see is:
>
>     abacus:tdpl sean$ ch13_7
>     aaaa
>     rx: 10
>     rx: 10
>     rx: 10
>     rx: 10
>     rx: 10
>     ^C
>     abacus:tdpl sean$
>
> Why if I send 4 'a' characters do I receive 5 \n characters?  Seems like the last character in the buffer is being copied over the preceding data.  I just thought I'd mention this in case someone has the time and inclination to look into it.
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list