www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - two std.boxer bugs -- patch - boxer.patch

If a null Object reference is box()'d and unboxable!(SubClass)(boxedNullObj) is
attempted, std.box.Box.unboxable tries to offset from null.

: import std.boxer, std.stdio;
:
: class Hmm {}
:
: void main ()
: {
:       // need this to get TypeInfo for Hmm, else I get linker error
:       if (typeid(Hmm) is null && false)  writefln("never");
:
:       Object nullObj;
:       Box nullBox = box(nullObj);
:
:       bool isUnBoxable = unboxable!(Hmm)(nullBox);
:
:       writefln("isUnBoxable: %s", isUnBoxable);
: }

: $ ./boxbug
: Box.unboxable(Hmm) begin...
:         this.type = Object  this.data = 0xbffff2c0(4)[00,00,00,00,]
:         both are classes, casting this.data to an Object reference...
:         o is null: true
: Uncaught:
: SegmentationFault: unmapped address 0x00000000

After fixing this, I discovered another bug: 'template unbox (T : Object)' will
always return null if the boxed thing is a null-Object-reference regardless if
it should be unboxable as the requested type, causing 'template unboxTest (T)'
used in the unittest to fail.

(On a side note, bug
http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/4172 is preventing
'bit fails (void delegate()func)' in the unittest from working, so you have to
do all the fails cases one by one.)

I've attached my patch.



begin 0644 boxer.patch
M+2TM("]U<W(O;&EB+V1M9"]P:&]B;W,O<W1D+V)O>&5R+F0),C`P-2TP-2TR
M."`Q-3HP,#HR-BXP


M("8F(&-B("$]/2!N=6QL*0T*("` ("` ("` >PT*+2` ("` ("` ("` ($-L
M87-S26YF;R!I82`](" J8V%S="A/8FIE8W0 *BD 9&%T82DN8VQA<W-I;F9O



M("` ("` ("` ("` ("` (&EA(#T 8V$N:6YF;SL-"BL ("` ("` ("` ("!E


M:6$ /2!I82YB87-E*0T*("` ("` ("` ("` ("` ("!I9B`H:6$ :7, :6(I

M*2`]/2!V86QU92YT>7!E('Q\(&-A<W0H5'EP94EN9F]?0VQA<W,I('9A;'5E

M="`]("IC87-T*$]B:F5C="HI=F%L=64N9&%T83L-"BT ("` ("` ("` ("!4

M("` ("` ("` :68 *&]B:F5C="!I<R!N=6QL*0T**R` ("` ("` ("` (&EF


M;SL-"BL ("` ("` ("` ("` ("` 0VQA<W-);F9O(&EB(#T *&-A<W0H5'EP
M94EN9F]?0VQA<W,I('1Y<&5I9"A4*2DN:6YF;SL-"BL ("` ("` ("` ("` 
M("` 9F]R("  .R!I82`A/3T ;G5L;#L :6$ /2!I82YB87-E*0T**R` ("` 
M("` ("` ("` ("` ("` :68 *&EA(&ES(&EB*0T*("` ("` ("` ("` ("` 
M("!R971U<FX ;G5L;#L-"BL ("` ("` ("` ("` ("` =&AR;W< ;F5W(%5N
M8F]X17AC97!T:6]N*'9A;'5E+"!T>7!E:60H5"DI.PT**R` ("` ("` ("` 
M('T-"BL-"BL ("` ("` ("` ("!4(')E<W5L="`](&-A<W0H5"D ;V)J96-T
M.PT*("` ("` ("` ("` (&EF("AR97-U;'0 :7, ;G5L;"D-"B` ("` ("` 
M("` ("` ("` =&AR;W< ;F5W(%5N8F]X17AC97!T:6]N*'9A;'5E+"!T>7!E


M96=A;"!O8FIE8W0 8V%S=&EN9R!F86EL<R!P<F]P97)L>2X *B\ ("`-"B` 
M("` 87-S97)T("AF86EL<RAD96QE9V%T92!V;VED*"D >R!U;F)O>%1E<W0A

M96=A=&4 =F]I9" I('L =6YB;WA497-T(2A"*2AB;W H8V%S="A!*6YU;&PI
M*3L ?2DI.PT*("` ("`-"B` ("` +RH 07-S97)T('1H870 =V4 8V%N('5N
M8F]X(&$ ;G5L;"X *B\-"B` ("` 87-S97)T("AU;F)O>%1E<W0A*$$I*&)O
M>"AC87-T*$$I;G5L;"DI(&ES(&YU;&PI.PT*("` ("!A<W-E<G0 *'5N8F]X
M5&5S="$H02DH8F]X*&YU;&PI*2!I<R!N=6QL*3L-"BL ("` 87-S97)T("AU
M;F)O>%1E<W0A*$$I*&)O>"AC87-T*$(I;G5L;"DI(&ES(&YU;&PI.PT*("` 
M("`-"B` ("` +RH 56YB;WAI;F< ;G5L;"!I;B!V87)I;W5S(&-O;G1E>'1S
M+B`J+PT*("` ("!A<W-E<G0 *'5N8F]X5&5S="$H8VAA<EM=*2AB;W H;G5L
/;"DI(&ES(&YU;&PI.PT*
`
end
Jun 03 2005