summaryrefslogtreecommitdiffstats
path: root/Modules/imgfile.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-03-23 18:21:32 (GMT)
committerGuido van Rossum <guido@python.org>1992-03-23 18:21:32 (GMT)
commit3e94197a524fde94311e4dc9c076bb6047a02b57 (patch)
tree216dd2ae11c26af71cde4ba2a4d2859d8d407ee1 /Modules/imgfile.c
parentb3a0e4c842c5dd207518a95e2c9f0e68b79e0364 (diff)
downloadcpython-3e94197a524fde94311e4dc9c076bb6047a02b57.zip
cpython-3e94197a524fde94311e4dc9c076bb6047a02b57.tar.gz
cpython-3e94197a524fde94311e4dc9c076bb6047a02b57.tar.bz2
Improved error handling.
Diffstat (limited to 'Modules/imgfile.c')
-rw-r--r--Modules/imgfile.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/imgfile.c b/Modules/imgfile.c
index 4c452d6..8bf6d06 100644
--- a/Modules/imgfile.c
+++ b/Modules/imgfile.c
@@ -43,6 +43,15 @@ static object * ImgfileError;
static char gfname[1024];
static IMAGE *image;
+static int error_called;
+
+static imgfile_error(str)
+ char *str;
+{
+ err_setstr(ImgfileError, str);
+ error_called = 1;
+ return; /* To imglib, which will return a failure indictaor */
+}
static
imgfile_open(args)
@@ -52,13 +61,17 @@ imgfile_open(args)
if ( !getargs(args, "s", &fname) )
return 0;
+ i_seterror(imgfile_error);
+ error_called = 0;
if ( image != NULL && strcmp(fname, gfname) != 0 ) {
iclose(image);
image = NULL;
gfname[0] = '\0';
}
if ( (image=iopen(fname, "r")) == NULL ) {
- err_setstr(ImgfileError, "Cannot open image file");
+ /* Error may already be set by imgfile_error */
+ if ( !error_called )
+ err_setstr(ImgfileError, "Cannot open image file");
return 0;
}
strcpy(gfname, fname);
@@ -103,7 +116,7 @@ imgfile_read(self, args)
return NULL;
cdatap = getstringvalue(rv);
idatap = (long *)cdatap;
- for ( y=0; y < ysize; y++ ) {
+ for ( y=0; y < ysize && !error_called; y++ ) {
if ( zsize == 1 ) {
getrow(image, rs, y, 0);
for(x=0; x<xsize; x++ )
@@ -118,6 +131,10 @@ imgfile_read(self, args)
((bs[x] & 0xff)<<16);
}
}
+ if ( error_called ) {
+ DECREF(rv);
+ return NULL;
+ }
return rv;
}