Skip to content

Commit 0fd17d6

Browse files
authored
Merge pull request #684 from mozbugbox/pageCount-with-exception
Guard pageCount, chapterCount with exceptions
2 parents e88eaa1 + 1820687 commit 0fd17d6

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

fitz/fitz.i

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,18 +872,34 @@ struct Document
872872
return doc;
873873
}
874874
875+
FITZEXCEPTION(pageCount, !result)
875876
CLOSECHECK0(pageCount, """Number of pages.""")
876877
%pythoncode%{@property%}
877878
PyObject *pageCount()
878879
{
879-
return Py_BuildValue("i", fz_count_pages(gctx, (fz_document *) $self));
880+
PyObject *ret;
881+
fz_try(gctx) {
882+
ret = Py_BuildValue("i", fz_count_pages(gctx, (fz_document *) $self));
883+
}
884+
fz_catch(gctx) {
885+
return NULL;
886+
}
887+
return ret;
880888
}
881889
890+
FITZEXCEPTION(chapterCount, !result)
882891
CLOSECHECK0(chapterCount, """Number of chapters.""")
883892
%pythoncode%{@property%}
884893
PyObject *chapterCount()
885894
{
886-
return Py_BuildValue("i", fz_count_chapters(gctx, (fz_document *) $self));
895+
PyObject *ret;
896+
fz_try(gctx) {
897+
ret = Py_BuildValue("i", fz_count_chapters(gctx, (fz_document *) $self));
898+
}
899+
fz_catch(gctx) {
900+
return NULL;
901+
}
902+
return ret;
887903
}
888904
889905
FITZEXCEPTION(lastLocation, !result)
@@ -907,9 +923,9 @@ struct Document
907923
CLOSECHECK0(chapterPageCount, """Page count of chapter.""")
908924
PyObject *chapterPageCount(int chapter)
909925
{
910-
int chapters = fz_count_chapters(gctx, (fz_document *) $self);
911926
int pages = 0;
912927
fz_try(gctx) {
928+
int chapters = fz_count_chapters(gctx, (fz_document *) $self);
913929
if (chapter < 0 || chapter >= chapters)
914930
THROWMSG("bad chapter number");
915931
pages = fz_count_chapter_pages(gctx, (fz_document *) $self, chapter);

0 commit comments

Comments
 (0)