www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 154] New: invalid code generation on linux with custom allocators/deallocators + 'auto' doubts

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=154

           Summary: invalid code generation on linux with custom
                    allocators/deallocators + 'auto' doubts
           Product: D
           Version: 0.157
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: h3r3tic mat.uni.torun.pl


The following code:


tmp3.d:
----

import std.c.stdlib;

class Foo
{
    new (size_t sz)
    {
        return std.c.stdlib.malloc(sz);
    }

    delete(void* p)
    {
        if (p) std.c.stdlib.free(p);
    }
}

void main() {
    Foo f = new Foo;
    delete f;
}

----

doesn't seem to like linux at all...


h3 h3:~/coding> dmd tmp3.d
gcc tmp3.o -o tmp3 -lphobos -lpthread -lm
h3 h3:~/coding> ./tmp3
Illegal instruction
h3 h3:~/coding> gdb tmp3
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library
"/lib/tls/libthread_db.so.1".

(gdb) r
Starting program: /home/h3/coding/tmp3
[Thread debugging using libthread_db enabled]
[New Thread 1075353280 (LWP 22608)]

Program received signal SIGILL, Illegal instruction.
[Switching to Thread 1075353280 (LWP 22608)]
0x0805c474 in _Class_8TypeInfo ()
(gdb) bt







Adding an empty constructor ("this() {}") to the Foo class fixes the problem.
It's also been reported that it runs fine on Windows.


----

By the way, using custom deallocators in conjunction with 'auto' classes seems
to be problematic. The spec states "When an auto class reference goes out of
scope, the destructor (if any) for it is automatically called. This holds true
even if the scope was exited via a thrown exception.", yet it doesn't mention
custom deallocators.
When a class declares custom allocators and deallocators and an 'auto' instance
of such class is created, its custom allocator is called, but the custom
deallocator isn't. Is that the desired behaviour ? I hope not...

Thanks,
Tom


-- 
May 23 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-05-23:
 The following code:


 tmp3.d:
 ----

 import std.c.stdlib;

 class Foo
 {
     new (size_t sz)
     {
         return std.c.stdlib.malloc(sz);
     }

     delete(void* p)
     {
         if (p) std.c.stdlib.free(p);
     }
 }

 void main() {
     Foo f = new Foo;
     delete f;
 }

 ----

 doesn't seem to like linux at all...


 h3 h3:~/coding> dmd tmp3.d
 gcc tmp3.o -o tmp3 -lphobos -lpthread -lm
 h3 h3:~/coding> ./tmp3
 Illegal instruction
 h3 h3:~/coding> gdb tmp3
 GNU gdb 6.3
 Copyright 2004 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you are
 welcome to change it and/or distribute copies of it under certain
 conditions.Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for details.
 This GDB was configured as "i586-suse-linux"...Using host libthread_db library
 "/lib/tls/libthread_db.so.1".

 (gdb) r
 Starting program: /home/h3/coding/tmp3
 [Thread debugging using libthread_db enabled]
 [New Thread 1075353280 (LWP 22608)]

 Program received signal SIGILL, Illegal instruction.
 [Switching to Thread 1075353280 (LWP 22608)]
 0x0805c474 in _Class_8TypeInfo ()
 (gdb) bt







 Adding an empty constructor ("this() {}") to the Foo class fixes the problem.
 It's also been reported that it runs fine on Windows.
Added to DStress as http://dstress.kuehne.cn/run/d/delete_14_A.d http://dstress.kuehne.cn/run/d/delete_14_B.d see also: http://dstress.kuehne.cn/run/d/delete_12_A.d http://dstress.kuehne.cn/run/d/delete_12_B.d http://dstress.kuehne.cn/run/d/delete_12_C.d http://dstress.kuehne.cn/run/d/delete_12_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEdD7H3w+/yD4P9tIRAjrGAJ9C1IglWAxit5L7a/DTdsqWgWZulACdHZou Fwg0p8uuRF0+QAvHOTRyET0= =FDF+ -----END PGP SIGNATURE-----
May 24 2006
parent Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
Thomas Kuehne wrote:
 Added to DStress as
 http://dstress.kuehne.cn/run/d/delete_14_A.d
 http://dstress.kuehne.cn/run/d/delete_14_B.d
 
 see also:
 http://dstress.kuehne.cn/run/d/delete_12_A.d
 http://dstress.kuehne.cn/run/d/delete_12_B.d
 http://dstress.kuehne.cn/run/d/delete_12_C.d
 http://dstress.kuehne.cn/run/d/delete_12_D.d
Thanks a lot ! :) -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O !M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y ------END GEEK CODE BLOCK------ Tomasz Stachowiak /+ a.k.a. h3r3tic +/
May 24 2006