Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

pyerrors.h 17 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  1. #ifndef Py_ERRORS_H
  2. #define Py_ERRORS_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Error objects */
  7. #ifndef Py_LIMITED_API
  8. /* PyException_HEAD defines the initial segment of every exception class. */
  9. #define PyException_HEAD PyObject_HEAD PyObject *dict;\
  10. PyObject *args; PyObject *traceback;\
  11. PyObject *context; PyObject *cause;\
  12. char suppress_context;
  13. typedef struct {
  14. PyException_HEAD
  15. } PyBaseExceptionObject;
  16. typedef struct {
  17. PyException_HEAD
  18. PyObject *msg;
  19. PyObject *filename;
  20. PyObject *lineno;
  21. PyObject *offset;
  22. PyObject *text;
  23. PyObject *print_file_and_line;
  24. } PySyntaxErrorObject;
  25. typedef struct {
  26. PyException_HEAD
  27. PyObject *msg;
  28. PyObject *name;
  29. PyObject *path;
  30. } PyImportErrorObject;
  31. typedef struct {
  32. PyException_HEAD
  33. PyObject *encoding;
  34. PyObject *object;
  35. Py_ssize_t start;
  36. Py_ssize_t end;
  37. PyObject *reason;
  38. } PyUnicodeErrorObject;
  39. typedef struct {
  40. PyException_HEAD
  41. PyObject *code;
  42. } PySystemExitObject;
  43. typedef struct {
  44. PyException_HEAD
  45. PyObject *myerrno;
  46. PyObject *strerror;
  47. PyObject *filename;
  48. PyObject *filename2;
  49. #ifdef MS_WINDOWS
  50. PyObject *winerror;
  51. #endif
  52. Py_ssize_t written; /* only for BlockingIOError, -1 otherwise */
  53. } PyOSErrorObject;
  54. typedef struct {
  55. PyException_HEAD
  56. PyObject *value;
  57. } PyStopIterationObject;
  58. /* Compatibility typedefs */
  59. typedef PyOSErrorObject PyEnvironmentErrorObject;
  60. #ifdef MS_WINDOWS
  61. typedef PyOSErrorObject PyWindowsErrorObject;
  62. #endif
  63. #endif /* !Py_LIMITED_API */
  64. /* Error handling definitions */
  65. PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
  66. PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
  67. #ifndef Py_LIMITED_API
  68. PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *);
  69. _PyErr_StackItem *_PyErr_GetTopmostException(PyThreadState *tstate);
  70. #endif
  71. PyAPI_FUNC(void) PyErr_SetString(
  72. PyObject *exception,
  73. const char *string /* decoded from utf-8 */
  74. );
  75. PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
  76. PyAPI_FUNC(void) PyErr_Clear(void);
  77. PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
  78. PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
  79. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  80. PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **, PyObject **, PyObject **);
  81. PyAPI_FUNC(void) PyErr_SetExcInfo(PyObject *, PyObject *, PyObject *);
  82. #endif
  83. #if defined(__clang__) || \
  84. (defined(__GNUC__) && \
  85. ((__GNUC__ >= 3) || \
  86. (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
  87. #define _Py_NO_RETURN __attribute__((__noreturn__))
  88. #else
  89. #define _Py_NO_RETURN
  90. #endif
  91. /* Defined in Python/pylifecycle.c */
  92. PyAPI_FUNC(void) Py_FatalError(const char *message) _Py_NO_RETURN;
  93. #if defined(Py_DEBUG) || defined(Py_LIMITED_API)
  94. #define _PyErr_OCCURRED() PyErr_Occurred()
  95. #else
  96. #define _PyErr_OCCURRED() (PyThreadState_GET()->curexc_type)
  97. #endif
  98. /* Error testing and normalization */
  99. PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
  100. PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
  101. PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
  102. /* Traceback manipulation (PEP 3134) */
  103. PyAPI_FUNC(int) PyException_SetTraceback(PyObject *, PyObject *);
  104. PyAPI_FUNC(PyObject *) PyException_GetTraceback(PyObject *);
  105. /* Cause manipulation (PEP 3134) */
  106. PyAPI_FUNC(PyObject *) PyException_GetCause(PyObject *);
  107. PyAPI_FUNC(void) PyException_SetCause(PyObject *, PyObject *);
  108. /* Context manipulation (PEP 3134) */
  109. PyAPI_FUNC(PyObject *) PyException_GetContext(PyObject *);
  110. PyAPI_FUNC(void) PyException_SetContext(PyObject *, PyObject *);
  111. #ifndef Py_LIMITED_API
  112. PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
  113. #endif
  114. /* */
  115. #define PyExceptionClass_Check(x) \
  116. (PyType_Check((x)) && \
  117. PyType_FastSubclass((PyTypeObject*)(x), Py_TPFLAGS_BASE_EXC_SUBCLASS))
  118. #define PyExceptionInstance_Check(x) \
  119. PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS)
  120. #define PyExceptionClass_Name(x) \
  121. ((char *)(((PyTypeObject*)(x))->tp_name))
  122. #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
  123. /* Predefined exceptions */
  124. PyAPI_DATA(PyObject *) PyExc_BaseException;
  125. PyAPI_DATA(PyObject *) PyExc_Exception;
  126. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  127. PyAPI_DATA(PyObject *) PyExc_StopAsyncIteration;
  128. #endif
  129. PyAPI_DATA(PyObject *) PyExc_StopIteration;
  130. PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
  131. PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
  132. PyAPI_DATA(PyObject *) PyExc_LookupError;
  133. PyAPI_DATA(PyObject *) PyExc_AssertionError;
  134. PyAPI_DATA(PyObject *) PyExc_AttributeError;
  135. PyAPI_DATA(PyObject *) PyExc_BufferError;
  136. PyAPI_DATA(PyObject *) PyExc_EOFError;
  137. PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
  138. PyAPI_DATA(PyObject *) PyExc_OSError;
  139. PyAPI_DATA(PyObject *) PyExc_ImportError;
  140. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
  141. PyAPI_DATA(PyObject *) PyExc_ModuleNotFoundError;
  142. #endif
  143. PyAPI_DATA(PyObject *) PyExc_IndexError;
  144. PyAPI_DATA(PyObject *) PyExc_KeyError;
  145. PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
  146. PyAPI_DATA(PyObject *) PyExc_MemoryError;
  147. PyAPI_DATA(PyObject *) PyExc_NameError;
  148. PyAPI_DATA(PyObject *) PyExc_OverflowError;
  149. PyAPI_DATA(PyObject *) PyExc_RuntimeError;
  150. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  151. PyAPI_DATA(PyObject *) PyExc_RecursionError;
  152. #endif
  153. PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
  154. PyAPI_DATA(PyObject *) PyExc_SyntaxError;
  155. PyAPI_DATA(PyObject *) PyExc_IndentationError;
  156. PyAPI_DATA(PyObject *) PyExc_TabError;
  157. PyAPI_DATA(PyObject *) PyExc_ReferenceError;
  158. PyAPI_DATA(PyObject *) PyExc_SystemError;
  159. PyAPI_DATA(PyObject *) PyExc_SystemExit;
  160. PyAPI_DATA(PyObject *) PyExc_TypeError;
  161. PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
  162. PyAPI_DATA(PyObject *) PyExc_UnicodeError;
  163. PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
  164. PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
  165. PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
  166. PyAPI_DATA(PyObject *) PyExc_ValueError;
  167. PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
  168. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  169. PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
  170. PyAPI_DATA(PyObject *) PyExc_BrokenPipeError;
  171. PyAPI_DATA(PyObject *) PyExc_ChildProcessError;
  172. PyAPI_DATA(PyObject *) PyExc_ConnectionError;
  173. PyAPI_DATA(PyObject *) PyExc_ConnectionAbortedError;
  174. PyAPI_DATA(PyObject *) PyExc_ConnectionRefusedError;
  175. PyAPI_DATA(PyObject *) PyExc_ConnectionResetError;
  176. PyAPI_DATA(PyObject *) PyExc_FileExistsError;
  177. PyAPI_DATA(PyObject *) PyExc_FileNotFoundError;
  178. PyAPI_DATA(PyObject *) PyExc_InterruptedError;
  179. PyAPI_DATA(PyObject *) PyExc_IsADirectoryError;
  180. PyAPI_DATA(PyObject *) PyExc_NotADirectoryError;
  181. PyAPI_DATA(PyObject *) PyExc_PermissionError;
  182. PyAPI_DATA(PyObject *) PyExc_ProcessLookupError;
  183. PyAPI_DATA(PyObject *) PyExc_TimeoutError;
  184. #endif
  185. /* Compatibility aliases */
  186. PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
  187. PyAPI_DATA(PyObject *) PyExc_IOError;
  188. #ifdef MS_WINDOWS
  189. PyAPI_DATA(PyObject *) PyExc_WindowsError;
  190. #endif
  191. /* Predefined warning categories */
  192. PyAPI_DATA(PyObject *) PyExc_Warning;
  193. PyAPI_DATA(PyObject *) PyExc_UserWarning;
  194. PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
  195. PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
  196. PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
  197. PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
  198. PyAPI_DATA(PyObject *) PyExc_FutureWarning;
  199. PyAPI_DATA(PyObject *) PyExc_ImportWarning;
  200. PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
  201. PyAPI_DATA(PyObject *) PyExc_BytesWarning;
  202. PyAPI_DATA(PyObject *) PyExc_ResourceWarning;
  203. /* Convenience functions */
  204. PyAPI_FUNC(int) PyErr_BadArgument(void);
  205. PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
  206. PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
  207. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
  208. PyObject *, PyObject *);
  209. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
  210. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObjects(
  211. PyObject *, PyObject *, PyObject *);
  212. #endif
  213. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
  214. PyObject *exc,
  215. const char *filename /* decoded from the filesystem encoding */
  216. );
  217. #if defined(MS_WINDOWS) && !defined(Py_LIMITED_API)
  218. PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
  219. PyObject *, const Py_UNICODE *) Py_DEPRECATED(3.3);
  220. #endif /* MS_WINDOWS */
  221. PyAPI_FUNC(PyObject *) PyErr_Format(
  222. PyObject *exception,
  223. const char *format, /* ASCII-encoded string */
  224. ...
  225. );
  226. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
  227. PyAPI_FUNC(PyObject *) PyErr_FormatV(
  228. PyObject *exception,
  229. const char *format,
  230. va_list vargs);
  231. #endif
  232. #ifndef Py_LIMITED_API
  233. /* Like PyErr_Format(), but saves current exception as __context__ and
  234. __cause__.
  235. */
  236. PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
  237. PyObject *exception,
  238. const char *format, /* ASCII-encoded string */
  239. ...
  240. );
  241. #endif
  242. #ifdef MS_WINDOWS
  243. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
  244. int ierr,
  245. const char *filename /* decoded from the filesystem encoding */
  246. );
  247. #ifndef Py_LIMITED_API
  248. /* XXX redeclare to use WSTRING */
  249. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
  250. int, const Py_UNICODE *) Py_DEPRECATED(3.3);
  251. #endif
  252. PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
  253. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
  254. PyObject *,int, PyObject *);
  255. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
  256. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObjects(
  257. PyObject *,int, PyObject *, PyObject *);
  258. #endif
  259. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
  260. PyObject *exc,
  261. int ierr,
  262. const char *filename /* decoded from the filesystem encoding */
  263. );
  264. #ifndef Py_LIMITED_API
  265. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
  266. PyObject *,int, const Py_UNICODE *) Py_DEPRECATED(3.3);
  267. #endif
  268. PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
  269. #endif /* MS_WINDOWS */
  270. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03060000
  271. PyAPI_FUNC(PyObject *) PyErr_SetImportErrorSubclass(PyObject *, PyObject *,
  272. PyObject *, PyObject *);
  273. #endif
  274. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  275. PyAPI_FUNC(PyObject *) PyErr_SetImportError(PyObject *, PyObject *,
  276. PyObject *);
  277. #endif
  278. /* Export the old function so that the existing API remains available: */
  279. PyAPI_FUNC(void) PyErr_BadInternalCall(void);
  280. PyAPI_FUNC(void) _PyErr_BadInternalCall(const char *filename, int lineno);
  281. /* Mask the old API with a call to the new API for code compiled under
  282. Python 2.0: */
  283. #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
  284. /* Function to create a new exception */
  285. PyAPI_FUNC(PyObject *) PyErr_NewException(
  286. const char *name, PyObject *base, PyObject *dict);
  287. PyAPI_FUNC(PyObject *) PyErr_NewExceptionWithDoc(
  288. const char *name, const char *doc, PyObject *base, PyObject *dict);
  289. PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
  290. /* In exceptions.c */
  291. #ifndef Py_LIMITED_API
  292. /* Helper that attempts to replace the current exception with one of the
  293. * same type but with a prefix added to the exception text. The resulting
  294. * exception description looks like:
  295. *
  296. * prefix (exc_type: original_exc_str)
  297. *
  298. * Only some exceptions can be safely replaced. If the function determines
  299. * it isn't safe to perform the replacement, it will leave the original
  300. * unmodified exception in place.
  301. *
  302. * Returns a borrowed reference to the new exception (if any), NULL if the
  303. * existing exception was left in place.
  304. */
  305. PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
  306. const char *prefix_format, /* ASCII-encoded string */
  307. ...
  308. );
  309. #endif
  310. /* In signalmodule.c */
  311. PyAPI_FUNC(int) PyErr_CheckSignals(void);
  312. PyAPI_FUNC(void) PyErr_SetInterrupt(void);
  313. /* In signalmodule.c */
  314. #ifndef Py_LIMITED_API
  315. int PySignal_SetWakeupFd(int fd);
  316. #endif
  317. /* Support for adding program text to SyntaxErrors */
  318. PyAPI_FUNC(void) PyErr_SyntaxLocation(
  319. const char *filename, /* decoded from the filesystem encoding */
  320. int lineno);
  321. PyAPI_FUNC(void) PyErr_SyntaxLocationEx(
  322. const char *filename, /* decoded from the filesystem encoding */
  323. int lineno,
  324. int col_offset);
  325. #ifndef Py_LIMITED_API
  326. PyAPI_FUNC(void) PyErr_SyntaxLocationObject(
  327. PyObject *filename,
  328. int lineno,
  329. int col_offset);
  330. #endif
  331. PyAPI_FUNC(PyObject *) PyErr_ProgramText(
  332. const char *filename, /* decoded from the filesystem encoding */
  333. int lineno);
  334. #ifndef Py_LIMITED_API
  335. PyAPI_FUNC(PyObject *) PyErr_ProgramTextObject(
  336. PyObject *filename,
  337. int lineno);
  338. #endif
  339. /* The following functions are used to create and modify unicode
  340. exceptions from C */
  341. /* create a UnicodeDecodeError object */
  342. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
  343. const char *encoding, /* UTF-8 encoded string */
  344. const char *object,
  345. Py_ssize_t length,
  346. Py_ssize_t start,
  347. Py_ssize_t end,
  348. const char *reason /* UTF-8 encoded string */
  349. );
  350. /* create a UnicodeEncodeError object */
  351. #ifndef Py_LIMITED_API
  352. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
  353. const char *encoding, /* UTF-8 encoded string */
  354. const Py_UNICODE *object,
  355. Py_ssize_t length,
  356. Py_ssize_t start,
  357. Py_ssize_t end,
  358. const char *reason /* UTF-8 encoded string */
  359. ) Py_DEPRECATED(3.3);
  360. #endif
  361. /* create a UnicodeTranslateError object */
  362. #ifndef Py_LIMITED_API
  363. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
  364. const Py_UNICODE *object,
  365. Py_ssize_t length,
  366. Py_ssize_t start,
  367. Py_ssize_t end,
  368. const char *reason /* UTF-8 encoded string */
  369. ) Py_DEPRECATED(3.3);
  370. PyAPI_FUNC(PyObject *) _PyUnicodeTranslateError_Create(
  371. PyObject *object,
  372. Py_ssize_t start,
  373. Py_ssize_t end,
  374. const char *reason /* UTF-8 encoded string */
  375. );
  376. #endif
  377. /* get the encoding attribute */
  378. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
  379. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
  380. /* get the object attribute */
  381. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
  382. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
  383. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
  384. /* get the value of the start attribute (the int * may not be NULL)
  385. return 0 on success, -1 on failure */
  386. PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
  387. PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
  388. PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
  389. /* assign a new value to the start attribute
  390. return 0 on success, -1 on failure */
  391. PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
  392. PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
  393. PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
  394. /* get the value of the end attribute (the int *may not be NULL)
  395. return 0 on success, -1 on failure */
  396. PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
  397. PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
  398. PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
  399. /* assign a new value to the end attribute
  400. return 0 on success, -1 on failure */
  401. PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
  402. PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
  403. PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
  404. /* get the value of the reason attribute */
  405. PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
  406. PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
  407. PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
  408. /* assign a new value to the reason attribute
  409. return 0 on success, -1 on failure */
  410. PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
  411. PyObject *exc,
  412. const char *reason /* UTF-8 encoded string */
  413. );
  414. PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
  415. PyObject *exc,
  416. const char *reason /* UTF-8 encoded string */
  417. );
  418. PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
  419. PyObject *exc,
  420. const char *reason /* UTF-8 encoded string */
  421. );
  422. /* These APIs aren't really part of the error implementation, but
  423. often needed to format error messages; the native C lib APIs are
  424. not available on all platforms, which is why we provide emulations
  425. for those platforms in Python/mysnprintf.c,
  426. WARNING: The return value of snprintf varies across platforms; do
  427. not rely on any particular behavior; eventually the C99 defn may
  428. be reliable.
  429. */
  430. #if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
  431. # define HAVE_SNPRINTF
  432. # define snprintf _snprintf
  433. # define vsnprintf _vsnprintf
  434. #endif
  435. #include <stdarg.h>
  436. PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
  437. Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
  438. PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
  439. Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
  440. #ifdef __cplusplus
  441. }
  442. #endif
  443. #endif /* !Py_ERRORS_H */
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...