cvsuser 03/10/20 14:01:32
Modified: classes perlint.pmc
t/pmc perlint.t
Log:
Throw exception on division by zero
Revision Changes Path
1.48 +9 -2 parrot/classes/perlint.pmc
Index: perlint.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/perlint.pmc,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -w -r1.47 -r1.48
--- perlint.pmc 20 Oct 2003 17:18:59 -0000 1.47
+++ perlint.pmc 20 Oct 2003 21:01:30 -0000 1.48
@@ -1,7 +1,7 @@
/* perlint.pmc
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: perlint.pmc,v 1.47 2003/10/20 17:18:59 dan Exp $
+ * $Id: perlint.pmc,v 1.48 2003/10/20 21:01:30 scog Exp $
* Overview:
* These are the vtable functions for the PerlInt base class
* Data Structure and Algorithms:
@@ -195,13 +195,20 @@
FLOATVAL valf;
FLOATVAL divf;
+ /* TODO: Is this the appropriate way to throw the exception? */
+
pmci = SELF->cache.int_val;
if (vtype == enum_class_PerlUndef) {
- VTABLE_set_integer_native(INTERP, dest, pmci);
+ internal_exception(DIV_BY_ZERO, "division by zero!\n");
return;
}
valf = VTABLE_get_number(INTERP, value);
+ if (valf == 0.0) {
+ internal_exception(DIV_BY_ZERO, "division by zero!\n");
+ return;
+ }
+
divf = pmci / valf;
if (vtype == enum_class_PerlNum) {
VTABLE_set_number_native(INTERP, dest, divf);
1.11 +36 -1 parrot/t/pmc/perlint.t
Index: perlint.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/perlint.t,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -r1.10 -r1.11
--- perlint.t 22 Sep 2003 15:01:08 -0000 1.10
+++ perlint.t 20 Oct 2003 21:01:32 -0000 1.11
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 18;
+use Parrot::Test tests => 21;
use Parrot::PMC '%pmc_types';
my $perlint = $pmc_types{'PerlInt'};
my $ok = '"ok 1\n"';
@@ -400,6 +400,41 @@
6
3
1.500000
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "division by zero, #1");
+ new P0, .PerlInt
+ new P1, .PerlInt
+ new P2, .PerlUndef
+ set P0, 12
+ set P1, 0
+ div P2, P0, P1
+ end
+CODE
+division by zero!
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "division by zero, #2");
+ new P0, .PerlInt
+ new P1, .PerlUndef
+ new P2, .PerlUndef
+ set P0, 12
+ div P2, P0, P1
+ end
+CODE
+division by zero!
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "division by zero, #3");
+ new P0, .PerlInt
+ new P1, .PerlNum
+ new P2, .PerlUndef
+ set P0, 12
+ set P1, 0.0
+ div P2, P0, P1
+ end
+CODE
+division by zero!
OUTPUT
output_is(<<'CODE', <<OUTPUT, "subtract native integer from PerlInt");