www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Box.opEqualsInternal's or TypeInfo_Class's fault?

reply derick_eddington nospam.yashmoo.com writes:
std.boxer.Box.opEqualsInternal's last line is:

return cast(bit)type.equals(data, other.data);

but when you've boxed a null Object reference, 'data' is all zeros, 'type' is a
TypeInfo_Class, and TypeInfo_Class.equals is:

:     int equals(void *p1, void *p2)
:     {
:         Object o1 = *cast(Object*)p1;
:         Object o2 = *cast(Object*)p2;
:
:         return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
:     }

and o1 and o2 are made into null references, causing a seg-fault.

Which one should be fixed?
Jun 03 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
<derick_eddington nospam.yashmoo.com> wrote in message 
news:d7rd9q$20hk$1 digitaldaemon.com...
 std.boxer.Box.opEqualsInternal's last line is:

 return cast(bit)type.equals(data, other.data);

 but when you've boxed a null Object reference, 'data' is all zeros, 'type' 
 is a
 TypeInfo_Class, and TypeInfo_Class.equals is:

 :     int equals(void *p1, void *p2)
 :     {
 :         Object o1 = *cast(Object*)p1;
 :         Object o2 = *cast(Object*)p2;
 :
 :         return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
 :     }

 and o1 and o2 are made into null references, causing a seg-fault.

 Which one should be fixed?
I think equals should be fixed. see http://www.digitalmars.com/d/archives/digitalmars/D/bugs/1306.html It looks like compare was changed but equals wasn't.
Jun 04 2005
parent reply derick_eddington nospam.yashmoo.com writes:
'compare' also seg-faults if its 'o1' is null:

:     int compare(void *p1, void *p2)
:     {
:         Object o1 = *cast(Object*)p1;
:         Object o2 = *cast(Object*)p2;
:         int c = 0;
:
:         // Regard null references as always being "less than"
:         if (o1 != o2)  // <--- tries o1.opEquals(o2)
:         {
:             if (o1)
:             {   if (!o2)
:                     c = 1;
:                 else
:                     c = o1.opCmp(o2);
:             }
:             else
:                 c = -1;
:         }
:         return c;
:     }


In article <d7smh2$30pc$1 digitaldaemon.com>, Ben Hinkle says...
<derick_eddington nospam.yashmoo.com> wrote in message 
news:d7rd9q$20hk$1 digitaldaemon.com...
 std.boxer.Box.opEqualsInternal's last line is:

 return cast(bit)type.equals(data, other.data);

 but when you've boxed a null Object reference, 'data' is all zeros, 'type' 
 is a
 TypeInfo_Class, and TypeInfo_Class.equals is:

 :     int equals(void *p1, void *p2)
 :     {
 :         Object o1 = *cast(Object*)p1;
 :         Object o2 = *cast(Object*)p2;
 :
 :         return o1 == o2 || (o1 && o1.opCmp(o2) == 0);
 :     }

 and o1 and o2 are made into null references, causing a seg-fault.

 Which one should be fixed?
I think equals should be fixed. see http://www.digitalmars.com/d/archives/digitalmars/D/bugs/1306.html It looks like compare was changed but equals wasn't.
Jun 04 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
<derick_eddington nospam.yashmoo.com> wrote in message 
news:d7u5eq$ufd$1 digitaldaemon.com...
 'compare' also seg-faults if its 'o1' is null:
Which version of dmd are you using? In dmd.125 compare has been fixed to have if (!(o1 is o2))
Jun 05 2005
parent derick_eddington nospam.yashmoo.com writes:
TypeInfo_C in std/typeinfo/ti_C.d has the fixed 'compare' but TypeInfo_Class in
internal/object.d does not.

In article <d7urnf$1dtc$1 digitaldaemon.com>, Ben Hinkle says...
<derick_eddington nospam.yashmoo.com> wrote in message 
news:d7u5eq$ufd$1 digitaldaemon.com...
 'compare' also seg-faults if its 'o1' is null:
Which version of dmd are you using? In dmd.125 compare has been fixed to have if (!(o1 is o2))
Jun 05 2005