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.

328 lines
11 KiB

36 years ago
36 years ago
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/trunk-bytearray ........ r61750 | christian.heimes | 2008-03-22 20:47:44 +0100 (Sat, 22 Mar 2008) | 1 line Copied files from py3k w/o modifications ........ r61752 | christian.heimes | 2008-03-22 20:53:20 +0100 (Sat, 22 Mar 2008) | 7 lines Take One * Added initialization code, warnings, flags etc. to the appropriate places * Added new buffer interface to string type * Modified tests * Modified Makefile.pre.in to compile the new files * Added bytesobject.c to Python.h ........ r61754 | christian.heimes | 2008-03-22 21:22:19 +0100 (Sat, 22 Mar 2008) | 2 lines Disabled bytearray.extend for now since it causes an infinite recursion Fixed serveral unit tests ........ r61756 | christian.heimes | 2008-03-22 21:43:38 +0100 (Sat, 22 Mar 2008) | 5 lines Added PyBytes support to several places: str + bytearray ord(bytearray) bytearray(str, encoding) ........ r61760 | christian.heimes | 2008-03-22 21:56:32 +0100 (Sat, 22 Mar 2008) | 1 line Fixed more unit tests related to type('') is not unicode ........ r61763 | christian.heimes | 2008-03-22 22:20:28 +0100 (Sat, 22 Mar 2008) | 2 lines Fixed more unit tests Fixed bytearray.extend ........ r61768 | christian.heimes | 2008-03-22 22:40:50 +0100 (Sat, 22 Mar 2008) | 1 line Implemented old buffer interface for bytearray ........ r61772 | christian.heimes | 2008-03-22 23:24:52 +0100 (Sat, 22 Mar 2008) | 1 line Added backport of the io module ........ r61775 | christian.heimes | 2008-03-23 03:50:49 +0100 (Sun, 23 Mar 2008) | 1 line Fix str assignement to bytearray. Assignment of a str of size 1 is interpreted as a single byte ........ r61805 | christian.heimes | 2008-03-23 19:33:48 +0100 (Sun, 23 Mar 2008) | 3 lines Fixed more tests Fixed bytearray() comparsion with unicode() Fixed iterator assignment of bytearray ........ r61809 | christian.heimes | 2008-03-23 21:02:21 +0100 (Sun, 23 Mar 2008) | 2 lines str(bytesarray()) now returns the bytes and not the representation of the bytearray object Enabled and fixed more unit tests ........ r61812 | christian.heimes | 2008-03-23 21:53:08 +0100 (Sun, 23 Mar 2008) | 3 lines Clear error PyNumber_AsSsize_t() fails Use CHARMASK for ob_svall access disabled a test with memoryview again ........ r61819 | christian.heimes | 2008-03-23 23:05:57 +0100 (Sun, 23 Mar 2008) | 1 line Untested updates to the PCBuild directory ........ r61917 | christian.heimes | 2008-03-26 00:57:06 +0100 (Wed, 26 Mar 2008) | 1 line The type system of Python 2.6 has subtle differences to 3.0's. I've removed the Py_TPFLAGS_BASETYPE flags from bytearray for now. bytearray can't be subclasses until the issues with bytearray subclasses are fixed. ........ r61920 | christian.heimes | 2008-03-26 01:44:08 +0100 (Wed, 26 Mar 2008) | 2 lines Disabled last failing test I don't understand what the test is testing and how it suppose to work. Ka-Ping, please check it out. ........ r61930 | christian.heimes | 2008-03-26 12:46:18 +0100 (Wed, 26 Mar 2008) | 1 line Re-enabled bytes warning code ........ r61933 | christian.heimes | 2008-03-26 13:20:46 +0100 (Wed, 26 Mar 2008) | 1 line Fixed a bug in the new buffer protocol. The buffer slots weren't copied into a subclass. ........ r61934 | christian.heimes | 2008-03-26 13:25:09 +0100 (Wed, 26 Mar 2008) | 1 line Re-enabled bytearray subclassing - all tests are passing. ........
19 years ago
  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. Py_ssize_t start;
  34. Py_ssize_t 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)) || (PyType_Check((x)) && \
  86. PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS)))
  87. #define PyExceptionInstance_Check(x) \
  88. (PyInstance_Check((x)) || \
  89. PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS))
  90. #define PyExceptionClass_Name(x) \
  91. (PyClass_Check((x)) \
  92. ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
  93. : (char *)(((PyTypeObject*)(x))->tp_name))
  94. #define PyExceptionInstance_Class(x) \
  95. ((PyInstance_Check((x)) \
  96. ? (PyObject*)((PyInstanceObject*)(x))->in_class \
  97. : (PyObject*)((x)->ob_type)))
  98. /* Predefined exceptions */
  99. PyAPI_DATA(PyObject *) PyExc_BaseException;
  100. PyAPI_DATA(PyObject *) PyExc_Exception;
  101. PyAPI_DATA(PyObject *) PyExc_StopIteration;
  102. PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
  103. PyAPI_DATA(PyObject *) PyExc_StandardError;
  104. PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
  105. PyAPI_DATA(PyObject *) PyExc_LookupError;
  106. PyAPI_DATA(PyObject *) PyExc_AssertionError;
  107. PyAPI_DATA(PyObject *) PyExc_AttributeError;
  108. PyAPI_DATA(PyObject *) PyExc_EOFError;
  109. PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
  110. PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
  111. PyAPI_DATA(PyObject *) PyExc_IOError;
  112. PyAPI_DATA(PyObject *) PyExc_OSError;
  113. PyAPI_DATA(PyObject *) PyExc_ImportError;
  114. PyAPI_DATA(PyObject *) PyExc_IndexError;
  115. PyAPI_DATA(PyObject *) PyExc_KeyError;
  116. PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
  117. PyAPI_DATA(PyObject *) PyExc_MemoryError;
  118. PyAPI_DATA(PyObject *) PyExc_NameError;
  119. PyAPI_DATA(PyObject *) PyExc_OverflowError;
  120. PyAPI_DATA(PyObject *) PyExc_RuntimeError;
  121. PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
  122. PyAPI_DATA(PyObject *) PyExc_SyntaxError;
  123. PyAPI_DATA(PyObject *) PyExc_IndentationError;
  124. PyAPI_DATA(PyObject *) PyExc_TabError;
  125. PyAPI_DATA(PyObject *) PyExc_ReferenceError;
  126. PyAPI_DATA(PyObject *) PyExc_SystemError;
  127. PyAPI_DATA(PyObject *) PyExc_SystemExit;
  128. PyAPI_DATA(PyObject *) PyExc_TypeError;
  129. PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
  130. PyAPI_DATA(PyObject *) PyExc_UnicodeError;
  131. PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
  132. PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
  133. PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
  134. PyAPI_DATA(PyObject *) PyExc_ValueError;
  135. PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
  136. #ifdef MS_WINDOWS
  137. PyAPI_DATA(PyObject *) PyExc_WindowsError;
  138. #endif
  139. #ifdef __VMS
  140. PyAPI_DATA(PyObject *) PyExc_VMSError;
  141. #endif
  142. PyAPI_DATA(PyObject *) PyExc_BufferError;
  143. PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
  144. PyAPI_DATA(PyObject *) PyExc_RecursionErrorInst;
  145. /* Predefined warning categories */
  146. PyAPI_DATA(PyObject *) PyExc_Warning;
  147. PyAPI_DATA(PyObject *) PyExc_UserWarning;
  148. PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
  149. PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
  150. PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
  151. PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
  152. PyAPI_DATA(PyObject *) PyExc_FutureWarning;
  153. PyAPI_DATA(PyObject *) PyExc_ImportWarning;
  154. PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
  155. PyAPI_DATA(PyObject *) PyExc_BytesWarning;
  156. /* Convenience functions */
  157. PyAPI_FUNC(int) PyErr_BadArgument(void);
  158. PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
  159. PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
  160. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
  161. PyObject *, PyObject *);
  162. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
  163. PyObject *, const char *);
  164. #ifdef MS_WINDOWS
  165. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
  166. PyObject *, const Py_UNICODE *);
  167. #endif /* MS_WINDOWS */
  168. PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
  169. Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
  170. #ifdef MS_WINDOWS
  171. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
  172. int, const char *);
  173. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
  174. int, const char *);
  175. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
  176. int, const Py_UNICODE *);
  177. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
  178. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
  179. PyObject *,int, PyObject *);
  180. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
  181. PyObject *,int, const char *);
  182. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
  183. PyObject *,int, const Py_UNICODE *);
  184. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
  185. #endif /* MS_WINDOWS */
  186. /* Export the old function so that the existing API remains available: */
  187. PyAPI_FUNC(void) PyErr_BadInternalCall(void);
  188. PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
  189. /* Mask the old API with a call to the new API for code compiled under
  190. Python 2.0: */
  191. #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
  192. /* Function to create a new exception */
  193. PyAPI_FUNC(PyObject *) PyErr_NewException(
  194. char *name, PyObject *base, PyObject *dict);
  195. PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
  196. char *name, char *doc, PyObject *base, PyObject *dict);
  197. PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
  198. /* In sigcheck.c or signalmodule.c */
  199. PyAPI_FUNC(int) PyErr_CheckSignals(void);
  200. PyAPI_FUNC(void) PyErr_SetInterrupt(void);
  201. /* In signalmodule.c */
  202. int PySignal_SetWakeupFd(int fd);
  203. /* Support for adding program text to SyntaxErrors */
  204. PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
  205. PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
  206. #ifdef Py_USING_UNICODE
  207. /* The following functions are used to create and modify unicode
  208. exceptions from C */
  209. /* create a UnicodeDecodeError object */
  210. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
  211. const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  212. /* create a UnicodeEncodeError object */
  213. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
  214. const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  215. /* create a UnicodeTranslateError object */
  216. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
  217. const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
  218. /* get the encoding attribute */
  219. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
  220. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
  221. /* get the object attribute */
  222. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
  223. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
  224. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
  225. /* get the value of the start attribute (the int * may not be NULL)
  226. return 0 on success, -1 on failure */
  227. PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
  228. PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
  229. PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
  230. /* assign a new value to the start attribute
  231. return 0 on success, -1 on failure */
  232. PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
  233. PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
  234. PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
  235. /* get the value of the end attribute (the int *may not be NULL)
  236. return 0 on success, -1 on failure */
  237. PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
  238. PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
  239. PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
  240. /* assign a new value to the end attribute
  241. return 0 on success, -1 on failure */
  242. PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
  243. PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
  244. PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
  245. /* get the value of the reason attribute */
  246. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
  247. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
  248. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
  249. /* assign a new value to the reason attribute
  250. return 0 on success, -1 on failure */
  251. PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
  252. PyObject *, const char *);
  253. PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
  254. PyObject *, const char *);
  255. PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
  256. PyObject *, const char *);
  257. #endif
  258. /* These APIs aren't really part of the error implementation, but
  259. often needed to format error messages; the native C lib APIs are
  260. not available on all platforms, which is why we provide emulations
  261. for those platforms in Python/mysnprintf.c,
  262. WARNING: The return value of snprintf varies across platforms; do
  263. not rely on any particular behavior; eventually the C99 defn may
  264. be reliable.
  265. */
  266. #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
  267. # define HAVE_SNPRINTF
  268. # define snprintf _snprintf
  269. # define vsnprintf _vsnprintf
  270. #endif
  271. #include <stdarg.h>
  272. PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
  273. Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
  274. PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
  275. Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
  276. #ifdef __cplusplus
  277. }
  278. #endif
  279. #endif /* !Py_ERRORS_H */