OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2006-2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 #ifndef INCLUDED_NVERROR_H |
| 34 #define INCLUDED_NVERROR_H |
| 35 |
| 36 /** |
| 37 * @defgroup nverror Error Handling |
| 38 * |
| 39 * nverror.h contains our error code enumeration and helper macros. |
| 40 * |
| 41 * @{ |
| 42 */ |
| 43 |
| 44 /** |
| 45 * The NvError enumeration contains ALL return / error codes. Error codes |
| 46 * are specifically explicit to make it easy to identify where an error |
| 47 * came from. |
| 48 * |
| 49 * All error codes are derived from the macros in nverrval.h. |
| 50 * @ingroup nv_errors |
| 51 */ |
| 52 typedef enum |
| 53 { |
| 54 #define NVERROR(_name_, _value_, _desc_) NvError_##_name_ = _value_, |
| 55 /* header included for macro expansion of error codes */ |
| 56 #include "nverrval.h" |
| 57 #undef NVERROR |
| 58 |
| 59 // An alias for success |
| 60 NvSuccess = NvError_Success, |
| 61 |
| 62 NvError_Force32 = 0x7FFFFFFF |
| 63 } NvError; |
| 64 |
| 65 /** |
| 66 * A helper macro to check a function's error return code and propagate any |
| 67 * errors upward. This assumes that no cleanup is necessary in the event of |
| 68 * failure. This macro does not locally define its own NvError variable out of |
| 69 * fear that this might burn too much stack space, particularly in debug builds |
| 70 * or with mediocre optimizing compilers. The user of this macro is therefore |
| 71 * expected to provide their own local variable "NvError e;". |
| 72 */ |
| 73 #define NV_CHECK_ERROR(expr) \ |
| 74 do \ |
| 75 { \ |
| 76 e = (expr); \ |
| 77 if (e != NvSuccess) \ |
| 78 return e; \ |
| 79 } while (0) |
| 80 |
| 81 /** |
| 82 * A helper macro to check a function's error return code and, if an error |
| 83 * occurs, jump to a label where cleanup can take place. Like NV_CHECK_ERROR, |
| 84 * this macro does not locally define its own NvError variable. (Even if we |
| 85 * wanted it to, this one can't, because the code at the "fail" label probably |
| 86 * needs to do a "return e;" to propagate the error upwards.) |
| 87 */ |
| 88 #define NV_CHECK_ERROR_CLEANUP(expr) \ |
| 89 do \ |
| 90 { \ |
| 91 e = (expr); \ |
| 92 if (e != NvSuccess) \ |
| 93 goto fail; \ |
| 94 } while (0) |
| 95 |
| 96 |
| 97 /** |
| 98 * Prints err if it is an error (does nothing if err==NvSuccess). |
| 99 * Always returns err unchanged |
| 100 * never prints anything if err==NvSuccess) |
| 101 * |
| 102 * NOTE: Do not use this with errors that are expected to occur under normal |
| 103 * situations. |
| 104 * |
| 105 * @param err - the error to return |
| 106 * @returns err |
| 107 */ |
| 108 #define NV_SHOW_ERRORS NV_DEBUG |
| 109 #if NV_SHOW_ERRORS |
| 110 #define NV_SHOW_ERROR(err) NvOsShowError(err,__FILE__,__LINE__) |
| 111 #else |
| 112 #define NV_SHOW_ERROR(err) (err) |
| 113 #endif |
| 114 |
| 115 |
| 116 /** @} */ |
| 117 |
| 118 #endif // INCLUDED_NVERROR_H |
OLD | NEW |