pyerrors.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Exception interface */
  2. #ifndef Py_PYERRORS_H
  3. #define Py_PYERRORS_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define PyExceptionClass_Check(x) \
  8. ((PyType_Check((x)) && \
  9. PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))
  10. #define PyExceptionInstance_Check(x) \
  11. (PyObject_IsSubclass((PyObject *)Py_TYPE(x), PyExc_BaseException))
  12. PyAPI_FUNC(PyObject *) PyErr_NewException(const char *name, PyObject *base, PyObject *dict);
  13. PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(const char *name, const char *doc, PyObject *base, PyObject *dict);
  14. PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *exception, const char *format, ...);
  15. /* These APIs aren't really part of the error implementation, but
  16. often needed to format error messages; the native C lib APIs are
  17. not available on all platforms, which is why we provide emulations
  18. for those platforms in Python/mysnprintf.c,
  19. WARNING: The return value of snprintf varies across platforms; do
  20. not rely on any particular behavior; eventually the C99 defn may
  21. be reliable.
  22. */
  23. #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
  24. # define HAVE_SNPRINTF
  25. # define snprintf _snprintf
  26. # define vsnprintf _vsnprintf
  27. #endif
  28. #include <stdarg.h>
  29. PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...);
  30. PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va);
  31. typedef struct {
  32. PyObject_HEAD /* xxx PyException_HEAD in CPython */
  33. PyObject *value;
  34. } PyStopIterationObject;
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif /* !Py_PYERRORS_H */