Jump to page: 1 2
Thread overview
[Issue 10543] New: std.algorithm.map incorrectly uses source range length for narrow strings
Jul 04, 2013
Peter Alexander
Jul 04, 2013
Peter Alexander
Jul 04, 2013
Peter Alexander
Jul 04, 2013
9999
Jul 04, 2013
Peter Alexander
Jul 04, 2013
Peter Alexander
Jul 06, 2013
Kenji Hara
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543

           Summary: std.algorithm.map incorrectly uses source range length
                    for narrow strings
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: peter.alexander.au@gmail.com


--- Comment #0 from Peter Alexander <peter.alexander.au@gmail.com> 2013-07-04 09:30:32 PDT ---
void main()
{
    import std.algorithm;
    import std.stdio;
    string s = "こんにちは世界";
    auto m = s.map!(a => 1);
    writeln(m, ", ", m.length);
}

Gives:

[1, 1, 1, 1, 1, 1, 1], 21

Clearly the reported length (21) is wrong, it should be 7.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543



--- Comment #1 from Peter Alexander <peter.alexander.au@gmail.com> 2013-07-04 09:31:54 PDT ---
(In reply to comment #0)
> Clearly the reported length (21) is wrong, it should be 7.

Scratch that. length shouldn't be available at all for narrow strings as it is unobtainable in constant time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #2 from bearophile_hugs@eml.cc 2013-07-04 10:41:41 PDT ---
Where's the bug here?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543



--- Comment #3 from Peter Alexander <peter.alexander.au@gmail.com> 2013-07-04 10:43:22 PDT ---
(In reply to comment #2)
> Where's the bug here?

It says the length of [1, 1, 1, 1, 1, 1, 1] is 21. It isn't. It's 7.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543


9999 <mailnew4ster@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mailnew4ster@gmail.com


--- Comment #4 from 9999 <mailnew4ster@gmail.com> 2013-07-04 10:47:52 PDT ---
21 is the number of UTF-8 code units.
Using dstring produces 7.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543



--- Comment #5 from Peter Alexander <peter.alexander.au@gmail.com> 2013-07-04 10:54:42 PDT ---
(In reply to comment #4)
> 21 is the number of UTF-8 code units.
> Using dstring produces 7.

I am not requesting the length of the string, I am requesting the length of the map over the string. As ranges, strings are ranges of code points, not code units, so the number of elements in the *map* (confirmed by the output) is seven, i.e. that is the number of times you can safely call popFront on the map.

I'm struggling to understand the confusion.

m is a range of seven integers
m.length is 21
walkLength(m) is also 21

This is completely broken.

I fully understand that narrow strings use length to report code units, not code points, but m is not a string, so that distinction does not apply.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com


--- Comment #6 from monarchdodra@gmail.com 2013-07-04 12:51:16 PDT ---
(In reply to comment #5)
> I'm struggling to understand the confusion.

The problem is perfectly clear.

Are you already correcting this? If not, I'll take care of it.

I remember having seen this in one of my first pulls correcting map, but got confused about the fact there is an *explicit* test to do things wrong... Time to correct it for good I guess.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543



--- Comment #7 from Peter Alexander <peter.alexander.au@gmail.com> 2013-07-04 13:15:10 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > I'm struggling to understand the confusion.
> 
> The problem is perfectly clear.
> 
> Are you already correcting this? If not, I'll take care of it.
> 
> I remember having seen this in one of my first pulls correcting map, but got confused about the fact there is an *explicit* test to do things wrong... Time to correct it for good I guess.

I'm not fixing it right now, go ahead.

I only noticed it when I looked at the source. No idea why it's explicitly coded to be wrong...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543


monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody@puremagic.com        |monarchdodra@gmail.com


--- Comment #8 from monarchdodra@gmail.com 2013-07-05 05:49:13 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1389

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10543



--- Comment #9 from github-bugzilla@puremagic.com 2013-07-06 02:24:49 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/0a710876007bf8509d4f62453311e0bb6adbc7ca
Fix Issue 10543 - std.algorithm.map incorrectly uses source range length for
narrow strings

Strange, because there was an explicit override for strings to forward length.

In any case, this is now fixed.

https://github.com/D-Programming-Language/phobos/commit/201edf4c8055ca0ac0079b9a8b711b68668c7974 Merge pull request #1389 from monarchdodra/mapString

Fix Issue 10543 - std.algorithm.map incorrectly uses source range length...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2