[Issue 9092] New: GC.extend allocates less then it reports

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 28 08:53:28 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9092

           Summary: GC.extend allocates less then it reports
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2012-11-28 08:53:23 PST ---
Basically, when calling "GC.extend", after a while, the actual length of the
allocated memory is just a few bytes short of the actual reported value.

In this particular case, it reports to have extended to 65536 bytes, but trying
to access any of the last few bytes (in this case, the last 4 DWORDS) will
create an access violation error.

Here is the test program:
//----
import core.memory;
import std.stdio;

void main()
{
    auto a = new ubyte[] (4000);
    for ( ; ; )
    {
        writefln("The length of a (a.length) is: %s", a.length);
        auto u = GC.extend(a.ptr, 40, 400);
        writefln("GC.extend claims to have extended it %s bytes", u);
        if(u)
        {
            a = a.ptr[0 .. u];
            foreach_reverse(k;1..21)
            {
                writef("Trying to access index at u - %2s (%s)... ", k, u-k);
                stdout.flush();
                a.ptr[u -  k] = 0x01;
                writefln("OK!");
            }
            writefln("OK! GC.Extend didn't lie to us, \"a\" really is %s bytes
long.", u);
            writefln("On to the next iteration...\n");
        }
        else
            return;
    }
}
//----

And an exerpt of the last iteration.

//----
...
Trying to access index at u -  4 (61436)... OK!
Trying to access index at u -  3 (61437)... OK!
Trying to access index at u -  2 (61438)... OK!
Trying to access index at u -  1 (61439)... OK!
OK! GC.Extend didn't lie to us, "a" really is 61440 bytes long
On to the next iteration...

The length of a (a.length) is: 61440
GC.extend claims to have extended it 65536 bytes
Trying to access index at u - 20 (65516)... OK!
Trying to access index at u - 19 (65517)... OK!
Trying to access index at u - 18 (65518)... OK!
Trying to access index at u - 17 (65519)... OK!
Trying to access index at u - 16 (65520)... object.Error: Access Violation
//----

Extra tests seem to reveal this only comes up if the returned value is a mod of
2^^16: I get an error on the lengths:
65536, 131072, 196608 etc..., up to 983040

By adding "if ((u % 0x10000) == 0) continue;",
then the program continues, until it finishes at 1044480 bytes.

Done on a win7x64 with 2.060 and 2.061alpha.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list