Commits

Anonymous committed de1cb33

Jeremy's patches for more robust handling of unmarshallable types.

Comments (0)

Files changed (1)

 
 typedef struct {
 	FILE *fp;
+	int error;
 	/* If fp == NULL, the following are valid: */
 	object *str;
 	char *ptr;
 	}
 	else {
 		w_byte(TYPE_UNKNOWN, p);
+		p->error = 1;
 	}
 }
 
 {
 	WFILE wf;
 	wf.fp = fp;
+	wf.error = 0;
 	w_long(x, &wf);
 }
 
 {
 	WFILE wf;
 	wf.fp = fp;
+	wf.error = 0;
 	w_object(x, &wf);
 }
 
 			object *key, *val;
 			key = r_object(p);
 			if (key == NULL)
-				break; /* XXXX and how about memory errors? */
+				break; /* XXX Assume TYPE_NULL, not an error */
 			val = r_object(p);
-			/* XXXX error check? */
-			dict2insert(v, key, val);
+			if (val != NULL)
+				dict2insert(v, key, val);
 			DECREF(key);
 			XDECREF(val);
 		}
 		return v;
 	
 	default:
-		err_setstr(TypeError, "read unknown object");
-		return NULL;
+		/* Bogus data got written, which isn't ideal.
+		   This will let you keep working and recover. */
+		INCREF(None);
+		return None;
 	
 	}
 }
 	wf.fp = getfilefile(f);
 	wf.str = NULL;
 	wf.ptr = wf.end = NULL;
+	wf.error = 0;
 	w_object(x, &wf);
+	if (wf.error) {
+		err_setstr(ValueError, "unmarshallable object");
+		return NULL;
+	}
 	INCREF(None);
 	return None;
 }
 		return NULL;
 	wf.ptr = GETSTRINGVALUE((stringobject *)wf.str);
 	wf.end = wf.ptr + getstringsize(wf.str);
+	wf.error = 0;
 	w_object(x, &wf);
 	if (wf.str != NULL)
 		resizestring(&wf.str,
 		    (int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str)));
+	if (wf.error) {
+		XDECREF(wf.str);
+		err_setstr(ValueError, "unmarshallable object");
+		return NULL;
+	}
 	return wf.str;
 }