Author: leo
Date: Mon Apr 11 08:06:28 2005
New Revision: 7805

Modified:
   trunk/include/parrot/exceptions.h
   trunk/ops/var.ops
   trunk/src/exceptions.c
Log:
fix segfault with no pads

Modified: trunk/include/parrot/exceptions.h
==============================================================================
--- trunk/include/parrot/exceptions.h   (original)
+++ trunk/include/parrot/exceptions.h   Mon Apr 11 08:06:28 2005
@@ -114,6 +114,7 @@
         NO_PREV_CS,
         NO_CLASS,
         LEX_NOT_FOUND,
+        PAD_NOT_FOUND,
         GLOBAL_NOT_FOUND,
         METH_NOT_FOUND,
         WRITE_TO_CONSTCLASS,

Modified: trunk/ops/var.ops
==============================================================================
--- trunk/ops/var.ops   (original)
+++ trunk/ops/var.ops   Mon Apr 11 08:06:28 2005
@@ -138,18 +138,27 @@
 
 op store_lex(in STR, in PMC) {
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, NULL, PAD_NOT_FOUND,
+               "empty lexical pad");
     scratchpad_store(interpreter, pad, $1, $2);
     goto NEXT();
 }
 
 op store_lex(in INT, in STR, in PMC) {
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, NULL, PAD_NOT_FOUND,
+               "empty lexical pad");
     scratchpad_store_by_name(interpreter, pad, $1, $2, $3);
     goto NEXT();
 }
 
 op store_lex(in INT, in INT, in PMC) {
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, NULL, PAD_NOT_FOUND,
+               "empty lexical pad");
     scratchpad_store_by_index(interpreter, pad, $1, $2, $3);
     goto NEXT();
 }
@@ -182,6 +191,9 @@
     opcode_t * next = expr NEXT();
     PMC *pad = scratchpad_get_current(interpreter);
     $1 = scratchpad_find(interpreter, pad, $2);
+    if (!pad)
+        real_exception(interpreter, next, PAD_NOT_FOUND,
+               "empty lexical pad");
     if (!$1)
         real_exception(interpreter, next, LEX_NOT_FOUND,
             "Lexical '%Ss' not found", $2);
@@ -191,6 +203,9 @@
 op find_lex(out PMC, in INT) {
     opcode_t * next = expr NEXT();
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, next, PAD_NOT_FOUND,
+               "empty lexical pad");
     $1 = scratchpad_get_by_index(interpreter, pad, -1, $2);
     if (!$1)
         real_exception(interpreter, next, LEX_NOT_FOUND,
@@ -201,6 +216,9 @@
 op find_lex(out PMC, in INT, in STR) {
     opcode_t * next = expr NEXT();
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, next, PAD_NOT_FOUND,
+               "empty lexical pad");
     $1 = scratchpad_get_by_name(interpreter, pad, $2, $3);
     if (!$1)
         real_exception(interpreter, next, LEX_NOT_FOUND,
@@ -211,6 +229,9 @@
 op find_lex(out PMC, in INT, in INT) {
     opcode_t * next = expr NEXT();
     PMC *pad = scratchpad_get_current(interpreter);
+    if (!pad)
+        real_exception(interpreter, next, PAD_NOT_FOUND,
+               "empty lexical pad");
     $1 = scratchpad_get_by_index(interpreter, pad, $2, $3);
     if (!$1)
         real_exception(interpreter, next, LEX_NOT_FOUND,

Modified: trunk/src/exceptions.c
==============================================================================
--- trunk/src/exceptions.c      (original)
+++ trunk/src/exceptions.c      Mon Apr 11 08:06:28 2005
@@ -520,7 +520,8 @@
      * if the exception number is in the range of our known exceptions
      * use the precreated exception
      */
-    if (the_exception->error <= E_LAST_PYTHON_E) {
+    if (the_exception->error <= E_LAST_PYTHON_E &&
+            the_exception->error >= 0) {
         exception = interpreter->exception_list[the_exception->error];
     }
     else {

Reply via email to