You need to sign in before continuing.
Commit 7f5d78c2d15565dd8a2357268f187045eb3ebc27
1 parent
75ea1971
improve C error handling interface
git-svn-id: svn+q:///qpdf/trunk@884 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
6 changed files
with
28 additions
and
13 deletions
examples/pdf-linearize.c
| @@ -24,7 +24,6 @@ int main(int argc, char* argv[]) | @@ -24,7 +24,6 @@ int main(int argc, char* argv[]) | ||
| 24 | int warnings = 0; | 24 | int warnings = 0; |
| 25 | int errors = 0; | 25 | int errors = 0; |
| 26 | char* p = 0; | 26 | char* p = 0; |
| 27 | - qpdf_error e = 0; | ||
| 28 | 27 | ||
| 29 | if ((p = strrchr(argv[0], '/')) != NULL) | 28 | if ((p = strrchr(argv[0], '/')) != NULL) |
| 30 | { | 29 | { |
| @@ -57,11 +56,11 @@ int main(int argc, char* argv[]) | @@ -57,11 +56,11 @@ int main(int argc, char* argv[]) | ||
| 57 | printf("warning: %s\n", | 56 | printf("warning: %s\n", |
| 58 | qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); | 57 | qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf))); |
| 59 | } | 58 | } |
| 60 | - e = qpdf_get_error(qpdf); | ||
| 61 | - if (e) | 59 | + if (qpdf_has_error(qpdf)) |
| 62 | { | 60 | { |
| 63 | errors = 1; | 61 | errors = 1; |
| 64 | - printf("error: %s\n", qpdf_get_error_full_text(qpdf, e)); | 62 | + printf("error: %s\n", |
| 63 | + qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf))); | ||
| 65 | } | 64 | } |
| 66 | qpdf_cleanup(&qpdf); | 65 | qpdf_cleanup(&qpdf); |
| 67 | if (errors) | 66 | if (errors) |
include/qpdf/Constants.h
| @@ -17,8 +17,7 @@ | @@ -17,8 +17,7 @@ | ||
| 17 | 17 | ||
| 18 | enum qpdf_error_code_e | 18 | enum qpdf_error_code_e |
| 19 | { | 19 | { |
| 20 | - qpdf_e_success = 0, | ||
| 21 | - qpdf_e_internal, /* logic/programming error -- indicates bug */ | 20 | + qpdf_e_internal = 1, /* logic/programming error -- indicates bug */ |
| 22 | qpdf_e_system, /* I/O error, memory error, etc. */ | 21 | qpdf_e_system, /* I/O error, memory error, etc. */ |
| 23 | qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */ | 22 | qpdf_e_unsupported, /* PDF feature not (yet) supported by qpdf */ |
| 24 | qpdf_e_password, /* incorrect password for encrypted file */ | 23 | qpdf_e_password, /* incorrect password for encrypted file */ |
include/qpdf/qpdf-c.h
| @@ -106,9 +106,18 @@ extern "C" { | @@ -106,9 +106,18 @@ extern "C" { | ||
| 106 | 106 | ||
| 107 | /* ERROR REPORTING */ | 107 | /* ERROR REPORTING */ |
| 108 | 108 | ||
| 109 | + /* Returns 1 if there is an error condition. The error condition | ||
| 110 | + * can be retrieved by a single call to qpdf_get_error. | ||
| 111 | + */ | ||
| 112 | + QPDF_DLL | ||
| 113 | + QPDF_BOOL qpdf_has_error(qpdf_data qpdf); | ||
| 114 | + | ||
| 109 | /* Returns the error condition, if any. The return value is a | 115 | /* Returns the error condition, if any. The return value is a |
| 110 | - * pointer to data that will become invalid the next time an error | ||
| 111 | - * occurs or after this function is called gain. | 116 | + * pointer to data that will become invalid after the next call to |
| 117 | + * this function, qpdf_next_warning, or qpdf_destroy. After this | ||
| 118 | + * function is called, qpdf_has_error will return QPDF_FALSE until | ||
| 119 | + * the next error condition occurs. If there is no error | ||
| 120 | + * condition, this function returns a null pointer. | ||
| 112 | */ | 121 | */ |
| 113 | QPDF_DLL | 122 | QPDF_DLL |
| 114 | qpdf_error qpdf_get_error(qpdf_data qpdf); | 123 | qpdf_error qpdf_get_error(qpdf_data qpdf); |
| @@ -133,7 +142,8 @@ extern "C" { | @@ -133,7 +142,8 @@ extern "C" { | ||
| 133 | char const* qpdf_get_error_full_text(qpdf_data q, qpdf_error e); | 142 | char const* qpdf_get_error_full_text(qpdf_data q, qpdf_error e); |
| 134 | 143 | ||
| 135 | /* Use these functions to extract individual fields from the | 144 | /* Use these functions to extract individual fields from the |
| 136 | - * error; see QPDFExc.hh for details. */ | 145 | + * error; see QPDFExc.hh for details. It is invalid for e to be a |
| 146 | + * null pointer for any of these calls. */ | ||
| 137 | QPDF_DLL | 147 | QPDF_DLL |
| 138 | enum qpdf_error_code_e qpdf_get_error_code(qpdf_data q, qpdf_error e); | 148 | enum qpdf_error_code_e qpdf_get_error_code(qpdf_data q, qpdf_error e); |
| 139 | QPDF_DLL | 149 | QPDF_DLL |
libqpdf/qpdf-c.cc
| @@ -128,13 +128,19 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf) | @@ -128,13 +128,19 @@ QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf) | ||
| 128 | } | 128 | } |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | +QPDF_BOOL qpdf_has_error(qpdf_data qpdf) | ||
| 132 | +{ | ||
| 133 | + QTC::TC("qpdf", "qpdf-c called qpdf_has_error"); | ||
| 134 | + return (qpdf->error.getPointer() ? QPDF_TRUE : QPDF_FALSE); | ||
| 135 | +} | ||
| 136 | + | ||
| 131 | qpdf_error qpdf_get_error(qpdf_data qpdf) | 137 | qpdf_error qpdf_get_error(qpdf_data qpdf) |
| 132 | { | 138 | { |
| 133 | if (qpdf->error.getPointer()) | 139 | if (qpdf->error.getPointer()) |
| 134 | { | 140 | { |
| 135 | qpdf->tmp_error.exc = qpdf->error; | 141 | qpdf->tmp_error.exc = qpdf->error; |
| 136 | qpdf->error = 0; | 142 | qpdf->error = 0; |
| 137 | - QTC::TC("qpdf", "qpdf-c qpdf_next_error returned error"); | 143 | + QTC::TC("qpdf", "qpdf-c qpdf_get_error returned error"); |
| 138 | return &qpdf->tmp_error; | 144 | return &qpdf->tmp_error; |
| 139 | } | 145 | } |
| 140 | else | 146 | else |
qpdf/qpdf-ctest.c
| @@ -18,9 +18,9 @@ static void report_errors() | @@ -18,9 +18,9 @@ static void report_errors() | ||
| 18 | printf(" pos : %ld\n", qpdf_get_error_file_position(qpdf, e)); | 18 | printf(" pos : %ld\n", qpdf_get_error_file_position(qpdf, e)); |
| 19 | printf(" text: %s\n", qpdf_get_error_message_detail(qpdf, e)); | 19 | printf(" text: %s\n", qpdf_get_error_message_detail(qpdf, e)); |
| 20 | } | 20 | } |
| 21 | - e = qpdf_get_error(qpdf); | ||
| 22 | - if (e) | 21 | + if (qpdf_has_error(qpdf)) |
| 23 | { | 22 | { |
| 23 | + e = qpdf_get_error(qpdf); | ||
| 24 | printf("error: %s\n", qpdf_get_error_full_text(qpdf, e)); | 24 | printf("error: %s\n", qpdf_get_error_full_text(qpdf, e)); |
| 25 | printf(" code: %d\n", qpdf_get_error_code(qpdf, e)); | 25 | printf(" code: %d\n", qpdf_get_error_code(qpdf, e)); |
| 26 | printf(" file: %s\n", qpdf_get_error_filename(qpdf, e)); | 26 | printf(" file: %s\n", qpdf_get_error_filename(qpdf, e)); |
qpdf/qpdf.testcov
| @@ -121,7 +121,7 @@ QPDF_Stream ignore non-dictionary DecodeParms 0 | @@ -121,7 +121,7 @@ QPDF_Stream ignore non-dictionary DecodeParms 0 | ||
| 121 | qpdf-c called qpdf_init 0 | 121 | qpdf-c called qpdf_init 0 |
| 122 | qpdf-c called qpdf_cleanup 0 | 122 | qpdf-c called qpdf_cleanup 0 |
| 123 | qpdf-c called qpdf_more_warnings 0 | 123 | qpdf-c called qpdf_more_warnings 0 |
| 124 | -qpdf-c qpdf_next_error returned error 0 | 124 | +qpdf-c qpdf_get_error returned error 0 |
| 125 | qpdf-c qpdf_next_warning returned warning 0 | 125 | qpdf-c qpdf_next_warning returned warning 0 |
| 126 | qpdf-c called qpdf_set_suppress_warnings 0 | 126 | qpdf-c called qpdf_set_suppress_warnings 0 |
| 127 | qpdf-c called qpdf_set_ignore_xref_streams 0 | 127 | qpdf-c called qpdf_set_ignore_xref_streams 0 |
| @@ -172,3 +172,4 @@ qpdf-c called qpdf_set_static_aes_IV 0 | @@ -172,3 +172,4 @@ qpdf-c called qpdf_set_static_aes_IV 0 | ||
| 172 | QPDF_encryption stream crypt filter 0 | 172 | QPDF_encryption stream crypt filter 0 |
| 173 | QPDF ERR object stream with wrong type 0 | 173 | QPDF ERR object stream with wrong type 0 |
| 174 | QPDF object gone after xref reconstruction 0 | 174 | QPDF object gone after xref reconstruction 0 |
| 175 | +qpdf-c called qpdf_has_error 0 |