Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:33:38

0001 /* Copyright (C) 2001-2023 Artifex Software, Inc.
0002    All Rights Reserved.
0003 
0004    This software is provided AS-IS with no warranty, either express or
0005    implied.
0006 
0007    This software is distributed under license and may not be copied,
0008    modified or distributed except as expressly authorized under the terms
0009    of the license contained in the file LICENSE in this distribution.
0010 
0011    Refer to licensing information at http://www.artifex.com or contact
0012    Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
0013    CA 94129, USA, for further information.
0014 */
0015 
0016 
0017 /* Error code definitions */
0018 
0019 #ifndef gserrors_INCLUDED
0020 #  define gserrors_INCLUDED
0021 
0022 /* A procedure that may return an error always returns */
0023 /* a non-negative value (zero, unless otherwise noted) for success, */
0024 /* or negative for failure. */
0025 /* We don't use a typedef internally to avoid a lot of casting. */
0026 
0027 enum gs_error_type {
0028     gs_error_ok = 0,
0029     gs_error_unknownerror = -1, /* unknown error */
0030     gs_error_dictfull = -2,
0031     gs_error_dictstackoverflow = -3,
0032     gs_error_dictstackunderflow = -4,
0033     gs_error_execstackoverflow = -5,
0034     gs_error_interrupt = -6,
0035     gs_error_invalidaccess = -7,
0036     gs_error_invalidexit = -8,
0037     gs_error_invalidfileaccess = -9,
0038     gs_error_invalidfont = -10,
0039     gs_error_invalidrestore = -11,
0040     gs_error_ioerror = -12,
0041     gs_error_limitcheck = -13,
0042     gs_error_nocurrentpoint = -14,
0043     gs_error_rangecheck = -15,
0044     gs_error_stackoverflow = -16,
0045     gs_error_stackunderflow = -17,
0046     gs_error_syntaxerror = -18,
0047     gs_error_timeout = -19,
0048     gs_error_typecheck = -20,
0049     gs_error_undefined = -21,
0050     gs_error_undefinedfilename = -22,
0051     gs_error_undefinedresult = -23,
0052     gs_error_unmatchedmark = -24,
0053     gs_error_VMerror = -25,     /* must be the last Level 1 error */
0054 
0055         /* ------ Additional Level 2 errors (also in DPS, ------ */
0056 
0057     gs_error_configurationerror = -26,
0058     gs_error_undefinedresource = -27,
0059 
0060     gs_error_unregistered = -28,
0061     gs_error_invalidcontext = -29,
0062 /* invalidid is for the NeXT DPS extension. */
0063     gs_error_invalidid = -30,
0064 
0065 /* We need a specific stackoverflow error for the PDF interpreter to avoid dropping into
0066  * the Postscript interpreter's stack extending code, when the PDF interpreter is called from
0067  * Postscript
0068  */
0069     gs_error_pdf_stackoverflow = -31,
0070 
0071 /* Internal error for the C-based PDF interpreter, to indicate a circular PDF reference */
0072     gs_error_circular_reference = -32,
0073 
0074         /* ------ Pseudo-errors used internally ------ */
0075 
0076     gs_error_hit_detected = -99,
0077 
0078     gs_error_Fatal = -100,
0079 /*
0080  * Internal code for the .quit operator.
0081  * The real quit code is an integer on the operand stack.
0082  * gs_interpret returns this only for a .quit with a zero exit code.
0083  */
0084     gs_error_Quit = -101,
0085 
0086 /*
0087  * Internal code for a normal exit from the interpreter.
0088  * Do not use outside of interp.c.
0089  */
0090     gs_error_InterpreterExit = -102,
0091 
0092 /* Need the remap color error for high level pattern support */
0093     gs_error_Remap_Color = -103,
0094 
0095 /*
0096  * Internal code to indicate we have underflowed the top block
0097  * of the e-stack.
0098  */
0099     gs_error_ExecStackUnderflow = -104,
0100 
0101 /*
0102  * Internal code for the vmreclaim operator with a positive operand.
0103  * We need to handle this as an error because otherwise the interpreter
0104  * won't reload enough of its state when the operator returns.
0105  */
0106     gs_error_VMreclaim = -105,
0107 
0108 /*
0109  * Internal code for requesting more input from run_string.
0110  */
0111     gs_error_NeedInput = -106,
0112 
0113 /*
0114  * Internal code to all run_string to request that the data is rerun
0115  * using run_file.
0116  */
0117     gs_error_NeedFile = -107,
0118 
0119 /*
0120  * Internal code for a normal exit when usage info is displayed.
0121  * This allows Window versions of Ghostscript to pause until
0122  * the message can be read.
0123  */
0124     gs_error_Info = -110,
0125 
0126 /* A special 'error', like reamp color above. This is used by a subclassing
0127  * device to indicate that it has fully processed a device method, and parent
0128  * subclasses should not perform any further action. Currently this is limited
0129  * to compositor creation.
0130  */
0131     gs_error_handled = -111,
0132 
0133 };
0134 
0135 /* We do provide a typedef type for external API use */
0136 typedef enum gs_error_type gs_error_t;
0137 
0138 int gs_log_error(int, const char *, int);
0139 #if !defined(DEBUG)
0140 #  define gs_log_error(err, file, line) (err)
0141 #endif
0142 #define gs_note_error(err) gs_log_error(err, __FILE__, __LINE__)
0143 #define return_error(err) return gs_note_error(err)
0144 
0145 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
0146 #  if defined(__GNUC__) && __GNUC__ >= 2
0147 #    define __func__ __FUNCTION__
0148 #  elif defined(__FUNCTION__)
0149 #    define __func__ __FUNCTION__
0150 #  elif defined(__FUNC__)
0151 #    define __func__ __FUNC__
0152 #  else
0153 #    define __func__ "<unknown>"
0154 #  endif
0155 #endif
0156 
0157 /*
0158  * Error reporting macros.
0159  *
0160  */
0161 
0162 #ifndef __printflike
0163 #if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
0164 #define __printflike(fmtarg, firstvararg) \
0165     __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
0166 #else
0167 #define __printflike(fmtarg, firstvararg)
0168 #endif
0169 #endif
0170 
0171 const char *gs_errstr(int code);
0172 
0173 int gs_throw_imp(const char *func, const char *file, int line,
0174         int op, int code, const char *fmt, ...) __printflike(6, 7);
0175 
0176 /* Use throw at origin of error
0177 */
0178 #define gs_throw_code(code) \
0179     gs_throw1((code), "%s", gs_errstr((code)))
0180 
0181 #define gs_throw(code, fmt) \
0182     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt)
0183 #define gs_throw1(code, fmt, arg1) \
0184     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1)
0185 #define gs_throw2(code, fmt, arg1, arg2) \
0186     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2)
0187 #define gs_throw3(code, fmt, arg1, arg2, arg3) \
0188     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3)
0189 #define gs_throw4(code, fmt, arg1, arg2, arg3, arg4) \
0190     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4)
0191 #define gs_throw5(code, fmt, arg1, arg2, arg3, arg4, arg5) \
0192     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4, arg5)
0193 #define gs_throw6(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
0194     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0195 #define gs_throw7(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
0196     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0197 #define gs_throw8(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
0198     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0199 #define gs_throw9(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
0200     gs_throw_imp(__func__, __FILE__, __LINE__, 0, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
0201 
0202 /* Bubble the code up the stack
0203 */
0204 #define gs_rethrow_code(code) \
0205     gs_rethrow1((code), "%s", gs_errstr((code)))
0206 
0207 #define gs_rethrow(code, fmt) \
0208     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt)
0209 #define gs_rethrow1(code, fmt, arg1) \
0210     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1)
0211 #define gs_rethrow2(code, fmt, arg1, arg2) \
0212     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2)
0213 #define gs_rethrow3(code, fmt, arg1, arg2, arg3) \
0214     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3)
0215 #define gs_rethrow4(code, fmt, arg1, arg2, arg3, arg4) \
0216     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4)
0217 #define gs_rethrow5(code, fmt, arg1, arg2, arg3, arg4, arg5) \
0218     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4, arg5)
0219 #define gs_rethrow6(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
0220     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0221 #define gs_rethrow7(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
0222     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0223 #define gs_rethrow8(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
0224     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0225 #define gs_rethrow9(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
0226     gs_throw_imp(__func__, __FILE__, __LINE__, 1, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
0227 
0228 /* This will cause trouble, as it implies you are fixing an error
0229  * the system will spew messages
0230  */
0231 #define gs_catch(code, fmt) \
0232     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt)
0233 #define gs_catch1(code, fmt, arg1) \
0234     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1)
0235 #define gs_catch2(code, fmt, arg1, arg2) \
0236     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2)
0237 #define gs_catch3(code, fmt, arg1, arg2, arg3) \
0238     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3)
0239 #define gs_catch4(code, fmt, arg1, arg2, arg3, arg4) \
0240     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4)
0241 #define gs_catch5(code, fmt, arg1, arg2, arg3, arg4, arg5) \
0242     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4, arg5)
0243 #define gs_catch6(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
0244     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0245 #define gs_catch7(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
0246     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0247 #define gs_catch8(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
0248     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0249 #define gs_catch9(code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
0250     gs_throw_imp(__func__, __FILE__, __LINE__, 2, code, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
0251 
0252 /* gs_warn is a printf
0253  */
0254 #define gs_warn(fmt) \
0255     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt)
0256 #define gs_warn1(fmt, arg1) \
0257     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1)
0258 #define gs_warn2(fmt, arg1, arg2) \
0259     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2)
0260 #define gs_warn3(fmt, arg1, arg2, arg3) \
0261     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3)
0262 #define gs_warn4(fmt, arg1, arg2, arg3, arg4) \
0263     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4)
0264 #define gs_warn5(fmt, arg1, arg2, arg3, arg4, arg5) \
0265     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4, arg5)
0266 #define gs_warn6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
0267     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4, arg5, arg6)
0268 #define gs_warn7(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
0269     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7)
0270 #define gs_warn8(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
0271     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
0272 #define gs_warn9(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \
0273     (void)gs_throw_imp(__func__, __FILE__, __LINE__, 3, 0, fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
0274 
0275 /* just in case you don't know 0 means no error
0276  * other return codes are errors.
0277  */
0278 #define gs_okay 0
0279 
0280 #endif /* gserrors_INCLUDED */