Skip to content

Commit 4b95281

Browse files
committed
Add workaround for bug #1811.
It can be actually proper fix due MMD distance for divide(Int, Default) vs divide(TclInt, TclFloat) can be same. Requiares very recent parrot with exported PMC boxing functions.
1 parent 4069e65 commit 4b95281

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/pmc/tclint.pmc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pmclass TclInt
3838
* TclInt shouldn't automatically promote division to float;
3939
* also, explicitly use floor when dividing.
4040
*/
41-
MULTI PMC *divide(Integer value, PMC* dest) {
41+
MULTI PMC *divide(Integer *value, PMC* dest) {
4242
FLOATVAL d = VTABLE_get_number(INTERP, value);
4343

4444
if (d == 0)
@@ -51,6 +51,21 @@ pmclass TclInt
5151
VTABLE_set_integer_native(INTERP, dest, floor(SELF.get_integer() / d));
5252
return dest;
5353
}
54+
55+
/*
56+
* Workaround for bug #1811 when "div TclInt, TclFloat" dispatched
57+
* to Integer.divide(DEFAULT).
58+
*/
59+
MULTI PMC *divide(DEFAULT *value, PMC* dest) {
60+
FLOATVAL d = VTABLE_get_number(INTERP, value);
61+
62+
if (d == 0)
63+
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_DIV_BY_ZERO,
64+
"divide by zero");
65+
66+
dest = Parrot_pmc_box_number(INTERP, SELF.get_integer() / d);
67+
return dest;
68+
}
5469
}
5570

5671
/*

0 commit comments

Comments
 (0)