Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
11 KiB

  1. #ifndef Py_ERRORS_H
  2. #define Py_ERRORS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Error objects */
  7. typedef struct {
  8. PyObject_HEAD
  9. PyObject *dict;
  10. PyObject *args;
  11. PyObject *message;
  12. } PyBaseExceptionObject;
  13. typedef struct {
  14. PyObject_HEAD
  15. PyObject *dict;
  16. PyObject *args;
  17. PyObject *message;
  18. PyObject *msg;
  19. PyObject *filename;
  20. PyObject *lineno;
  21. PyObject *offset;
  22. PyObject *text;
  23. PyObject *print_file_and_line;
  24. } PySyntaxErrorObject;
  25. #ifdef Py_USING_UNICODE
  26. typedef struct {
  27. PyObject_HEAD
  28. PyObject *dict;
  29. PyObject *args;
  30. PyObject *message;
  31. PyObject *encoding;
  32. PyObject *object;
  33. PyObject *start;
  34. PyObject *end;
  35. PyObject *reason;
  36. } PyUnicodeErrorObject;
  37. #endif
  38. typedef struct {
  39. PyObject_HEAD
  40. PyObject *dict;
  41. PyObject *args;
  42. PyObject *message;
  43. PyObject *code;
  44. } PySystemExitObject;
  45. typedef struct {
  46. PyObject_HEAD
  47. PyObject *dict;
  48. PyObject *args;
  49. PyObject *message;
  50. PyObject *myerrno;
  51. PyObject *strerror;
  52. PyObject *filename;
  53. } PyEnvironmentErrorObject;
  54. #ifdef MS_WINDOWS
  55. typedef struct {
  56. PyObject_HEAD
  57. PyObject *dict;
  58. PyObject *args;
  59. PyObject *message;
  60. PyObject *myerrno;
  61. PyObject *strerror;
  62. PyObject *filename;
  63. PyObject *winerror;
  64. } PyWindowsErrorObject;
  65. #endif
  66. /* Error handling definitions */
  67. PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
  68. PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
  69. PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
  70. PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
  71. PyAPI_FUNC(void) PyErr_Clear(void);
  72. PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
  73. PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
  74. #ifdef Py_DEBUG
  75. #define _PyErr_OCCURRED() PyErr_Occurred()
  76. #else
  77. #define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
  78. #endif
  79. /* Error testing and normalization */
  80. PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
  81. PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
  82. PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
  83. /* */
  84. #define PyExceptionClass_Check(x) \
  85. (PyClass_Check((x)) \
  86. || (PyType_Check((x)) && PyType_IsSubtype( \
  87. (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException)))
  88. #define PyExceptionInstance_Check(x) \
  89. (PyInstance_Check((x)) || \
  90. (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException)))
  91. #define PyExceptionClass_Name(x) \
  92. (PyClass_Check((x)) \
  93. ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
  94. : (char *)(((PyTypeObject*)(x))->tp_name))
  95. #define PyExceptionInstance_Class(x) \
  96. ((PyInstance_Check((x)) \
  97. ? (PyObject*)((PyInstanceObject*)(x))->in_class \
  98. : (PyObject*)((x)->ob_type)))
  99. /* Predefined exceptions */
  100. PyAPI_DATA(PyObject *) PyExc_BaseException;
  101. PyAPI_DATA(PyObject *) PyExc_Exception;
  102. PyAPI_DATA(PyObject *) PyExc_StopIteration;
  103. PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
  104. PyAPI_DATA(PyObject *) PyExc_StandardError;
  105. PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
  106. PyAPI_DATA(PyObject *) PyExc_LookupError;
  107. PyAPI_DATA(PyObject *) PyExc_AssertionError;
  108. PyAPI_DATA(PyObject *) PyExc_AttributeError;
  109. PyAPI_DATA(PyObject *) PyExc_EOFError;
  110. PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
  111. PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
  112. PyAPI_DATA(PyObject *) PyExc_IOError;
  113. PyAPI_DATA(PyObject *) PyExc_OSError;
  114. PyAPI_DATA(PyObject *) PyExc_ImportError;
  115. PyAPI_DATA(PyObject *) PyExc_IndexError;
  116. PyAPI_DATA(PyObject *) PyExc_KeyError;
  117. PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
  118. PyAPI_DATA(PyObject *) PyExc_MemoryError;
  119. PyAPI_DATA(PyObject *) PyExc_NameError;
  120. PyAPI_DATA(PyObject *) PyExc_OverflowError;
  121. PyAPI_DATA(PyObject *) PyExc_RuntimeError;
  122. PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
  123. PyAPI_DATA(PyObject *) PyExc_SyntaxError;
  124. PyAPI_DATA(PyObject *) PyExc_IndentationError;
  125. PyAPI_DATA(PyObject *) PyExc_TabError;
  126. PyAPI_DATA(PyObject *) PyExc_ReferenceError;
  127. PyAPI_DATA(PyObject *) PyExc_SystemError;
  128. PyAPI_DATA(PyObject *) PyExc_SystemExit;
  129. PyAPI_DATA(PyObject *) PyExc_TypeError;
  130. PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
  131. PyAPI_DATA(PyObject *) PyExc_UnicodeError;
  132. PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
  133. PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
  134. PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
  135. PyAPI_DATA(PyObject *) PyExc_ValueError;
  136. PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
  137. #ifdef MS_WINDOWS
  138. PyAPI_DATA(PyObject *) PyExc_WindowsError;
  139. #endif
  140. #ifdef __VMS
  141. PyAPI_DATA(PyObject *) PyExc_VMSError;
  142. #endif
  143. PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
  144. /* Predefined warning categories */
  145. PyAPI_DATA(PyObject *) PyExc_Warning;
  146. PyAPI_DATA(PyObject *) PyExc_UserWarning;
  147. PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
  148. PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
  149. PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
  150. PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
  151. PyAPI_DATA(PyObject *) PyExc_FutureWarning;
  152. PyAPI_DATA(PyObject *) PyExc_ImportWarning;
  153. PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
  154. /* Convenience functions */
  155. PyAPI_FUNC(int) PyErr_BadArgument(void);
  156. PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
  157. PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
  158. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
  159. PyObject *, PyObject *);
  160. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
  161. #ifdef Py_WIN_WIDE_FILENAMES
  162. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
  163. PyObject *, Py_UNICODE *);
  164. #endif /* Py_WIN_WIDE_FILENAMES */
  165. PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
  166. Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
  167. #ifdef MS_WINDOWS
  168. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
  169. int, const char *);
  170. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
  171. int, const char *);
  172. #ifdef Py_WIN_WIDE_FILENAMES
  173. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
  174. int, const Py_UNICODE *);
  175. #endif /* Py_WIN_WIDE_FILENAMES */
  176. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
  177. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
  178. PyObject *,int, PyObject *);
  179. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
  180. PyObject *,int, const char *);
  181. #ifdef Py_WIN_WIDE_FILENAMES
  182. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
  183. PyObject *,int, const Py_UNICODE *);
  184. #endif /* Py_WIN_WIDE_FILENAMES */
  185. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
  186. #endif /* MS_WINDOWS */
  187. /* Export the old function so that the existing API remains available: */
  188. PyAPI_FUNC(void) PyErr_BadInternalCall(void);
  189. PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
  190. /* Mask the old API with a call to the new API for code compiled under
  191. Python 2.0: */
  192. #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
  193. /* Function to create a new exception */
  194. PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
  195. PyObject *dict);
  196. PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
  197. /* Issue a warning or exception */
  198. PyAPI_FUNC(int) PyErr_WarnEx(PyObject *category, const char *msg,
  199. Py_ssize_t stack_level);
  200. PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *,
  201. const char *, int,
  202. const char *, PyObject *);
  203. /* PyErr_Warn is only for backwards compatability and will be removed.
  204. Use PyErr_WarnEx instead. */
  205. #define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
  206. /* In sigcheck.c or signalmodule.c */
  207. PyAPI_FUNC(int) PyErr_CheckSignals(void);
  208. PyAPI_FUNC(void) PyErr_SetInterrupt(void);
  209. /* Support for adding program text to SyntaxErrors */
  210. PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
  211. PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
  212. #ifdef Py_USING_UNICODE
  213. /* The following functions are used to create and modify unicode
  214. exceptions from C */
  215. /* create a UnicodeDecodeError object */
  216. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
  217. const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  218. /* create a UnicodeEncodeError object */
  219. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
  220. const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  221. /* create a UnicodeTranslateError object */
  222. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
  223. const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  224. /* get the encoding attribute */
  225. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
  226. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
  227. /* get the object attribute */
  228. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
  229. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
  230. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
  231. /* get the value of the start attribute (the int * may not be NULL)
  232. return 0 on success, -1 on failure */
  233. PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
  234. PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
  235. PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
  236. /* assign a new value to the start attribute
  237. return 0 on success, -1 on failure */
  238. PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
  239. PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
  240. PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
  241. /* get the value of the end attribute (the int *may not be NULL)
  242. return 0 on success, -1 on failure */
  243. PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
  244. PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
  245. PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
  246. /* assign a new value to the end attribute
  247. return 0 on success, -1 on failure */
  248. PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
  249. PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
  250. PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
  251. /* get the value of the reason attribute */
  252. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
  253. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
  254. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
  255. /* assign a new value to the reason attribute
  256. return 0 on success, -1 on failure */
  257. PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
  258. PyObject *, const char *);
  259. PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
  260. PyObject *, const char *);
  261. PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
  262. PyObject *, const char *);
  263. #endif
  264. /* These APIs aren't really part of the error implementation, but
  265. often needed to format error messages; the native C lib APIs are
  266. not available on all platforms, which is why we provide emulations
  267. for those platforms in Python/mysnprintf.c,
  268. WARNING: The return value of snprintf varies across platforms; do
  269. not rely on any particular behavior; eventually the C99 defn may
  270. be reliable.
  271. */
  272. #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
  273. # define HAVE_SNPRINTF
  274. # define snprintf _snprintf
  275. # define vsnprintf _vsnprintf
  276. #endif
  277. #include <stdarg.h>
  278. PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
  279. Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
  280. PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
  281. Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
  282. #ifdef __cplusplus
  283. }
  284. #endif
  285. #endif /* !Py_ERRORS_H */