History

add hg and python

cinap_lenrek committed 15 years ago

Commit 4bb9e221 parent 987265c3706 files · +1228772 −-233Browse files

Showing the changes to sys/src/cmd/python/Include (80 of 3706 files). Show all

Unified · Split

80 files
  1. sys/src/cmd/python/Include/Python-ast.h +501 −0
  2. sys/src/cmd/python/Include/Python.h +173 −0
  3. sys/src/cmd/python/Include/abstract.h +1276 −0
  4. sys/src/cmd/python/Include/asdl.h +45 −0
  5. sys/src/cmd/python/Include/ast.h +13 −0
  6. sys/src/cmd/python/Include/bitset.h +32 −0
  7. sys/src/cmd/python/Include/boolobject.h +36 −0
  8. sys/src/cmd/python/Include/bufferobject.h +33 −0
  9. sys/src/cmd/python/Include/cStringIO.h +70 −0
  10. sys/src/cmd/python/Include/cellobject.h +28 −0
  11. sys/src/cmd/python/Include/ceval.h +157 −0
  12. sys/src/cmd/python/Include/classobject.h +81 −0
  13. sys/src/cmd/python/Include/cobject.h +54 −0
  14. sys/src/cmd/python/Include/code.h +94 −0
  15. sys/src/cmd/python/Include/codecs.h +167 −0
  16. sys/src/cmd/python/Include/compile.h +39 −0
  17. sys/src/cmd/python/Include/complexobject.h +58 −0
  18. sys/src/cmd/python/Include/datetime.h +245 −0
  19. sys/src/cmd/python/Include/descrobject.h +91 −0
  20. sys/src/cmd/python/Include/dictobject.h +141 −0
  21. sys/src/cmd/python/Include/enumobject.h +17 −0
  22. sys/src/cmd/python/Include/errcode.h +36 −0
  23. sys/src/cmd/python/Include/eval.h +25 −0
  24. sys/src/cmd/python/Include/fileobject.h +63 −0
  25. sys/src/cmd/python/Include/floatobject.h +100 −0
  26. sys/src/cmd/python/Include/frameobject.h +81 −0
  27. sys/src/cmd/python/Include/funcobject.h +76 −0
  28. sys/src/cmd/python/Include/genobject.h +37 −0
  29. sys/src/cmd/python/Include/graminit.h +84 −0
  30. sys/src/cmd/python/Include/grammar.h +93 −0
  31. sys/src/cmd/python/Include/import.h +64 −0
  32. sys/src/cmd/python/Include/intobject.h +64 −0
  33. sys/src/cmd/python/Include/intrcheck.h +15 −0
  34. sys/src/cmd/python/Include/iterobject.h +23 −0
  35. sys/src/cmd/python/Include/listobject.h +67 −0
  36. sys/src/cmd/python/Include/longintrepr.h +63 −0
  37. sys/src/cmd/python/Include/longobject.h +114 −0
  38. sys/src/cmd/python/Include/marshal.h +25 −0
  39. sys/src/cmd/python/Include/metagrammar.h +18 −0
  40. sys/src/cmd/python/Include/methodobject.h +91 −0
  41. sys/src/cmd/python/Include/modsupport.h +133 −0
  42. sys/src/cmd/python/Include/moduleobject.h +24 −0
  43. sys/src/cmd/python/Include/node.h +40 −0
  44. sys/src/cmd/python/Include/object.h +868 −0
  45. sys/src/cmd/python/Include/objimpl.h +336 −0
  46. sys/src/cmd/python/Include/opcode.h +152 −0
  47. sys/src/cmd/python/Include/osdefs.h +55 −0
  48. sys/src/cmd/python/Include/parsetok.h +50 −0
  49. sys/src/cmd/python/Include/patchlevel.h +40 −0
  50. sys/src/cmd/python/Include/pgen.h +18 −0
  51. sys/src/cmd/python/Include/pgenheaders.h +42 −0
  52. sys/src/cmd/python/Include/py_curses.h +176 −0
  53. sys/src/cmd/python/Include/pyarena.h +62 −0
  54. sys/src/cmd/python/Include/pydebug.h +34 −0
  55. sys/src/cmd/python/Include/pyerrors.h +334 −0
  56. sys/src/cmd/python/Include/pyexpat.h +47 −0
  57. sys/src/cmd/python/Include/pyfpe.h +176 −0
  58. sys/src/cmd/python/Include/pygetopt.h +17 −0
  59. sys/src/cmd/python/Include/pymactoolbox.h +189 −0
  60. sys/src/cmd/python/Include/pymem.h +105 −0
  61. sys/src/cmd/python/Include/pyport.h +771 −0
  62. sys/src/cmd/python/Include/pystate.h +195 −0
  63. sys/src/cmd/python/Include/pystrtod.h +18 −0
  64. sys/src/cmd/python/Include/pythonrun.h +171 −0
  65. sys/src/cmd/python/Include/pythread.h +47 −0
  66. sys/src/cmd/python/Include/rangeobject.h +28 −0
  67. sys/src/cmd/python/Include/setobject.h +93 −0
  68. sys/src/cmd/python/Include/sliceobject.h +43 −0
  69. sys/src/cmd/python/Include/stringobject.h +183 −0
  70. sys/src/cmd/python/Include/structmember.h +93 −0
  71. sys/src/cmd/python/Include/structseq.h +41 −0
  72. sys/src/cmd/python/Include/symtable.h +103 −0
  73. sys/src/cmd/python/Include/sysmodule.h +30 −0
  74. sys/src/cmd/python/Include/timefuncs.h +23 −0
  75. sys/src/cmd/python/Include/token.h +83 −0
  76. sys/src/cmd/python/Include/traceback.h +30 −0
  77. sys/src/cmd/python/Include/tupleobject.h +57 −0
  78. sys/src/cmd/python/Include/ucnhash.h +31 −0
  79. sys/src/cmd/python/Include/unicodeobject.h +1265 −0
  80. sys/src/cmd/python/Include/weakrefobject.h +75 −0
sys/src/cmd/python/Include/Python-ast.h+501−0
@@ -0,0 +1,501 @@
1/* File automatically generated by Parser/asdl_c.py */
2
3#include "asdl.h"
4
5typedef struct _mod *mod_ty;
6
7typedef struct _stmt *stmt_ty;
8
9typedef struct _expr *expr_ty;
10
11typedef enum _expr_context { Load=1, Store=2, Del=3, AugLoad=4, AugStore=5,
12 Param=6 } expr_context_ty;
13
14typedef struct _slice *slice_ty;
15
16typedef enum _boolop { And=1, Or=2 } boolop_ty;
17
18typedef enum _operator { Add=1, Sub=2, Mult=3, Div=4, Mod=5, Pow=6, LShift=7,
19 RShift=8, BitOr=9, BitXor=10, BitAnd=11, FloorDiv=12 }
20 operator_ty;
21
22typedef enum _unaryop { Invert=1, Not=2, UAdd=3, USub=4 } unaryop_ty;
23
24typedef enum _cmpop { Eq=1, NotEq=2, Lt=3, LtE=4, Gt=5, GtE=6, Is=7, IsNot=8,
25 In=9, NotIn=10 } cmpop_ty;
26
27typedef struct _comprehension *comprehension_ty;
28
29typedef struct _excepthandler *excepthandler_ty;
30
31typedef struct _arguments *arguments_ty;
32
33typedef struct _keyword *keyword_ty;
34
35typedef struct _alias *alias_ty;
36
37
38enum _mod_kind {Module_kind=1, Interactive_kind=2, Expression_kind=3,
39 Suite_kind=4};
40struct _mod {
41 enum _mod_kind kind;
42 union {
43 struct {
44 asdl_seq *body;
45 } Module;
46
47 struct {
48 asdl_seq *body;
49 } Interactive;
50
51 struct {
52 expr_ty body;
53 } Expression;
54
55 struct {
56 asdl_seq *body;
57 } Suite;
58
59 } v;
60};
61
62enum _stmt_kind {FunctionDef_kind=1, ClassDef_kind=2, Return_kind=3,
63 Delete_kind=4, Assign_kind=5, AugAssign_kind=6, Print_kind=7,
64 For_kind=8, While_kind=9, If_kind=10, With_kind=11,
65 Raise_kind=12, TryExcept_kind=13, TryFinally_kind=14,
66 Assert_kind=15, Import_kind=16, ImportFrom_kind=17,
67 Exec_kind=18, Global_kind=19, Expr_kind=20, Pass_kind=21,
68 Break_kind=22, Continue_kind=23};
69struct _stmt {
70 enum _stmt_kind kind;
71 union {
72 struct {
73 identifier name;
74 arguments_ty args;
75 asdl_seq *body;
76 asdl_seq *decorators;
77 } FunctionDef;
78
79 struct {
80 identifier name;
81 asdl_seq *bases;
82 asdl_seq *body;
83 } ClassDef;
84
85 struct {
86 expr_ty value;
87 } Return;
88
89 struct {
90 asdl_seq *targets;
91 } Delete;
92
93 struct {
94 asdl_seq *targets;
95 expr_ty value;
96 } Assign;
97
98 struct {
99 expr_ty target;
100 operator_ty op;
101 expr_ty value;
102 } AugAssign;
103
104 struct {
105 expr_ty dest;
106 asdl_seq *values;
107 bool nl;
108 } Print;
109
110 struct {
111 expr_ty target;
112 expr_ty iter;
113 asdl_seq *body;
114 asdl_seq *orelse;
115 } For;
116
117 struct {
118 expr_ty test;
119 asdl_seq *body;
120 asdl_seq *orelse;
121 } While;
122
123 struct {
124 expr_ty test;
125 asdl_seq *body;
126 asdl_seq *orelse;
127 } If;
128
129 struct {
130 expr_ty context_expr;
131 expr_ty optional_vars;
132 asdl_seq *body;
133 } With;
134
135 struct {
136 expr_ty type;
137 expr_ty inst;
138 expr_ty tback;
139 } Raise;
140
141 struct {
142 asdl_seq *body;
143 asdl_seq *handlers;
144 asdl_seq *orelse;
145 } TryExcept;
146
147 struct {
148 asdl_seq *body;
149 asdl_seq *finalbody;
150 } TryFinally;
151
152 struct {
153 expr_ty test;
154 expr_ty msg;
155 } Assert;
156
157 struct {
158 asdl_seq *names;
159 } Import;
160
161 struct {
162 identifier module;
163 asdl_seq *names;
164 int level;
165 } ImportFrom;
166
167 struct {
168 expr_ty body;
169 expr_ty globals;
170 expr_ty locals;
171 } Exec;
172
173 struct {
174 asdl_seq *names;
175 } Global;
176
177 struct {
178 expr_ty value;
179 } Expr;
180
181 } v;
182 int lineno;
183 int col_offset;
184};
185
186enum _expr_kind {BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4,
187 IfExp_kind=5, Dict_kind=6, ListComp_kind=7,
188 GeneratorExp_kind=8, Yield_kind=9, Compare_kind=10,
189 Call_kind=11, Repr_kind=12, Num_kind=13, Str_kind=14,
190 Attribute_kind=15, Subscript_kind=16, Name_kind=17,
191 List_kind=18, Tuple_kind=19};
192struct _expr {
193 enum _expr_kind kind;
194 union {
195 struct {
196 boolop_ty op;
197 asdl_seq *values;
198 } BoolOp;
199
200 struct {
201 expr_ty left;
202 operator_ty op;
203 expr_ty right;
204 } BinOp;
205
206 struct {
207 unaryop_ty op;
208 expr_ty operand;
209 } UnaryOp;
210
211 struct {
212 arguments_ty args;
213 expr_ty body;
214 } Lambda;
215
216 struct {
217 expr_ty test;
218 expr_ty body;
219 expr_ty orelse;
220 } IfExp;
221
222 struct {
223 asdl_seq *keys;
224 asdl_seq *values;
225 } Dict;
226
227 struct {
228 expr_ty elt;
229 asdl_seq *generators;
230 } ListComp;
231
232 struct {
233 expr_ty elt;
234 asdl_seq *generators;
235 } GeneratorExp;
236
237 struct {
238 expr_ty value;
239 } Yield;
240
241 struct {
242 expr_ty left;
243 asdl_int_seq *ops;
244 asdl_seq *comparators;
245 } Compare;
246
247 struct {
248 expr_ty func;
249 asdl_seq *args;
250 asdl_seq *keywords;
251 expr_ty starargs;
252 expr_ty kwargs;
253 } Call;
254
255 struct {
256 expr_ty value;
257 } Repr;
258
259 struct {
260 object n;
261 } Num;
262
263 struct {
264 string s;
265 } Str;
266
267 struct {
268 expr_ty value;
269 identifier attr;
270 expr_context_ty ctx;
271 } Attribute;
272
273 struct {
274 expr_ty value;
275 slice_ty slice;
276 expr_context_ty ctx;
277 } Subscript;
278
279 struct {
280 identifier id;
281 expr_context_ty ctx;
282 } Name;
283
284 struct {
285 asdl_seq *elts;
286 expr_context_ty ctx;
287 } List;
288
289 struct {
290 asdl_seq *elts;
291 expr_context_ty ctx;
292 } Tuple;
293
294 } v;
295 int lineno;
296 int col_offset;
297};
298
299enum _slice_kind {Ellipsis_kind=1, Slice_kind=2, ExtSlice_kind=3, Index_kind=4};
300struct _slice {
301 enum _slice_kind kind;
302 union {
303 struct {
304 expr_ty lower;
305 expr_ty upper;
306 expr_ty step;
307 } Slice;
308
309 struct {
310 asdl_seq *dims;
311 } ExtSlice;
312
313 struct {
314 expr_ty value;
315 } Index;
316
317 } v;
318};
319
320struct _comprehension {
321 expr_ty target;
322 expr_ty iter;
323 asdl_seq *ifs;
324};
325
326struct _excepthandler {
327 expr_ty type;
328 expr_ty name;
329 asdl_seq *body;
330 int lineno;
331 int col_offset;
332};
333
334struct _arguments {
335 asdl_seq *args;
336 identifier vararg;
337 identifier kwarg;
338 asdl_seq *defaults;
339};
340
341struct _keyword {
342 identifier arg;
343 expr_ty value;
344};
345
346struct _alias {
347 identifier name;
348 identifier asname;
349};
350
351
352#define Module(a0, a1) _Py_Module(a0, a1)
353mod_ty _Py_Module(asdl_seq * body, PyArena *arena);
354#define Interactive(a0, a1) _Py_Interactive(a0, a1)
355mod_ty _Py_Interactive(asdl_seq * body, PyArena *arena);
356#define Expression(a0, a1) _Py_Expression(a0, a1)
357mod_ty _Py_Expression(expr_ty body, PyArena *arena);
358#define Suite(a0, a1) _Py_Suite(a0, a1)
359mod_ty _Py_Suite(asdl_seq * body, PyArena *arena);
360#define FunctionDef(a0, a1, a2, a3, a4, a5, a6) _Py_FunctionDef(a0, a1, a2, a3, a4, a5, a6)
361stmt_ty _Py_FunctionDef(identifier name, arguments_ty args, asdl_seq * body,
362 asdl_seq * decorators, int lineno, int col_offset,
363 PyArena *arena);
364#define ClassDef(a0, a1, a2, a3, a4, a5) _Py_ClassDef(a0, a1, a2, a3, a4, a5)
365stmt_ty _Py_ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int
366 lineno, int col_offset, PyArena *arena);
367#define Return(a0, a1, a2, a3) _Py_Return(a0, a1, a2, a3)
368stmt_ty _Py_Return(expr_ty value, int lineno, int col_offset, PyArena *arena);
369#define Delete(a0, a1, a2, a3) _Py_Delete(a0, a1, a2, a3)
370stmt_ty _Py_Delete(asdl_seq * targets, int lineno, int col_offset, PyArena
371 *arena);
372#define Assign(a0, a1, a2, a3, a4) _Py_Assign(a0, a1, a2, a3, a4)
373stmt_ty _Py_Assign(asdl_seq * targets, expr_ty value, int lineno, int
374 col_offset, PyArena *arena);
375#define AugAssign(a0, a1, a2, a3, a4, a5) _Py_AugAssign(a0, a1, a2, a3, a4, a5)
376stmt_ty _Py_AugAssign(expr_ty target, operator_ty op, expr_ty value, int
377 lineno, int col_offset, PyArena *arena);
378#define Print(a0, a1, a2, a3, a4, a5) _Py_Print(a0, a1, a2, a3, a4, a5)
379stmt_ty _Py_Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int
380 col_offset, PyArena *arena);
381#define For(a0, a1, a2, a3, a4, a5, a6) _Py_For(a0, a1, a2, a3, a4, a5, a6)
382stmt_ty _Py_For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq *
383 orelse, int lineno, int col_offset, PyArena *arena);
384#define While(a0, a1, a2, a3, a4, a5) _Py_While(a0, a1, a2, a3, a4, a5)
385stmt_ty _Py_While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,
386 int col_offset, PyArena *arena);
387#define If(a0, a1, a2, a3, a4, a5) _Py_If(a0, a1, a2, a3, a4, a5)
388stmt_ty _Py_If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno,
389 int col_offset, PyArena *arena);
390#define With(a0, a1, a2, a3, a4, a5) _Py_With(a0, a1, a2, a3, a4, a5)
391stmt_ty _Py_With(expr_ty context_expr, expr_ty optional_vars, asdl_seq * body,
392 int lineno, int col_offset, PyArena *arena);
393#define Raise(a0, a1, a2, a3, a4, a5) _Py_Raise(a0, a1, a2, a3, a4, a5)
394stmt_ty _Py_Raise(expr_ty type, expr_ty inst, expr_ty tback, int lineno, int
395 col_offset, PyArena *arena);
396#define TryExcept(a0, a1, a2, a3, a4, a5) _Py_TryExcept(a0, a1, a2, a3, a4, a5)
397stmt_ty _Py_TryExcept(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse,
398 int lineno, int col_offset, PyArena *arena);
399#define TryFinally(a0, a1, a2, a3, a4) _Py_TryFinally(a0, a1, a2, a3, a4)
400stmt_ty _Py_TryFinally(asdl_seq * body, asdl_seq * finalbody, int lineno, int
401 col_offset, PyArena *arena);
402#define Assert(a0, a1, a2, a3, a4) _Py_Assert(a0, a1, a2, a3, a4)
403stmt_ty _Py_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset,
404 PyArena *arena);
405#define Import(a0, a1, a2, a3) _Py_Import(a0, a1, a2, a3)
406stmt_ty _Py_Import(asdl_seq * names, int lineno, int col_offset, PyArena
407 *arena);
408#define ImportFrom(a0, a1, a2, a3, a4, a5) _Py_ImportFrom(a0, a1, a2, a3, a4, a5)
409stmt_ty _Py_ImportFrom(identifier module, asdl_seq * names, int level, int
410 lineno, int col_offset, PyArena *arena);
411#define Exec(a0, a1, a2, a3, a4, a5) _Py_Exec(a0, a1, a2, a3, a4, a5)
412stmt_ty _Py_Exec(expr_ty body, expr_ty globals, expr_ty locals, int lineno, int
413 col_offset, PyArena *arena);
414#define Global(a0, a1, a2, a3) _Py_Global(a0, a1, a2, a3)
415stmt_ty _Py_Global(asdl_seq * names, int lineno, int col_offset, PyArena
416 *arena);
417#define Expr(a0, a1, a2, a3) _Py_Expr(a0, a1, a2, a3)
418stmt_ty _Py_Expr(expr_ty value, int lineno, int col_offset, PyArena *arena);
419#define Pass(a0, a1, a2) _Py_Pass(a0, a1, a2)
420stmt_ty _Py_Pass(int lineno, int col_offset, PyArena *arena);
421#define Break(a0, a1, a2) _Py_Break(a0, a1, a2)
422stmt_ty _Py_Break(int lineno, int col_offset, PyArena *arena);
423#define Continue(a0, a1, a2) _Py_Continue(a0, a1, a2)
424stmt_ty _Py_Continue(int lineno, int col_offset, PyArena *arena);
425#define BoolOp(a0, a1, a2, a3, a4) _Py_BoolOp(a0, a1, a2, a3, a4)
426expr_ty _Py_BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset,
427 PyArena *arena);
428#define BinOp(a0, a1, a2, a3, a4, a5) _Py_BinOp(a0, a1, a2, a3, a4, a5)
429expr_ty _Py_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
430 col_offset, PyArena *arena);
431#define UnaryOp(a0, a1, a2, a3, a4) _Py_UnaryOp(a0, a1, a2, a3, a4)
432expr_ty _Py_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset,
433 PyArena *arena);
434#define Lambda(a0, a1, a2, a3, a4) _Py_Lambda(a0, a1, a2, a3, a4)
435expr_ty _Py_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset,
436 PyArena *arena);
437#define IfExp(a0, a1, a2, a3, a4, a5) _Py_IfExp(a0, a1, a2, a3, a4, a5)
438expr_ty _Py_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
439 col_offset, PyArena *arena);
440#define Dict(a0, a1, a2, a3, a4) _Py_Dict(a0, a1, a2, a3, a4)
441expr_ty _Py_Dict(asdl_seq * keys, asdl_seq * values, int lineno, int
442 col_offset, PyArena *arena);
443#define ListComp(a0, a1, a2, a3, a4) _Py_ListComp(a0, a1, a2, a3, a4)
444expr_ty _Py_ListComp(expr_ty elt, asdl_seq * generators, int lineno, int
445 col_offset, PyArena *arena);
446#define GeneratorExp(a0, a1, a2, a3, a4) _Py_GeneratorExp(a0, a1, a2, a3, a4)
447expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int
448 col_offset, PyArena *arena);
449#define Yield(a0, a1, a2, a3) _Py_Yield(a0, a1, a2, a3)
450expr_ty _Py_Yield(expr_ty value, int lineno, int col_offset, PyArena *arena);
451#define Compare(a0, a1, a2, a3, a4, a5) _Py_Compare(a0, a1, a2, a3, a4, a5)
452expr_ty _Py_Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators,
453 int lineno, int col_offset, PyArena *arena);
454#define Call(a0, a1, a2, a3, a4, a5, a6, a7) _Py_Call(a0, a1, a2, a3, a4, a5, a6, a7)
455expr_ty _Py_Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty
456 starargs, expr_ty kwargs, int lineno, int col_offset, PyArena
457 *arena);
458#define Repr(a0, a1, a2, a3) _Py_Repr(a0, a1, a2, a3)
459expr_ty _Py_Repr(expr_ty value, int lineno, int col_offset, PyArena *arena);
460#define Num(a0, a1, a2, a3) _Py_Num(a0, a1, a2, a3)
461expr_ty _Py_Num(object n, int lineno, int col_offset, PyArena *arena);
462#define Str(a0, a1, a2, a3) _Py_Str(a0, a1, a2, a3)
463expr_ty _Py_Str(string s, int lineno, int col_offset, PyArena *arena);
464#define Attribute(a0, a1, a2, a3, a4, a5) _Py_Attribute(a0, a1, a2, a3, a4, a5)
465expr_ty _Py_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
466 lineno, int col_offset, PyArena *arena);
467#define Subscript(a0, a1, a2, a3, a4, a5) _Py_Subscript(a0, a1, a2, a3, a4, a5)
468expr_ty _Py_Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int
469 lineno, int col_offset, PyArena *arena);
470#define Name(a0, a1, a2, a3, a4) _Py_Name(a0, a1, a2, a3, a4)
471expr_ty _Py_Name(identifier id, expr_context_ty ctx, int lineno, int
472 col_offset, PyArena *arena);
473#define List(a0, a1, a2, a3, a4) _Py_List(a0, a1, a2, a3, a4)
474expr_ty _Py_List(asdl_seq * elts, expr_context_ty ctx, int lineno, int
475 col_offset, PyArena *arena);
476#define Tuple(a0, a1, a2, a3, a4) _Py_Tuple(a0, a1, a2, a3, a4)
477expr_ty _Py_Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int
478 col_offset, PyArena *arena);
479#define Ellipsis(a0) _Py_Ellipsis(a0)
480slice_ty _Py_Ellipsis(PyArena *arena);
481#define Slice(a0, a1, a2, a3) _Py_Slice(a0, a1, a2, a3)
482slice_ty _Py_Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena);
483#define ExtSlice(a0, a1) _Py_ExtSlice(a0, a1)
484slice_ty _Py_ExtSlice(asdl_seq * dims, PyArena *arena);
485#define Index(a0, a1) _Py_Index(a0, a1)
486slice_ty _Py_Index(expr_ty value, PyArena *arena);
487#define comprehension(a0, a1, a2, a3) _Py_comprehension(a0, a1, a2, a3)
488comprehension_ty _Py_comprehension(expr_ty target, expr_ty iter, asdl_seq *
489 ifs, PyArena *arena);
490#define excepthandler(a0, a1, a2, a3, a4, a5) _Py_excepthandler(a0, a1, a2, a3, a4, a5)
491excepthandler_ty _Py_excepthandler(expr_ty type, expr_ty name, asdl_seq * body,
492 int lineno, int col_offset, PyArena *arena);
493#define arguments(a0, a1, a2, a3, a4) _Py_arguments(a0, a1, a2, a3, a4)
494arguments_ty _Py_arguments(asdl_seq * args, identifier vararg, identifier
495 kwarg, asdl_seq * defaults, PyArena *arena);
496#define keyword(a0, a1, a2) _Py_keyword(a0, a1, a2)
497keyword_ty _Py_keyword(identifier arg, expr_ty value, PyArena *arena);
498#define alias(a0, a1, a2) _Py_alias(a0, a1, a2)
499alias_ty _Py_alias(identifier name, identifier asname, PyArena *arena);
500
501PyObject* PyAST_mod2obj(mod_ty t);
sys/src/cmd/python/Include/Python.h+173−0
@@ -0,0 +1,173 @@
1#ifndef Py_PYTHON_H
2#define Py_PYTHON_H
3/* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
4
5/* Include nearly all Python header files */
6
7#include "patchlevel.h"
8#include "pyconfig.h"
9
10/* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
11 * old symbol for the benefit of extension modules written before then
12 * that may be conditionalizing on it. The core doesn't use it anymore.
13 */
14#ifndef WITH_CYCLE_GC
15#define WITH_CYCLE_GC 1
16#endif
17
18#include <limits.h>
19
20#ifndef UCHAR_MAX
21#error "Something's broken. UCHAR_MAX should be defined in limits.h."
22#endif
23
24#if UCHAR_MAX != 255
25#error "Python's source code assumes C's unsigned char is an 8-bit type."
26#endif
27
28#if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
29#define _SGI_MP_SOURCE
30#endif
31
32#include <stdio.h>
33#ifndef NULL
34# error "Python.h requires that stdio.h define NULL."
35#endif
36
37#include <string.h>
38#ifdef HAVE_ERRNO_H
39#include <errno.h>
40#endif
41#include <stdlib.h>
42#ifdef HAVE_UNISTD_H
43#include <unistd.h>
44#endif
45
46/* For uintptr_t, intptr_t */
47#ifdef HAVE_STDDEF_H
48#include <stddef.h>
49#endif
50
51/* CAUTION: Build setups should ensure that NDEBUG is defined on the
52 * compiler command line when building Python in release mode; else
53 * assert() calls won't be removed.
54 */
55#include <assert.h>
56
57#include "pyport.h"
58
59/* pyconfig.h or pyport.h may or may not define DL_IMPORT */
60#ifndef DL_IMPORT /* declarations for DLL import/export */
61#define DL_IMPORT(RTYPE) RTYPE
62#endif
63#ifndef DL_EXPORT /* declarations for DLL import/export */
64#define DL_EXPORT(RTYPE) RTYPE
65#endif
66
67/* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.
68 * PYMALLOC_DEBUG is in error if pymalloc is not in use.
69 */
70#if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG)
71#define PYMALLOC_DEBUG
72#endif
73#if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)
74#error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
75#endif
76#include "pymem.h"
77
78#include "object.h"
79#include "objimpl.h"
80
81#include "pydebug.h"
82
83#include "unicodeobject.h"
84#include "intobject.h"
85#include "boolobject.h"
86#include "longobject.h"
87#include "floatobject.h"
88#ifndef WITHOUT_COMPLEX
89#include "complexobject.h"
90#endif
91#include "rangeobject.h"
92#include "stringobject.h"
93#include "bufferobject.h"
94#include "tupleobject.h"
95#include "listobject.h"
96#include "dictobject.h"
97#include "enumobject.h"
98#include "setobject.h"
99#include "methodobject.h"
100#include "moduleobject.h"
101#include "funcobject.h"
102#include "classobject.h"
103#include "fileobject.h"
104#include "cobject.h"
105#include "traceback.h"
106#include "sliceobject.h"
107#include "cellobject.h"
108#include "iterobject.h"
109#include "genobject.h"
110#include "descrobject.h"
111#include "weakrefobject.h"
112
113#include "codecs.h"
114#include "pyerrors.h"
115
116#include "pystate.h"
117
118#include "pyarena.h"
119#include "modsupport.h"
120#include "pythonrun.h"
121#include "ceval.h"
122#include "sysmodule.h"
123#include "intrcheck.h"
124#include "import.h"
125
126#include "abstract.h"
127
128#include "compile.h"
129#include "eval.h"
130
131#include "pystrtod.h"
132
133/* _Py_Mangle is defined in compile.c */
134PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
135
136/* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */
137#define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
138
139/* PyArg_NoArgs should not be necessary.
140 Set ml_flags in the PyMethodDef to METH_NOARGS. */
141#define PyArg_NoArgs(v) PyArg_Parse(v, "")
142
143/* Convert a possibly signed character to a nonnegative int */
144/* XXX This assumes characters are 8 bits wide */
145#ifdef __CHAR_UNSIGNED__
146#define Py_CHARMASK(c) (c)
147#else
148#define Py_CHARMASK(c) ((c) & 0xff)
149#endif
150
151#include "pyfpe.h"
152
153/* These definitions must match corresponding definitions in graminit.h.
154 There's code in compile.c that checks that they are the same. */
155#define Py_single_input 256
156#define Py_file_input 257
157#define Py_eval_input 258
158
159#ifdef HAVE_PTH
160/* GNU pth user-space thread support */
161#include <pth.h>
162#endif
163
164/* Define macros for inline documentation. */
165#define PyDoc_VAR(name) static char name[]
166#define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
167#ifdef WITH_DOC_STRINGS
168#define PyDoc_STR(str) str
169#else
170#define PyDoc_STR(str) ""
171#endif
172
173#endif /* !Py_PYTHON_H */
sys/src/cmd/python/Include/abstract.h+1276−0
@@ -0,0 +1,1276 @@
1#ifndef Py_ABSTRACTOBJECT_H
2#define Py_ABSTRACTOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#ifdef PY_SSIZE_T_CLEAN
8#define PyObject_CallFunction _PyObject_CallFunction_SizeT
9#define PyObject_CallMethod _PyObject_CallMethod_SizeT
10#endif
11
12/* Abstract Object Interface (many thanks to Jim Fulton) */
13
14/*
15 PROPOSAL: A Generic Python Object Interface for Python C Modules
16
17Problem
18
19 Python modules written in C that must access Python objects must do
20 so through routines whose interfaces are described by a set of
21 include files. Unfortunately, these routines vary according to the
22 object accessed. To use these routines, the C programmer must check
23 the type of the object being used and must call a routine based on
24 the object type. For example, to access an element of a sequence,
25 the programmer must determine whether the sequence is a list or a
26 tuple:
27
28 if(is_tupleobject(o))
29 e=gettupleitem(o,i)
30 else if(is_listitem(o))
31 e=getlistitem(o,i)
32
33 If the programmer wants to get an item from another type of object
34 that provides sequence behavior, there is no clear way to do it
35 correctly.
36
37 The persistent programmer may peruse object.h and find that the
38 _typeobject structure provides a means of invoking up to (currently
39 about) 41 special operators. So, for example, a routine can get an
40 item from any object that provides sequence behavior. However, to
41 use this mechanism, the programmer must make their code dependent on
42 the current Python implementation.
43
44 Also, certain semantics, especially memory management semantics, may
45 differ by the type of object being used. Unfortunately, these
46 semantics are not clearly described in the current include files.
47 An abstract interface providing more consistent semantics is needed.
48
49Proposal
50
51 I propose the creation of a standard interface (with an associated
52 library of routines and/or macros) for generically obtaining the
53 services of Python objects. This proposal can be viewed as one
54 components of a Python C interface consisting of several components.
55
56 From the viewpoint of C access to Python services, we have (as
57 suggested by Guido in off-line discussions):
58
59 - "Very high level layer": two or three functions that let you exec or
60 eval arbitrary Python code given as a string in a module whose name is
61 given, passing C values in and getting C values out using
62 mkvalue/getargs style format strings. This does not require the user
63 to declare any variables of type "PyObject *". This should be enough
64 to write a simple application that gets Python code from the user,
65 execs it, and returns the output or errors. (Error handling must also
66 be part of this API.)
67
68 - "Abstract objects layer": which is the subject of this proposal.
69 It has many functions operating on objects, and lest you do many
70 things from C that you can also write in Python, without going
71 through the Python parser.
72
73 - "Concrete objects layer": This is the public type-dependent
74 interface provided by the standard built-in types, such as floats,
75 strings, and lists. This interface exists and is currently
76 documented by the collection of include files provided with the
77 Python distributions.
78
79 From the point of view of Python accessing services provided by C
80 modules:
81
82 - "Python module interface": this interface consist of the basic
83 routines used to define modules and their members. Most of the
84 current extensions-writing guide deals with this interface.
85
86 - "Built-in object interface": this is the interface that a new
87 built-in type must provide and the mechanisms and rules that a
88 developer of a new built-in type must use and follow.
89
90 This proposal is a "first-cut" that is intended to spur
91 discussion. See especially the lists of notes.
92
93 The Python C object interface will provide four protocols: object,
94 numeric, sequence, and mapping. Each protocol consists of a
95 collection of related operations. If an operation that is not
96 provided by a particular type is invoked, then a standard exception,
97 NotImplementedError is raised with a operation name as an argument.
98 In addition, for convenience this interface defines a set of
99 constructors for building objects of built-in types. This is needed
100 so new objects can be returned from C functions that otherwise treat
101 objects generically.
102
103Memory Management
104
105 For all of the functions described in this proposal, if a function
106 retains a reference to a Python object passed as an argument, then the
107 function will increase the reference count of the object. It is
108 unnecessary for the caller to increase the reference count of an
109 argument in anticipation of the object's retention.
110
111 All Python objects returned from functions should be treated as new
112 objects. Functions that return objects assume that the caller will
113 retain a reference and the reference count of the object has already
114 been incremented to account for this fact. A caller that does not
115 retain a reference to an object that is returned from a function
116 must decrement the reference count of the object (using
117 DECREF(object)) to prevent memory leaks.
118
119 Note that the behavior mentioned here is different from the current
120 behavior for some objects (e.g. lists and tuples) when certain
121 type-specific routines are called directly (e.g. setlistitem). The
122 proposed abstraction layer will provide a consistent memory
123 management interface, correcting for inconsistent behavior for some
124 built-in types.
125
126Protocols
127
128xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
129
130/* Object Protocol: */
131
132 /* Implemented elsewhere:
133
134 int PyObject_Print(PyObject *o, FILE *fp, int flags);
135
136 Print an object, o, on file, fp. Returns -1 on
137 error. The flags argument is used to enable certain printing
138 options. The only option currently supported is Py_Print_RAW.
139
140 (What should be said about Py_Print_RAW?)
141
142 */
143
144 /* Implemented elsewhere:
145
146 int PyObject_HasAttrString(PyObject *o, char *attr_name);
147
148 Returns 1 if o has the attribute attr_name, and 0 otherwise.
149 This is equivalent to the Python expression:
150 hasattr(o,attr_name).
151
152 This function always succeeds.
153
154 */
155
156 /* Implemented elsewhere:
157
158 PyObject* PyObject_GetAttrString(PyObject *o, char *attr_name);
159
160 Retrieve an attributed named attr_name form object o.
161 Returns the attribute value on success, or NULL on failure.
162 This is the equivalent of the Python expression: o.attr_name.
163
164 */
165
166 /* Implemented elsewhere:
167
168 int PyObject_HasAttr(PyObject *o, PyObject *attr_name);
169
170 Returns 1 if o has the attribute attr_name, and 0 otherwise.
171 This is equivalent to the Python expression:
172 hasattr(o,attr_name).
173
174 This function always succeeds.
175
176 */
177
178 /* Implemented elsewhere:
179
180 PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name);
181
182 Retrieve an attributed named attr_name form object o.
183 Returns the attribute value on success, or NULL on failure.
184 This is the equivalent of the Python expression: o.attr_name.
185
186 */
187
188
189 /* Implemented elsewhere:
190
191 int PyObject_SetAttrString(PyObject *o, char *attr_name, PyObject *v);
192
193 Set the value of the attribute named attr_name, for object o,
194 to the value, v. Returns -1 on failure. This is
195 the equivalent of the Python statement: o.attr_name=v.
196
197 */
198
199 /* Implemented elsewhere:
200
201 int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v);
202
203 Set the value of the attribute named attr_name, for object o,
204 to the value, v. Returns -1 on failure. This is
205 the equivalent of the Python statement: o.attr_name=v.
206
207 */
208
209 /* implemented as a macro:
210
211 int PyObject_DelAttrString(PyObject *o, char *attr_name);
212
213 Delete attribute named attr_name, for object o. Returns
214 -1 on failure. This is the equivalent of the Python
215 statement: del o.attr_name.
216
217 */
218#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A),NULL)
219
220 /* implemented as a macro:
221
222 int PyObject_DelAttr(PyObject *o, PyObject *attr_name);
223
224 Delete attribute named attr_name, for object o. Returns -1
225 on failure. This is the equivalent of the Python
226 statement: del o.attr_name.
227
228 */
229#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A),NULL)
230
231 PyAPI_FUNC(int) PyObject_Cmp(PyObject *o1, PyObject *o2, int *result);
232
233 /*
234 Compare the values of o1 and o2 using a routine provided by
235 o1, if one exists, otherwise with a routine provided by o2.
236 The result of the comparison is returned in result. Returns
237 -1 on failure. This is the equivalent of the Python
238 statement: result=cmp(o1,o2).
239
240 */
241
242 /* Implemented elsewhere:
243
244 int PyObject_Compare(PyObject *o1, PyObject *o2);
245
246 Compare the values of o1 and o2 using a routine provided by
247 o1, if one exists, otherwise with a routine provided by o2.
248 Returns the result of the comparison on success. On error,
249 the value returned is undefined. This is equivalent to the
250 Python expression: cmp(o1,o2).
251
252 */
253
254 /* Implemented elsewhere:
255
256 PyObject *PyObject_Repr(PyObject *o);
257
258 Compute the string representation of object, o. Returns the
259 string representation on success, NULL on failure. This is
260 the equivalent of the Python expression: repr(o).
261
262 Called by the repr() built-in function and by reverse quotes.
263
264 */
265
266 /* Implemented elsewhere:
267
268 PyObject *PyObject_Str(PyObject *o);
269
270 Compute the string representation of object, o. Returns the
271 string representation on success, NULL on failure. This is
272 the equivalent of the Python expression: str(o).)
273
274 Called by the str() built-in function and by the print
275 statement.
276
277 */
278
279 /* Implemented elsewhere:
280
281 PyObject *PyObject_Unicode(PyObject *o);
282
283 Compute the unicode representation of object, o. Returns the
284 unicode representation on success, NULL on failure. This is
285 the equivalent of the Python expression: unistr(o).)
286
287 Called by the unistr() built-in function.
288
289 */
290
291 /* Declared elsewhere
292
293 PyAPI_FUNC(int) PyCallable_Check(PyObject *o);
294
295 Determine if the object, o, is callable. Return 1 if the
296 object is callable and 0 otherwise.
297
298 This function always succeeds.
299
300 */
301
302
303
304 PyAPI_FUNC(PyObject *) PyObject_Call(PyObject *callable_object,
305 PyObject *args, PyObject *kw);
306
307 /*
308 Call a callable Python object, callable_object, with
309 arguments and keywords arguments. The 'args' argument can not be
310 NULL, but the 'kw' argument can be NULL.
311
312 */
313
314 PyAPI_FUNC(PyObject *) PyObject_CallObject(PyObject *callable_object,
315 PyObject *args);
316
317 /*
318 Call a callable Python object, callable_object, with
319 arguments given by the tuple, args. If no arguments are
320 needed, then args may be NULL. Returns the result of the
321 call on success, or NULL on failure. This is the equivalent
322 of the Python expression: apply(o,args).
323
324 */
325
326 PyAPI_FUNC(PyObject *) PyObject_CallFunction(PyObject *callable_object,
327 char *format, ...);
328
329 /*
330 Call a callable Python object, callable_object, with a
331 variable number of C arguments. The C arguments are described
332 using a mkvalue-style format string. The format may be NULL,
333 indicating that no arguments are provided. Returns the
334 result of the call on success, or NULL on failure. This is
335 the equivalent of the Python expression: apply(o,args).
336
337 */
338
339
340 PyAPI_FUNC(PyObject *) PyObject_CallMethod(PyObject *o, char *m,
341 char *format, ...);
342
343 /*
344 Call the method named m of object o with a variable number of
345 C arguments. The C arguments are described by a mkvalue
346 format string. The format may be NULL, indicating that no
347 arguments are provided. Returns the result of the call on
348 success, or NULL on failure. This is the equivalent of the
349 Python expression: o.method(args).
350 */
351
352 PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable,
353 char *format, ...);
354 PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *o,
355 char *name,
356 char *format, ...);
357
358 PyAPI_FUNC(PyObject *) PyObject_CallFunctionObjArgs(PyObject *callable,
359 ...);
360
361 /*
362 Call a callable Python object, callable_object, with a
363 variable number of C arguments. The C arguments are provided
364 as PyObject * values, terminated by a NULL. Returns the
365 result of the call on success, or NULL on failure. This is
366 the equivalent of the Python expression: apply(o,args).
367 */
368
369
370 PyAPI_FUNC(PyObject *) PyObject_CallMethodObjArgs(PyObject *o,
371 PyObject *m, ...);
372
373 /*
374 Call the method named m of object o with a variable number of
375 C arguments. The C arguments are provided as PyObject *
376 values, terminated by NULL. Returns the result of the call
377 on success, or NULL on failure. This is the equivalent of
378 the Python expression: o.method(args).
379 */
380
381
382 /* Implemented elsewhere:
383
384 long PyObject_Hash(PyObject *o);
385
386 Compute and return the hash, hash_value, of an object, o. On
387 failure, return -1. This is the equivalent of the Python
388 expression: hash(o).
389
390 */
391
392
393 /* Implemented elsewhere:
394
395 int PyObject_IsTrue(PyObject *o);
396
397 Returns 1 if the object, o, is considered to be true, 0 if o is
398 considered to be false and -1 on failure. This is equivalent to the
399 Python expression: not not o
400
401 */
402
403 /* Implemented elsewhere:
404
405 int PyObject_Not(PyObject *o);
406
407 Returns 0 if the object, o, is considered to be true, 1 if o is
408 considered to be false and -1 on failure. This is equivalent to the
409 Python expression: not o
410
411 */
412
413 PyAPI_FUNC(PyObject *) PyObject_Type(PyObject *o);
414
415 /*
416 On success, returns a type object corresponding to the object
417 type of object o. On failure, returns NULL. This is
418 equivalent to the Python expression: type(o).
419 */
420
421 PyAPI_FUNC(Py_ssize_t) PyObject_Size(PyObject *o);
422
423 /*
424 Return the size of object o. If the object, o, provides
425 both sequence and mapping protocols, the sequence size is
426 returned. On error, -1 is returned. This is the equivalent
427 to the Python expression: len(o).
428
429 */
430
431 /* For DLL compatibility */
432#undef PyObject_Length
433 PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
434#define PyObject_Length PyObject_Size
435
436 PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o);
437
438 /*
439 Return the size of object o. If the object, o, provides
440 both sequence and mapping protocols, the sequence size is
441 returned. On error, -1 is returned. If the object provides
442 a __length_hint__() method, its value is returned. This is an
443 internal undocumented API provided for performance reasons;
444 for compatibility, don't use it outside the core. This is the
445 equivalent to the Python expression:
446 try:
447 return len(o)
448 except (AttributeError, TypeError):
449 exc_type, exc_value, exc_tb = sys.exc_info()
450 try:
451 return o.__length_hint__()
452 except:
453 pass
454 raise exc_type, exc_value, exc_tb
455 */
456
457 PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
458
459 /*
460 Return element of o corresponding to the object, key, or NULL
461 on failure. This is the equivalent of the Python expression:
462 o[key].
463
464 */
465
466 PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
467
468 /*
469 Map the object, key, to the value, v. Returns
470 -1 on failure. This is the equivalent of the Python
471 statement: o[key]=v.
472 */
473
474 PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
475
476 /*
477 Remove the mapping for object, key, from the object *o.
478 Returns -1 on failure. This is equivalent to
479 the Python statement: del o[key].
480 */
481
482 PyAPI_FUNC(int) PyObject_DelItem(PyObject *o, PyObject *key);
483
484 /*
485 Delete the mapping for key from *o. Returns -1 on failure.
486 This is the equivalent of the Python statement: del o[key].
487 */
488
489 PyAPI_FUNC(int) PyObject_AsCharBuffer(PyObject *obj,
490 const char **buffer,
491 Py_ssize_t *buffer_len);
492
493 /*
494 Takes an arbitrary object which must support the (character,
495 single segment) buffer interface and returns a pointer to a
496 read-only memory location useable as character based input
497 for subsequent processing.
498
499 0 is returned on success. buffer and buffer_len are only
500 set in case no error occurs. Otherwise, -1 is returned and
501 an exception set.
502
503 */
504
505 PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *obj);
506
507 /*
508 Checks whether an arbitrary object supports the (character,
509 single segment) buffer interface. Returns 1 on success, 0
510 on failure.
511
512 */
513
514 PyAPI_FUNC(int) PyObject_AsReadBuffer(PyObject *obj,
515 const void **buffer,
516 Py_ssize_t *buffer_len);
517
518 /*
519 Same as PyObject_AsCharBuffer() except that this API expects
520 (readable, single segment) buffer interface and returns a
521 pointer to a read-only memory location which can contain
522 arbitrary data.
523
524 0 is returned on success. buffer and buffer_len are only
525 set in case no error occurrs. Otherwise, -1 is returned and
526 an exception set.
527
528 */
529
530 PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *obj,
531 void **buffer,
532 Py_ssize_t *buffer_len);
533
534 /*
535 Takes an arbitrary object which must support the (writeable,
536 single segment) buffer interface and returns a pointer to a
537 writeable memory location in buffer of size buffer_len.
538
539 0 is returned on success. buffer and buffer_len are only
540 set in case no error occurrs. Otherwise, -1 is returned and
541 an exception set.
542
543 */
544
545/* Iterators */
546
547 PyAPI_FUNC(PyObject *) PyObject_GetIter(PyObject *);
548 /* Takes an object and returns an iterator for it.
549 This is typically a new iterator but if the argument
550 is an iterator, this returns itself. */
551
552#define PyIter_Check(obj) \
553 (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
554 (obj)->ob_type->tp_iternext != NULL)
555
556 PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
557 /* Takes an iterator object and calls its tp_iternext slot,
558 returning the next value. If the iterator is exhausted,
559 this returns NULL without setting an exception.
560 NULL with an exception means an error occurred. */
561
562/* Number Protocol:*/
563
564 PyAPI_FUNC(int) PyNumber_Check(PyObject *o);
565
566 /*
567 Returns 1 if the object, o, provides numeric protocols, and
568 false otherwise.
569
570 This function always succeeds.
571
572 */
573
574 PyAPI_FUNC(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
575
576 /*
577 Returns the result of adding o1 and o2, or null on failure.
578 This is the equivalent of the Python expression: o1+o2.
579
580
581 */
582
583 PyAPI_FUNC(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
584
585 /*
586 Returns the result of subtracting o2 from o1, or null on
587 failure. This is the equivalent of the Python expression:
588 o1-o2.
589
590 */
591
592 PyAPI_FUNC(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
593
594 /*
595 Returns the result of multiplying o1 and o2, or null on
596 failure. This is the equivalent of the Python expression:
597 o1*o2.
598
599
600 */
601
602 PyAPI_FUNC(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
603
604 /*
605 Returns the result of dividing o1 by o2, or null on failure.
606 This is the equivalent of the Python expression: o1/o2.
607
608
609 */
610
611 PyAPI_FUNC(PyObject *) PyNumber_FloorDivide(PyObject *o1, PyObject *o2);
612
613 /*
614 Returns the result of dividing o1 by o2 giving an integral result,
615 or null on failure.
616 This is the equivalent of the Python expression: o1//o2.
617
618
619 */
620
621 PyAPI_FUNC(PyObject *) PyNumber_TrueDivide(PyObject *o1, PyObject *o2);
622
623 /*
624 Returns the result of dividing o1 by o2 giving a float result,
625 or null on failure.
626 This is the equivalent of the Python expression: o1/o2.
627
628
629 */
630
631 PyAPI_FUNC(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
632
633 /*
634 Returns the remainder of dividing o1 by o2, or null on
635 failure. This is the equivalent of the Python expression:
636 o1%o2.
637
638
639 */
640
641 PyAPI_FUNC(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
642
643 /*
644 See the built-in function divmod. Returns NULL on failure.
645 This is the equivalent of the Python expression:
646 divmod(o1,o2).
647
648
649 */
650
651 PyAPI_FUNC(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,
652 PyObject *o3);
653
654 /*
655 See the built-in function pow. Returns NULL on failure.
656 This is the equivalent of the Python expression:
657 pow(o1,o2,o3), where o3 is optional.
658
659 */
660
661 PyAPI_FUNC(PyObject *) PyNumber_Negative(PyObject *o);
662
663 /*
664 Returns the negation of o on success, or null on failure.
665 This is the equivalent of the Python expression: -o.
666
667 */
668
669 PyAPI_FUNC(PyObject *) PyNumber_Positive(PyObject *o);
670
671 /*
672 Returns the (what?) of o on success, or NULL on failure.
673 This is the equivalent of the Python expression: +o.
674
675 */
676
677 PyAPI_FUNC(PyObject *) PyNumber_Absolute(PyObject *o);
678
679 /*
680 Returns the absolute value of o, or null on failure. This is
681 the equivalent of the Python expression: abs(o).
682
683 */
684
685 PyAPI_FUNC(PyObject *) PyNumber_Invert(PyObject *o);
686
687 /*
688 Returns the bitwise negation of o on success, or NULL on
689 failure. This is the equivalent of the Python expression:
690 ~o.
691
692
693 */
694
695 PyAPI_FUNC(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
696
697 /*
698 Returns the result of left shifting o1 by o2 on success, or
699 NULL on failure. This is the equivalent of the Python
700 expression: o1 << o2.
701
702
703 */
704
705 PyAPI_FUNC(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
706
707 /*
708 Returns the result of right shifting o1 by o2 on success, or
709 NULL on failure. This is the equivalent of the Python
710 expression: o1 >> o2.
711
712 */
713
714 PyAPI_FUNC(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
715
716 /*
717 Returns the result of bitwise and of o1 and o2 on success, or
718 NULL on failure. This is the equivalent of the Python
719 expression: o1&o2.
720
721
722 */
723
724 PyAPI_FUNC(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
725
726 /*
727 Returns the bitwise exclusive or of o1 by o2 on success, or
728 NULL on failure. This is the equivalent of the Python
729 expression: o1^o2.
730
731
732 */
733
734 PyAPI_FUNC(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
735
736 /*
737 Returns the result of bitwise or on o1 and o2 on success, or
738 NULL on failure. This is the equivalent of the Python
739 expression: o1|o2.
740
741 */
742
743 /* Implemented elsewhere:
744
745 int PyNumber_Coerce(PyObject **p1, PyObject **p2);
746
747 This function takes the addresses of two variables of type
748 PyObject*.
749
750 If the objects pointed to by *p1 and *p2 have the same type,
751 increment their reference count and return 0 (success).
752 If the objects can be converted to a common numeric type,
753 replace *p1 and *p2 by their converted value (with 'new'
754 reference counts), and return 0.
755 If no conversion is possible, or if some other error occurs,
756 return -1 (failure) and don't increment the reference counts.
757 The call PyNumber_Coerce(&o1, &o2) is equivalent to the Python
758 statement o1, o2 = coerce(o1, o2).
759
760 */
761
762#define PyIndex_Check(obj) \
763 ((obj)->ob_type->tp_as_number != NULL && \
764 PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_INDEX) && \
765 (obj)->ob_type->tp_as_number->nb_index != NULL)
766
767 PyAPI_FUNC(PyObject *) PyNumber_Index(PyObject *o);
768
769 /*
770 Returns the object converted to a Python long or int
771 or NULL with an error raised on failure.
772 */
773
774 PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
775
776 /*
777 Returns the object converted to Py_ssize_t by going through
778 PyNumber_Index first. If an overflow error occurs while
779 converting the int-or-long to Py_ssize_t, then the second argument
780 is the error-type to return. If it is NULL, then the overflow error
781 is cleared and the value is clipped.
782 */
783
784 PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
785
786 /*
787 Returns the o converted to an integer object on success, or
788 NULL on failure. This is the equivalent of the Python
789 expression: int(o).
790
791 */
792
793 PyAPI_FUNC(PyObject *) PyNumber_Long(PyObject *o);
794
795 /*
796 Returns the o converted to a long integer object on success,
797 or NULL on failure. This is the equivalent of the Python
798 expression: long(o).
799
800 */
801
802 PyAPI_FUNC(PyObject *) PyNumber_Float(PyObject *o);
803
804 /*
805 Returns the o converted to a float object on success, or NULL
806 on failure. This is the equivalent of the Python expression:
807 float(o).
808 */
809
810/* In-place variants of (some of) the above number protocol functions */
811
812 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
813
814 /*
815 Returns the result of adding o2 to o1, possibly in-place, or null
816 on failure. This is the equivalent of the Python expression:
817 o1 += o2.
818
819 */
820
821 PyAPI_FUNC(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
822
823 /*
824 Returns the result of subtracting o2 from o1, possibly in-place or
825 null on failure. This is the equivalent of the Python expression:
826 o1 -= o2.
827
828 */
829
830 PyAPI_FUNC(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
831
832 /*
833 Returns the result of multiplying o1 by o2, possibly in-place, or
834 null on failure. This is the equivalent of the Python expression:
835 o1 *= o2.
836
837 */
838
839 PyAPI_FUNC(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
840
841 /*
842 Returns the result of dividing o1 by o2, possibly in-place, or null
843 on failure. This is the equivalent of the Python expression:
844 o1 /= o2.
845
846 */
847
848 PyAPI_FUNC(PyObject *) PyNumber_InPlaceFloorDivide(PyObject *o1,
849 PyObject *o2);
850
851 /*
852 Returns the result of dividing o1 by o2 giving an integral result,
853 possibly in-place, or null on failure.
854 This is the equivalent of the Python expression:
855 o1 /= o2.
856
857 */
858
859 PyAPI_FUNC(PyObject *) PyNumber_InPlaceTrueDivide(PyObject *o1,
860 PyObject *o2);
861
862 /*
863 Returns the result of dividing o1 by o2 giving a float result,
864 possibly in-place, or null on failure.
865 This is the equivalent of the Python expression:
866 o1 /= o2.
867
868 */
869
870 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
871
872 /*
873 Returns the remainder of dividing o1 by o2, possibly in-place, or
874 null on failure. This is the equivalent of the Python expression:
875 o1 %= o2.
876
877 */
878
879 PyAPI_FUNC(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,
880 PyObject *o3);
881
882 /*
883 Returns the result of raising o1 to the power of o2, possibly
884 in-place, or null on failure. This is the equivalent of the Python
885 expression: o1 **= o2, or pow(o1, o2, o3) if o3 is present.
886
887 */
888
889 PyAPI_FUNC(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
890
891 /*
892 Returns the result of left shifting o1 by o2, possibly in-place, or
893 null on failure. This is the equivalent of the Python expression:
894 o1 <<= o2.
895
896 */
897
898 PyAPI_FUNC(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
899
900 /*
901 Returns the result of right shifting o1 by o2, possibly in-place or
902 null on failure. This is the equivalent of the Python expression:
903 o1 >>= o2.
904
905 */
906
907 PyAPI_FUNC(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
908
909 /*
910 Returns the result of bitwise and of o1 and o2, possibly in-place,
911 or null on failure. This is the equivalent of the Python
912 expression: o1 &= o2.
913
914 */
915
916 PyAPI_FUNC(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
917
918 /*
919 Returns the bitwise exclusive or of o1 by o2, possibly in-place, or
920 null on failure. This is the equivalent of the Python expression:
921 o1 ^= o2.
922
923 */
924
925 PyAPI_FUNC(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
926
927 /*
928 Returns the result of bitwise or of o1 and o2, possibly in-place,
929 or null on failure. This is the equivalent of the Python
930 expression: o1 |= o2.
931
932 */
933
934
935/* Sequence protocol:*/
936
937 PyAPI_FUNC(int) PySequence_Check(PyObject *o);
938
939 /*
940 Return 1 if the object provides sequence protocol, and zero
941 otherwise.
942
943 This function always succeeds.
944
945 */
946
947 PyAPI_FUNC(Py_ssize_t) PySequence_Size(PyObject *o);
948
949 /*
950 Return the size of sequence object o, or -1 on failure.
951
952 */
953
954 /* For DLL compatibility */
955#undef PySequence_Length
956 PyAPI_FUNC(Py_ssize_t) PySequence_Length(PyObject *o);
957#define PySequence_Length PySequence_Size
958
959
960 PyAPI_FUNC(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
961
962 /*
963 Return the concatenation of o1 and o2 on success, and NULL on
964 failure. This is the equivalent of the Python
965 expression: o1+o2.
966
967 */
968
969 PyAPI_FUNC(PyObject *) PySequence_Repeat(PyObject *o, Py_ssize_t count);
970
971 /*
972 Return the result of repeating sequence object o count times,
973 or NULL on failure. This is the equivalent of the Python
974 expression: o1*count.
975
976 */
977
978 PyAPI_FUNC(PyObject *) PySequence_GetItem(PyObject *o, Py_ssize_t i);
979
980 /*
981 Return the ith element of o, or NULL on failure. This is the
982 equivalent of the Python expression: o[i].
983 */
984
985 PyAPI_FUNC(PyObject *) PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
986
987 /*
988 Return the slice of sequence object o between i1 and i2, or
989 NULL on failure. This is the equivalent of the Python
990 expression: o[i1:i2].
991
992 */
993
994 PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
995
996 /*
997 Assign object v to the ith element of o. Returns
998 -1 on failure. This is the equivalent of the Python
999 statement: o[i]=v.
1000
1001 */
1002
1003 PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
1004
1005 /*
1006 Delete the ith element of object v. Returns
1007 -1 on failure. This is the equivalent of the Python
1008 statement: del o[i].
1009 */
1010
1011 PyAPI_FUNC(int) PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2,
1012 PyObject *v);
1013
1014 /*
1015 Assign the sequence object, v, to the slice in sequence
1016 object, o, from i1 to i2. Returns -1 on failure. This is the
1017 equivalent of the Python statement: o[i1:i2]=v.
1018 */
1019
1020 PyAPI_FUNC(int) PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2);
1021
1022 /*
1023 Delete the slice in sequence object, o, from i1 to i2.
1024 Returns -1 on failure. This is the equivalent of the Python
1025 statement: del o[i1:i2].
1026 */
1027
1028 PyAPI_FUNC(PyObject *) PySequence_Tuple(PyObject *o);
1029
1030 /*
1031 Returns the sequence, o, as a tuple on success, and NULL on failure.
1032 This is equivalent to the Python expression: tuple(o)
1033 */
1034
1035
1036 PyAPI_FUNC(PyObject *) PySequence_List(PyObject *o);
1037 /*
1038 Returns the sequence, o, as a list on success, and NULL on failure.
1039 This is equivalent to the Python expression: list(o)
1040 */
1041
1042 PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
1043 /*
1044 Returns the sequence, o, as a tuple, unless it's already a
1045 tuple or list. Use PySequence_Fast_GET_ITEM to access the
1046 members of this list, and PySequence_Fast_GET_SIZE to get its length.
1047
1048 Returns NULL on failure. If the object does not support iteration,
1049 raises a TypeError exception with m as the message text.
1050 */
1051
1052#define PySequence_Fast_GET_SIZE(o) \
1053 (PyList_Check(o) ? PyList_GET_SIZE(o) : PyTuple_GET_SIZE(o))
1054 /*
1055 Return the size of o, assuming that o was returned by
1056 PySequence_Fast and is not NULL.
1057 */
1058
1059#define PySequence_Fast_GET_ITEM(o, i)\
1060 (PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
1061 /*
1062 Return the ith element of o, assuming that o was returned by
1063 PySequence_Fast, and that i is within bounds.
1064 */
1065
1066#define PySequence_ITEM(o, i)\
1067 ( o->ob_type->tp_as_sequence->sq_item(o, i) )
1068 /* Assume tp_as_sequence and sq_item exist and that i does not
1069 need to be corrected for a negative index
1070 */
1071
1072#define PySequence_Fast_ITEMS(sf) \
1073 (PyList_Check(sf) ? ((PyListObject *)(sf))->ob_item \
1074 : ((PyTupleObject *)(sf))->ob_item)
1075 /* Return a pointer to the underlying item array for
1076 an object retured by PySequence_Fast */
1077
1078 PyAPI_FUNC(Py_ssize_t) PySequence_Count(PyObject *o, PyObject *value);
1079
1080 /*
1081 Return the number of occurrences on value on o, that is,
1082 return the number of keys for which o[key]==value. On
1083 failure, return -1. This is equivalent to the Python
1084 expression: o.count(value).
1085 */
1086
1087 PyAPI_FUNC(int) PySequence_Contains(PyObject *seq, PyObject *ob);
1088 /*
1089 Return -1 if error; 1 if ob in seq; 0 if ob not in seq.
1090 Use __contains__ if possible, else _PySequence_IterSearch().
1091 */
1092
1093#define PY_ITERSEARCH_COUNT 1
1094#define PY_ITERSEARCH_INDEX 2
1095#define PY_ITERSEARCH_CONTAINS 3
1096 PyAPI_FUNC(Py_ssize_t) _PySequence_IterSearch(PyObject *seq,
1097 PyObject *obj, int operation);
1098 /*
1099 Iterate over seq. Result depends on the operation:
1100 PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
1101 error.
1102 PY_ITERSEARCH_INDEX: return 0-based index of first occurrence of
1103 obj in seq; set ValueError and return -1 if none found;
1104 also return -1 on error.
1105 PY_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on
1106 error.
1107 */
1108
1109/* For DLL-level backwards compatibility */
1110#undef PySequence_In
1111 PyAPI_FUNC(int) PySequence_In(PyObject *o, PyObject *value);
1112
1113/* For source-level backwards compatibility */
1114#define PySequence_In PySequence_Contains
1115
1116 /*
1117 Determine if o contains value. If an item in o is equal to
1118 X, return 1, otherwise return 0. On error, return -1. This
1119 is equivalent to the Python expression: value in o.
1120 */
1121
1122 PyAPI_FUNC(Py_ssize_t) PySequence_Index(PyObject *o, PyObject *value);
1123
1124 /*
1125 Return the first index for which o[i]=value. On error,
1126 return -1. This is equivalent to the Python
1127 expression: o.index(value).
1128 */
1129
1130/* In-place versions of some of the above Sequence functions. */
1131
1132 PyAPI_FUNC(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
1133
1134 /*
1135 Append o2 to o1, in-place when possible. Return the resulting
1136 object, which could be o1, or NULL on failure. This is the
1137 equivalent of the Python expression: o1 += o2.
1138
1139 */
1140
1141 PyAPI_FUNC(PyObject *) PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count);
1142
1143 /*
1144 Repeat o1 by count, in-place when possible. Return the resulting
1145 object, which could be o1, or NULL on failure. This is the
1146 equivalent of the Python expression: o1 *= count.
1147
1148 */
1149
1150/* Mapping protocol:*/
1151
1152 PyAPI_FUNC(int) PyMapping_Check(PyObject *o);
1153
1154 /*
1155 Return 1 if the object provides mapping protocol, and zero
1156 otherwise.
1157
1158 This function always succeeds.
1159 */
1160
1161 PyAPI_FUNC(Py_ssize_t) PyMapping_Size(PyObject *o);
1162
1163 /*
1164 Returns the number of keys in object o on success, and -1 on
1165 failure. For objects that do not provide sequence protocol,
1166 this is equivalent to the Python expression: len(o).
1167 */
1168
1169 /* For DLL compatibility */
1170#undef PyMapping_Length
1171 PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
1172#define PyMapping_Length PyMapping_Size
1173
1174
1175 /* implemented as a macro:
1176
1177 int PyMapping_DelItemString(PyObject *o, char *key);
1178
1179 Remove the mapping for object, key, from the object *o.
1180 Returns -1 on failure. This is equivalent to
1181 the Python statement: del o[key].
1182 */
1183#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
1184
1185 /* implemented as a macro:
1186
1187 int PyMapping_DelItem(PyObject *o, PyObject *key);
1188
1189 Remove the mapping for object, key, from the object *o.
1190 Returns -1 on failure. This is equivalent to
1191 the Python statement: del o[key].
1192 */
1193#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
1194
1195 PyAPI_FUNC(int) PyMapping_HasKeyString(PyObject *o, char *key);
1196
1197 /*
1198 On success, return 1 if the mapping object has the key, key,
1199 and 0 otherwise. This is equivalent to the Python expression:
1200 o.has_key(key).
1201
1202 This function always succeeds.
1203 */
1204
1205 PyAPI_FUNC(int) PyMapping_HasKey(PyObject *o, PyObject *key);
1206
1207 /*
1208 Return 1 if the mapping object has the key, key,
1209 and 0 otherwise. This is equivalent to the Python expression:
1210 o.has_key(key).
1211
1212 This function always succeeds.
1213
1214 */
1215
1216 /* Implemented as macro:
1217
1218 PyObject *PyMapping_Keys(PyObject *o);
1219
1220 On success, return a list of the keys in object o. On
1221 failure, return NULL. This is equivalent to the Python
1222 expression: o.keys().
1223 */
1224#define PyMapping_Keys(O) PyObject_CallMethod(O,"keys",NULL)
1225
1226 /* Implemented as macro:
1227
1228 PyObject *PyMapping_Values(PyObject *o);
1229
1230 On success, return a list of the values in object o. On
1231 failure, return NULL. This is equivalent to the Python
1232 expression: o.values().
1233 */
1234#define PyMapping_Values(O) PyObject_CallMethod(O,"values",NULL)
1235
1236 /* Implemented as macro:
1237
1238 PyObject *PyMapping_Items(PyObject *o);
1239
1240 On success, return a list of the items in object o, where
1241 each item is a tuple containing a key-value pair. On
1242 failure, return NULL. This is equivalent to the Python
1243 expression: o.items().
1244
1245 */
1246#define PyMapping_Items(O) PyObject_CallMethod(O,"items",NULL)
1247
1248 PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
1249
1250 /*
1251 Return element of o corresponding to the object, key, or NULL
1252 on failure. This is the equivalent of the Python expression:
1253 o[key].
1254 */
1255
1256 PyAPI_FUNC(int) PyMapping_SetItemString(PyObject *o, char *key,
1257 PyObject *value);
1258
1259 /*
1260 Map the object, key, to the value, v. Returns
1261 -1 on failure. This is the equivalent of the Python
1262 statement: o[key]=v.
1263 */
1264
1265
1266PyAPI_FUNC(int) PyObject_IsInstance(PyObject *object, PyObject *typeorclass);
1267 /* isinstance(object, typeorclass) */
1268
1269PyAPI_FUNC(int) PyObject_IsSubclass(PyObject *object, PyObject *typeorclass);
1270 /* issubclass(object, typeorclass) */
1271
1272
1273#ifdef __cplusplus
1274}
1275#endif
1276#endif /* Py_ABSTRACTOBJECT_H */
sys/src/cmd/python/Include/asdl.h+45−0
@@ -0,0 +1,45 @@
1#ifndef Py_ASDL_H
2#define Py_ASDL_H
3
4typedef PyObject * identifier;
5typedef PyObject * string;
6typedef PyObject * object;
7
8#ifndef __cplusplus
9typedef enum {false, true} bool;
10#endif
11
12/* It would be nice if the code generated by asdl_c.py was completely
13 independent of Python, but it is a goal the requires too much work
14 at this stage. So, for example, I'll represent identifiers as
15 interned Python strings.
16*/
17
18/* XXX A sequence should be typed so that its use can be typechecked. */
19
20typedef struct {
21 int size;
22 void *elements[1];
23} asdl_seq;
24
25typedef struct {
26 int size;
27 int elements[1];
28} asdl_int_seq;
29
30asdl_seq *asdl_seq_new(int size, PyArena *arena);
31asdl_int_seq *asdl_int_seq_new(int size, PyArena *arena);
32
33#define asdl_seq_GET(S, I) (S)->elements[(I)]
34#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
35#ifdef Py_DEBUG
36#define asdl_seq_SET(S, I, V) { \
37 int _asdl_i = (I); \
38 assert((S) && _asdl_i < (S)->size); \
39 (S)->elements[_asdl_i] = (V); \
40}
41#else
42#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
43#endif
44
45#endif /* !Py_ASDL_H */
sys/src/cmd/python/Include/ast.h+13−0
@@ -0,0 +1,13 @@
1#ifndef Py_AST_H
2#define Py_AST_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7PyAPI_FUNC(mod_ty) PyAST_FromNode(const node *, PyCompilerFlags *flags,
8 const char *, PyArena *);
9
10#ifdef __cplusplus
11}
12#endif
13#endif /* !Py_AST_H */
sys/src/cmd/python/Include/bitset.h+32−0
@@ -0,0 +1,32 @@
1
2#ifndef Py_BITSET_H
3#define Py_BITSET_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* Bitset interface */
9
10#define BYTE char
11
12typedef BYTE *bitset;
13
14bitset newbitset(int nbits);
15void delbitset(bitset bs);
16#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)
17int addbit(bitset bs, int ibit); /* Returns 0 if already set */
18int samebitset(bitset bs1, bitset bs2, int nbits);
19void mergebitset(bitset bs1, bitset bs2, int nbits);
20
21#define BITSPERBYTE (8*sizeof(BYTE))
22#define NBYTES(nbits) (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
23
24#define BIT2BYTE(ibit) ((ibit) / BITSPERBYTE)
25#define BIT2SHIFT(ibit) ((ibit) % BITSPERBYTE)
26#define BIT2MASK(ibit) (1 << BIT2SHIFT(ibit))
27#define BYTE2BIT(ibyte) ((ibyte) * BITSPERBYTE)
28
29#ifdef __cplusplus
30}
31#endif
32#endif /* !Py_BITSET_H */
sys/src/cmd/python/Include/boolobject.h+36−0
@@ -0,0 +1,36 @@
1/* Boolean object interface */
2
3#ifndef Py_BOOLOBJECT_H
4#define Py_BOOLOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9
10typedef PyIntObject PyBoolObject;
11
12PyAPI_DATA(PyTypeObject) PyBool_Type;
13
14#define PyBool_Check(x) ((x)->ob_type == &PyBool_Type)
15
16/* Py_False and Py_True are the only two bools in existence.
17Don't forget to apply Py_INCREF() when returning either!!! */
18
19/* Don't use these directly */
20PyAPI_DATA(PyIntObject) _Py_ZeroStruct, _Py_TrueStruct;
21
22/* Use these macros */
23#define Py_False ((PyObject *) &_Py_ZeroStruct)
24#define Py_True ((PyObject *) &_Py_TrueStruct)
25
26/* Macros for returning Py_True or Py_False, respectively */
27#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True
28#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False
29
30/* Function to return a bool from a C long */
31PyAPI_FUNC(PyObject *) PyBool_FromLong(long);
32
33#ifdef __cplusplus
34}
35#endif
36#endif /* !Py_BOOLOBJECT_H */
sys/src/cmd/python/Include/bufferobject.h+33−0
@@ -0,0 +1,33 @@
1
2/* Buffer object interface */
3
4/* Note: the object's structure is private */
5
6#ifndef Py_BUFFEROBJECT_H
7#define Py_BUFFEROBJECT_H
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12
13PyAPI_DATA(PyTypeObject) PyBuffer_Type;
14
15#define PyBuffer_Check(op) ((op)->ob_type == &PyBuffer_Type)
16
17#define Py_END_OF_BUFFER (-1)
18
19PyAPI_FUNC(PyObject *) PyBuffer_FromObject(PyObject *base,
20 Py_ssize_t offset, Py_ssize_t size);
21PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteObject(PyObject *base,
22 Py_ssize_t offset,
23 Py_ssize_t size);
24
25PyAPI_FUNC(PyObject *) PyBuffer_FromMemory(void *ptr, Py_ssize_t size);
26PyAPI_FUNC(PyObject *) PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size);
27
28PyAPI_FUNC(PyObject *) PyBuffer_New(Py_ssize_t size);
29
30#ifdef __cplusplus
31}
32#endif
33#endif /* !Py_BUFFEROBJECT_H */
sys/src/cmd/python/Include/cStringIO.h+70−0
@@ -0,0 +1,70 @@
1#ifndef Py_CSTRINGIO_H
2#define Py_CSTRINGIO_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6/*
7
8 This header provides access to cStringIO objects from C.
9 Functions are provided for calling cStringIO objects and
10 macros are provided for testing whether you have cStringIO
11 objects.
12
13 Before calling any of the functions or macros, you must initialize
14 the routines with:
15
16 PycString_IMPORT
17
18 This would typically be done in your init function.
19
20*/
21#define PycString_IMPORT \
22 PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \
23 "cStringIO_CAPI")
24
25/* Basic functions to manipulate cStringIO objects from C */
26
27static struct PycStringIO_CAPI {
28
29 /* Read a string from an input object. If the last argument
30 is -1, the remainder will be read.
31 */
32 int(*cread)(PyObject *, char **, Py_ssize_t);
33
34 /* Read a line from an input object. Returns the length of the read
35 line as an int and a pointer inside the object buffer as char** (so
36 the caller doesn't have to provide its own buffer as destination).
37 */
38 int(*creadline)(PyObject *, char **);
39
40 /* Write a string to an output object*/
41 int(*cwrite)(PyObject *, const char *, Py_ssize_t);
42
43 /* Get the output object as a Python string (returns new reference). */
44 PyObject *(*cgetvalue)(PyObject *);
45
46 /* Create a new output object */
47 PyObject *(*NewOutput)(int);
48
49 /* Create an input object from a Python string
50 (copies the Python string reference).
51 */
52 PyObject *(*NewInput)(PyObject *);
53
54 /* The Python types for cStringIO input and output objects.
55 Note that you can do input on an output object.
56 */
57 PyTypeObject *InputType, *OutputType;
58
59} *PycStringIO;
60
61/* These can be used to test if you have one */
62#define PycStringIO_InputCheck(O) \
63 ((O)->ob_type==PycStringIO->InputType)
64#define PycStringIO_OutputCheck(O) \
65 ((O)->ob_type==PycStringIO->OutputType)
66
67#ifdef __cplusplus
68}
69#endif
70#endif /* !Py_CSTRINGIO_H */
sys/src/cmd/python/Include/cellobject.h+28−0
@@ -0,0 +1,28 @@
1/* Cell object interface */
2
3#ifndef Py_CELLOBJECT_H
4#define Py_CELLOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9typedef struct {
10 PyObject_HEAD
11 PyObject *ob_ref; /* Content of the cell or NULL when empty */
12} PyCellObject;
13
14PyAPI_DATA(PyTypeObject) PyCell_Type;
15
16#define PyCell_Check(op) ((op)->ob_type == &PyCell_Type)
17
18PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
19PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
20PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
21
22#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
23#define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v)
24
25#ifdef __cplusplus
26}
27#endif
28#endif /* !Py_TUPLEOBJECT_H */
sys/src/cmd/python/Include/ceval.h+157−0
@@ -0,0 +1,157 @@
1#ifndef Py_CEVAL_H
2#define Py_CEVAL_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Interface to random parts in ceval.c */
9
10PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
11 PyObject *, PyObject *, PyObject *);
12
13/* DLL-level Backwards compatibility: */
14#undef PyEval_CallObject
15PyAPI_FUNC(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
16
17/* Inline this */
18#define PyEval_CallObject(func,arg) \
19 PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
20
21PyAPI_FUNC(PyObject *) PyEval_CallFunction(PyObject *obj,
22 const char *format, ...);
23PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
24 const char *methodname,
25 const char *format, ...);
26
27PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
28PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
29
30struct _frame; /* Avoid including frameobject.h */
31
32PyAPI_FUNC(PyObject *) PyEval_GetBuiltins(void);
33PyAPI_FUNC(PyObject *) PyEval_GetGlobals(void);
34PyAPI_FUNC(PyObject *) PyEval_GetLocals(void);
35PyAPI_FUNC(struct _frame *) PyEval_GetFrame(void);
36PyAPI_FUNC(int) PyEval_GetRestricted(void);
37
38/* Look at the current frame's (if any) code's co_flags, and turn on
39 the corresponding compiler flags in cf->cf_flags. Return 1 if any
40 flag was set, else return 0. */
41PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
42
43PyAPI_FUNC(int) Py_FlushLine(void);
44
45PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
46PyAPI_FUNC(int) Py_MakePendingCalls(void);
47
48/* Protection against deeply nested recursive calls */
49PyAPI_FUNC(void) Py_SetRecursionLimit(int);
50PyAPI_FUNC(int) Py_GetRecursionLimit(void);
51
52#define Py_EnterRecursiveCall(where) \
53 (_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
54 _Py_CheckRecursiveCall(where))
55#define Py_LeaveRecursiveCall() \
56 (--PyThreadState_GET()->recursion_depth)
57PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
58PyAPI_DATA(int) _Py_CheckRecursionLimit;
59#ifdef USE_STACKCHECK
60# define _Py_MakeRecCheck(x) (++(x) > --_Py_CheckRecursionLimit)
61#else
62# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
63#endif
64
65PyAPI_FUNC(const char *) PyEval_GetFuncName(PyObject *);
66PyAPI_FUNC(const char *) PyEval_GetFuncDesc(PyObject *);
67
68PyAPI_FUNC(PyObject *) PyEval_GetCallStats(PyObject *);
69PyAPI_FUNC(PyObject *) PyEval_EvalFrame(struct _frame *);
70PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
71
72/* this used to be handled on a per-thread basis - now just two globals */
73PyAPI_DATA(volatile int) _Py_Ticker;
74PyAPI_DATA(int) _Py_CheckInterval;
75
76/* Interface for threads.
77
78 A module that plans to do a blocking system call (or something else
79 that lasts a long time and doesn't touch Python data) can allow other
80 threads to run as follows:
81
82 ...preparations here...
83 Py_BEGIN_ALLOW_THREADS
84 ...blocking system call here...
85 Py_END_ALLOW_THREADS
86 ...interpret result here...
87
88 The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
89 {}-surrounded block.
90 To leave the block in the middle (e.g., with return), you must insert
91 a line containing Py_BLOCK_THREADS before the return, e.g.
92
93 if (...premature_exit...) {
94 Py_BLOCK_THREADS
95 PyErr_SetFromErrno(PyExc_IOError);
96 return NULL;
97 }
98
99 An alternative is:
100
101 Py_BLOCK_THREADS
102 if (...premature_exit...) {
103 PyErr_SetFromErrno(PyExc_IOError);
104 return NULL;
105 }
106 Py_UNBLOCK_THREADS
107
108 For convenience, that the value of 'errno' is restored across
109 Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
110
111 WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
112 Py_END_ALLOW_THREADS!!!
113
114 The function PyEval_InitThreads() should be called only from
115 initthread() in "threadmodule.c".
116
117 Note that not yet all candidates have been converted to use this
118 mechanism!
119*/
120
121PyAPI_FUNC(PyThreadState *) PyEval_SaveThread(void);
122PyAPI_FUNC(void) PyEval_RestoreThread(PyThreadState *);
123
124#ifdef WITH_THREAD
125
126PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
127PyAPI_FUNC(void) PyEval_InitThreads(void);
128PyAPI_FUNC(void) PyEval_AcquireLock(void);
129PyAPI_FUNC(void) PyEval_ReleaseLock(void);
130PyAPI_FUNC(void) PyEval_AcquireThread(PyThreadState *tstate);
131PyAPI_FUNC(void) PyEval_ReleaseThread(PyThreadState *tstate);
132PyAPI_FUNC(void) PyEval_ReInitThreads(void);
133
134#define Py_BEGIN_ALLOW_THREADS { \
135 PyThreadState *_save; \
136 _save = PyEval_SaveThread();
137#define Py_BLOCK_THREADS PyEval_RestoreThread(_save);
138#define Py_UNBLOCK_THREADS _save = PyEval_SaveThread();
139#define Py_END_ALLOW_THREADS PyEval_RestoreThread(_save); \
140 }
141
142#else /* !WITH_THREAD */
143
144#define Py_BEGIN_ALLOW_THREADS {
145#define Py_BLOCK_THREADS
146#define Py_UNBLOCK_THREADS
147#define Py_END_ALLOW_THREADS }
148
149#endif /* !WITH_THREAD */
150
151PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
152
153
154#ifdef __cplusplus
155}
156#endif
157#endif /* !Py_CEVAL_H */
sys/src/cmd/python/Include/classobject.h+81−0
@@ -0,0 +1,81 @@
1
2/* Class object interface */
3
4/* Revealing some structures (not for general use) */
5
6#ifndef Py_CLASSOBJECT_H
7#define Py_CLASSOBJECT_H
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12typedef struct {
13 PyObject_HEAD
14 PyObject *cl_bases; /* A tuple of class objects */
15 PyObject *cl_dict; /* A dictionary */
16 PyObject *cl_name; /* A string */
17 /* The following three are functions or NULL */
18 PyObject *cl_getattr;
19 PyObject *cl_setattr;
20 PyObject *cl_delattr;
21} PyClassObject;
22
23typedef struct {
24 PyObject_HEAD
25 PyClassObject *in_class; /* The class object */
26 PyObject *in_dict; /* A dictionary */
27 PyObject *in_weakreflist; /* List of weak references */
28} PyInstanceObject;
29
30typedef struct {
31 PyObject_HEAD
32 PyObject *im_func; /* The callable object implementing the method */
33 PyObject *im_self; /* The instance it is bound to, or NULL */
34 PyObject *im_class; /* The class that asked for the method */
35 PyObject *im_weakreflist; /* List of weak references */
36} PyMethodObject;
37
38PyAPI_DATA(PyTypeObject) PyClass_Type, PyInstance_Type, PyMethod_Type;
39
40#define PyClass_Check(op) ((op)->ob_type == &PyClass_Type)
41#define PyInstance_Check(op) ((op)->ob_type == &PyInstance_Type)
42#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type)
43
44PyAPI_FUNC(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
45PyAPI_FUNC(PyObject *) PyInstance_New(PyObject *, PyObject *,
46 PyObject *);
47PyAPI_FUNC(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
48PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
49
50PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
51PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
52PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *);
53
54/* Look up attribute with name (a string) on instance object pinst, using
55 * only the instance and base class dicts. If a descriptor is found in
56 * a class dict, the descriptor is returned without calling it.
57 * Returns NULL if nothing found, else a borrowed reference to the
58 * value associated with name in the dict in which name was found.
59 * The point of this routine is that it never calls arbitrary Python
60 * code, so is always "safe": all it does is dict lookups. The function
61 * can't fail, never sets an exception, and NULL is not an error (it just
62 * means "not found").
63 */
64PyAPI_FUNC(PyObject *) _PyInstance_Lookup(PyObject *pinst, PyObject *name);
65
66/* Macros for direct access to these values. Type checks are *not*
67 done, so use with care. */
68#define PyMethod_GET_FUNCTION(meth) \
69 (((PyMethodObject *)meth) -> im_func)
70#define PyMethod_GET_SELF(meth) \
71 (((PyMethodObject *)meth) -> im_self)
72#define PyMethod_GET_CLASS(meth) \
73 (((PyMethodObject *)meth) -> im_class)
74
75PyAPI_FUNC(int) PyClass_IsSubclass(PyObject *, PyObject *);
76
77
78#ifdef __cplusplus
79}
80#endif
81#endif /* !Py_CLASSOBJECT_H */
sys/src/cmd/python/Include/cobject.h+54−0
@@ -0,0 +1,54 @@
1
2/* C objects to be exported from one extension module to another.
3
4 C objects are used for communication between extension modules.
5 They provide a way for an extension module to export a C interface
6 to other extension modules, so that extension modules can use the
7 Python import mechanism to link to one another.
8
9*/
10
11#ifndef Py_COBJECT_H
12#define Py_COBJECT_H
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17PyAPI_DATA(PyTypeObject) PyCObject_Type;
18
19#define PyCObject_Check(op) ((op)->ob_type == &PyCObject_Type)
20
21/* Create a PyCObject from a pointer to a C object and an optional
22 destructor function. If the second argument is non-null, then it
23 will be called with the first argument if and when the PyCObject is
24 destroyed.
25
26*/
27PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtr(
28 void *cobj, void (*destruct)(void*));
29
30
31/* Create a PyCObject from a pointer to a C object, a description object,
32 and an optional destructor function. If the third argument is non-null,
33 then it will be called with the first and second arguments if and when
34 the PyCObject is destroyed.
35*/
36PyAPI_FUNC(PyObject *) PyCObject_FromVoidPtrAndDesc(
37 void *cobj, void *desc, void (*destruct)(void*,void*));
38
39/* Retrieve a pointer to a C object from a PyCObject. */
40PyAPI_FUNC(void *) PyCObject_AsVoidPtr(PyObject *);
41
42/* Retrieve a pointer to a description object from a PyCObject. */
43PyAPI_FUNC(void *) PyCObject_GetDesc(PyObject *);
44
45/* Import a pointer to a C object from a module using a PyCObject. */
46PyAPI_FUNC(void *) PyCObject_Import(char *module_name, char *cobject_name);
47
48/* Modify a C object. Fails (==0) if object has a destructor. */
49PyAPI_FUNC(int) PyCObject_SetVoidPtr(PyObject *self, void *cobj);
50
51#ifdef __cplusplus
52}
53#endif
54#endif /* !Py_COBJECT_H */
sys/src/cmd/python/Include/code.h+94−0
@@ -0,0 +1,94 @@
1/* Definitions for bytecode */
2
3#ifndef Py_CODE_H
4#define Py_CODE_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9/* Bytecode object */
10typedef struct {
11 PyObject_HEAD
12 int co_argcount; /* #arguments, except *args */
13 int co_nlocals; /* #local variables */
14 int co_stacksize; /* #entries needed for evaluation stack */
15 int co_flags; /* CO_..., see below */
16 PyObject *co_code; /* instruction opcodes */
17 PyObject *co_consts; /* list (constants used) */
18 PyObject *co_names; /* list of strings (names used) */
19 PyObject *co_varnames; /* tuple of strings (local variable names) */
20 PyObject *co_freevars; /* tuple of strings (free variable names) */
21 PyObject *co_cellvars; /* tuple of strings (cell variable names) */
22 /* The rest doesn't count for hash/cmp */
23 PyObject *co_filename; /* string (where it was loaded from) */
24 PyObject *co_name; /* string (name, for reference) */
25 int co_firstlineno; /* first source line number */
26 PyObject *co_lnotab; /* string (encoding addr<->lineno mapping) */
27 void *co_zombieframe; /* for optimization only (see frameobject.c) */
28} PyCodeObject;
29
30/* Masks for co_flags above */
31#define CO_OPTIMIZED 0x0001
32#define CO_NEWLOCALS 0x0002
33#define CO_VARARGS 0x0004
34#define CO_VARKEYWORDS 0x0008
35#define CO_NESTED 0x0010
36#define CO_GENERATOR 0x0020
37/* The CO_NOFREE flag is set if there are no free or cell variables.
38 This information is redundant, but it allows a single flag test
39 to determine whether there is any extra work to be done when the
40 call frame it setup.
41*/
42#define CO_NOFREE 0x0040
43
44#if 0
45/* This is no longer used. Stopped defining in 2.5, do not re-use. */
46#define CO_GENERATOR_ALLOWED 0x1000
47#endif
48#define CO_FUTURE_DIVISION 0x2000
49#define CO_FUTURE_ABSOLUTE_IMPORT 0x4000 /* do absolute imports by default */
50#define CO_FUTURE_WITH_STATEMENT 0x8000
51
52/* This should be defined if a future statement modifies the syntax.
53 For example, when a keyword is added.
54*/
55#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
56
57#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */
58
59PyAPI_DATA(PyTypeObject) PyCode_Type;
60
61#define PyCode_Check(op) ((op)->ob_type == &PyCode_Type)
62#define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars))
63
64/* Public interface */
65PyAPI_FUNC(PyCodeObject *) PyCode_New(
66 int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
67 PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
68 /* same as struct above */
69PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
70
71/* for internal use only */
72#define _PyCode_GETCODEPTR(co, pp) \
73 ((*(co)->co_code->ob_type->tp_as_buffer->bf_getreadbuffer) \
74 ((co)->co_code, 0, (void **)(pp)))
75
76typedef struct _addr_pair {
77 int ap_lower;
78 int ap_upper;
79} PyAddrPair;
80
81/* Check whether lasti (an instruction offset) falls outside bounds
82 and whether it is a line number that should be traced. Returns
83 a line number if it should be traced or -1 if the line should not.
84
85 If lasti is not within bounds, updates bounds.
86*/
87
88PyAPI_FUNC(int) PyCode_CheckLineNumber(PyCodeObject* co,
89 int lasti, PyAddrPair *bounds);
90
91#ifdef __cplusplus
92}
93#endif
94#endif /* !Py_CODE_H */
sys/src/cmd/python/Include/codecs.h+167−0
@@ -0,0 +1,167 @@
1#ifndef Py_CODECREGISTRY_H
2#define Py_CODECREGISTRY_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/* ------------------------------------------------------------------------
8
9 Python Codec Registry and support functions
10
11
12Written by Marc-Andre Lemburg (mal@lemburg.com).
13
14Copyright (c) Corporation for National Research Initiatives.
15
16 ------------------------------------------------------------------------ */
17
18/* Register a new codec search function.
19
20 As side effect, this tries to load the encodings package, if not
21 yet done, to make sure that it is always first in the list of
22 search functions.
23
24 The search_function's refcount is incremented by this function. */
25
26PyAPI_FUNC(int) PyCodec_Register(
27 PyObject *search_function
28 );
29
30/* Codec register lookup API.
31
32 Looks up the given encoding and returns a CodecInfo object with
33 function attributes which implement the different aspects of
34 processing the encoding.
35
36 The encoding string is looked up converted to all lower-case
37 characters. This makes encodings looked up through this mechanism
38 effectively case-insensitive.
39
40 If no codec is found, a KeyError is set and NULL returned.
41
42 As side effect, this tries to load the encodings package, if not
43 yet done. This is part of the lazy load strategy for the encodings
44 package.
45
46 */
47
48PyAPI_FUNC(PyObject *) _PyCodec_Lookup(
49 const char *encoding
50 );
51
52/* Generic codec based encoding API.
53
54 object is passed through the encoder function found for the given
55 encoding using the error handling method defined by errors. errors
56 may be NULL to use the default method defined for the codec.
57
58 Raises a LookupError in case no encoder can be found.
59
60 */
61
62PyAPI_FUNC(PyObject *) PyCodec_Encode(
63 PyObject *object,
64 const char *encoding,
65 const char *errors
66 );
67
68/* Generic codec based decoding API.
69
70 object is passed through the decoder function found for the given
71 encoding using the error handling method defined by errors. errors
72 may be NULL to use the default method defined for the codec.
73
74 Raises a LookupError in case no encoder can be found.
75
76 */
77
78PyAPI_FUNC(PyObject *) PyCodec_Decode(
79 PyObject *object,
80 const char *encoding,
81 const char *errors
82 );
83
84/* --- Codec Lookup APIs --------------------------------------------------
85
86 All APIs return a codec object with incremented refcount and are
87 based on _PyCodec_Lookup(). The same comments w/r to the encoding
88 name also apply to these APIs.
89
90*/
91
92/* Get an encoder function for the given encoding. */
93
94PyAPI_FUNC(PyObject *) PyCodec_Encoder(
95 const char *encoding
96 );
97
98/* Get a decoder function for the given encoding. */
99
100PyAPI_FUNC(PyObject *) PyCodec_Decoder(
101 const char *encoding
102 );
103
104/* Get a IncrementalEncoder object for the given encoding. */
105
106PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
107 const char *encoding,
108 const char *errors
109 );
110
111/* Get a IncrementalDecoder object function for the given encoding. */
112
113PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
114 const char *encoding,
115 const char *errors
116 );
117
118/* Get a StreamReader factory function for the given encoding. */
119
120PyAPI_FUNC(PyObject *) PyCodec_StreamReader(
121 const char *encoding,
122 PyObject *stream,
123 const char *errors
124 );
125
126/* Get a StreamWriter factory function for the given encoding. */
127
128PyAPI_FUNC(PyObject *) PyCodec_StreamWriter(
129 const char *encoding,
130 PyObject *stream,
131 const char *errors
132 );
133
134/* Unicode encoding error handling callback registry API */
135
136/* Register the error handling callback function error under the name
137 name. This function will be called by the codec when it encounters
138 unencodable characters/undecodable bytes and doesn't know the
139 callback name, when name is specified as the error parameter
140 in the call to the encode/decode function.
141 Return 0 on success, -1 on error */
142PyAPI_FUNC(int) PyCodec_RegisterError(const char *name, PyObject *error);
143
144/* Lookup the error handling callback function registered under the
145 name error. As a special case NULL can be passed, in which case
146 the error handling callback for "strict" will be returned. */
147PyAPI_FUNC(PyObject *) PyCodec_LookupError(const char *name);
148
149/* raise exc as an exception */
150PyAPI_FUNC(PyObject *) PyCodec_StrictErrors(PyObject *exc);
151
152/* ignore the unicode error, skipping the faulty input */
153PyAPI_FUNC(PyObject *) PyCodec_IgnoreErrors(PyObject *exc);
154
155/* replace the unicode error with ? or U+FFFD */
156PyAPI_FUNC(PyObject *) PyCodec_ReplaceErrors(PyObject *exc);
157
158/* replace the unicode encode error with XML character references */
159PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
160
161/* replace the unicode encode error with backslash escapes (\x, \u and \U) */
162PyAPI_FUNC(PyObject *) PyCodec_BackslashReplaceErrors(PyObject *exc);
163
164#ifdef __cplusplus
165}
166#endif
167#endif /* !Py_CODECREGISTRY_H */
sys/src/cmd/python/Include/compile.h+39−0
@@ -0,0 +1,39 @@
1
2#ifndef Py_COMPILE_H
3#define Py_COMPILE_H
4
5#include "code.h"
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/* Public interface */
12struct _node; /* Declare the existence of this type */
13PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
14
15/* Future feature support */
16
17typedef struct {
18 int ff_features; /* flags set by future statements */
19 int ff_lineno; /* line number of last future statement */
20} PyFutureFeatures;
21
22#define FUTURE_NESTED_SCOPES "nested_scopes"
23#define FUTURE_GENERATORS "generators"
24#define FUTURE_DIVISION "division"
25#define FUTURE_ABSOLUTE_IMPORT "absolute_import"
26#define FUTURE_WITH_STATEMENT "with_statement"
27
28struct _mod; /* Declare the existence of this type */
29PyAPI_FUNC(PyCodeObject *) PyAST_Compile(struct _mod *, const char *,
30 PyCompilerFlags *, PyArena *);
31PyAPI_FUNC(PyFutureFeatures *) PyFuture_FromAST(struct _mod *, const char *);
32
33#define ERR_LATE_FUTURE \
34"from __future__ imports must occur at the beginning of the file"
35
36#ifdef __cplusplus
37}
38#endif
39#endif /* !Py_COMPILE_H */
sys/src/cmd/python/Include/complexobject.h+58−0
@@ -0,0 +1,58 @@
1/* Complex number structure */
2
3#ifndef Py_COMPLEXOBJECT_H
4#define Py_COMPLEXOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9typedef struct {
10 double real;
11 double imag;
12} Py_complex;
13
14/* Operations on complex numbers from complexmodule.c */
15
16#define c_sum _Py_c_sum
17#define c_diff _Py_c_diff
18#define c_neg _Py_c_neg
19#define c_prod _Py_c_prod
20#define c_quot _Py_c_quot
21#define c_pow _Py_c_pow
22
23PyAPI_FUNC(Py_complex) c_sum(Py_complex, Py_complex);
24PyAPI_FUNC(Py_complex) c_diff(Py_complex, Py_complex);
25PyAPI_FUNC(Py_complex) c_neg(Py_complex);
26PyAPI_FUNC(Py_complex) c_prod(Py_complex, Py_complex);
27PyAPI_FUNC(Py_complex) c_quot(Py_complex, Py_complex);
28PyAPI_FUNC(Py_complex) c_pow(Py_complex, Py_complex);
29
30
31/* Complex object interface */
32
33/*
34PyComplexObject represents a complex number with double-precision
35real and imaginary parts.
36*/
37
38typedef struct {
39 PyObject_HEAD
40 Py_complex cval;
41} PyComplexObject;
42
43PyAPI_DATA(PyTypeObject) PyComplex_Type;
44
45#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type)
46#define PyComplex_CheckExact(op) ((op)->ob_type == &PyComplex_Type)
47
48PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex);
49PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag);
50
51PyAPI_FUNC(double) PyComplex_RealAsDouble(PyObject *op);
52PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op);
53PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op);
54
55#ifdef __cplusplus
56}
57#endif
58#endif /* !Py_COMPLEXOBJECT_H */
sys/src/cmd/python/Include/datetime.h+245−0
@@ -0,0 +1,245 @@
1/* datetime.h
2 */
3
4#ifndef DATETIME_H
5#define DATETIME_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/* Fields are packed into successive bytes, each viewed as unsigned and
11 * big-endian, unless otherwise noted:
12 *
13 * byte offset
14 * 0 year 2 bytes, 1-9999
15 * 2 month 1 byte, 1-12
16 * 3 day 1 byte, 1-31
17 * 4 hour 1 byte, 0-23
18 * 5 minute 1 byte, 0-59
19 * 6 second 1 byte, 0-59
20 * 7 usecond 3 bytes, 0-999999
21 * 10
22 */
23
24/* # of bytes for year, month, and day. */
25#define _PyDateTime_DATE_DATASIZE 4
26
27/* # of bytes for hour, minute, second, and usecond. */
28#define _PyDateTime_TIME_DATASIZE 6
29
30/* # of bytes for year, month, day, hour, minute, second, and usecond. */
31#define _PyDateTime_DATETIME_DATASIZE 10
32
33
34typedef struct
35{
36 PyObject_HEAD
37 long hashcode; /* -1 when unknown */
38 int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
39 int seconds; /* 0 <= seconds < 24*3600 is invariant */
40 int microseconds; /* 0 <= microseconds < 1000000 is invariant */
41} PyDateTime_Delta;
42
43typedef struct
44{
45 PyObject_HEAD /* a pure abstract base clase */
46} PyDateTime_TZInfo;
47
48
49/* The datetime and time types have hashcodes, and an optional tzinfo member,
50 * present if and only if hastzinfo is true.
51 */
52#define _PyTZINFO_HEAD \
53 PyObject_HEAD \
54 long hashcode; \
55 char hastzinfo; /* boolean flag */
56
57/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
58 * convenient to cast to, when getting at the hastzinfo member of objects
59 * starting with _PyTZINFO_HEAD.
60 */
61typedef struct
62{
63 _PyTZINFO_HEAD
64} _PyDateTime_BaseTZInfo;
65
66/* All time objects are of PyDateTime_TimeType, but that can be allocated
67 * in two ways, with or without a tzinfo member. Without is the same as
68 * tzinfo == None, but consumes less memory. _PyDateTime_BaseTime is an
69 * internal struct used to allocate the right amount of space for the
70 * "without" case.
71 */
72#define _PyDateTime_TIMEHEAD \
73 _PyTZINFO_HEAD \
74 unsigned char data[_PyDateTime_TIME_DATASIZE];
75
76typedef struct
77{
78 _PyDateTime_TIMEHEAD
79} _PyDateTime_BaseTime; /* hastzinfo false */
80
81typedef struct
82{
83 _PyDateTime_TIMEHEAD
84 PyObject *tzinfo;
85} PyDateTime_Time; /* hastzinfo true */
86
87
88/* All datetime objects are of PyDateTime_DateTimeType, but that can be
89 * allocated in two ways too, just like for time objects above. In addition,
90 * the plain date type is a base class for datetime, so it must also have
91 * a hastzinfo member (although it's unused there).
92 */
93typedef struct
94{
95 _PyTZINFO_HEAD
96 unsigned char data[_PyDateTime_DATE_DATASIZE];
97} PyDateTime_Date;
98
99#define _PyDateTime_DATETIMEHEAD \
100 _PyTZINFO_HEAD \
101 unsigned char data[_PyDateTime_DATETIME_DATASIZE];
102
103typedef struct
104{
105 _PyDateTime_DATETIMEHEAD
106} _PyDateTime_BaseDateTime; /* hastzinfo false */
107
108typedef struct
109{
110 _PyDateTime_DATETIMEHEAD
111 PyObject *tzinfo;
112} PyDateTime_DateTime; /* hastzinfo true */
113
114
115/* Apply for date and datetime instances. */
116#define PyDateTime_GET_YEAR(o) ((((PyDateTime_Date*)o)->data[0] << 8) | \
117 ((PyDateTime_Date*)o)->data[1])
118#define PyDateTime_GET_MONTH(o) (((PyDateTime_Date*)o)->data[2])
119#define PyDateTime_GET_DAY(o) (((PyDateTime_Date*)o)->data[3])
120
121#define PyDateTime_DATE_GET_HOUR(o) (((PyDateTime_DateTime*)o)->data[4])
122#define PyDateTime_DATE_GET_MINUTE(o) (((PyDateTime_DateTime*)o)->data[5])
123#define PyDateTime_DATE_GET_SECOND(o) (((PyDateTime_DateTime*)o)->data[6])
124#define PyDateTime_DATE_GET_MICROSECOND(o) \
125 ((((PyDateTime_DateTime*)o)->data[7] << 16) | \
126 (((PyDateTime_DateTime*)o)->data[8] << 8) | \
127 ((PyDateTime_DateTime*)o)->data[9])
128
129/* Apply for time instances. */
130#define PyDateTime_TIME_GET_HOUR(o) (((PyDateTime_Time*)o)->data[0])
131#define PyDateTime_TIME_GET_MINUTE(o) (((PyDateTime_Time*)o)->data[1])
132#define PyDateTime_TIME_GET_SECOND(o) (((PyDateTime_Time*)o)->data[2])
133#define PyDateTime_TIME_GET_MICROSECOND(o) \
134 ((((PyDateTime_Time*)o)->data[3] << 16) | \
135 (((PyDateTime_Time*)o)->data[4] << 8) | \
136 ((PyDateTime_Time*)o)->data[5])
137
138
139/* Define structure for C API. */
140typedef struct {
141 /* type objects */
142 PyTypeObject *DateType;
143 PyTypeObject *DateTimeType;
144 PyTypeObject *TimeType;
145 PyTypeObject *DeltaType;
146 PyTypeObject *TZInfoType;
147
148 /* constructors */
149 PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
150 PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
151 PyObject*, PyTypeObject*);
152 PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
153 PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
154
155 /* constructors for the DB API */
156 PyObject *(*DateTime_FromTimestamp)(PyObject*, PyObject*, PyObject*);
157 PyObject *(*Date_FromTimestamp)(PyObject*, PyObject*);
158
159} PyDateTime_CAPI;
160
161
162/* "magic" constant used to partially protect against developer mistakes. */
163#define DATETIME_API_MAGIC 0x414548d5
164
165#ifdef Py_BUILD_CORE
166
167/* Macros for type checking when building the Python core. */
168#define PyDate_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateType)
169#define PyDate_CheckExact(op) ((op)->ob_type == &PyDateTime_DateType)
170
171#define PyDateTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_DateTimeType)
172#define PyDateTime_CheckExact(op) ((op)->ob_type == &PyDateTime_DateTimeType)
173
174#define PyTime_Check(op) PyObject_TypeCheck(op, &PyDateTime_TimeType)
175#define PyTime_CheckExact(op) ((op)->ob_type == &PyDateTime_TimeType)
176
177#define PyDelta_Check(op) PyObject_TypeCheck(op, &PyDateTime_DeltaType)
178#define PyDelta_CheckExact(op) ((op)->ob_type == &PyDateTime_DeltaType)
179
180#define PyTZInfo_Check(op) PyObject_TypeCheck(op, &PyDateTime_TZInfoType)
181#define PyTZInfo_CheckExact(op) ((op)->ob_type == &PyDateTime_TZInfoType)
182
183#else
184
185/* Define global variable for the C API and a macro for setting it. */
186static PyDateTime_CAPI *PyDateTimeAPI;
187
188#define PyDateTime_IMPORT \
189 PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
190 "datetime_CAPI")
191
192/* This macro would be used if PyCObject_ImportEx() was created.
193#define PyDateTime_IMPORT \
194 PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_ImportEx("datetime", \
195 "datetime_CAPI", \
196 DATETIME_API_MAGIC)
197*/
198
199/* Macros for type checking when not building the Python core. */
200#define PyDate_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateType)
201#define PyDate_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateType)
202
203#define PyDateTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DateTimeType)
204#define PyDateTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DateTimeType)
205
206#define PyTime_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TimeType)
207#define PyTime_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TimeType)
208
209#define PyDelta_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->DeltaType)
210#define PyDelta_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->DeltaType)
211
212#define PyTZInfo_Check(op) PyObject_TypeCheck(op, PyDateTimeAPI->TZInfoType)
213#define PyTZInfo_CheckExact(op) ((op)->ob_type == PyDateTimeAPI->TZInfoType)
214
215/* Macros for accessing constructors in a simplified fashion. */
216#define PyDate_FromDate(year, month, day) \
217 PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
218
219#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
220 PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
221 min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
222
223#define PyTime_FromTime(hour, minute, second, usecond) \
224 PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
225 Py_None, PyDateTimeAPI->TimeType)
226
227#define PyDelta_FromDSU(days, seconds, useconds) \
228 PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
229 PyDateTimeAPI->DeltaType)
230
231/* Macros supporting the DB API. */
232#define PyDateTime_FromTimestamp(args) \
233 PyDateTimeAPI->DateTime_FromTimestamp( \
234 (PyObject*) (PyDateTimeAPI->DateTimeType), args, NULL)
235
236#define PyDate_FromTimestamp(args) \
237 PyDateTimeAPI->Date_FromTimestamp( \
238 (PyObject*) (PyDateTimeAPI->DateType), args)
239
240#endif /* Py_BUILD_CORE */
241
242#ifdef __cplusplus
243}
244#endif
245#endif
sys/src/cmd/python/Include/descrobject.h+91−0
@@ -0,0 +1,91 @@
1/* Descriptors */
2#ifndef Py_DESCROBJECT_H
3#define Py_DESCROBJECT_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8typedef PyObject *(*getter)(PyObject *, void *);
9typedef int (*setter)(PyObject *, PyObject *, void *);
10
11typedef struct PyGetSetDef {
12 char *name;
13 getter get;
14 setter set;
15 char *doc;
16 void *closure;
17} PyGetSetDef;
18
19typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
20 void *wrapped);
21
22typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
23 void *wrapped, PyObject *kwds);
24
25struct wrapperbase {
26 char *name;
27 int offset;
28 void *function;
29 wrapperfunc wrapper;
30 char *doc;
31 int flags;
32 PyObject *name_strobj;
33};
34
35/* Flags for above struct */
36#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */
37
38/* Various kinds of descriptor objects */
39
40#define PyDescr_COMMON \
41 PyObject_HEAD \
42 PyTypeObject *d_type; \
43 PyObject *d_name
44
45typedef struct {
46 PyDescr_COMMON;
47} PyDescrObject;
48
49typedef struct {
50 PyDescr_COMMON;
51 PyMethodDef *d_method;
52} PyMethodDescrObject;
53
54typedef struct {
55 PyDescr_COMMON;
56 struct PyMemberDef *d_member;
57} PyMemberDescrObject;
58
59typedef struct {
60 PyDescr_COMMON;
61 PyGetSetDef *d_getset;
62} PyGetSetDescrObject;
63
64typedef struct {
65 PyDescr_COMMON;
66 struct wrapperbase *d_base;
67 void *d_wrapped; /* This can be any function pointer */
68} PyWrapperDescrObject;
69
70PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
71
72PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
73PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
74PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
75 struct PyMemberDef *);
76PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
77 struct PyGetSetDef *);
78PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
79 struct wrapperbase *, void *);
80#define PyDescr_IsData(d) ((d)->ob_type->tp_descr_set != NULL)
81
82PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
83PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
84
85
86PyAPI_DATA(PyTypeObject) PyProperty_Type;
87#ifdef __cplusplus
88}
89#endif
90#endif /* !Py_DESCROBJECT_H */
91
sys/src/cmd/python/Include/dictobject.h+141−0
@@ -0,0 +1,141 @@
1#ifndef Py_DICTOBJECT_H
2#define Py_DICTOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Dictionary object type -- mapping from hashable object to object */
9
10/* The distribution includes a separate file, Objects/dictnotes.txt,
11 describing explorations into dictionary design and optimization.
12 It covers typical dictionary use patterns, the parameters for
13 tuning dictionaries, and several ideas for possible optimizations.
14*/
15
16/*
17There are three kinds of slots in the table:
18
191. Unused. me_key == me_value == NULL
20 Does not hold an active (key, value) pair now and never did. Unused can
21 transition to Active upon key insertion. This is the only case in which
22 me_key is NULL, and is each slot's initial state.
23
242. Active. me_key != NULL and me_key != dummy and me_value != NULL
25 Holds an active (key, value) pair. Active can transition to Dummy upon
26 key deletion. This is the only case in which me_value != NULL.
27
283. Dummy. me_key == dummy and me_value == NULL
29 Previously held an active (key, value) pair, but that was deleted and an
30 active pair has not yet overwritten the slot. Dummy can transition to
31 Active upon key insertion. Dummy slots cannot be made Unused again
32 (cannot have me_key set to NULL), else the probe sequence in case of
33 collision would have no way to know they were once active.
34
35Note: .popitem() abuses the me_hash field of an Unused or Dummy slot to
36hold a search finger. The me_hash field of Unused or Dummy slots has no
37meaning otherwise.
38*/
39
40/* PyDict_MINSIZE is the minimum size of a dictionary. This many slots are
41 * allocated directly in the dict object (in the ma_smalltable member).
42 * It must be a power of 2, and at least 4. 8 allows dicts with no more
43 * than 5 active entries to live in ma_smalltable (and so avoid an
44 * additional malloc); instrumentation suggested this suffices for the
45 * majority of dicts (consisting mostly of usually-small instance dicts and
46 * usually-small dicts created to pass keyword arguments).
47 */
48#define PyDict_MINSIZE 8
49
50typedef struct {
51 /* Cached hash code of me_key. Note that hash codes are C longs.
52 * We have to use Py_ssize_t instead because dict_popitem() abuses
53 * me_hash to hold a search finger.
54 */
55 Py_ssize_t me_hash;
56 PyObject *me_key;
57 PyObject *me_value;
58} PyDictEntry;
59
60/*
61To ensure the lookup algorithm terminates, there must be at least one Unused
62slot (NULL key) in the table.
63The value ma_fill is the number of non-NULL keys (sum of Active and Dummy);
64ma_used is the number of non-NULL, non-dummy keys (== the number of non-NULL
65values == the number of Active items).
66To avoid slowing down lookups on a near-full table, we resize the table when
67it's two-thirds full.
68*/
69typedef struct _dictobject PyDictObject;
70struct _dictobject {
71 PyObject_HEAD
72 Py_ssize_t ma_fill; /* # Active + # Dummy */
73 Py_ssize_t ma_used; /* # Active */
74
75 /* The table contains ma_mask + 1 slots, and that's a power of 2.
76 * We store the mask instead of the size because the mask is more
77 * frequently needed.
78 */
79 Py_ssize_t ma_mask;
80
81 /* ma_table points to ma_smalltable for small tables, else to
82 * additional malloc'ed memory. ma_table is never NULL! This rule
83 * saves repeated runtime null-tests in the workhorse getitem and
84 * setitem calls.
85 */
86 PyDictEntry *ma_table;
87 PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
88 PyDictEntry ma_smalltable[PyDict_MINSIZE];
89};
90
91PyAPI_DATA(PyTypeObject) PyDict_Type;
92
93#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
94#define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type)
95
96PyAPI_FUNC(PyObject *) PyDict_New(void);
97PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
98PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
99PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);
100PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
101PyAPI_FUNC(int) PyDict_Next(
102 PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
103PyAPI_FUNC(int) _PyDict_Next(
104 PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);
105PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
106PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
107PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
108PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
109PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);
110PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);
111PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, long hash);
112
113/* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */
114PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);
115
116/* PyDict_Merge updates/merges from a mapping object (an object that
117 supports PyMapping_Keys() and PyObject_GetItem()). If override is true,
118 the last occurrence of a key wins, else the first. The Python
119 dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).
120*/
121PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,
122 PyObject *other,
123 int override);
124
125/* PyDict_MergeFromSeq2 updates/merges from an iterable object producing
126 iterable objects of length 2. If override is true, the last occurrence
127 of a key wins, else the first. The Python dict constructor dict(seq2)
128 is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).
129*/
130PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,
131 PyObject *seq2,
132 int override);
133
134PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);
135PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
136PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
137
138#ifdef __cplusplus
139}
140#endif
141#endif /* !Py_DICTOBJECT_H */
sys/src/cmd/python/Include/enumobject.h+17−0
@@ -0,0 +1,17 @@
1#ifndef Py_ENUMOBJECT_H
2#define Py_ENUMOBJECT_H
3
4/* Enumerate Object */
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_DATA(PyTypeObject) PyEnum_Type;
11PyAPI_DATA(PyTypeObject) PyReversed_Type;
12
13#ifdef __cplusplus
14}
15#endif
16
17#endif /* !Py_ENUMOBJECT_H */
sys/src/cmd/python/Include/errcode.h+36−0
@@ -0,0 +1,36 @@
1#ifndef Py_ERRCODE_H
2#define Py_ERRCODE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Error codes passed around between file input, tokenizer, parser and
9 interpreter. This is necessary so we can turn them into Python
10 exceptions at a higher level. Note that some errors have a
11 slightly different meaning when passed from the tokenizer to the
12 parser than when passed from the parser to the interpreter; e.g.
13 the parser only returns E_EOF when it hits EOF immediately, and it
14 never returns E_OK. */
15
16#define E_OK 10 /* No error */
17#define E_EOF 11 /* End Of File */
18#define E_INTR 12 /* Interrupted */
19#define E_TOKEN 13 /* Bad token */
20#define E_SYNTAX 14 /* Syntax error */
21#define E_NOMEM 15 /* Ran out of memory */
22#define E_DONE 16 /* Parsing complete */
23#define E_ERROR 17 /* Execution error */
24#define E_TABSPACE 18 /* Inconsistent mixing of tabs and spaces */
25#define E_OVERFLOW 19 /* Node had too many children */
26#define E_TOODEEP 20 /* Too many indentation levels */
27#define E_DEDENT 21 /* No matching outer block for dedent */
28#define E_DECODE 22 /* Error in decoding into Unicode */
29#define E_EOFS 23 /* EOF in triple-quoted string */
30#define E_EOLS 24 /* EOL in single-quoted string */
31#define E_LINECONT 25 /* Unexpected characters after a line continuation */
32
33#ifdef __cplusplus
34}
35#endif
36#endif /* !Py_ERRCODE_H */
sys/src/cmd/python/Include/eval.h+25−0
@@ -0,0 +1,25 @@
1
2/* Interface to execute compiled code */
3
4#ifndef Py_EVAL_H
5#define Py_EVAL_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *);
11
12PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyCodeObject *co,
13 PyObject *globals,
14 PyObject *locals,
15 PyObject **args, int argc,
16 PyObject **kwds, int kwdc,
17 PyObject **defs, int defc,
18 PyObject *closure);
19
20PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
21
22#ifdef __cplusplus
23}
24#endif
25#endif /* !Py_EVAL_H */
sys/src/cmd/python/Include/fileobject.h+63−0
@@ -0,0 +1,63 @@
1
2/* File object interface */
3
4#ifndef Py_FILEOBJECT_H
5#define Py_FILEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct {
11 PyObject_HEAD
12 FILE *f_fp;
13 PyObject *f_name;
14 PyObject *f_mode;
15 int (*f_close)(FILE *);
16 int f_softspace; /* Flag used by 'print' command */
17 int f_binary; /* Flag which indicates whether the file is
18 open in binary (1) or text (0) mode */
19 char* f_buf; /* Allocated readahead buffer */
20 char* f_bufend; /* Points after last occupied position */
21 char* f_bufptr; /* Current buffer position */
22 char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
23 int f_univ_newline; /* Handle any newline convention */
24 int f_newlinetypes; /* Types of newlines seen */
25 int f_skipnextlf; /* Skip next \n */
26 PyObject *f_encoding;
27 PyObject *weakreflist; /* List of weak references */
28} PyFileObject;
29
30PyAPI_DATA(PyTypeObject) PyFile_Type;
31
32#define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
33#define PyFile_CheckExact(op) ((op)->ob_type == &PyFile_Type)
34
35PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
36PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
37PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
38PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
39 int (*)(FILE *));
40PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
41PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
42PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
43PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
44PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
45PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
46PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
47
48/* The default encoding used by the platform file system APIs
49 If non-NULL, this is different than the default encoding for strings
50*/
51PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
52
53/* Routines to replace fread() and fgets() which accept any of \r, \n
54 or \r\n as line terminators.
55*/
56#define PY_STDIOTEXTMODE "b"
57char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
58size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
59
60#ifdef __cplusplus
61}
62#endif
63#endif /* !Py_FILEOBJECT_H */
sys/src/cmd/python/Include/floatobject.h+100−0
@@ -0,0 +1,100 @@
1
2/* Float object interface */
3
4/*
5PyFloatObject represents a (double precision) floating point number.
6*/
7
8#ifndef Py_FLOATOBJECT_H
9#define Py_FLOATOBJECT_H
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14typedef struct {
15 PyObject_HEAD
16 double ob_fval;
17} PyFloatObject;
18
19PyAPI_DATA(PyTypeObject) PyFloat_Type;
20
21#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
22#define PyFloat_CheckExact(op) ((op)->ob_type == &PyFloat_Type)
23
24/* Return Python float from string PyObject. Second argument ignored on
25 input, and, if non-NULL, NULL is stored into *junk (this tried to serve a
26 purpose once but can't be made to work as intended). */
27PyAPI_FUNC(PyObject *) PyFloat_FromString(PyObject*, char** junk);
28
29/* Return Python float from C double. */
30PyAPI_FUNC(PyObject *) PyFloat_FromDouble(double);
31
32/* Extract C double from Python float. The macro version trades safety for
33 speed. */
34PyAPI_FUNC(double) PyFloat_AsDouble(PyObject *);
35#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
36
37/* Write repr(v) into the char buffer argument, followed by null byte. The
38 buffer must be "big enough"; >= 100 is very safe.
39 PyFloat_AsReprString(buf, x) strives to print enough digits so that
40 PyFloat_FromString(buf) then reproduces x exactly. */
41PyAPI_FUNC(void) PyFloat_AsReprString(char*, PyFloatObject *v);
42
43/* Write str(v) into the char buffer argument, followed by null byte. The
44 buffer must be "big enough"; >= 100 is very safe. Note that it's
45 unusual to be able to get back the float you started with from
46 PyFloat_AsString's result -- use PyFloat_AsReprString() if you want to
47 preserve precision across conversions. */
48PyAPI_FUNC(void) PyFloat_AsString(char*, PyFloatObject *v);
49
50/* _PyFloat_{Pack,Unpack}{4,8}
51 *
52 * The struct and pickle (at least) modules need an efficient platform-
53 * independent way to store floating-point values as byte strings.
54 * The Pack routines produce a string from a C double, and the Unpack
55 * routines produce a C double from such a string. The suffix (4 or 8)
56 * specifies the number of bytes in the string.
57 *
58 * On platforms that appear to use (see _PyFloat_Init()) IEEE-754 formats
59 * these functions work by copying bits. On other platforms, the formats the
60 * 4- byte format is identical to the IEEE-754 single precision format, and
61 * the 8-byte format to the IEEE-754 double precision format, although the
62 * packing of INFs and NaNs (if such things exist on the platform) isn't
63 * handled correctly, and attempting to unpack a string containing an IEEE
64 * INF or NaN will raise an exception.
65 *
66 * On non-IEEE platforms with more precision, or larger dynamic range, than
67 * 754 supports, not all values can be packed; on non-IEEE platforms with less
68 * precision, or smaller dynamic range, not all values can be unpacked. What
69 * happens in such cases is partly accidental (alas).
70 */
71
72/* The pack routines write 4 or 8 bytes, starting at p. le is a bool
73 * argument, true if you want the string in little-endian format (exponent
74 * last, at p+3 or p+7), false if you want big-endian format (exponent
75 * first, at p).
76 * Return value: 0 if all is OK, -1 if error (and an exception is
77 * set, most likely OverflowError).
78 * There are two problems on non-IEEE platforms:
79 * 1): What this does is undefined if x is a NaN or infinity.
80 * 2): -0.0 and +0.0 produce the same string.
81 */
82PyAPI_FUNC(int) _PyFloat_Pack4(double x, unsigned char *p, int le);
83PyAPI_FUNC(int) _PyFloat_Pack8(double x, unsigned char *p, int le);
84
85/* The unpack routines read 4 or 8 bytes, starting at p. le is a bool
86 * argument, true if the string is in little-endian format (exponent
87 * last, at p+3 or p+7), false if big-endian (exponent first, at p).
88 * Return value: The unpacked double. On error, this is -1.0 and
89 * PyErr_Occurred() is true (and an exception is set, most likely
90 * OverflowError). Note that on a non-IEEE platform this will refuse
91 * to unpack a string that represents a NaN or infinity.
92 */
93PyAPI_FUNC(double) _PyFloat_Unpack4(const unsigned char *p, int le);
94PyAPI_FUNC(double) _PyFloat_Unpack8(const unsigned char *p, int le);
95
96
97#ifdef __cplusplus
98}
99#endif
100#endif /* !Py_FLOATOBJECT_H */
sys/src/cmd/python/Include/frameobject.h+81−0
@@ -0,0 +1,81 @@
1
2/* Frame object interface */
3
4#ifndef Py_FRAMEOBJECT_H
5#define Py_FRAMEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct {
11 int b_type; /* what kind of block this is */
12 int b_handler; /* where to jump to find handler */
13 int b_level; /* value stack level to pop to */
14} PyTryBlock;
15
16typedef struct _frame {
17 PyObject_VAR_HEAD
18 struct _frame *f_back; /* previous frame, or NULL */
19 PyCodeObject *f_code; /* code segment */
20 PyObject *f_builtins; /* builtin symbol table (PyDictObject) */
21 PyObject *f_globals; /* global symbol table (PyDictObject) */
22 PyObject *f_locals; /* local symbol table (any mapping) */
23 PyObject **f_valuestack; /* points after the last local */
24 /* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
25 Frame evaluation usually NULLs it, but a frame that yields sets it
26 to the current stack top. */
27 PyObject **f_stacktop;
28 PyObject *f_trace; /* Trace function */
29
30 /* If an exception is raised in this frame, the next three are used to
31 * record the exception info (if any) originally in the thread state. See
32 * comments before set_exc_info() -- it's not obvious.
33 * Invariant: if _type is NULL, then so are _value and _traceback.
34 * Desired invariant: all three are NULL, or all three are non-NULL. That
35 * one isn't currently true, but "should be".
36 */
37 PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;
38
39 PyThreadState *f_tstate;
40 int f_lasti; /* Last instruction if called */
41 /* As of 2.3 f_lineno is only valid when tracing is active (i.e. when
42 f_trace is set) -- at other times use PyCode_Addr2Line instead. */
43 int f_lineno; /* Current line number */
44 int f_iblock; /* index in f_blockstack */
45 PyTryBlock f_blockstack[CO_MAXBLOCKS]; /* for try and loop blocks */
46 PyObject *f_localsplus[1]; /* locals+stack, dynamically sized */
47} PyFrameObject;
48
49
50/* Standard object interface */
51
52PyAPI_DATA(PyTypeObject) PyFrame_Type;
53
54#define PyFrame_Check(op) ((op)->ob_type == &PyFrame_Type)
55#define PyFrame_IsRestricted(f) \
56 ((f)->f_builtins != (f)->f_tstate->interp->builtins)
57
58PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
59 PyObject *, PyObject *);
60
61
62/* The rest of the interface is specific for frame objects */
63
64/* Block management functions */
65
66PyAPI_FUNC(void) PyFrame_BlockSetup(PyFrameObject *, int, int, int);
67PyAPI_FUNC(PyTryBlock *) PyFrame_BlockPop(PyFrameObject *);
68
69/* Extend the value stack */
70
71PyAPI_FUNC(PyObject **) PyFrame_ExtendStack(PyFrameObject *, int, int);
72
73/* Conversions between "fast locals" and locals in dictionary */
74
75PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
76PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
77
78#ifdef __cplusplus
79}
80#endif
81#endif /* !Py_FRAMEOBJECT_H */
sys/src/cmd/python/Include/funcobject.h+76−0
@@ -0,0 +1,76 @@
1
2/* Function object interface */
3
4#ifndef Py_FUNCOBJECT_H
5#define Py_FUNCOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/* Function objects and code objects should not be confused with each other:
11 *
12 * Function objects are created by the execution of the 'def' statement.
13 * They reference a code object in their func_code attribute, which is a
14 * purely syntactic object, i.e. nothing more than a compiled version of some
15 * source code lines. There is one code object per source code "fragment",
16 * but each code object can be referenced by zero or many function objects
17 * depending only on how many times the 'def' statement in the source was
18 * executed so far.
19 */
20
21typedef struct {
22 PyObject_HEAD
23 PyObject *func_code; /* A code object */
24 PyObject *func_globals; /* A dictionary (other mappings won't do) */
25 PyObject *func_defaults; /* NULL or a tuple */
26 PyObject *func_closure; /* NULL or a tuple of cell objects */
27 PyObject *func_doc; /* The __doc__ attribute, can be anything */
28 PyObject *func_name; /* The __name__ attribute, a string object */
29 PyObject *func_dict; /* The __dict__ attribute, a dict or NULL */
30 PyObject *func_weakreflist; /* List of weak references */
31 PyObject *func_module; /* The __module__ attribute, can be anything */
32
33 /* Invariant:
34 * func_closure contains the bindings for func_code->co_freevars, so
35 * PyTuple_Size(func_closure) == PyCode_GetNumFree(func_code)
36 * (func_closure may be NULL if PyCode_GetNumFree(func_code) == 0).
37 */
38} PyFunctionObject;
39
40PyAPI_DATA(PyTypeObject) PyFunction_Type;
41
42#define PyFunction_Check(op) ((op)->ob_type == &PyFunction_Type)
43
44PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
45PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *);
46PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
47PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
48PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
49PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
50PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
51PyAPI_FUNC(int) PyFunction_SetClosure(PyObject *, PyObject *);
52
53/* Macros for direct access to these values. Type checks are *not*
54 done, so use with care. */
55#define PyFunction_GET_CODE(func) \
56 (((PyFunctionObject *)func) -> func_code)
57#define PyFunction_GET_GLOBALS(func) \
58 (((PyFunctionObject *)func) -> func_globals)
59#define PyFunction_GET_MODULE(func) \
60 (((PyFunctionObject *)func) -> func_module)
61#define PyFunction_GET_DEFAULTS(func) \
62 (((PyFunctionObject *)func) -> func_defaults)
63#define PyFunction_GET_CLOSURE(func) \
64 (((PyFunctionObject *)func) -> func_closure)
65
66/* The classmethod and staticmethod types lives here, too */
67PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
68PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
69
70PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
71PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
72
73#ifdef __cplusplus
74}
75#endif
76#endif /* !Py_FUNCOBJECT_H */
sys/src/cmd/python/Include/genobject.h+37−0
@@ -0,0 +1,37 @@
1
2/* Generator object interface */
3
4#ifndef Py_GENOBJECT_H
5#define Py_GENOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10struct _frame; /* Avoid including frameobject.h */
11
12typedef struct {
13 PyObject_HEAD
14 /* The gi_ prefix is intended to remind of generator-iterator. */
15
16 /* Note: gi_frame can be NULL if the generator is "finished" */
17 struct _frame *gi_frame;
18
19 /* True if generator is being executed. */
20 int gi_running;
21
22 /* List of weak reference. */
23 PyObject *gi_weakreflist;
24} PyGenObject;
25
26PyAPI_DATA(PyTypeObject) PyGen_Type;
27
28#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
29#define PyGen_CheckExact(op) ((op)->ob_type == &PyGen_Type)
30
31PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *);
32PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *);
33
34#ifdef __cplusplus
35}
36#endif
37#endif /* !Py_GENOBJECT_H */
sys/src/cmd/python/Include/graminit.h+84−0
@@ -0,0 +1,84 @@
1#define single_input 256
2#define file_input 257
3#define eval_input 258
4#define decorator 259
5#define decorators 260
6#define funcdef 261
7#define parameters 262
8#define varargslist 263
9#define fpdef 264
10#define fplist 265
11#define stmt 266
12#define simple_stmt 267
13#define small_stmt 268
14#define expr_stmt 269
15#define augassign 270
16#define print_stmt 271
17#define del_stmt 272
18#define pass_stmt 273
19#define flow_stmt 274
20#define break_stmt 275
21#define continue_stmt 276
22#define return_stmt 277
23#define yield_stmt 278
24#define raise_stmt 279
25#define import_stmt 280
26#define import_name 281
27#define import_from 282
28#define import_as_name 283
29#define dotted_as_name 284
30#define import_as_names 285
31#define dotted_as_names 286
32#define dotted_name 287
33#define global_stmt 288
34#define exec_stmt 289
35#define assert_stmt 290
36#define compound_stmt 291
37#define if_stmt 292
38#define while_stmt 293
39#define for_stmt 294
40#define try_stmt 295
41#define with_stmt 296
42#define with_var 297
43#define except_clause 298
44#define suite 299
45#define testlist_safe 300
46#define old_test 301
47#define old_lambdef 302
48#define test 303
49#define or_test 304
50#define and_test 305
51#define not_test 306
52#define comparison 307
53#define comp_op 308
54#define expr 309
55#define xor_expr 310
56#define and_expr 311
57#define shift_expr 312
58#define arith_expr 313
59#define term 314
60#define factor 315
61#define power 316
62#define atom 317
63#define listmaker 318
64#define testlist_gexp 319
65#define lambdef 320
66#define trailer 321
67#define subscriptlist 322
68#define subscript 323
69#define sliceop 324
70#define exprlist 325
71#define testlist 326
72#define dictmaker 327
73#define classdef 328
74#define arglist 329
75#define argument 330
76#define list_iter 331
77#define list_for 332
78#define list_if 333
79#define gen_iter 334
80#define gen_for 335
81#define gen_if 336
82#define testlist1 337
83#define encoding_decl 338
84#define yield_expr 339
sys/src/cmd/python/Include/grammar.h+93−0
@@ -0,0 +1,93 @@
1
2/* Grammar interface */
3
4#ifndef Py_GRAMMAR_H
5#define Py_GRAMMAR_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#include "bitset.h" /* Sigh... */
11
12/* A label of an arc */
13
14typedef struct {
15 int lb_type;
16 char *lb_str;
17} label;
18
19#define EMPTY 0 /* Label number 0 is by definition the empty label */
20
21/* A list of labels */
22
23typedef struct {
24 int ll_nlabels;
25 label *ll_label;
26} labellist;
27
28/* An arc from one state to another */
29
30typedef struct {
31 short a_lbl; /* Label of this arc */
32 short a_arrow; /* State where this arc goes to */
33} arc;
34
35/* A state in a DFA */
36
37typedef struct {
38 int s_narcs;
39 arc *s_arc; /* Array of arcs */
40
41 /* Optional accelerators */
42 int s_lower; /* Lowest label index */
43 int s_upper; /* Highest label index */
44 int *s_accel; /* Accelerator */
45 int s_accept; /* Nonzero for accepting state */
46} state;
47
48/* A DFA */
49
50typedef struct {
51 int d_type; /* Non-terminal this represents */
52 char *d_name; /* For printing */
53 int d_initial; /* Initial state */
54 int d_nstates;
55 state *d_state; /* Array of states */
56 bitset d_first;
57} dfa;
58
59/* A grammar */
60
61typedef struct {
62 int g_ndfas;
63 dfa *g_dfa; /* Array of DFAs */
64 labellist g_ll;
65 int g_start; /* Start symbol of the grammar */
66 int g_accel; /* Set if accelerators present */
67} grammar;
68
69/* FUNCTIONS */
70
71grammar *newgrammar(int start);
72dfa *adddfa(grammar *g, int type, char *name);
73int addstate(dfa *d);
74void addarc(dfa *d, int from, int to, int lbl);
75dfa *PyGrammar_FindDFA(grammar *g, int type);
76
77int addlabel(labellist *ll, int type, char *str);
78int findlabel(labellist *ll, int type, char *str);
79char *PyGrammar_LabelRepr(label *lb);
80void translatelabels(grammar *g);
81
82void addfirstsets(grammar *g);
83
84void PyGrammar_AddAccelerators(grammar *g);
85void PyGrammar_RemoveAccelerators(grammar *);
86
87void printgrammar(grammar *g, FILE *fp);
88void printnonterminals(grammar *g, FILE *fp);
89
90#ifdef __cplusplus
91}
92#endif
93#endif /* !Py_GRAMMAR_H */
sys/src/cmd/python/Include/import.h+64−0
@@ -0,0 +1,64 @@
1
2/* Module definition and import interface */
3
4#ifndef Py_IMPORT_H
5#define Py_IMPORT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_FUNC(long) PyImport_GetMagicNumber(void);
11PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co);
12PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx(
13 char *name, PyObject *co, char *pathname);
14PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void);
15PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name);
16PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name);
17PyAPI_FUNC(PyObject *) PyImport_ImportModuleLevel(char *name,
18 PyObject *globals, PyObject *locals, PyObject *fromlist, int level);
19
20/* For DLL compatibility */
21#undef PyImport_ImportModuleEx
22PyAPI_FUNC(PyObject *) PyImport_ImportModuleEx(
23 char *name, PyObject *globals, PyObject *locals, PyObject *fromlist);
24#define PyImport_ImportModuleEx(n, g, l, f) \
25 PyImport_ImportModuleLevel(n, g, l, f, -1)
26
27PyAPI_FUNC(PyObject *) PyImport_Import(PyObject *name);
28PyAPI_FUNC(PyObject *) PyImport_ReloadModule(PyObject *m);
29PyAPI_FUNC(void) PyImport_Cleanup(void);
30PyAPI_FUNC(int) PyImport_ImportFrozenModule(char *);
31
32PyAPI_FUNC(struct filedescr *) _PyImport_FindModule(
33 const char *, PyObject *, char *, size_t, FILE **, PyObject **);
34PyAPI_FUNC(int) _PyImport_IsScript(struct filedescr *);
35PyAPI_FUNC(void) _PyImport_ReInitLock(void);
36
37PyAPI_FUNC(PyObject *)_PyImport_FindExtension(char *, char *);
38PyAPI_FUNC(PyObject *)_PyImport_FixupExtension(char *, char *);
39
40struct _inittab {
41 char *name;
42 void (*initfunc)(void);
43};
44
45PyAPI_DATA(struct _inittab *) PyImport_Inittab;
46
47PyAPI_FUNC(int) PyImport_AppendInittab(char *name, void (*initfunc)(void));
48PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
49
50struct _frozen {
51 char *name;
52 unsigned char *code;
53 int size;
54};
55
56/* Embedding apps may change this pointer to point to their favorite
57 collection of frozen modules: */
58
59PyAPI_DATA(struct _frozen *) PyImport_FrozenModules;
60
61#ifdef __cplusplus
62}
63#endif
64#endif /* !Py_IMPORT_H */
sys/src/cmd/python/Include/intobject.h+64−0
@@ -0,0 +1,64 @@
1
2/* Integer object interface */
3
4/*
5PyIntObject represents a (long) integer. This is an immutable object;
6an integer cannot change its value after creation.
7
8There are functions to create new integer objects, to test an object
9for integer-ness, and to get the integer value. The latter functions
10returns -1 and sets errno to EBADF if the object is not an PyIntObject.
11None of the functions should be applied to nil objects.
12
13The type PyIntObject is (unfortunately) exposed here so we can declare
14_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
15*/
16
17#ifndef Py_INTOBJECT_H
18#define Py_INTOBJECT_H
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23typedef struct {
24 PyObject_HEAD
25 long ob_ival;
26} PyIntObject;
27
28PyAPI_DATA(PyTypeObject) PyInt_Type;
29
30#define PyInt_Check(op) PyObject_TypeCheck(op, &PyInt_Type)
31#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
32
33PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
34#ifdef Py_USING_UNICODE
35PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
36#endif
37PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
38PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
39PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
40PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
41PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
42PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
43#ifdef HAVE_LONG_LONG
44PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
45#endif
46
47PyAPI_FUNC(long) PyInt_GetMax(void);
48
49/* Macro, trading safety for speed */
50#define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
51
52/* These aren't really part of the Int object, but they're handy; the protos
53 * are necessary for systems that need the magic of PyAPI_FUNC and that want
54 * to have stropmodule as a dynamically loaded module instead of building it
55 * into the main Python shared library/DLL. Guido thinks I'm weird for
56 * building it this way. :-) [cjh]
57 */
58PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
59PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
60
61#ifdef __cplusplus
62}
63#endif
64#endif /* !Py_INTOBJECT_H */
sys/src/cmd/python/Include/intrcheck.h+15−0
@@ -0,0 +1,15 @@
1
2#ifndef Py_INTRCHECK_H
3#define Py_INTRCHECK_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8PyAPI_FUNC(int) PyOS_InterruptOccurred(void);
9PyAPI_FUNC(void) PyOS_InitInterrupts(void);
10PyAPI_FUNC(void) PyOS_AfterFork(void);
11
12#ifdef __cplusplus
13}
14#endif
15#endif /* !Py_INTRCHECK_H */
sys/src/cmd/python/Include/iterobject.h+23−0
@@ -0,0 +1,23 @@
1#ifndef Py_ITEROBJECT_H
2#define Py_ITEROBJECT_H
3/* Iterators (the basic kind, over a sequence) */
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8PyAPI_DATA(PyTypeObject) PySeqIter_Type;
9
10#define PySeqIter_Check(op) ((op)->ob_type == &PySeqIter_Type)
11
12PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *);
13
14PyAPI_DATA(PyTypeObject) PyCallIter_Type;
15
16#define PyCallIter_Check(op) ((op)->ob_type == &PyCallIter_Type)
17
18PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *);
19#ifdef __cplusplus
20}
21#endif
22#endif /* !Py_ITEROBJECT_H */
23
sys/src/cmd/python/Include/listobject.h+67−0
@@ -0,0 +1,67 @@
1
2/* List object interface */
3
4/*
5Another generally useful object type is an list of object pointers.
6This is a mutable type: the list items can be changed, and items can be
7added or removed. Out-of-range indices or non-list objects are ignored.
8
9*** WARNING *** PyList_SetItem does not increment the new item's reference
10count, but does decrement the reference count of the item it replaces,
11if not nil. It does *decrement* the reference count if it is *not*
12inserted in the list. Similarly, PyList_GetItem does not increment the
13returned item's reference count.
14*/
15
16#ifndef Py_LISTOBJECT_H
17#define Py_LISTOBJECT_H
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22typedef struct {
23 PyObject_VAR_HEAD
24 /* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
25 PyObject **ob_item;
26
27 /* ob_item contains space for 'allocated' elements. The number
28 * currently in use is ob_size.
29 * Invariants:
30 * 0 <= ob_size <= allocated
31 * len(list) == ob_size
32 * ob_item == NULL implies ob_size == allocated == 0
33 * list.sort() temporarily sets allocated to -1 to detect mutations.
34 *
35 * Items must normally not be NULL, except during construction when
36 * the list is not yet visible outside the function that builds it.
37 */
38 Py_ssize_t allocated;
39} PyListObject;
40
41PyAPI_DATA(PyTypeObject) PyList_Type;
42
43#define PyList_Check(op) PyObject_TypeCheck(op, &PyList_Type)
44#define PyList_CheckExact(op) ((op)->ob_type == &PyList_Type)
45
46PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size);
47PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *);
48PyAPI_FUNC(PyObject *) PyList_GetItem(PyObject *, Py_ssize_t);
49PyAPI_FUNC(int) PyList_SetItem(PyObject *, Py_ssize_t, PyObject *);
50PyAPI_FUNC(int) PyList_Insert(PyObject *, Py_ssize_t, PyObject *);
51PyAPI_FUNC(int) PyList_Append(PyObject *, PyObject *);
52PyAPI_FUNC(PyObject *) PyList_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
53PyAPI_FUNC(int) PyList_SetSlice(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
54PyAPI_FUNC(int) PyList_Sort(PyObject *);
55PyAPI_FUNC(int) PyList_Reverse(PyObject *);
56PyAPI_FUNC(PyObject *) PyList_AsTuple(PyObject *);
57PyAPI_FUNC(PyObject *) _PyList_Extend(PyListObject *, PyObject *);
58
59/* Macro, trading safety for speed */
60#define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
61#define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
62#define PyList_GET_SIZE(op) (((PyListObject *)(op))->ob_size)
63
64#ifdef __cplusplus
65}
66#endif
67#endif /* !Py_LISTOBJECT_H */
sys/src/cmd/python/Include/longintrepr.h+63−0
@@ -0,0 +1,63 @@
1#ifndef Py_LONGINTREPR_H
2#define Py_LONGINTREPR_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* This is published for the benefit of "friend" marshal.c only. */
9
10/* Parameters of the long integer representation.
11 These shouldn't have to be changed as C should guarantee that a short
12 contains at least 16 bits, but it's made changeable anyway.
13 Note: 'digit' should be able to hold 2*MASK+1, and 'twodigits'
14 should be able to hold the intermediate results in 'mul'
15 (at most (BASE-1)*(2*BASE+1) == MASK*(2*MASK+3)).
16 Also, x_sub assumes that 'digit' is an unsigned type, and overflow
17 is handled by taking the result mod 2**N for some N > SHIFT.
18 And, at some places it is assumed that MASK fits in an int, as well.
19 long_pow() requires that SHIFT be divisible by 5. */
20
21typedef unsigned short digit;
22typedef unsigned int wdigit; /* digit widened to parameter size */
23#define BASE_TWODIGITS_TYPE long
24typedef unsigned BASE_TWODIGITS_TYPE twodigits;
25typedef BASE_TWODIGITS_TYPE stwodigits; /* signed variant of twodigits */
26
27#define SHIFT 15
28#define BASE ((digit)1 << SHIFT)
29#define MASK ((int)(BASE - 1))
30
31#if SHIFT % 5 != 0
32#error "longobject.c requires that SHIFT be divisible by 5"
33#endif
34
35/* Long integer representation.
36 The absolute value of a number is equal to
37 SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
38 Negative numbers are represented with ob_size < 0;
39 zero is represented by ob_size == 0.
40 In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
41 digit) is never zero. Also, in all cases, for all valid i,
42 0 <= ob_digit[i] <= MASK.
43 The allocation function takes care of allocating extra memory
44 so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.
45
46 CAUTION: Generic code manipulating subtypes of PyVarObject has to
47 aware that longs abuse ob_size's sign bit.
48*/
49
50struct _longobject {
51 PyObject_VAR_HEAD
52 digit ob_digit[1];
53};
54
55PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
56
57/* Return a copy of src. */
58PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
59
60#ifdef __cplusplus
61}
62#endif
63#endif /* !Py_LONGINTREPR_H */
sys/src/cmd/python/Include/longobject.h+114−0
@@ -0,0 +1,114 @@
1#ifndef Py_LONGOBJECT_H
2#define Py_LONGOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Long (arbitrary precision) integer object interface */
9
10typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
11
12PyAPI_DATA(PyTypeObject) PyLong_Type;
13
14#define PyLong_Check(op) PyObject_TypeCheck(op, &PyLong_Type)
15#define PyLong_CheckExact(op) ((op)->ob_type == &PyLong_Type)
16
17PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
18PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
19PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
20PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
21PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
22PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
23
24/* For use by intobject.c only */
25PyAPI_FUNC(Py_ssize_t) _PyLong_AsSsize_t(PyObject *);
26PyAPI_FUNC(PyObject *) _PyLong_FromSize_t(size_t);
27PyAPI_FUNC(PyObject *) _PyLong_FromSsize_t(Py_ssize_t);
28PyAPI_DATA(int) _PyLong_DigitValue[256];
29
30/* _PyLong_AsScaledDouble returns a double x and an exponent e such that
31 the true value is approximately equal to x * 2**(SHIFT*e). e is >= 0.
32 x is 0.0 if and only if the input is 0 (in which case, e and x are both
33 zeroes). Overflow is impossible. Note that the exponent returned must
34 be multiplied by SHIFT! There may not be enough room in an int to store
35 e*SHIFT directly. */
36PyAPI_FUNC(double) _PyLong_AsScaledDouble(PyObject *vv, int *e);
37
38PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
39PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
40PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
41
42#ifdef HAVE_LONG_LONG
43PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
44PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
45PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
46PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
47PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
48#endif /* HAVE_LONG_LONG */
49
50PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
51#ifdef Py_USING_UNICODE
52PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
53#endif
54
55/* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
56 v must not be NULL, and must be a normalized long.
57 There are no error cases.
58*/
59PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
60
61
62/* _PyLong_NumBits. Return the number of bits needed to represent the
63 absolute value of a long. For example, this returns 1 for 1 and -1, 2
64 for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
65 v must not be NULL, and must be a normalized long.
66 (size_t)-1 is returned and OverflowError set if the true result doesn't
67 fit in a size_t.
68*/
69PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
70
71/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
72 base 256, and return a Python long with the same numeric value.
73 If n is 0, the integer is 0. Else:
74 If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB;
75 else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the
76 LSB.
77 If is_signed is 0/false, view the bytes as a non-negative integer.
78 If is_signed is 1/true, view the bytes as a 2's-complement integer,
79 non-negative if bit 0x80 of the MSB is clear, negative if set.
80 Error returns:
81 + Return NULL with the appropriate exception set if there's not
82 enough memory to create the Python long.
83*/
84PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
85 const unsigned char* bytes, size_t n,
86 int little_endian, int is_signed);
87
88/* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long
89 v to a base-256 integer, stored in array bytes. Normally return 0,
90 return -1 on error.
91 If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at
92 bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and
93 the LSB at bytes[n-1].
94 If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes
95 are filled and there's nothing special about bit 0x80 of the MSB.
96 If is_signed is 1/true, bytes is filled with the 2's-complement
97 representation of v's value. Bit 0x80 of the MSB is the sign bit.
98 Error returns (-1):
99 + is_signed is 0 and v < 0. TypeError is set in this case, and bytes
100 isn't altered.
101 + n isn't big enough to hold the full mathematical value of v. For
102 example, if is_signed is 0 and there are more digits in the v than
103 fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of
104 being large enough to hold a sign bit. OverflowError is set in this
105 case, but bytes holds the least-signficant n bytes of the true value.
106*/
107PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
108 unsigned char* bytes, size_t n,
109 int little_endian, int is_signed);
110
111#ifdef __cplusplus
112}
113#endif
114#endif /* !Py_LONGOBJECT_H */
sys/src/cmd/python/Include/marshal.h+25−0
@@ -0,0 +1,25 @@
1
2/* Interface for marshal.c */
3
4#ifndef Py_MARSHAL_H
5#define Py_MARSHAL_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define Py_MARSHAL_VERSION 2
11
12PyAPI_FUNC(void) PyMarshal_WriteLongToFile(long, FILE *, int);
13PyAPI_FUNC(void) PyMarshal_WriteObjectToFile(PyObject *, FILE *, int);
14PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
15
16PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);
17PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);
18PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromFile(FILE *);
19PyAPI_FUNC(PyObject *) PyMarshal_ReadLastObjectFromFile(FILE *);
20PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
21
22#ifdef __cplusplus
23}
24#endif
25#endif /* !Py_MARSHAL_H */
sys/src/cmd/python/Include/metagrammar.h+18−0
@@ -0,0 +1,18 @@
1#ifndef Py_METAGRAMMAR_H
2#define Py_METAGRAMMAR_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8#define MSTART 256
9#define RULE 257
10#define RHS 258
11#define ALT 259
12#define ITEM 260
13#define ATOM 261
14
15#ifdef __cplusplus
16}
17#endif
18#endif /* !Py_METAGRAMMAR_H */
sys/src/cmd/python/Include/methodobject.h+91−0
@@ -0,0 +1,91 @@
1
2/* Method object interface */
3
4#ifndef Py_METHODOBJECT_H
5#define Py_METHODOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/* This is about the type 'builtin_function_or_method',
11 not Python methods in user-defined classes. See classobject.h
12 for the latter. */
13
14PyAPI_DATA(PyTypeObject) PyCFunction_Type;
15
16#define PyCFunction_Check(op) ((op)->ob_type == &PyCFunction_Type)
17
18typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
19typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
20 PyObject *);
21typedef PyObject *(*PyNoArgsFunction)(PyObject *);
22
23PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *);
24PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *);
25PyAPI_FUNC(int) PyCFunction_GetFlags(PyObject *);
26
27/* Macros for direct access to these values. Type checks are *not*
28 done, so use with care. */
29#define PyCFunction_GET_FUNCTION(func) \
30 (((PyCFunctionObject *)func) -> m_ml -> ml_meth)
31#define PyCFunction_GET_SELF(func) \
32 (((PyCFunctionObject *)func) -> m_self)
33#define PyCFunction_GET_FLAGS(func) \
34 (((PyCFunctionObject *)func) -> m_ml -> ml_flags)
35PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
36
37struct PyMethodDef {
38 const char *ml_name; /* The name of the built-in function/method */
39 PyCFunction ml_meth; /* The C function that implements it */
40 int ml_flags; /* Combination of METH_xxx flags, which mostly
41 describe the args expected by the C func */
42 const char *ml_doc; /* The __doc__ attribute, or NULL */
43};
44typedef struct PyMethodDef PyMethodDef;
45
46PyAPI_FUNC(PyObject *) Py_FindMethod(PyMethodDef[], PyObject *, const char *);
47
48#define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL)
49PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *,
50 PyObject *);
51
52/* Flag passed to newmethodobject */
53#define METH_OLDARGS 0x0000
54#define METH_VARARGS 0x0001
55#define METH_KEYWORDS 0x0002
56/* METH_NOARGS and METH_O must not be combined with the flags above. */
57#define METH_NOARGS 0x0004
58#define METH_O 0x0008
59
60/* METH_CLASS and METH_STATIC are a little different; these control
61 the construction of methods for a class. These cannot be used for
62 functions in modules. */
63#define METH_CLASS 0x0010
64#define METH_STATIC 0x0020
65
66/* METH_COEXIST allows a method to be entered eventhough a slot has
67 already filled the entry. When defined, the flag allows a separate
68 method, "__contains__" for example, to coexist with a defined
69 slot like sq_contains. */
70
71#define METH_COEXIST 0x0040
72
73typedef struct PyMethodChain {
74 PyMethodDef *methods; /* Methods of this type */
75 struct PyMethodChain *link; /* NULL or base type */
76} PyMethodChain;
77
78PyAPI_FUNC(PyObject *) Py_FindMethodInChain(PyMethodChain *, PyObject *,
79 const char *);
80
81typedef struct {
82 PyObject_HEAD
83 PyMethodDef *m_ml; /* Description of the C function to call */
84 PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
85 PyObject *m_module; /* The __module__ attribute, can be anything */
86} PyCFunctionObject;
87
88#ifdef __cplusplus
89}
90#endif
91#endif /* !Py_METHODOBJECT_H */
sys/src/cmd/python/Include/modsupport.h+133−0
@@ -0,0 +1,133 @@
1
2#ifndef Py_MODSUPPORT_H
3#define Py_MODSUPPORT_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* Module support interface */
9
10#include <stdarg.h>
11
12/* If PY_SSIZE_T_CLEAN is defined, each functions treats #-specifier
13 to mean Py_ssize_t */
14#ifdef PY_SSIZE_T_CLEAN
15#define PyArg_Parse _PyArg_Parse_SizeT
16#define PyArg_ParseTuple _PyArg_ParseTuple_SizeT
17#define PyArg_ParseTupleAndKeywords _PyArg_ParseTupleAndKeywords_SizeT
18#define PyArg_VaParse _PyArg_VaParse_SizeT
19#define PyArg_VaParseTupleAndKeywords _PyArg_VaParseTupleAndKeywords_SizeT
20#define Py_BuildValue _Py_BuildValue_SizeT
21#define Py_VaBuildValue _Py_VaBuildValue_SizeT
22#else
23PyAPI_FUNC(PyObject *) _Py_VaBuildValue_SizeT(const char *, va_list);
24#endif
25
26PyAPI_FUNC(int) PyArg_Parse(PyObject *, const char *, ...);
27PyAPI_FUNC(int) PyArg_ParseTuple(PyObject *, const char *, ...);
28PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
29 const char *, char **, ...);
30PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, const char *, Py_ssize_t, Py_ssize_t, ...);
31PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...);
32PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...);
33PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw);
34
35PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list);
36PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,
37 const char *, char **, va_list);
38PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
39
40PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
41PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
42PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
43
44
45#define PYTHON_API_VERSION 1013
46#define PYTHON_API_STRING "1013"
47/* The API version is maintained (independently from the Python version)
48 so we can detect mismatches between the interpreter and dynamically
49 loaded modules. These are diagnosed by an error message but
50 the module is still loaded (because the mismatch can only be tested
51 after loading the module). The error message is intended to
52 explain the core dump a few seconds later.
53
54 The symbol PYTHON_API_STRING defines the same value as a string
55 literal. *** PLEASE MAKE SURE THE DEFINITIONS MATCH. ***
56
57 Please add a line or two to the top of this log for each API
58 version change:
59
60 22-Feb-2006 MvL 1013 PEP 353 - long indices for sequence lengths
61
62 19-Aug-2002 GvR 1012 Changes to string object struct for
63 interning changes, saving 3 bytes.
64
65 17-Jul-2001 GvR 1011 Descr-branch, just to be on the safe side
66
67 25-Jan-2001 FLD 1010 Parameters added to PyCode_New() and
68 PyFrame_New(); Python 2.1a2
69
70 14-Mar-2000 GvR 1009 Unicode API added
71
72 3-Jan-1999 GvR 1007 Decided to change back! (Don't reuse 1008!)
73
74 3-Dec-1998 GvR 1008 Python 1.5.2b1
75
76 18-Jan-1997 GvR 1007 string interning and other speedups
77
78 11-Oct-1996 GvR renamed Py_Ellipses to Py_Ellipsis :-(
79
80 30-Jul-1996 GvR Slice and ellipses syntax added
81
82 23-Jul-1996 GvR For 1.4 -- better safe than sorry this time :-)
83
84 7-Nov-1995 GvR Keyword arguments (should've been done at 1.3 :-( )
85
86 10-Jan-1995 GvR Renamed globals to new naming scheme
87
88 9-Jan-1995 GvR Initial version (incompatible with older API)
89*/
90
91#ifdef MS_WINDOWS
92/* Special defines for Windows versions used to live here. Things
93 have changed, and the "Version" is now in a global string variable.
94 Reason for this is that this for easier branding of a "custom DLL"
95 without actually needing a recompile. */
96#endif /* MS_WINDOWS */
97
98#if SIZEOF_SIZE_T != SIZEOF_INT
99/* On a 64-bit system, rename the Py_InitModule4 so that 2.4
100 modules cannot get loaded into a 2.5 interpreter */
101#define Py_InitModule4 Py_InitModule4_64
102#endif
103
104#ifdef Py_TRACE_REFS
105 /* When we are tracing reference counts, rename Py_InitModule4 so
106 modules compiled with incompatible settings will generate a
107 link-time error. */
108 #if SIZEOF_SIZE_T != SIZEOF_INT
109 #undef Py_InitModule4
110 #define Py_InitModule4 Py_InitModule4TraceRefs_64
111 #else
112 #define Py_InitModule4 Py_InitModule4TraceRefs
113 #endif
114#endif
115
116PyAPI_FUNC(PyObject *) Py_InitModule4(const char *name, PyMethodDef *methods,
117 const char *doc, PyObject *self,
118 int apiver);
119
120#define Py_InitModule(name, methods) \
121 Py_InitModule4(name, methods, (char *)NULL, (PyObject *)NULL, \
122 PYTHON_API_VERSION)
123
124#define Py_InitModule3(name, methods, doc) \
125 Py_InitModule4(name, methods, doc, (PyObject *)NULL, \
126 PYTHON_API_VERSION)
127
128PyAPI_DATA(char *) _Py_PackageContext;
129
130#ifdef __cplusplus
131}
132#endif
133#endif /* !Py_MODSUPPORT_H */
sys/src/cmd/python/Include/moduleobject.h+24−0
@@ -0,0 +1,24 @@
1
2/* Module object interface */
3
4#ifndef Py_MODULEOBJECT_H
5#define Py_MODULEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_DATA(PyTypeObject) PyModule_Type;
11
12#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type)
13#define PyModule_CheckExact(op) ((op)->ob_type == &PyModule_Type)
14
15PyAPI_FUNC(PyObject *) PyModule_New(const char *);
16PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *);
17PyAPI_FUNC(char *) PyModule_GetName(PyObject *);
18PyAPI_FUNC(char *) PyModule_GetFilename(PyObject *);
19PyAPI_FUNC(void) _PyModule_Clear(PyObject *);
20
21#ifdef __cplusplus
22}
23#endif
24#endif /* !Py_MODULEOBJECT_H */
sys/src/cmd/python/Include/node.h+40−0
@@ -0,0 +1,40 @@
1
2/* Parse tree node interface */
3
4#ifndef Py_NODE_H
5#define Py_NODE_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct _node {
11 short n_type;
12 char *n_str;
13 int n_lineno;
14 int n_col_offset;
15 int n_nchildren;
16 struct _node *n_child;
17} node;
18
19PyAPI_FUNC(node *) PyNode_New(int type);
20PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
21 char *str, int lineno, int col_offset);
22PyAPI_FUNC(void) PyNode_Free(node *n);
23
24/* Node access functions */
25#define NCH(n) ((n)->n_nchildren)
26
27#define CHILD(n, i) (&(n)->n_child[i])
28#define RCHILD(n, i) (CHILD(n, NCH(n) + i))
29#define TYPE(n) ((n)->n_type)
30#define STR(n) ((n)->n_str)
31
32/* Assert that the type of a node is what we expect */
33#define REQ(n, type) assert(TYPE(n) == (type))
34
35PyAPI_FUNC(void) PyNode_ListTree(node *);
36
37#ifdef __cplusplus
38}
39#endif
40#endif /* !Py_NODE_H */
sys/src/cmd/python/Include/object.h+868−0
@@ -0,0 +1,868 @@
1#ifndef Py_OBJECT_H
2#define Py_OBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Object and type object interface */
9
10/*
11Objects are structures allocated on the heap. Special rules apply to
12the use of objects to ensure they are properly garbage-collected.
13Objects are never allocated statically or on the stack; they must be
14accessed through special macros and functions only. (Type objects are
15exceptions to the first rule; the standard types are represented by
16statically initialized type objects, although work on type/class unification
17for Python 2.2 made it possible to have heap-allocated type objects too).
18
19An object has a 'reference count' that is increased or decreased when a
20pointer to the object is copied or deleted; when the reference count
21reaches zero there are no references to the object left and it can be
22removed from the heap.
23
24An object has a 'type' that determines what it represents and what kind
25of data it contains. An object's type is fixed when it is created.
26Types themselves are represented as objects; an object contains a
27pointer to the corresponding type object. The type itself has a type
28pointer pointing to the object representing the type 'type', which
29contains a pointer to itself!).
30
31Objects do not float around in memory; once allocated an object keeps
32the same size and address. Objects that must hold variable-size data
33can contain pointers to variable-size parts of the object. Not all
34objects of the same type have the same size; but the size cannot change
35after allocation. (These restrictions are made so a reference to an
36object can be simply a pointer -- moving an object would require
37updating all the pointers, and changing an object's size would require
38moving it if there was another object right next to it.)
39
40Objects are always accessed through pointers of the type 'PyObject *'.
41The type 'PyObject' is a structure that only contains the reference count
42and the type pointer. The actual memory allocated for an object
43contains other data that can only be accessed after casting the pointer
44to a pointer to a longer structure type. This longer type must start
45with the reference count and type fields; the macro PyObject_HEAD should be
46used for this (to accommodate for future changes). The implementation
47of a particular object type can cast the object pointer to the proper
48type and back.
49
50A standard interface exists for objects that contain an array of items
51whose size is determined when the object is allocated.
52*/
53
54/* Py_DEBUG implies Py_TRACE_REFS. */
55#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS)
56#define Py_TRACE_REFS
57#endif
58
59/* Py_TRACE_REFS implies Py_REF_DEBUG. */
60#if defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
61#define Py_REF_DEBUG
62#endif
63
64#ifdef Py_TRACE_REFS
65/* Define pointers to support a doubly-linked list of all live heap objects. */
66#define _PyObject_HEAD_EXTRA \
67 struct _object *_ob_next; \
68 struct _object *_ob_prev;
69
70#define _PyObject_EXTRA_INIT 0, 0,
71
72#else
73#define _PyObject_HEAD_EXTRA
74#define _PyObject_EXTRA_INIT
75#endif
76
77/* PyObject_HEAD defines the initial segment of every PyObject. */
78#define PyObject_HEAD \
79 _PyObject_HEAD_EXTRA \
80 Py_ssize_t ob_refcnt; \
81 struct _typeobject *ob_type;
82
83#define PyObject_HEAD_INIT(type) \
84 _PyObject_EXTRA_INIT \
85 1, type,
86
87/* PyObject_VAR_HEAD defines the initial segment of all variable-size
88 * container objects. These end with a declaration of an array with 1
89 * element, but enough space is malloc'ed so that the array actually
90 * has room for ob_size elements. Note that ob_size is an element count,
91 * not necessarily a byte count.
92 */
93#define PyObject_VAR_HEAD \
94 PyObject_HEAD \
95 Py_ssize_t ob_size; /* Number of items in variable part */
96#define Py_INVALID_SIZE (Py_ssize_t)-1
97
98/* Nothing is actually declared to be a PyObject, but every pointer to
99 * a Python object can be cast to a PyObject*. This is inheritance built
100 * by hand. Similarly every pointer to a variable-size Python object can,
101 * in addition, be cast to PyVarObject*.
102 */
103typedef struct _object {
104 PyObject_HEAD
105} PyObject;
106
107typedef struct {
108 PyObject_VAR_HEAD
109} PyVarObject;
110
111
112/*
113Type objects contain a string containing the type name (to help somewhat
114in debugging), the allocation parameters (see PyObject_New() and
115PyObject_NewVar()),
116and methods for accessing objects of the type. Methods are optional, a
117nil pointer meaning that particular kind of access is not available for
118this type. The Py_DECREF() macro uses the tp_dealloc method without
119checking for a nil pointer; it should always be implemented except if
120the implementation can guarantee that the reference count will never
121reach zero (e.g., for statically allocated type objects).
122
123NB: the methods for certain type groups are now contained in separate
124method blocks.
125*/
126
127typedef PyObject * (*unaryfunc)(PyObject *);
128typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
129typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
130typedef int (*inquiry)(PyObject *);
131typedef Py_ssize_t (*lenfunc)(PyObject *);
132typedef int (*coercion)(PyObject **, PyObject **);
133typedef PyObject *(*intargfunc)(PyObject *, int) Py_DEPRECATED(2.5);
134typedef PyObject *(*intintargfunc)(PyObject *, int, int) Py_DEPRECATED(2.5);
135typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
136typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
137typedef int(*intobjargproc)(PyObject *, int, PyObject *);
138typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
139typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
140typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
141typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
142
143/* int-based buffer interface */
144typedef int (*getreadbufferproc)(PyObject *, int, void **);
145typedef int (*getwritebufferproc)(PyObject *, int, void **);
146typedef int (*getsegcountproc)(PyObject *, int *);
147typedef int (*getcharbufferproc)(PyObject *, int, char **);
148/* ssize_t-based buffer interface */
149typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **);
150typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **);
151typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *);
152typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **);
153
154typedef int (*objobjproc)(PyObject *, PyObject *);
155typedef int (*visitproc)(PyObject *, void *);
156typedef int (*traverseproc)(PyObject *, visitproc, void *);
157
158typedef struct {
159 /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
160 arguments are guaranteed to be of the object's type (modulo
161 coercion hacks -- i.e. if the type's coercion function
162 returns other types, then these are allowed as well). Numbers that
163 have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
164 arguments for proper type and implement the necessary conversions
165 in the slot functions themselves. */
166
167 binaryfunc nb_add;
168 binaryfunc nb_subtract;
169 binaryfunc nb_multiply;
170 binaryfunc nb_divide;
171 binaryfunc nb_remainder;
172 binaryfunc nb_divmod;
173 ternaryfunc nb_power;
174 unaryfunc nb_negative;
175 unaryfunc nb_positive;
176 unaryfunc nb_absolute;
177 inquiry nb_nonzero;
178 unaryfunc nb_invert;
179 binaryfunc nb_lshift;
180 binaryfunc nb_rshift;
181 binaryfunc nb_and;
182 binaryfunc nb_xor;
183 binaryfunc nb_or;
184 coercion nb_coerce;
185 unaryfunc nb_int;
186 unaryfunc nb_long;
187 unaryfunc nb_float;
188 unaryfunc nb_oct;
189 unaryfunc nb_hex;
190 /* Added in release 2.0 */
191 binaryfunc nb_inplace_add;
192 binaryfunc nb_inplace_subtract;
193 binaryfunc nb_inplace_multiply;
194 binaryfunc nb_inplace_divide;
195 binaryfunc nb_inplace_remainder;
196 ternaryfunc nb_inplace_power;
197 binaryfunc nb_inplace_lshift;
198 binaryfunc nb_inplace_rshift;
199 binaryfunc nb_inplace_and;
200 binaryfunc nb_inplace_xor;
201 binaryfunc nb_inplace_or;
202
203 /* Added in release 2.2 */
204 /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
205 binaryfunc nb_floor_divide;
206 binaryfunc nb_true_divide;
207 binaryfunc nb_inplace_floor_divide;
208 binaryfunc nb_inplace_true_divide;
209
210 /* Added in release 2.5 */
211 unaryfunc nb_index;
212} PyNumberMethods;
213
214typedef struct {
215 lenfunc sq_length;
216 binaryfunc sq_concat;
217 ssizeargfunc sq_repeat;
218 ssizeargfunc sq_item;
219 ssizessizeargfunc sq_slice;
220 ssizeobjargproc sq_ass_item;
221 ssizessizeobjargproc sq_ass_slice;
222 objobjproc sq_contains;
223 /* Added in release 2.0 */
224 binaryfunc sq_inplace_concat;
225 ssizeargfunc sq_inplace_repeat;
226} PySequenceMethods;
227
228typedef struct {
229 lenfunc mp_length;
230 binaryfunc mp_subscript;
231 objobjargproc mp_ass_subscript;
232} PyMappingMethods;
233
234typedef struct {
235 readbufferproc bf_getreadbuffer;
236 writebufferproc bf_getwritebuffer;
237 segcountproc bf_getsegcount;
238 charbufferproc bf_getcharbuffer;
239} PyBufferProcs;
240
241
242typedef void (*freefunc)(void *);
243typedef void (*destructor)(PyObject *);
244typedef int (*printfunc)(PyObject *, FILE *, int);
245typedef PyObject *(*getattrfunc)(PyObject *, char *);
246typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
247typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
248typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
249typedef int (*cmpfunc)(PyObject *, PyObject *);
250typedef PyObject *(*reprfunc)(PyObject *);
251typedef long (*hashfunc)(PyObject *);
252typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
253typedef PyObject *(*getiterfunc) (PyObject *);
254typedef PyObject *(*iternextfunc) (PyObject *);
255typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
256typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
257typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
258typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
259typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
260
261typedef struct _typeobject {
262 PyObject_VAR_HEAD
263 const char *tp_name; /* For printing, in format "<module>.<name>" */
264 Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
265
266 /* Methods to implement standard operations */
267
268 destructor tp_dealloc;
269 printfunc tp_print;
270 getattrfunc tp_getattr;
271 setattrfunc tp_setattr;
272 cmpfunc tp_compare;
273 reprfunc tp_repr;
274
275 /* Method suites for standard classes */
276
277 PyNumberMethods *tp_as_number;
278 PySequenceMethods *tp_as_sequence;
279 PyMappingMethods *tp_as_mapping;
280
281 /* More standard operations (here for binary compatibility) */
282
283 hashfunc tp_hash;
284 ternaryfunc tp_call;
285 reprfunc tp_str;
286 getattrofunc tp_getattro;
287 setattrofunc tp_setattro;
288
289 /* Functions to access object as input/output buffer */
290 PyBufferProcs *tp_as_buffer;
291
292 /* Flags to define presence of optional/expanded features */
293 long tp_flags;
294
295 const char *tp_doc; /* Documentation string */
296
297 /* Assigned meaning in release 2.0 */
298 /* call function for all accessible objects */
299 traverseproc tp_traverse;
300
301 /* delete references to contained objects */
302 inquiry tp_clear;
303
304 /* Assigned meaning in release 2.1 */
305 /* rich comparisons */
306 richcmpfunc tp_richcompare;
307
308 /* weak reference enabler */
309 Py_ssize_t tp_weaklistoffset;
310
311 /* Added in release 2.2 */
312 /* Iterators */
313 getiterfunc tp_iter;
314 iternextfunc tp_iternext;
315
316 /* Attribute descriptor and subclassing stuff */
317 struct PyMethodDef *tp_methods;
318 struct PyMemberDef *tp_members;
319 struct PyGetSetDef *tp_getset;
320 struct _typeobject *tp_base;
321 PyObject *tp_dict;
322 descrgetfunc tp_descr_get;
323 descrsetfunc tp_descr_set;
324 Py_ssize_t tp_dictoffset;
325 initproc tp_init;
326 allocfunc tp_alloc;
327 newfunc tp_new;
328 freefunc tp_free; /* Low-level free-memory routine */
329 inquiry tp_is_gc; /* For PyObject_IS_GC */
330 PyObject *tp_bases;
331 PyObject *tp_mro; /* method resolution order */
332 PyObject *tp_cache;
333 PyObject *tp_subclasses;
334 PyObject *tp_weaklist;
335 destructor tp_del;
336
337#ifdef COUNT_ALLOCS
338 /* these must be last and never explicitly initialized */
339 Py_ssize_t tp_allocs;
340 Py_ssize_t tp_frees;
341 Py_ssize_t tp_maxalloc;
342 struct _typeobject *tp_prev;
343 struct _typeobject *tp_next;
344#endif
345} PyTypeObject;
346
347
348/* The *real* layout of a type object when allocated on the heap */
349typedef struct _heaptypeobject {
350 /* Note: there's a dependency on the order of these members
351 in slotptr() in typeobject.c . */
352 PyTypeObject ht_type;
353 PyNumberMethods as_number;
354 PyMappingMethods as_mapping;
355 PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
356 so that the mapping wins when both
357 the mapping and the sequence define
358 a given operator (e.g. __getitem__).
359 see add_operators() in typeobject.c . */
360 PyBufferProcs as_buffer;
361 PyObject *ht_name, *ht_slots;
362 /* here are optional user slots, followed by the members. */
363} PyHeapTypeObject;
364
365/* access macro to the members which are floating "behind" the object */
366#define PyHeapType_GET_MEMBERS(etype) \
367 ((PyMemberDef *)(((char *)etype) + (etype)->ht_type.ob_type->tp_basicsize))
368
369
370/* Generic type check */
371PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
372#define PyObject_TypeCheck(ob, tp) \
373 ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
374
375PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
376PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
377PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
378
379#define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type)
380#define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type)
381
382PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
383PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
384PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
385 PyObject *, PyObject *);
386PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
387
388/* Generic operations on objects */
389PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
390PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
391PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
392PyAPI_FUNC(PyObject *) _PyObject_Str(PyObject *);
393PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
394#ifdef Py_USING_UNICODE
395PyAPI_FUNC(PyObject *) PyObject_Unicode(PyObject *);
396#endif
397PyAPI_FUNC(int) PyObject_Compare(PyObject *, PyObject *);
398PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
399PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
400PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
401PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
402PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
403PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
404PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
405PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
406PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
407PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
408PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
409PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
410 PyObject *, PyObject *);
411PyAPI_FUNC(long) PyObject_Hash(PyObject *);
412PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
413PyAPI_FUNC(int) PyObject_Not(PyObject *);
414PyAPI_FUNC(int) PyCallable_Check(PyObject *);
415PyAPI_FUNC(int) PyNumber_Coerce(PyObject **, PyObject **);
416PyAPI_FUNC(int) PyNumber_CoerceEx(PyObject **, PyObject **);
417
418PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
419
420/* A slot function whose address we need to compare */
421extern int _PyObject_SlotCompare(PyObject *, PyObject *);
422
423
424/* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a
425 list of strings. PyObject_Dir(NULL) is like __builtin__.dir(),
426 returning the names of the current locals. In this case, if there are
427 no current locals, NULL is returned, and PyErr_Occurred() is false.
428*/
429PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
430
431
432/* Helpers for printing recursive container types */
433PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
434PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
435
436/* Helpers for hash functions */
437PyAPI_FUNC(long) _Py_HashDouble(double);
438PyAPI_FUNC(long) _Py_HashPointer(void*);
439
440/* Helper for passing objects to printf and the like */
441#define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))
442
443/* Flag bits for printing: */
444#define Py_PRINT_RAW 1 /* No string quotes etc. */
445
446/*
447`Type flags (tp_flags)
448
449These flags are used to extend the type structure in a backwards-compatible
450fashion. Extensions can use the flags to indicate (and test) when a given
451type structure contains a new feature. The Python core will use these when
452introducing new functionality between major revisions (to avoid mid-version
453changes in the PYTHON_API_VERSION).
454
455Arbitration of the flag bit positions will need to be coordinated among
456all extension writers who publically release their extensions (this will
457be fewer than you might expect!)..
458
459Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
460
461Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
462
463Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
464given type object has a specified feature.
465*/
466
467/* PyBufferProcs contains bf_getcharbuffer */
468#define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
469
470/* PySequenceMethods contains sq_contains */
471#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
472
473/* This is here for backwards compatibility. Extensions that use the old GC
474 * API will still compile but the objects will not be tracked by the GC. */
475#define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */
476
477/* PySequenceMethods and PyNumberMethods contain in-place operators */
478#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
479
480/* PyNumberMethods do their own coercion */
481#define Py_TPFLAGS_CHECKTYPES (1L<<4)
482
483/* tp_richcompare is defined */
484#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
485
486/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
487#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
488
489/* tp_iter is defined */
490#define Py_TPFLAGS_HAVE_ITER (1L<<7)
491
492/* New members introduced by Python 2.2 exist */
493#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
494
495/* Set if the type object is dynamically allocated */
496#define Py_TPFLAGS_HEAPTYPE (1L<<9)
497
498/* Set if the type allows subclassing */
499#define Py_TPFLAGS_BASETYPE (1L<<10)
500
501/* Set if the type is 'ready' -- fully initialized */
502#define Py_TPFLAGS_READY (1L<<12)
503
504/* Set while the type is being 'readied', to prevent recursive ready calls */
505#define Py_TPFLAGS_READYING (1L<<13)
506
507/* Objects support garbage collection (see objimp.h) */
508#define Py_TPFLAGS_HAVE_GC (1L<<14)
509
510/* These two bits are preserved for Stackless Python, next after this is 17 */
511#ifdef STACKLESS
512#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
513#else
514#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
515#endif
516
517/* Objects support nb_index in PyNumberMethods */
518#define Py_TPFLAGS_HAVE_INDEX (1L<<17)
519
520#define Py_TPFLAGS_DEFAULT ( \
521 Py_TPFLAGS_HAVE_GETCHARBUFFER | \
522 Py_TPFLAGS_HAVE_SEQUENCE_IN | \
523 Py_TPFLAGS_HAVE_INPLACEOPS | \
524 Py_TPFLAGS_HAVE_RICHCOMPARE | \
525 Py_TPFLAGS_HAVE_WEAKREFS | \
526 Py_TPFLAGS_HAVE_ITER | \
527 Py_TPFLAGS_HAVE_CLASS | \
528 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
529 Py_TPFLAGS_HAVE_INDEX | \
530 0)
531
532#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
533
534
535/*
536The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
537reference counts. Py_DECREF calls the object's deallocator function when
538the refcount falls to 0; for
539objects that don't contain references to other objects or heap memory
540this can be the standard function free(). Both macros can be used
541wherever a void expression is allowed. The argument must not be a
542NIL pointer. If it may be NIL, use Py_XINCREF/Py_XDECREF instead.
543The macro _Py_NewReference(op) initialize reference counts to 1, and
544in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional
545bookkeeping appropriate to the special build.
546
547We assume that the reference count field can never overflow; this can
548be proven when the size of the field is the same as the pointer size, so
549we ignore the possibility. Provided a C int is at least 32 bits (which
550is implicitly assumed in many parts of this code), that's enough for
551about 2**31 references to an object.
552
553XXX The following became out of date in Python 2.2, but I'm not sure
554XXX what the full truth is now. Certainly, heap-allocated type objects
555XXX can and should be deallocated.
556Type objects should never be deallocated; the type pointer in an object
557is not considered to be a reference to the type object, to save
558complications in the deallocation function. (This is actually a
559decision that's up to the implementer of each new type so if you want,
560you can count such references to the type object.)
561
562*** WARNING*** The Py_DECREF macro must have a side-effect-free argument
563since it may evaluate its argument multiple times. (The alternative
564would be to mace it a proper function or assign it to a global temporary
565variable first, both of which are slower; and in a multi-threaded
566environment the global variable trick is not safe.)
567*/
568
569/* First define a pile of simple helper macros, one set per special
570 * build symbol. These either expand to the obvious things, or to
571 * nothing at all when the special mode isn't in effect. The main
572 * macros can later be defined just once then, yet expand to different
573 * things depending on which special build options are and aren't in effect.
574 * Trust me <wink>: while painful, this is 20x easier to understand than,
575 * e.g, defining _Py_NewReference five different times in a maze of nested
576 * #ifdefs (we used to do that -- it was impenetrable).
577 */
578#ifdef Py_REF_DEBUG
579PyAPI_DATA(Py_ssize_t) _Py_RefTotal;
580PyAPI_FUNC(void) _Py_NegativeRefcount(const char *fname,
581 int lineno, PyObject *op);
582PyAPI_FUNC(PyObject *) _PyDict_Dummy(void);
583PyAPI_FUNC(PyObject *) _PySet_Dummy(void);
584PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
585#define _Py_INC_REFTOTAL _Py_RefTotal++
586#define _Py_DEC_REFTOTAL _Py_RefTotal--
587#define _Py_REF_DEBUG_COMMA ,
588#define _Py_CHECK_REFCNT(OP) \
589{ if ((OP)->ob_refcnt < 0) \
590 _Py_NegativeRefcount(__FILE__, __LINE__, \
591 (PyObject *)(OP)); \
592}
593#else
594#define _Py_INC_REFTOTAL
595#define _Py_DEC_REFTOTAL
596#define _Py_REF_DEBUG_COMMA
597#define _Py_CHECK_REFCNT(OP) /* a semicolon */;
598#endif /* Py_REF_DEBUG */
599
600#ifdef COUNT_ALLOCS
601PyAPI_FUNC(void) inc_count(PyTypeObject *);
602PyAPI_FUNC(void) dec_count(PyTypeObject *);
603#define _Py_INC_TPALLOCS(OP) inc_count((OP)->ob_type)
604#define _Py_INC_TPFREES(OP) dec_count((OP)->ob_type)
605#define _Py_DEC_TPFREES(OP) (OP)->ob_type->tp_frees--
606#define _Py_COUNT_ALLOCS_COMMA ,
607#else
608#define _Py_INC_TPALLOCS(OP)
609#define _Py_INC_TPFREES(OP)
610#define _Py_DEC_TPFREES(OP)
611#define _Py_COUNT_ALLOCS_COMMA
612#endif /* COUNT_ALLOCS */
613
614#ifdef Py_TRACE_REFS
615/* Py_TRACE_REFS is such major surgery that we call external routines. */
616PyAPI_FUNC(void) _Py_NewReference(PyObject *);
617PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
618PyAPI_FUNC(void) _Py_Dealloc(PyObject *);
619PyAPI_FUNC(void) _Py_PrintReferences(FILE *);
620PyAPI_FUNC(void) _Py_PrintReferenceAddresses(FILE *);
621PyAPI_FUNC(void) _Py_AddToAllObjects(PyObject *, int force);
622
623#else
624/* Without Py_TRACE_REFS, there's little enough to do that we expand code
625 * inline.
626 */
627#define _Py_NewReference(op) ( \
628 _Py_INC_TPALLOCS(op) _Py_COUNT_ALLOCS_COMMA \
629 _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
630 (op)->ob_refcnt = 1)
631
632#define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
633
634#define _Py_Dealloc(op) ( \
635 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
636 (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
637#endif /* !Py_TRACE_REFS */
638
639#define Py_INCREF(op) ( \
640 _Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
641 (op)->ob_refcnt++)
642
643#define Py_DECREF(op) \
644 if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
645 --(op)->ob_refcnt != 0) \
646 _Py_CHECK_REFCNT(op) \
647 else \
648 _Py_Dealloc((PyObject *)(op))
649
650/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
651 * and tp_dealloc implementatons.
652 *
653 * Note that "the obvious" code can be deadly:
654 *
655 * Py_XDECREF(op);
656 * op = NULL;
657 *
658 * Typically, `op` is something like self->containee, and `self` is done
659 * using its `containee` member. In the code sequence above, suppose
660 * `containee` is non-NULL with a refcount of 1. Its refcount falls to
661 * 0 on the first line, which can trigger an arbitrary amount of code,
662 * possibly including finalizers (like __del__ methods or weakref callbacks)
663 * coded in Python, which in turn can release the GIL and allow other threads
664 * to run, etc. Such code may even invoke methods of `self` again, or cause
665 * cyclic gc to trigger, but-- oops! --self->containee still points to the
666 * object being torn down, and it may be in an insane state while being torn
667 * down. This has in fact been a rich historic source of miserable (rare &
668 * hard-to-diagnose) segfaulting (and other) bugs.
669 *
670 * The safe way is:
671 *
672 * Py_CLEAR(op);
673 *
674 * That arranges to set `op` to NULL _before_ decref'ing, so that any code
675 * triggered as a side-effect of `op` getting torn down no longer believes
676 * `op` points to a valid object.
677 *
678 * There are cases where it's safe to use the naive code, but they're brittle.
679 * For example, if `op` points to a Python integer, you know that destroying
680 * one of those can't cause problems -- but in part that relies on that
681 * Python integers aren't currently weakly referencable. Best practice is
682 * to use Py_CLEAR() even if you can't think of a reason for why you need to.
683 */
684#define Py_CLEAR(op) \
685 do { \
686 if (op) { \
687 PyObject *tmp = (PyObject *)(op); \
688 (op) = NULL; \
689 Py_DECREF(tmp); \
690 } \
691 } while (0)
692
693/* Macros to use in case the object pointer may be NULL: */
694#define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
695#define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
696
697/*
698These are provided as conveniences to Python runtime embedders, so that
699they can have object code that is not dependent on Python compilation flags.
700*/
701PyAPI_FUNC(void) Py_IncRef(PyObject *);
702PyAPI_FUNC(void) Py_DecRef(PyObject *);
703
704/*
705_Py_NoneStruct is an object of undefined type which can be used in contexts
706where NULL (nil) is not suitable (since NULL often means 'error').
707
708Don't forget to apply Py_INCREF() when returning this value!!!
709*/
710PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
711#define Py_None (&_Py_NoneStruct)
712
713/* Macro for returning Py_None from a function */
714#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
715
716/*
717Py_NotImplemented is a singleton used to signal that an operation is
718not implemented for a given type combination.
719*/
720PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
721#define Py_NotImplemented (&_Py_NotImplementedStruct)
722
723/* Rich comparison opcodes */
724#define Py_LT 0
725#define Py_LE 1
726#define Py_EQ 2
727#define Py_NE 3
728#define Py_GT 4
729#define Py_GE 5
730
731/* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
732 * Defined in object.c.
733 */
734PyAPI_DATA(int) _Py_SwappedOp[];
735
736/*
737Define staticforward and statichere for source compatibility with old
738C extensions.
739
740The staticforward define was needed to support certain broken C
741compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the
742static keyword when it was used with a forward declaration of a static
743initialized structure. Standard C allows the forward declaration with
744static, and we've decided to stop catering to broken C compilers.
745(In fact, we expect that the compilers are all fixed eight years later.)
746*/
747
748#define staticforward static
749#define statichere static
750
751
752/*
753More conventions
754================
755
756Argument Checking
757-----------------
758
759Functions that take objects as arguments normally don't check for nil
760arguments, but they do check the type of the argument, and return an
761error if the function doesn't apply to the type.
762
763Failure Modes
764-------------
765
766Functions may fail for a variety of reasons, including running out of
767memory. This is communicated to the caller in two ways: an error string
768is set (see errors.h), and the function result differs: functions that
769normally return a pointer return NULL for failure, functions returning
770an integer return -1 (which could be a legal return value too!), and
771other functions return 0 for success and -1 for failure.
772Callers should always check for errors before using the result. If
773an error was set, the caller must either explicitly clear it, or pass
774the error on to its caller.
775
776Reference Counts
777----------------
778
779It takes a while to get used to the proper usage of reference counts.
780
781Functions that create an object set the reference count to 1; such new
782objects must be stored somewhere or destroyed again with Py_DECREF().
783Some functions that 'store' objects, such as PyTuple_SetItem() and
784PyList_SetItem(),
785don't increment the reference count of the object, since the most
786frequent use is to store a fresh object. Functions that 'retrieve'
787objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also
788don't increment
789the reference count, since most frequently the object is only looked at
790quickly. Thus, to retrieve an object and store it again, the caller
791must call Py_INCREF() explicitly.
792
793NOTE: functions that 'consume' a reference count, like
794PyList_SetItem(), consume the reference even if the object wasn't
795successfully stored, to simplify error handling.
796
797It seems attractive to make other functions that take an object as
798argument consume a reference count; however, this may quickly get
799confusing (even the current practice is already confusing). Consider
800it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
801times.
802*/
803
804
805/* Trashcan mechanism, thanks to Christian Tismer.
806
807When deallocating a container object, it's possible to trigger an unbounded
808chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
809next" object in the chain to 0. This can easily lead to stack faults, and
810especially in threads (which typically have less stack space to work with).
811
812A container object that participates in cyclic gc can avoid this by
813bracketing the body of its tp_dealloc function with a pair of macros:
814
815static void
816mytype_dealloc(mytype *p)
817{
818 ... declarations go here ...
819
820 PyObject_GC_UnTrack(p); // must untrack first
821 Py_TRASHCAN_SAFE_BEGIN(p)
822 ... The body of the deallocator goes here, including all calls ...
823 ... to Py_DECREF on contained objects. ...
824 Py_TRASHCAN_SAFE_END(p)
825}
826
827CAUTION: Never return from the middle of the body! If the body needs to
828"get out early", put a label immediately before the Py_TRASHCAN_SAFE_END
829call, and goto it. Else the call-depth counter (see below) will stay
830above 0 forever, and the trashcan will never get emptied.
831
832How it works: The BEGIN macro increments a call-depth counter. So long
833as this counter is small, the body of the deallocator is run directly without
834further ado. But if the counter gets large, it instead adds p to a list of
835objects to be deallocated later, skips the body of the deallocator, and
836resumes execution after the END macro. The tp_dealloc routine then returns
837without deallocating anything (and so unbounded call-stack depth is avoided).
838
839When the call stack finishes unwinding again, code generated by the END macro
840notices this, and calls another routine to deallocate all the objects that
841may have been added to the list of deferred deallocations. In effect, a
842chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
843with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
844*/
845
846PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
847PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
848PyAPI_DATA(int) _PyTrash_delete_nesting;
849PyAPI_DATA(PyObject *) _PyTrash_delete_later;
850
851#define PyTrash_UNWIND_LEVEL 50
852
853#define Py_TRASHCAN_SAFE_BEGIN(op) \
854 if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
855 ++_PyTrash_delete_nesting;
856 /* The body of the deallocator is here. */
857#define Py_TRASHCAN_SAFE_END(op) \
858 --_PyTrash_delete_nesting; \
859 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
860 _PyTrash_destroy_chain(); \
861 } \
862 else \
863 _PyTrash_deposit_object((PyObject*)op);
864
865#ifdef __cplusplus
866}
867#endif
868#endif /* !Py_OBJECT_H */
sys/src/cmd/python/Include/objimpl.h+336−0
@@ -0,0 +1,336 @@
1/* The PyObject_ memory family: high-level object memory interfaces.
2 See pymem.h for the low-level PyMem_ family.
3*/
4
5#ifndef Py_OBJIMPL_H
6#define Py_OBJIMPL_H
7
8#include "pymem.h"
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/* BEWARE:
15
16 Each interface exports both functions and macros. Extension modules should
17 use the functions, to ensure binary compatibility across Python versions.
18 Because the Python implementation is free to change internal details, and
19 the macros may (or may not) expose details for speed, if you do use the
20 macros you must recompile your extensions with each Python release.
21
22 Never mix calls to PyObject_ memory functions with calls to the platform
23 malloc/realloc/ calloc/free, or with calls to PyMem_.
24*/
25
26/*
27Functions and macros for modules that implement new object types.
28
29 - PyObject_New(type, typeobj) allocates memory for a new object of the given
30 type, and initializes part of it. 'type' must be the C structure type used
31 to represent the object, and 'typeobj' the address of the corresponding
32 type object. Reference count and type pointer are filled in; the rest of
33 the bytes of the object are *undefined*! The resulting expression type is
34 'type *'. The size of the object is determined by the tp_basicsize field
35 of the type object.
36
37 - PyObject_NewVar(type, typeobj, n) is similar but allocates a variable-size
38 object with room for n items. In addition to the refcount and type pointer
39 fields, this also fills in the ob_size field.
40
41 - PyObject_Del(op) releases the memory allocated for an object. It does not
42 run a destructor -- it only frees the memory. PyObject_Free is identical.
43
44 - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't
45 allocate memory. Instead of a 'type' parameter, they take a pointer to a
46 new object (allocated by an arbitrary allocator), and initialize its object
47 header fields.
48
49Note that objects created with PyObject_{New, NewVar} are allocated using the
50specialized Python allocator (implemented in obmalloc.c), if WITH_PYMALLOC is
51enabled. In addition, a special debugging allocator is used if PYMALLOC_DEBUG
52is also #defined.
53
54In case a specific form of memory management is needed (for example, if you
55must use the platform malloc heap(s), or shared memory, or C++ local storage or
56operator new), you must first allocate the object with your custom allocator,
57then pass its pointer to PyObject_{Init, InitVar} for filling in its Python-
58specific fields: reference count, type pointer, possibly others. You should
59be aware that Python no control over these objects because they don't
60cooperate with the Python memory manager. Such objects may not be eligible
61for automatic garbage collection and you have to make sure that they are
62released accordingly whenever their destructor gets called (cf. the specific
63form of memory management you're using).
64
65Unless you have specific memory management requirements, use
66PyObject_{New, NewVar, Del}.
67*/
68
69/*
70 * Raw object memory interface
71 * ===========================
72 */
73
74/* Functions to call the same malloc/realloc/free as used by Python's
75 object allocator. If WITH_PYMALLOC is enabled, these may differ from
76 the platform malloc/realloc/free. The Python object allocator is
77 designed for fast, cache-conscious allocation of many "small" objects,
78 and with low hidden memory overhead.
79
80 PyObject_Malloc(0) returns a unique non-NULL pointer if possible.
81
82 PyObject_Realloc(NULL, n) acts like PyObject_Malloc(n).
83 PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memory
84 at p.
85
86 Returned pointers must be checked for NULL explicitly; no action is
87 performed on failure other than to return NULL (no warning it printed, no
88 exception is set, etc).
89
90 For allocating objects, use PyObject_{New, NewVar} instead whenever
91 possible. The PyObject_{Malloc, Realloc, Free} family is exposed
92 so that you can exploit Python's small-block allocator for non-object
93 uses. If you must use these routines to allocate object memory, make sure
94 the object gets initialized via PyObject_{Init, InitVar} after obtaining
95 the raw memory.
96*/
97PyAPI_FUNC(void *) PyObject_Malloc(size_t);
98PyAPI_FUNC(void *) PyObject_Realloc(void *, size_t);
99PyAPI_FUNC(void) PyObject_Free(void *);
100
101
102/* Macros */
103#ifdef WITH_PYMALLOC
104#ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */
105PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes);
106PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes);
107PyAPI_FUNC(void) _PyObject_DebugFree(void *p);
108PyAPI_FUNC(void) _PyObject_DebugDumpAddress(const void *p);
109PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p);
110PyAPI_FUNC(void) _PyObject_DebugMallocStats(void);
111#define PyObject_MALLOC _PyObject_DebugMalloc
112#define PyObject_Malloc _PyObject_DebugMalloc
113#define PyObject_REALLOC _PyObject_DebugRealloc
114#define PyObject_Realloc _PyObject_DebugRealloc
115#define PyObject_FREE _PyObject_DebugFree
116#define PyObject_Free _PyObject_DebugFree
117
118#else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */
119#define PyObject_MALLOC PyObject_Malloc
120#define PyObject_REALLOC PyObject_Realloc
121#define PyObject_FREE PyObject_Free
122#endif
123
124#else /* ! WITH_PYMALLOC */
125#define PyObject_MALLOC PyMem_MALLOC
126#define PyObject_REALLOC PyMem_REALLOC
127#define PyObject_FREE PyMem_FREE
128
129#endif /* WITH_PYMALLOC */
130
131#define PyObject_Del PyObject_Free
132#define PyObject_DEL PyObject_FREE
133
134/* for source compatibility with 2.2 */
135#define _PyObject_Del PyObject_Free
136
137/*
138 * Generic object allocator interface
139 * ==================================
140 */
141
142/* Functions */
143PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *);
144PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *,
145 PyTypeObject *, Py_ssize_t);
146PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);
147PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
148
149#define PyObject_New(type, typeobj) \
150 ( (type *) _PyObject_New(typeobj) )
151#define PyObject_NewVar(type, typeobj, n) \
152 ( (type *) _PyObject_NewVar((typeobj), (n)) )
153
154/* Macros trading binary compatibility for speed. See also pymem.h.
155 Note that these macros expect non-NULL object pointers.*/
156#define PyObject_INIT(op, typeobj) \
157 ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
158#define PyObject_INIT_VAR(op, typeobj, size) \
159 ( (op)->ob_size = (size), PyObject_INIT((op), (typeobj)) )
160
161#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
162
163/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
164 vrbl-size object with nitems items, exclusive of gc overhead (if any). The
165 value is rounded up to the closest multiple of sizeof(void *), in order to
166 ensure that pointer fields at the end of the object are correctly aligned
167 for the platform (this is of special importance for subclasses of, e.g.,
168 str or long, so that pointers can be stored after the embedded data).
169
170 Note that there's no memory wastage in doing this, as malloc has to
171 return (at worst) pointer-aligned memory anyway.
172*/
173#if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0
174# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
175#endif
176
177#define _PyObject_VAR_SIZE(typeobj, nitems) \
178 (size_t) \
179 ( ( (typeobj)->tp_basicsize + \
180 (nitems)*(typeobj)->tp_itemsize + \
181 (SIZEOF_VOID_P - 1) \
182 ) & ~(SIZEOF_VOID_P - 1) \
183 )
184
185#define PyObject_NEW(type, typeobj) \
186( (type *) PyObject_Init( \
187 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
188
189#define PyObject_NEW_VAR(type, typeobj, n) \
190( (type *) PyObject_InitVar( \
191 (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
192 (typeobj), (n)) )
193
194/* This example code implements an object constructor with a custom
195 allocator, where PyObject_New is inlined, and shows the important
196 distinction between two steps (at least):
197 1) the actual allocation of the object storage;
198 2) the initialization of the Python specific fields
199 in this storage with PyObject_{Init, InitVar}.
200
201 PyObject *
202 YourObject_New(...)
203 {
204 PyObject *op;
205
206 op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));
207 if (op == NULL)
208 return PyErr_NoMemory();
209
210 PyObject_Init(op, &YourTypeStruct);
211
212 op->ob_field = value;
213 ...
214 return op;
215 }
216
217 Note that in C++, the use of the new operator usually implies that
218 the 1st step is performed automatically for you, so in a C++ class
219 constructor you would start directly with PyObject_Init/InitVar
220*/
221
222/*
223 * Garbage Collection Support
224 * ==========================
225 */
226
227/* C equivalent of gc.collect(). */
228PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
229
230/* Test if a type has a GC head */
231#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
232
233/* Test if an object has a GC head */
234#define PyObject_IS_GC(o) (PyType_IS_GC((o)->ob_type) && \
235 ((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))
236
237PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
238#define PyObject_GC_Resize(type, op, n) \
239 ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) )
240
241/* for source compatibility with 2.2 */
242#define _PyObject_GC_Del PyObject_GC_Del
243
244/* GC information is stored BEFORE the object structure. */
245typedef union _gc_head {
246 struct {
247 union _gc_head *gc_next;
248 union _gc_head *gc_prev;
249 Py_ssize_t gc_refs;
250 } gc;
251 long double dummy; /* force worst-case alignment */
252} PyGC_Head;
253
254extern PyGC_Head *_PyGC_generation0;
255
256#define _Py_AS_GC(o) ((PyGC_Head *)(o)-1)
257
258#define _PyGC_REFS_UNTRACKED (-2)
259#define _PyGC_REFS_REACHABLE (-3)
260#define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4)
261
262/* Tell the GC to track this object. NB: While the object is tracked the
263 * collector it must be safe to call the ob_traverse method. */
264#define _PyObject_GC_TRACK(o) do { \
265 PyGC_Head *g = _Py_AS_GC(o); \
266 if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \
267 Py_FatalError("GC object already tracked"); \
268 g->gc.gc_refs = _PyGC_REFS_REACHABLE; \
269 g->gc.gc_next = _PyGC_generation0; \
270 g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \
271 g->gc.gc_prev->gc.gc_next = g; \
272 _PyGC_generation0->gc.gc_prev = g; \
273 } while (0);
274
275/* Tell the GC to stop tracking this object.
276 * gc_next doesn't need to be set to NULL, but doing so is a good
277 * way to provoke memory errors if calling code is confused.
278 */
279#define _PyObject_GC_UNTRACK(o) do { \
280 PyGC_Head *g = _Py_AS_GC(o); \
281 assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \
282 g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \
283 g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \
284 g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \
285 g->gc.gc_next = NULL; \
286 } while (0);
287
288PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t);
289PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
290PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
291PyAPI_FUNC(void) PyObject_GC_Track(void *);
292PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
293PyAPI_FUNC(void) PyObject_GC_Del(void *);
294
295#define PyObject_GC_New(type, typeobj) \
296 ( (type *) _PyObject_GC_New(typeobj) )
297#define PyObject_GC_NewVar(type, typeobj, n) \
298 ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
299
300
301/* Utility macro to help write tp_traverse functions.
302 * To use this macro, the tp_traverse function must name its arguments
303 * "visit" and "arg". This is intended to keep tp_traverse functions
304 * looking as much alike as possible.
305 */
306#define Py_VISIT(op) \
307 do { \
308 if (op) { \
309 int vret = visit((PyObject *)(op), arg); \
310 if (vret) \
311 return vret; \
312 } \
313 } while (0)
314
315/* This is here for the sake of backwards compatibility. Extensions that
316 * use the old GC API will still compile but the objects will not be
317 * tracked by the GC. */
318#define PyGC_HEAD_SIZE 0
319#define PyObject_GC_Init(op)
320#define PyObject_GC_Fini(op)
321#define PyObject_AS_GC(op) (op)
322#define PyObject_FROM_GC(op) (op)
323
324
325/* Test if a type supports weak references */
326#define PyType_SUPPORTS_WEAKREFS(t) \
327 (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
328 && ((t)->tp_weaklistoffset > 0))
329
330#define PyObject_GET_WEAKREFS_LISTPTR(o) \
331 ((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))
332
333#ifdef __cplusplus
334}
335#endif
336#endif /* !Py_OBJIMPL_H */
sys/src/cmd/python/Include/opcode.h+152−0
@@ -0,0 +1,152 @@
1#ifndef Py_OPCODE_H
2#define Py_OPCODE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Instruction opcodes for compiled code */
9
10#define STOP_CODE 0
11#define POP_TOP 1
12#define ROT_TWO 2
13#define ROT_THREE 3
14#define DUP_TOP 4
15#define ROT_FOUR 5
16#define NOP 9
17
18#define UNARY_POSITIVE 10
19#define UNARY_NEGATIVE 11
20#define UNARY_NOT 12
21#define UNARY_CONVERT 13
22
23#define UNARY_INVERT 15
24
25#define LIST_APPEND 18
26#define BINARY_POWER 19
27
28#define BINARY_MULTIPLY 20
29#define BINARY_DIVIDE 21
30#define BINARY_MODULO 22
31#define BINARY_ADD 23
32#define BINARY_SUBTRACT 24
33#define BINARY_SUBSCR 25
34#define BINARY_FLOOR_DIVIDE 26
35#define BINARY_TRUE_DIVIDE 27
36#define INPLACE_FLOOR_DIVIDE 28
37#define INPLACE_TRUE_DIVIDE 29
38
39#define SLICE 30
40/* Also uses 31-33 */
41
42#define STORE_SLICE 40
43/* Also uses 41-43 */
44
45#define DELETE_SLICE 50
46/* Also uses 51-53 */
47
48#define INPLACE_ADD 55
49#define INPLACE_SUBTRACT 56
50#define INPLACE_MULTIPLY 57
51#define INPLACE_DIVIDE 58
52#define INPLACE_MODULO 59
53#define STORE_SUBSCR 60
54#define DELETE_SUBSCR 61
55
56#define BINARY_LSHIFT 62
57#define BINARY_RSHIFT 63
58#define BINARY_AND 64
59#define BINARY_XOR 65
60#define BINARY_OR 66
61#define INPLACE_POWER 67
62#define GET_ITER 68
63
64#define PRINT_EXPR 70
65#define PRINT_ITEM 71
66#define PRINT_NEWLINE 72
67#define PRINT_ITEM_TO 73
68#define PRINT_NEWLINE_TO 74
69#define INPLACE_LSHIFT 75
70#define INPLACE_RSHIFT 76
71#define INPLACE_AND 77
72#define INPLACE_XOR 78
73#define INPLACE_OR 79
74#define BREAK_LOOP 80
75#define WITH_CLEANUP 81
76#define LOAD_LOCALS 82
77#define RETURN_VALUE 83
78#define IMPORT_STAR 84
79#define EXEC_STMT 85
80#define YIELD_VALUE 86
81#define POP_BLOCK 87
82#define END_FINALLY 88
83#define BUILD_CLASS 89
84
85#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
86
87#define STORE_NAME 90 /* Index in name list */
88#define DELETE_NAME 91 /* "" */
89#define UNPACK_SEQUENCE 92 /* Number of sequence items */
90#define FOR_ITER 93
91
92#define STORE_ATTR 95 /* Index in name list */
93#define DELETE_ATTR 96 /* "" */
94#define STORE_GLOBAL 97 /* "" */
95#define DELETE_GLOBAL 98 /* "" */
96#define DUP_TOPX 99 /* number of items to duplicate */
97#define LOAD_CONST 100 /* Index in const list */
98#define LOAD_NAME 101 /* Index in name list */
99#define BUILD_TUPLE 102 /* Number of tuple items */
100#define BUILD_LIST 103 /* Number of list items */
101#define BUILD_MAP 104 /* Always zero for now */
102#define LOAD_ATTR 105 /* Index in name list */
103#define COMPARE_OP 106 /* Comparison operator */
104#define IMPORT_NAME 107 /* Index in name list */
105#define IMPORT_FROM 108 /* Index in name list */
106
107#define JUMP_FORWARD 110 /* Number of bytes to skip */
108#define JUMP_IF_FALSE 111 /* "" */
109#define JUMP_IF_TRUE 112 /* "" */
110#define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */
111
112#define LOAD_GLOBAL 116 /* Index in name list */
113
114#define CONTINUE_LOOP 119 /* Start of loop (absolute) */
115#define SETUP_LOOP 120 /* Target address (absolute) */
116#define SETUP_EXCEPT 121 /* "" */
117#define SETUP_FINALLY 122 /* "" */
118
119#define LOAD_FAST 124 /* Local variable number */
120#define STORE_FAST 125 /* Local variable number */
121#define DELETE_FAST 126 /* Local variable number */
122
123#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
124/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
125#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
126#define MAKE_FUNCTION 132 /* #defaults */
127#define BUILD_SLICE 133 /* Number of items */
128
129#define MAKE_CLOSURE 134 /* #free vars */
130#define LOAD_CLOSURE 135 /* Load free variable from closure */
131#define LOAD_DEREF 136 /* Load and dereference from closure cell */
132#define STORE_DEREF 137 /* Store into cell */
133
134/* The next 3 opcodes must be contiguous and satisfy
135 (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
136#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
137#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
138#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
139
140/* Support for opargs more than 16 bits long */
141#define EXTENDED_ARG 143
142
143
144enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,
145 PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
146
147#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
148
149#ifdef __cplusplus
150}
151#endif
152#endif /* !Py_OPCODE_H */
sys/src/cmd/python/Include/osdefs.h+55−0
@@ -0,0 +1,55 @@
1#ifndef Py_OSDEFS_H
2#define Py_OSDEFS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Operating system dependencies */
9
10/* Mod by chrish: QNX has WATCOM, but isn't DOS */
11#if !defined(__QNX__)
12#if defined(MS_WINDOWS) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__DJGPP__) || defined(PYOS_OS2)
13#if defined(PYOS_OS2) && defined(PYCC_GCC)
14#define MAXPATHLEN 260
15#define SEP '/'
16#define ALTSEP '\\'
17#else
18#define SEP '\\'
19#define ALTSEP '/'
20#define MAXPATHLEN 256
21#endif
22#define DELIM ';'
23#endif
24#endif
25
26#ifdef RISCOS
27#define SEP '.'
28#define MAXPATHLEN 256
29#define DELIM ','
30#endif
31
32
33/* Filename separator */
34#ifndef SEP
35#define SEP '/'
36#endif
37
38/* Max pathname length */
39#ifndef MAXPATHLEN
40#if defined(PATH_MAX) && PATH_MAX > 1024
41#define MAXPATHLEN PATH_MAX
42#else
43#define MAXPATHLEN 1024
44#endif
45#endif
46
47/* Search path entry delimiter */
48#ifndef DELIM
49#define DELIM ':'
50#endif
51
52#ifdef __cplusplus
53}
54#endif
55#endif /* !Py_OSDEFS_H */
sys/src/cmd/python/Include/parsetok.h+50−0
@@ -0,0 +1,50 @@
1
2/* Parser-tokenizer link interface */
3
4#ifndef Py_PARSETOK_H
5#define Py_PARSETOK_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct {
11 int error;
12 const char *filename;
13 int lineno;
14 int offset;
15 char *text;
16 int token;
17 int expected;
18} perrdetail;
19
20#if 0
21#define PyPARSE_YIELD_IS_KEYWORD 0x0001
22#endif
23
24#define PyPARSE_DONT_IMPLY_DEDENT 0x0002
25
26#define PyPARSE_WITH_IS_KEYWORD 0x0003
27
28PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,
29 perrdetail *);
30PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int,
31 char *, char *, perrdetail *);
32
33PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int,
34 perrdetail *, int);
35PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, grammar *,
36 int, char *, char *,
37 perrdetail *, int);
38
39PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *,
40 const char *,
41 grammar *, int,
42 perrdetail *, int);
43
44/* Note that he following function is defined in pythonrun.c not parsetok.c. */
45PyAPI_FUNC(void) PyParser_SetError(perrdetail *);
46
47#ifdef __cplusplus
48}
49#endif
50#endif /* !Py_PARSETOK_H */
sys/src/cmd/python/Include/patchlevel.h+40−0
@@ -0,0 +1,40 @@
1
2/* Newfangled version identification scheme.
3
4 This scheme was added in Python 1.5.2b2; before that time, only PATCHLEVEL
5 was available. To test for presence of the scheme, test for
6 defined(PY_MAJOR_VERSION).
7
8 When the major or minor version changes, the VERSION variable in
9 configure.in must also be changed.
10
11 There is also (independent) API version information in modsupport.h.
12*/
13
14/* Values for PY_RELEASE_LEVEL */
15#define PY_RELEASE_LEVEL_ALPHA 0xA
16#define PY_RELEASE_LEVEL_BETA 0xB
17#define PY_RELEASE_LEVEL_GAMMA 0xC /* For release candidates */
18#define PY_RELEASE_LEVEL_FINAL 0xF /* Serial should be 0 here */
19 /* Higher for patch releases */
20
21/* Version parsed out into numeric values */
22#define PY_MAJOR_VERSION 2
23#define PY_MINOR_VERSION 5
24#define PY_MICRO_VERSION 1
25#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
26#define PY_RELEASE_SERIAL 0
27
28/* Version as a string */
29#define PY_VERSION "2.5.1"
30
31/* Subversion Revision number of this file (not of the repository) */
32#define PY_PATCHLEVEL_REVISION "$Revision: 54863 $"
33
34/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
35 Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
36#define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \
37 (PY_MINOR_VERSION << 16) | \
38 (PY_MICRO_VERSION << 8) | \
39 (PY_RELEASE_LEVEL << 4) | \
40 (PY_RELEASE_SERIAL << 0))
sys/src/cmd/python/Include/pgen.h+18−0
@@ -0,0 +1,18 @@
1#ifndef Py_PGEN_H
2#define Py_PGEN_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Parser generator interface */
9
10extern grammar *meta_grammar(void);
11
12struct _node;
13extern grammar *pgen(struct _node *);
14
15#ifdef __cplusplus
16}
17#endif
18#endif /* !Py_PGEN_H */
sys/src/cmd/python/Include/pgenheaders.h+42−0
@@ -0,0 +1,42 @@
1#ifndef Py_PGENHEADERS_H
2#define Py_PGENHEADERS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Include files and extern declarations used by most of the parser. */
9
10#include "Python.h"
11
12PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
13 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
14PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
15 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
16
17#define addarc _Py_addarc
18#define addbit _Py_addbit
19#define adddfa _Py_adddfa
20#define addfirstsets _Py_addfirstsets
21#define addlabel _Py_addlabel
22#define addstate _Py_addstate
23#define delbitset _Py_delbitset
24#define dumptree _Py_dumptree
25#define findlabel _Py_findlabel
26#define mergebitset _Py_mergebitset
27#define meta_grammar _Py_meta_grammar
28#define newbitset _Py_newbitset
29#define newgrammar _Py_newgrammar
30#define pgen _Py_pgen
31#define printgrammar _Py_printgrammar
32#define printnonterminals _Py_printnonterminals
33#define printtree _Py_printtree
34#define samebitset _Py_samebitset
35#define showtree _Py_showtree
36#define tok_dump _Py_tok_dump
37#define translatelabels _Py_translatelabels
38
39#ifdef __cplusplus
40}
41#endif
42#endif /* !Py_PGENHEADERS_H */
sys/src/cmd/python/Include/py_curses.h+176−0
@@ -0,0 +1,176 @@
1
2#ifndef Py_CURSES_H
3#define Py_CURSES_H
4
5#ifdef __APPLE__
6/*
7** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
8** against multiple definition of wchar_t.
9*/
10#ifdef _BSD_WCHAR_T_DEFINED_
11#define _WCHAR_T
12#endif
13#endif
14
15#ifdef __FreeBSD__
16/*
17** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
18** against multiple definition of wchar_t and wint_t.
19*/
20#ifdef _XOPEN_SOURCE_EXTENDED
21#ifndef __FreeBSD_version
22#include <osreldate.h>
23#endif
24#if __FreeBSD_version >= 500000
25#ifndef __wchar_t
26#define __wchar_t
27#endif
28#ifndef __wint_t
29#define __wint_t
30#endif
31#else
32#ifndef _WCHAR_T
33#define _WCHAR_T
34#endif
35#ifndef _WINT_T
36#define _WINT_T
37#endif
38#endif
39#endif
40#endif
41
42#ifdef HAVE_NCURSES_H
43#include <ncurses.h>
44#else
45#include <curses.h>
46#ifdef HAVE_TERM_H
47/* for tigetstr, which is not declared in SysV curses */
48#include <term.h>
49#endif
50#endif
51
52#ifdef HAVE_NCURSES_H
53/* configure was checking <curses.h>, but we will
54 use <ncurses.h>, which has all these features. */
55#ifndef WINDOW_HAS_FLAGS
56#define WINDOW_HAS_FLAGS 1
57#endif
58#ifndef MVWDELCH_IS_EXPRESSION
59#define MVWDELCH_IS_EXPRESSION 1
60#endif
61#endif
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67#define PyCurses_API_pointers 4
68
69/* Type declarations */
70
71typedef struct {
72 PyObject_HEAD
73 WINDOW *win;
74} PyCursesWindowObject;
75
76#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
77
78#ifdef CURSES_MODULE
79/* This section is used when compiling _cursesmodule.c */
80
81#else
82/* This section is used in modules that use the _cursesmodule API */
83
84static void **PyCurses_API;
85
86#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
87#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
88#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
89#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
90
91#define import_curses() \
92{ \
93 PyObject *module = PyImport_ImportModule("_curses"); \
94 if (module != NULL) { \
95 PyObject *module_dict = PyModule_GetDict(module); \
96 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
97 if (PyCObject_Check(c_api_object)) { \
98 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
99 } \
100 } \
101}
102#endif
103
104/* general error messages */
105static char *catchall_ERR = "curses function returned ERR";
106static char *catchall_NULL = "curses function returned NULL";
107
108/* Function Prototype Macros - They are ugly but very, very useful. ;-)
109
110 X - function name
111 TYPE - parameter Type
112 ERGSTR - format string for construction of the return value
113 PARSESTR - format string for argument parsing
114 */
115
116#define NoArgNoReturnFunction(X) \
117static PyObject *PyCurses_ ## X (PyObject *self) \
118{ \
119 PyCursesInitialised \
120 return PyCursesCheckERR(X(), # X); }
121
122#define NoArgOrFlagNoReturnFunction(X) \
123static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
124{ \
125 int flag = 0; \
126 PyCursesInitialised \
127 switch(PyTuple_Size(args)) { \
128 case 0: \
129 return PyCursesCheckERR(X(), # X); \
130 case 1: \
131 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
132 if (flag) return PyCursesCheckERR(X(), # X); \
133 else return PyCursesCheckERR(no ## X (), # X); \
134 default: \
135 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
136 return NULL; } }
137
138#define NoArgReturnIntFunction(X) \
139static PyObject *PyCurses_ ## X (PyObject *self) \
140{ \
141 PyCursesInitialised \
142 return PyInt_FromLong((long) X()); }
143
144
145#define NoArgReturnStringFunction(X) \
146static PyObject *PyCurses_ ## X (PyObject *self) \
147{ \
148 PyCursesInitialised \
149 return PyString_FromString(X()); }
150
151#define NoArgTrueFalseFunction(X) \
152static PyObject *PyCurses_ ## X (PyObject *self) \
153{ \
154 PyCursesInitialised \
155 if (X () == FALSE) { \
156 Py_INCREF(Py_False); \
157 return Py_False; \
158 } \
159 Py_INCREF(Py_True); \
160 return Py_True; }
161
162#define NoArgNoReturnVoidFunction(X) \
163static PyObject *PyCurses_ ## X (PyObject *self) \
164{ \
165 PyCursesInitialised \
166 X(); \
167 Py_INCREF(Py_None); \
168 return Py_None; }
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* !defined(Py_CURSES_H) */
175
176
sys/src/cmd/python/Include/pyarena.h+62−0
@@ -0,0 +1,62 @@
1/* An arena-like memory interface for the compiler.
2 */
3
4#ifndef Py_PYARENA_H
5#define Py_PYARENA_H
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11 typedef struct _arena PyArena;
12
13 /* PyArena_New() and PyArena_Free() create a new arena and free it,
14 respectively. Once an arena has been created, it can be used
15 to allocate memory via PyArena_Malloc(). Pointers to PyObject can
16 also be registered with the arena via PyArena_AddPyObject(), and the
17 arena will ensure that the PyObjects stay alive at least until
18 PyArena_Free() is called. When an arena is freed, all the memory it
19 allocated is freed, the arena releases internal references to registered
20 PyObject*, and none of its pointers are valid.
21 XXX (tim) What does "none of its pointers are valid" mean? Does it
22 XXX mean that pointers previously obtained via PyArena_Malloc() are
23 XXX no longer valid? (That's clearly true, but not sure that's what
24 XXX the text is trying to say.)
25
26 PyArena_New() returns an arena pointer. On error, it
27 returns a negative number and sets an exception.
28 XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
29 XXX and looks like it may or may not set an exception (e.g., if the
30 XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
31 XXX and an exception is set; OTOH, if the internal
32 XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
33 XXX an exception is not set in that case).
34 */
35 PyAPI_FUNC(PyArena *) PyArena_New(void);
36 PyAPI_FUNC(void) PyArena_Free(PyArena *);
37
38 /* Mostly like malloc(), return the address of a block of memory spanning
39 * `size` bytes, or return NULL (without setting an exception) if enough
40 * new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
41 * size=0 does not guarantee to return a unique pointer (the pointer
42 * returned may equal one or more other pointers obtained from
43 * PyArena_Malloc()).
44 * Note that pointers obtained via PyArena_Malloc() must never be passed to
45 * the system free() or realloc(), or to any of Python's similar memory-
46 * management functions. PyArena_Malloc()-obtained pointers remain valid
47 * until PyArena_Free(ar) is called, at which point all pointers obtained
48 * from the arena `ar` become invalid simultaneously.
49 */
50 PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
51
52 /* This routine isn't a proper arena allocation routine. It takes
53 * a PyObject* and records it so that it can be DECREFed when the
54 * arena is freed.
55 */
56 PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
57
58#ifdef __cplusplus
59}
60#endif
61
62#endif /* !Py_PYARENA_H */
sys/src/cmd/python/Include/pydebug.h+34−0
@@ -0,0 +1,34 @@
1
2#ifndef Py_PYDEBUG_H
3#define Py_PYDEBUG_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8PyAPI_DATA(int) Py_DebugFlag;
9PyAPI_DATA(int) Py_VerboseFlag;
10PyAPI_DATA(int) Py_InteractiveFlag;
11PyAPI_DATA(int) Py_OptimizeFlag;
12PyAPI_DATA(int) Py_NoSiteFlag;
13PyAPI_DATA(int) Py_UseClassExceptionsFlag;
14PyAPI_DATA(int) Py_FrozenFlag;
15PyAPI_DATA(int) Py_TabcheckFlag;
16PyAPI_DATA(int) Py_UnicodeFlag;
17PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
18PyAPI_DATA(int) Py_DivisionWarningFlag;
19/* _XXX Py_QnewFlag should go away in 3.0. It's true iff -Qnew is passed,
20 on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
21 true divisions (which they will be in 3.0). */
22PyAPI_DATA(int) _Py_QnewFlag;
23
24/* this is a wrapper around getenv() that pays attention to
25 Py_IgnoreEnvironmentFlag. It should be used for getting variables like
26 PYTHONPATH and PYTHONHOME from the environment */
27#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
28
29PyAPI_FUNC(void) Py_FatalError(const char *message);
30
31#ifdef __cplusplus
32}
33#endif
34#endif /* !Py_PYDEBUG_H */
sys/src/cmd/python/Include/pyerrors.h+334−0
@@ -0,0 +1,334 @@
1#ifndef Py_ERRORS_H
2#define Py_ERRORS_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/* Error objects */
8
9typedef struct {
10 PyObject_HEAD
11 PyObject *dict;
12 PyObject *args;
13 PyObject *message;
14} PyBaseExceptionObject;
15
16typedef struct {
17 PyObject_HEAD
18 PyObject *dict;
19 PyObject *args;
20 PyObject *message;
21 PyObject *msg;
22 PyObject *filename;
23 PyObject *lineno;
24 PyObject *offset;
25 PyObject *text;
26 PyObject *print_file_and_line;
27} PySyntaxErrorObject;
28
29#ifdef Py_USING_UNICODE
30typedef struct {
31 PyObject_HEAD
32 PyObject *dict;
33 PyObject *args;
34 PyObject *message;
35 PyObject *encoding;
36 PyObject *object;
37 PyObject *start;
38 PyObject *end;
39 PyObject *reason;
40} PyUnicodeErrorObject;
41#endif
42
43typedef struct {
44 PyObject_HEAD
45 PyObject *dict;
46 PyObject *args;
47 PyObject *message;
48 PyObject *code;
49} PySystemExitObject;
50
51typedef struct {
52 PyObject_HEAD
53 PyObject *dict;
54 PyObject *args;
55 PyObject *message;
56 PyObject *myerrno;
57 PyObject *strerror;
58 PyObject *filename;
59} PyEnvironmentErrorObject;
60
61#ifdef MS_WINDOWS
62typedef struct {
63 PyObject_HEAD
64 PyObject *dict;
65 PyObject *args;
66 PyObject *message;
67 PyObject *myerrno;
68 PyObject *strerror;
69 PyObject *filename;
70 PyObject *winerror;
71} PyWindowsErrorObject;
72#endif
73
74/* Error handling definitions */
75
76PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
77PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
78PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
79PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
80PyAPI_FUNC(void) PyErr_Clear(void);
81PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
82PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
83
84#ifdef Py_DEBUG
85#define _PyErr_OCCURRED() PyErr_Occurred()
86#else
87#define _PyErr_OCCURRED() (_PyThreadState_Current->curexc_type)
88#endif
89
90/* Error testing and normalization */
91PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
92PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
93PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
94
95/* */
96
97#define PyExceptionClass_Check(x) \
98 (PyClass_Check((x)) \
99 || (PyType_Check((x)) && PyType_IsSubtype( \
100 (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException)))
101
102
103#define PyExceptionInstance_Check(x) \
104 (PyInstance_Check((x)) || \
105 (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException)))
106
107#define PyExceptionClass_Name(x) \
108 (PyClass_Check((x)) \
109 ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
110 : (char *)(((PyTypeObject*)(x))->tp_name))
111
112#define PyExceptionInstance_Class(x) \
113 ((PyInstance_Check((x)) \
114 ? (PyObject*)((PyInstanceObject*)(x))->in_class \
115 : (PyObject*)((x)->ob_type)))
116
117
118/* Predefined exceptions */
119
120PyAPI_DATA(PyObject *) PyExc_BaseException;
121PyAPI_DATA(PyObject *) PyExc_Exception;
122PyAPI_DATA(PyObject *) PyExc_StopIteration;
123PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
124PyAPI_DATA(PyObject *) PyExc_StandardError;
125PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
126PyAPI_DATA(PyObject *) PyExc_LookupError;
127
128PyAPI_DATA(PyObject *) PyExc_AssertionError;
129PyAPI_DATA(PyObject *) PyExc_AttributeError;
130PyAPI_DATA(PyObject *) PyExc_EOFError;
131PyAPI_DATA(PyObject *) PyExc_FloatingPointError;
132PyAPI_DATA(PyObject *) PyExc_EnvironmentError;
133PyAPI_DATA(PyObject *) PyExc_IOError;
134PyAPI_DATA(PyObject *) PyExc_OSError;
135PyAPI_DATA(PyObject *) PyExc_ImportError;
136PyAPI_DATA(PyObject *) PyExc_IndexError;
137PyAPI_DATA(PyObject *) PyExc_KeyError;
138PyAPI_DATA(PyObject *) PyExc_KeyboardInterrupt;
139PyAPI_DATA(PyObject *) PyExc_MemoryError;
140PyAPI_DATA(PyObject *) PyExc_NameError;
141PyAPI_DATA(PyObject *) PyExc_OverflowError;
142PyAPI_DATA(PyObject *) PyExc_RuntimeError;
143PyAPI_DATA(PyObject *) PyExc_NotImplementedError;
144PyAPI_DATA(PyObject *) PyExc_SyntaxError;
145PyAPI_DATA(PyObject *) PyExc_IndentationError;
146PyAPI_DATA(PyObject *) PyExc_TabError;
147PyAPI_DATA(PyObject *) PyExc_ReferenceError;
148PyAPI_DATA(PyObject *) PyExc_SystemError;
149PyAPI_DATA(PyObject *) PyExc_SystemExit;
150PyAPI_DATA(PyObject *) PyExc_TypeError;
151PyAPI_DATA(PyObject *) PyExc_UnboundLocalError;
152PyAPI_DATA(PyObject *) PyExc_UnicodeError;
153PyAPI_DATA(PyObject *) PyExc_UnicodeEncodeError;
154PyAPI_DATA(PyObject *) PyExc_UnicodeDecodeError;
155PyAPI_DATA(PyObject *) PyExc_UnicodeTranslateError;
156PyAPI_DATA(PyObject *) PyExc_ValueError;
157PyAPI_DATA(PyObject *) PyExc_ZeroDivisionError;
158#ifdef MS_WINDOWS
159PyAPI_DATA(PyObject *) PyExc_WindowsError;
160#endif
161#ifdef __VMS
162PyAPI_DATA(PyObject *) PyExc_VMSError;
163#endif
164
165PyAPI_DATA(PyObject *) PyExc_MemoryErrorInst;
166
167/* Predefined warning categories */
168PyAPI_DATA(PyObject *) PyExc_Warning;
169PyAPI_DATA(PyObject *) PyExc_UserWarning;
170PyAPI_DATA(PyObject *) PyExc_DeprecationWarning;
171PyAPI_DATA(PyObject *) PyExc_PendingDeprecationWarning;
172PyAPI_DATA(PyObject *) PyExc_SyntaxWarning;
173PyAPI_DATA(PyObject *) PyExc_RuntimeWarning;
174PyAPI_DATA(PyObject *) PyExc_FutureWarning;
175PyAPI_DATA(PyObject *) PyExc_ImportWarning;
176PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
177
178
179/* Convenience functions */
180
181PyAPI_FUNC(int) PyErr_BadArgument(void);
182PyAPI_FUNC(PyObject *) PyErr_NoMemory(void);
183PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
184PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
185 PyObject *, PyObject *);
186PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(PyObject *, char *);
187#ifdef Py_WIN_WIDE_FILENAMES
188PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
189 PyObject *, Py_UNICODE *);
190#endif /* Py_WIN_WIDE_FILENAMES */
191
192PyAPI_FUNC(PyObject *) PyErr_Format(PyObject *, const char *, ...)
193 Py_GCC_ATTRIBUTE((format(printf, 2, 3)));
194
195#ifdef MS_WINDOWS
196PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilenameObject(
197 int, const char *);
198PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
199 int, const char *);
200#ifdef Py_WIN_WIDE_FILENAMES
201PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithUnicodeFilename(
202 int, const Py_UNICODE *);
203#endif /* Py_WIN_WIDE_FILENAMES */
204PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int);
205PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject(
206 PyObject *,int, PyObject *);
207PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilename(
208 PyObject *,int, const char *);
209#ifdef Py_WIN_WIDE_FILENAMES
210PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithUnicodeFilename(
211 PyObject *,int, const Py_UNICODE *);
212#endif /* Py_WIN_WIDE_FILENAMES */
213PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErr(PyObject *, int);
214#endif /* MS_WINDOWS */
215
216/* Export the old function so that the existing API remains available: */
217PyAPI_FUNC(void) PyErr_BadInternalCall(void);
218PyAPI_FUNC(void) _PyErr_BadInternalCall(char *filename, int lineno);
219/* Mask the old API with a call to the new API for code compiled under
220 Python 2.0: */
221#define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__)
222
223/* Function to create a new exception */
224PyAPI_FUNC(PyObject *) PyErr_NewException(char *name, PyObject *base,
225 PyObject *dict);
226PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
227
228/* Issue a warning or exception */
229PyAPI_FUNC(int) PyErr_WarnEx(PyObject *category, const char *msg,
230 Py_ssize_t stack_level);
231PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *,
232 const char *, int,
233 const char *, PyObject *);
234/* PyErr_Warn is only for backwards compatability and will be removed.
235 Use PyErr_WarnEx instead. */
236#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
237
238/* In sigcheck.c or signalmodule.c */
239PyAPI_FUNC(int) PyErr_CheckSignals(void);
240PyAPI_FUNC(void) PyErr_SetInterrupt(void);
241
242/* Support for adding program text to SyntaxErrors */
243PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
244PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
245
246#ifdef Py_USING_UNICODE
247/* The following functions are used to create and modify unicode
248 exceptions from C */
249
250/* create a UnicodeDecodeError object */
251PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_Create(
252 const char *, const char *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
253
254/* create a UnicodeEncodeError object */
255PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_Create(
256 const char *, const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
257
258/* create a UnicodeTranslateError object */
259PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_Create(
260 const Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const char *);
261
262/* get the encoding attribute */
263PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetEncoding(PyObject *);
264PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetEncoding(PyObject *);
265
266/* get the object attribute */
267PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetObject(PyObject *);
268PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetObject(PyObject *);
269PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetObject(PyObject *);
270
271/* get the value of the start attribute (the int * may not be NULL)
272 return 0 on success, -1 on failure */
273PyAPI_FUNC(int) PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *);
274PyAPI_FUNC(int) PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *);
275PyAPI_FUNC(int) PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *);
276
277/* assign a new value to the start attribute
278 return 0 on success, -1 on failure */
279PyAPI_FUNC(int) PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t);
280PyAPI_FUNC(int) PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t);
281PyAPI_FUNC(int) PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t);
282
283/* get the value of the end attribute (the int *may not be NULL)
284 return 0 on success, -1 on failure */
285PyAPI_FUNC(int) PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *);
286PyAPI_FUNC(int) PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *);
287PyAPI_FUNC(int) PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *);
288
289/* assign a new value to the end attribute
290 return 0 on success, -1 on failure */
291PyAPI_FUNC(int) PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t);
292PyAPI_FUNC(int) PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t);
293PyAPI_FUNC(int) PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t);
294
295/* get the value of the reason attribute */
296PyAPI_FUNC(PyObject *) PyUnicodeEncodeError_GetReason(PyObject *);
297PyAPI_FUNC(PyObject *) PyUnicodeDecodeError_GetReason(PyObject *);
298PyAPI_FUNC(PyObject *) PyUnicodeTranslateError_GetReason(PyObject *);
299
300/* assign a new value to the reason attribute
301 return 0 on success, -1 on failure */
302PyAPI_FUNC(int) PyUnicodeEncodeError_SetReason(
303 PyObject *, const char *);
304PyAPI_FUNC(int) PyUnicodeDecodeError_SetReason(
305 PyObject *, const char *);
306PyAPI_FUNC(int) PyUnicodeTranslateError_SetReason(
307 PyObject *, const char *);
308#endif
309
310
311/* These APIs aren't really part of the error implementation, but
312 often needed to format error messages; the native C lib APIs are
313 not available on all platforms, which is why we provide emulations
314 for those platforms in Python/mysnprintf.c,
315 WARNING: The return value of snprintf varies across platforms; do
316 not rely on any particular behavior; eventually the C99 defn may
317 be reliable.
318*/
319#if defined(MS_WIN32) && !defined(HAVE_SNPRINTF)
320# define HAVE_SNPRINTF
321# define snprintf _snprintf
322# define vsnprintf _vsnprintf
323#endif
324
325#include <stdarg.h>
326PyAPI_FUNC(int) PyOS_snprintf(char *str, size_t size, const char *format, ...)
327 Py_GCC_ATTRIBUTE((format(printf, 3, 4)));
328PyAPI_FUNC(int) PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
329 Py_GCC_ATTRIBUTE((format(printf, 3, 0)));
330
331#ifdef __cplusplus
332}
333#endif
334#endif /* !Py_ERRORS_H */
sys/src/cmd/python/Include/pyexpat.h+47−0
@@ -0,0 +1,47 @@
1/* Stuff to export relevant 'expat' entry points from pyexpat to other
2 * parser modules, such as cElementTree. */
3
4/* note: you must import expat.h before importing this module! */
5
6#define PyExpat_CAPI_MAGIC "pyexpat.expat_CAPI 1.0"
7
8struct PyExpat_CAPI
9{
10 char* magic; /* set to PyExpat_CAPI_MAGIC */
11 int size; /* set to sizeof(struct PyExpat_CAPI) */
12 int MAJOR_VERSION;
13 int MINOR_VERSION;
14 int MICRO_VERSION;
15 /* pointers to selected expat functions. add new functions at
16 the end, if needed */
17 const XML_LChar * (*ErrorString)(enum XML_Error code);
18 enum XML_Error (*GetErrorCode)(XML_Parser parser);
19 XML_Size (*GetErrorColumnNumber)(XML_Parser parser);
20 XML_Size (*GetErrorLineNumber)(XML_Parser parser);
21 enum XML_Status (*Parse)(
22 XML_Parser parser, const char *s, int len, int isFinal);
23 XML_Parser (*ParserCreate_MM)(
24 const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite,
25 const XML_Char *namespaceSeparator);
26 void (*ParserFree)(XML_Parser parser);
27 void (*SetCharacterDataHandler)(
28 XML_Parser parser, XML_CharacterDataHandler handler);
29 void (*SetCommentHandler)(
30 XML_Parser parser, XML_CommentHandler handler);
31 void (*SetDefaultHandlerExpand)(
32 XML_Parser parser, XML_DefaultHandler handler);
33 void (*SetElementHandler)(
34 XML_Parser parser, XML_StartElementHandler start,
35 XML_EndElementHandler end);
36 void (*SetNamespaceDeclHandler)(
37 XML_Parser parser, XML_StartNamespaceDeclHandler start,
38 XML_EndNamespaceDeclHandler end);
39 void (*SetProcessingInstructionHandler)(
40 XML_Parser parser, XML_ProcessingInstructionHandler handler);
41 void (*SetUnknownEncodingHandler)(
42 XML_Parser parser, XML_UnknownEncodingHandler handler,
43 void *encodingHandlerData);
44 void (*SetUserData)(XML_Parser parser, void *userData);
45 /* always add new stuff to the end! */
46};
47
sys/src/cmd/python/Include/pyfpe.h+176−0
@@ -0,0 +1,176 @@
1#ifndef Py_PYFPE_H
2#define Py_PYFPE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6/*
7 ---------------------------------------------------------------------
8 / Copyright (c) 1996. \
9 | The Regents of the University of California. |
10 | All rights reserved. |
11 | |
12 | Permission to use, copy, modify, and distribute this software for |
13 | any purpose without fee is hereby granted, provided that this en- |
14 | tire notice is included in all copies of any software which is or |
15 | includes a copy or modification of this software and in all |
16 | copies of the supporting documentation for such software. |
17 | |
18 | This work was produced at the University of California, Lawrence |
19 | Livermore National Laboratory under contract no. W-7405-ENG-48 |
20 | between the U.S. Department of Energy and The Regents of the |
21 | University of California for the operation of UC LLNL. |
22 | |
23 | DISCLAIMER |
24 | |
25 | This software was prepared as an account of work sponsored by an |
26 | agency of the United States Government. Neither the United States |
27 | Government nor the University of California nor any of their em- |
28 | ployees, makes any warranty, express or implied, or assumes any |
29 | liability or responsibility for the accuracy, completeness, or |
30 | usefulness of any information, apparatus, product, or process |
31 | disclosed, or represents that its use would not infringe |
32 | privately-owned rights. Reference herein to any specific commer- |
33 | cial products, process, or service by trade name, trademark, |
34 | manufacturer, or otherwise, does not necessarily constitute or |
35 | imply its endorsement, recommendation, or favoring by the United |
36 | States Government or the University of California. The views and |
37 | opinions of authors expressed herein do not necessarily state or |
38 | reflect those of the United States Government or the University |
39 | of California, and shall not be used for advertising or product |
40 \ endorsement purposes. /
41 ---------------------------------------------------------------------
42*/
43
44/*
45 * Define macros for handling SIGFPE.
46 * Lee Busby, LLNL, November, 1996
47 * busby1@llnl.gov
48 *
49 *********************************************
50 * Overview of the system for handling SIGFPE:
51 *
52 * This file (Include/pyfpe.h) defines a couple of "wrapper" macros for
53 * insertion into your Python C code of choice. Their proper use is
54 * discussed below. The file Python/pyfpe.c defines a pair of global
55 * variables PyFPE_jbuf and PyFPE_counter which are used by the signal
56 * handler for SIGFPE to decide if a particular exception was protected
57 * by the macros. The signal handler itself, and code for enabling the
58 * generation of SIGFPE in the first place, is in a (new) Python module
59 * named fpectl. This module is standard in every respect. It can be loaded
60 * either statically or dynamically as you choose, and like any other
61 * Python module, has no effect until you import it.
62 *
63 * In the general case, there are three steps toward handling SIGFPE in any
64 * Python code:
65 *
66 * 1) Add the *_PROTECT macros to your C code as required to protect
67 * dangerous floating point sections.
68 *
69 * 2) Turn on the inclusion of the code by adding the ``--with-fpectl''
70 * flag at the time you run configure. If the fpectl or other modules
71 * which use the *_PROTECT macros are to be dynamically loaded, be
72 * sure they are compiled with WANT_SIGFPE_HANDLER defined.
73 *
74 * 3) When python is built and running, import fpectl, and execute
75 * fpectl.turnon_sigfpe(). This sets up the signal handler and enables
76 * generation of SIGFPE whenever an exception occurs. From this point
77 * on, any properly trapped SIGFPE should result in the Python
78 * FloatingPointError exception.
79 *
80 * Step 1 has been done already for the Python kernel code, and should be
81 * done soon for the NumPy array package. Step 2 is usually done once at
82 * python install time. Python's behavior with respect to SIGFPE is not
83 * changed unless you also do step 3. Thus you can control this new
84 * facility at compile time, or run time, or both.
85 *
86 ********************************
87 * Using the macros in your code:
88 *
89 * static PyObject *foobar(PyObject *self,PyObject *args)
90 * {
91 * ....
92 * PyFPE_START_PROTECT("Error in foobar", return 0)
93 * result = dangerous_op(somearg1, somearg2, ...);
94 * PyFPE_END_PROTECT(result)
95 * ....
96 * }
97 *
98 * If a floating point error occurs in dangerous_op, foobar returns 0 (NULL),
99 * after setting the associated value of the FloatingPointError exception to
100 * "Error in foobar". ``Dangerous_op'' can be a single operation, or a block
101 * of code, function calls, or any combination, so long as no alternate
102 * return is possible before the PyFPE_END_PROTECT macro is reached.
103 *
104 * The macros can only be used in a function context where an error return
105 * can be recognized as signaling a Python exception. (Generally, most
106 * functions that return a PyObject * will qualify.)
107 *
108 * Guido's original design suggestion for PyFPE_START_PROTECT and
109 * PyFPE_END_PROTECT had them open and close a local block, with a locally
110 * defined jmp_buf and jmp_buf pointer. This would allow recursive nesting
111 * of the macros. The Ansi C standard makes it clear that such local
112 * variables need to be declared with the "volatile" type qualifier to keep
113 * setjmp from corrupting their values. Some current implementations seem
114 * to be more restrictive. For example, the HPUX man page for setjmp says
115 *
116 * Upon the return from a setjmp() call caused by a longjmp(), the
117 * values of any non-static local variables belonging to the routine
118 * from which setjmp() was called are undefined. Code which depends on
119 * such values is not guaranteed to be portable.
120 *
121 * I therefore decided on a more limited form of nesting, using a counter
122 * variable (PyFPE_counter) to keep track of any recursion. If an exception
123 * occurs in an ``inner'' pair of macros, the return will apparently
124 * come from the outermost level.
125 *
126 */
127
128#ifdef WANT_SIGFPE_HANDLER
129#include <signal.h>
130#include <setjmp.h>
131#include <math.h>
132extern jmp_buf PyFPE_jbuf;
133extern int PyFPE_counter;
134extern double PyFPE_dummy(void *);
135
136#define PyFPE_START_PROTECT(err_string, leave_stmt) \
137if (!PyFPE_counter++ && setjmp(PyFPE_jbuf)) { \
138 PyErr_SetString(PyExc_FloatingPointError, err_string); \
139 PyFPE_counter = 0; \
140 leave_stmt; \
141}
142
143/*
144 * This (following) is a heck of a way to decrement a counter. However,
145 * unless the macro argument is provided, code optimizers will sometimes move
146 * this statement so that it gets executed *before* the unsafe expression
147 * which we're trying to protect. That pretty well messes things up,
148 * of course.
149 *
150 * If the expression(s) you're trying to protect don't happen to return a
151 * value, you will need to manufacture a dummy result just to preserve the
152 * correct ordering of statements. Note that the macro passes the address
153 * of its argument (so you need to give it something which is addressable).
154 * If your expression returns multiple results, pass the last such result
155 * to PyFPE_END_PROTECT.
156 *
157 * Note that PyFPE_dummy returns a double, which is cast to int.
158 * This seeming insanity is to tickle the Floating Point Unit (FPU).
159 * If an exception has occurred in a preceding floating point operation,
160 * some architectures (notably Intel 80x86) will not deliver the interrupt
161 * until the *next* floating point operation. This is painful if you've
162 * already decremented PyFPE_counter.
163 */
164#define PyFPE_END_PROTECT(v) PyFPE_counter -= (int)PyFPE_dummy(&(v));
165
166#else
167
168#define PyFPE_START_PROTECT(err_string, leave_stmt)
169#define PyFPE_END_PROTECT(v)
170
171#endif
172
173#ifdef __cplusplus
174}
175#endif
176#endif /* !Py_PYFPE_H */
sys/src/cmd/python/Include/pygetopt.h+17−0
@@ -0,0 +1,17 @@
1
2#ifndef Py_PYGETOPT_H
3#define Py_PYGETOPT_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8PyAPI_DATA(int) _PyOS_opterr;
9PyAPI_DATA(int) _PyOS_optind;
10PyAPI_DATA(char *) _PyOS_optarg;
11
12PyAPI_FUNC(int) _PyOS_GetOpt(int argc, char **argv, char *optstring);
13
14#ifdef __cplusplus
15}
16#endif
17#endif /* !Py_PYGETOPT_H */
sys/src/cmd/python/Include/pymactoolbox.h+189−0
@@ -0,0 +1,189 @@
1/*
2** pymactoolbox.h - globals defined in mactoolboxglue.c
3*/
4#ifndef Py_PYMACTOOLBOX_H
5#define Py_PYMACTOOLBOX_H
6#ifdef __cplusplus
7 extern "C" {
8#endif
9
10#include <Carbon/Carbon.h>
11#include <QuickTime/QuickTime.h>
12
13/*
14** Helper routines for error codes and such.
15*/
16char *PyMac_StrError(int); /* strerror with mac errors */
17extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
18PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
19PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
20PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
21extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert
22 fsspec->path */
23/*
24** These conversion routines are defined in mactoolboxglue.c itself.
25*/
26int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */
27PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */
28
29PyObject *PyMac_BuildNumVersion(NumVersion);/* Convert NumVersion to PyObject */
30
31int PyMac_GetStr255(PyObject *, Str255); /* argument parser for Str255 */
32PyObject *PyMac_BuildStr255(Str255); /* Convert Str255 to PyObject */
33PyObject *PyMac_BuildOptStr255(Str255); /* Convert Str255 to PyObject,
34 NULL to None */
35
36int PyMac_GetRect(PyObject *, Rect *); /* argument parser for Rect */
37PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */
38
39int PyMac_GetPoint(PyObject *, Point *); /* argument parser for Point */
40PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */
41
42int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for
43 EventRecord */
44PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to
45 PyObject */
46
47int PyMac_GetFixed(PyObject *, Fixed *); /* argument parser for Fixed */
48PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */
49int PyMac_Getwide(PyObject *, wide *); /* argument parser for wide */
50PyObject *PyMac_Buildwide(wide *); /* Convert wide to PyObject */
51
52/*
53** The rest of the routines are implemented by extension modules. If they are
54** dynamically loaded mactoolboxglue will contain a stub implementation of the
55** routine, which imports the module, whereupon the module's init routine will
56** communicate the routine pointer back to the stub.
57** If USE_TOOLBOX_OBJECT_GLUE is not defined there is no glue code, and the
58** extension modules simply declare the routine. This is the case for static
59** builds (and could be the case for MacPython CFM builds, because CFM extension
60** modules can reference each other without problems).
61*/
62
63#ifdef USE_TOOLBOX_OBJECT_GLUE
64/*
65** These macros are used in the module init code. If we use toolbox object glue
66** it sets the function pointer to point to the real function.
67*/
68#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn) { \
69 extern PyObject *(*PyMacGluePtr_##rtn)(object); \
70 PyMacGluePtr_##rtn = _##rtn; \
71}
72#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn) { \
73 extern int (*PyMacGluePtr_##rtn)(PyObject *, object *); \
74 PyMacGluePtr_##rtn = _##rtn; \
75}
76#else
77/*
78** If we don't use toolbox object glue the init macros are empty. Moreover, we define
79** _xxx_New to be the same as xxx_New, and the code in mactoolboxglue isn't included.
80*/
81#define PyMac_INIT_TOOLBOX_OBJECT_NEW(object, rtn)
82#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(object, rtn)
83#endif /* USE_TOOLBOX_OBJECT_GLUE */
84
85/* macfs exports */
86int PyMac_GetFSSpec(PyObject *, FSSpec *); /* argument parser for FSSpec */
87PyObject *PyMac_BuildFSSpec(FSSpec *); /* Convert FSSpec to PyObject */
88
89int PyMac_GetFSRef(PyObject *, FSRef *); /* argument parser for FSRef */
90PyObject *PyMac_BuildFSRef(FSRef *); /* Convert FSRef to PyObject */
91
92/* AE exports */
93extern PyObject *AEDesc_New(AppleEvent *); /* XXXX Why passed by address?? */
94extern PyObject *AEDesc_NewBorrowed(AppleEvent *);
95extern int AEDesc_Convert(PyObject *, AppleEvent *);
96
97/* Cm exports */
98extern PyObject *CmpObj_New(Component);
99extern int CmpObj_Convert(PyObject *, Component *);
100extern PyObject *CmpInstObj_New(ComponentInstance);
101extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);
102
103/* Ctl exports */
104extern PyObject *CtlObj_New(ControlHandle);
105extern int CtlObj_Convert(PyObject *, ControlHandle *);
106
107/* Dlg exports */
108extern PyObject *DlgObj_New(DialogPtr);
109extern int DlgObj_Convert(PyObject *, DialogPtr *);
110extern PyObject *DlgObj_WhichDialog(DialogPtr);
111
112/* Drag exports */
113extern PyObject *DragObj_New(DragReference);
114extern int DragObj_Convert(PyObject *, DragReference *);
115
116/* List exports */
117extern PyObject *ListObj_New(ListHandle);
118extern int ListObj_Convert(PyObject *, ListHandle *);
119
120/* Menu exports */
121extern PyObject *MenuObj_New(MenuHandle);
122extern int MenuObj_Convert(PyObject *, MenuHandle *);
123
124/* Qd exports */
125extern PyObject *GrafObj_New(GrafPtr);
126extern int GrafObj_Convert(PyObject *, GrafPtr *);
127extern PyObject *BMObj_New(BitMapPtr);
128extern int BMObj_Convert(PyObject *, BitMapPtr *);
129extern PyObject *QdRGB_New(RGBColor *);
130extern int QdRGB_Convert(PyObject *, RGBColor *);
131
132/* Qdoffs exports */
133extern PyObject *GWorldObj_New(GWorldPtr);
134extern int GWorldObj_Convert(PyObject *, GWorldPtr *);
135
136/* Qt exports */
137extern PyObject *TrackObj_New(Track);
138extern int TrackObj_Convert(PyObject *, Track *);
139extern PyObject *MovieObj_New(Movie);
140extern int MovieObj_Convert(PyObject *, Movie *);
141extern PyObject *MovieCtlObj_New(MovieController);
142extern int MovieCtlObj_Convert(PyObject *, MovieController *);
143extern PyObject *TimeBaseObj_New(TimeBase);
144extern int TimeBaseObj_Convert(PyObject *, TimeBase *);
145extern PyObject *UserDataObj_New(UserData);
146extern int UserDataObj_Convert(PyObject *, UserData *);
147extern PyObject *MediaObj_New(Media);
148extern int MediaObj_Convert(PyObject *, Media *);
149
150/* Res exports */
151extern PyObject *ResObj_New(Handle);
152extern int ResObj_Convert(PyObject *, Handle *);
153extern PyObject *OptResObj_New(Handle);
154extern int OptResObj_Convert(PyObject *, Handle *);
155
156/* TE exports */
157extern PyObject *TEObj_New(TEHandle);
158extern int TEObj_Convert(PyObject *, TEHandle *);
159
160/* Win exports */
161extern PyObject *WinObj_New(WindowPtr);
162extern int WinObj_Convert(PyObject *, WindowPtr *);
163extern PyObject *WinObj_WhichWindow(WindowPtr);
164
165/* CF exports */
166extern PyObject *CFObj_New(CFTypeRef);
167extern int CFObj_Convert(PyObject *, CFTypeRef *);
168extern PyObject *CFTypeRefObj_New(CFTypeRef);
169extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
170extern PyObject *CFStringRefObj_New(CFStringRef);
171extern int CFStringRefObj_Convert(PyObject *, CFStringRef *);
172extern PyObject *CFMutableStringRefObj_New(CFMutableStringRef);
173extern int CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
174extern PyObject *CFArrayRefObj_New(CFArrayRef);
175extern int CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
176extern PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef);
177extern int CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
178extern PyObject *CFDictionaryRefObj_New(CFDictionaryRef);
179extern int CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
180extern PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
181extern int CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
182extern PyObject *CFURLRefObj_New(CFURLRef);
183extern int CFURLRefObj_Convert(PyObject *, CFURLRef *);
184extern int OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
185
186#ifdef __cplusplus
187 }
188#endif
189#endif
sys/src/cmd/python/Include/pymem.h+105−0
@@ -0,0 +1,105 @@
1/* The PyMem_ family: low-level memory allocation interfaces.
2 See objimpl.h for the PyObject_ memory family.
3*/
4
5#ifndef Py_PYMEM_H
6#define Py_PYMEM_H
7
8#include "pyport.h"
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/* BEWARE:
15
16 Each interface exports both functions and macros. Extension modules should
17 use the functions, to ensure binary compatibility across Python versions.
18 Because the Python implementation is free to change internal details, and
19 the macros may (or may not) expose details for speed, if you do use the
20 macros you must recompile your extensions with each Python release.
21
22 Never mix calls to PyMem_ with calls to the platform malloc/realloc/
23 calloc/free. For example, on Windows different DLLs may end up using
24 different heaps, and if you use PyMem_Malloc you'll get the memory from the
25 heap used by the Python DLL; it could be a disaster if you free()'ed that
26 directly in your own extension. Using PyMem_Free instead ensures Python
27 can return the memory to the proper heap. As another example, in
28 PYMALLOC_DEBUG mode, Python wraps all calls to all PyMem_ and PyObject_
29 memory functions in special debugging wrappers that add additional
30 debugging info to dynamic memory blocks. The system routines have no idea
31 what to do with that stuff, and the Python wrappers have no idea what to do
32 with raw blocks obtained directly by the system routines then.
33*/
34
35/*
36 * Raw memory interface
37 * ====================
38 */
39
40/* Functions
41
42 Functions supplying platform-independent semantics for malloc/realloc/
43 free. These functions make sure that allocating 0 bytes returns a distinct
44 non-NULL pointer (whenever possible -- if we're flat out of memory, NULL
45 may be returned), even if the platform malloc and realloc don't.
46 Returned pointers must be checked for NULL explicitly. No action is
47 performed on failure (no exception is set, no warning is printed, etc).
48*/
49
50PyAPI_FUNC(void *) PyMem_Malloc(size_t);
51PyAPI_FUNC(void *) PyMem_Realloc(void *, size_t);
52PyAPI_FUNC(void) PyMem_Free(void *);
53
54/* Starting from Python 1.6, the wrappers Py_{Malloc,Realloc,Free} are
55 no longer supported. They used to call PyErr_NoMemory() on failure. */
56
57/* Macros. */
58#ifdef PYMALLOC_DEBUG
59/* Redirect all memory operations to Python's debugging allocator. */
60#define PyMem_MALLOC PyObject_MALLOC
61#define PyMem_REALLOC PyObject_REALLOC
62#define PyMem_FREE PyObject_FREE
63
64#else /* ! PYMALLOC_DEBUG */
65
66/* PyMem_MALLOC(0) means malloc(1). Some systems would return NULL
67 for malloc(0), which would be treated as an error. Some platforms
68 would return a pointer with no memory behind it, which would break
69 pymalloc. To solve these problems, allocate an extra byte. */
70#define PyMem_MALLOC(n) malloc((n) ? (n) : 1)
71#define PyMem_REALLOC(p, n) realloc((p), (n) ? (n) : 1)
72#define PyMem_FREE free
73
74#endif /* PYMALLOC_DEBUG */
75
76/*
77 * Type-oriented memory interface
78 * ==============================
79 *
80 * These are carried along for historical reasons. There's rarely a good
81 * reason to use them anymore (you can just as easily do the multiply and
82 * cast yourself).
83 */
84
85#define PyMem_New(type, n) \
86 ( (type *) PyMem_Malloc((n) * sizeof(type)) )
87#define PyMem_NEW(type, n) \
88 ( (type *) PyMem_MALLOC((n) * sizeof(type)) )
89
90#define PyMem_Resize(p, type, n) \
91 ( (p) = (type *) PyMem_Realloc((p), (n) * sizeof(type)) )
92#define PyMem_RESIZE(p, type, n) \
93 ( (p) = (type *) PyMem_REALLOC((p), (n) * sizeof(type)) )
94
95/* PyMem{Del,DEL} are left over from ancient days, and shouldn't be used
96 * anymore. They're just confusing aliases for PyMem_{Free,FREE} now.
97 */
98#define PyMem_Del PyMem_Free
99#define PyMem_DEL PyMem_FREE
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif /* !Py_PYMEM_H */
sys/src/cmd/python/Include/pyport.h+771−0
@@ -0,0 +1,771 @@
1#ifndef Py_PYPORT_H
2#define Py_PYPORT_H
3
4#include "pyconfig.h" /* include for defines */
5
6#ifdef HAVE_STDINT_H
7#include <stdint.h>
8#endif
9
10/**************************************************************************
11Symbols and macros to supply platform-independent interfaces to basic
12C language & library operations whose spellings vary across platforms.
13
14Please try to make documentation here as clear as possible: by definition,
15the stuff here is trying to illuminate C's darkest corners.
16
17Config #defines referenced here:
18
19SIGNED_RIGHT_SHIFT_ZERO_FILLS
20Meaning: To be defined iff i>>j does not extend the sign bit when i is a
21 signed integral type and i < 0.
22Used in: Py_ARITHMETIC_RIGHT_SHIFT
23
24Py_DEBUG
25Meaning: Extra checks compiled in for debug mode.
26Used in: Py_SAFE_DOWNCAST
27
28HAVE_UINTPTR_T
29Meaning: The C9X type uintptr_t is supported by the compiler
30Used in: Py_uintptr_t
31
32HAVE_LONG_LONG
33Meaning: The compiler supports the C type "long long"
34Used in: PY_LONG_LONG
35
36**************************************************************************/
37
38
39/* For backward compatibility only. Obsolete, do not use. */
40#ifdef HAVE_PROTOTYPES
41#define Py_PROTO(x) x
42#else
43#define Py_PROTO(x) ()
44#endif
45#ifndef Py_FPROTO
46#define Py_FPROTO(x) Py_PROTO(x)
47#endif
48
49/* typedefs for some C9X-defined synonyms for integral types.
50 *
51 * The names in Python are exactly the same as the C9X names, except with a
52 * Py_ prefix. Until C9X is universally implemented, this is the only way
53 * to ensure that Python gets reliable names that don't conflict with names
54 * in non-Python code that are playing their own tricks to define the C9X
55 * names.
56 *
57 * NOTE: don't go nuts here! Python has no use for *most* of the C9X
58 * integral synonyms. Only define the ones we actually need.
59 */
60
61#ifdef HAVE_LONG_LONG
62#ifndef PY_LONG_LONG
63#define PY_LONG_LONG long long
64#endif
65#endif /* HAVE_LONG_LONG */
66
67/* uintptr_t is the C9X name for an unsigned integral type such that a
68 * legitimate void* can be cast to uintptr_t and then back to void* again
69 * without loss of information. Similarly for intptr_t, wrt a signed
70 * integral type.
71 */
72#ifdef HAVE_UINTPTR_T
73typedef uintptr_t Py_uintptr_t;
74typedef intptr_t Py_intptr_t;
75
76#elif SIZEOF_VOID_P <= SIZEOF_INT
77typedef unsigned int Py_uintptr_t;
78typedef int Py_intptr_t;
79
80#elif SIZEOF_VOID_P <= SIZEOF_LONG
81typedef unsigned long Py_uintptr_t;
82typedef long Py_intptr_t;
83
84#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
85typedef unsigned PY_LONG_LONG Py_uintptr_t;
86typedef PY_LONG_LONG Py_intptr_t;
87
88#else
89# error "Python needs a typedef for Py_uintptr_t in pyport.h."
90#endif /* HAVE_UINTPTR_T */
91
92/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
93 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
94 * unsigned integral type). See PEP 353 for details.
95 */
96#ifdef HAVE_SSIZE_T
97typedef ssize_t Py_ssize_t;
98#elif SIZEOF_VOID_P == SIZEOF_SIZE_T
99typedef Py_intptr_t Py_ssize_t;
100#else
101# error "Python needs a typedef for Py_ssize_t in pyport.h."
102#endif
103
104/* Largest positive value of type Py_ssize_t. */
105#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
106/* Smallest negative value of type Py_ssize_t. */
107#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
108
109/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
110 * format to convert an argument with the width of a size_t or Py_ssize_t.
111 * C99 introduced "z" for this purpose, but not all platforms support that;
112 * e.g., MS compilers use "I" instead.
113 *
114 * These "high level" Python format functions interpret "z" correctly on
115 * all platforms (Python interprets the format string itself, and does whatever
116 * the platform C requires to convert a size_t/Py_ssize_t argument):
117 *
118 * PyString_FromFormat
119 * PyErr_Format
120 * PyString_FromFormatV
121 *
122 * Lower-level uses require that you interpolate the correct format modifier
123 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
124 * example,
125 *
126 * Py_ssize_t index;
127 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
128 *
129 * That will expand to %ld, or %Id, or to something else correct for a
130 * Py_ssize_t on the platform.
131 */
132#ifndef PY_FORMAT_SIZE_T
133# if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
134# define PY_FORMAT_SIZE_T ""
135# elif SIZEOF_SIZE_T == SIZEOF_LONG
136# define PY_FORMAT_SIZE_T "l"
137# elif defined(MS_WINDOWS)
138# define PY_FORMAT_SIZE_T "I"
139# else
140# error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
141# endif
142#endif
143
144/* Py_LOCAL can be used instead of static to get the fastest possible calling
145 * convention for functions that are local to a given module.
146 *
147 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
148 * for platforms that support that.
149 *
150 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
151 * "aggressive" inlining/optimizaion is enabled for the entire module. This
152 * may lead to code bloat, and may slow things down for those reasons. It may
153 * also lead to errors, if the code relies on pointer aliasing. Use with
154 * care.
155 *
156 * NOTE: You can only use this for functions that are entirely local to a
157 * module; functions that are exported via method tables, callbacks, etc,
158 * should keep using static.
159 */
160
161#undef USE_INLINE /* XXX - set via configure? */
162
163#if defined(_MSC_VER)
164#if defined(PY_LOCAL_AGGRESSIVE)
165/* enable more aggressive optimization for visual studio */
166#pragma optimize("agtw", on)
167#endif
168/* ignore warnings if the compiler decides not to inline a function */
169#pragma warning(disable: 4710)
170/* fastest possible local call under MSVC */
171#define Py_LOCAL(type) static type __fastcall
172#define Py_LOCAL_INLINE(type) static __inline type __fastcall
173#elif defined(USE_INLINE)
174#define Py_LOCAL(type) static type
175#define Py_LOCAL_INLINE(type) static inline type
176#else
177#define Py_LOCAL(type) static type
178#define Py_LOCAL_INLINE(type) static type
179#endif
180
181/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
182 * are often very short. While most platforms have highly optimized code for
183 * large transfers, the setup costs for memcpy are often quite high. MEMCPY
184 * solves this by doing short copies "in line".
185 */
186
187#if defined(_MSC_VER)
188#define Py_MEMCPY(target, source, length) do { \
189 size_t i_, n_ = (length); \
190 char *t_ = (void*) (target); \
191 const char *s_ = (void*) (source); \
192 if (n_ >= 16) \
193 memcpy(t_, s_, n_); \
194 else \
195 for (i_ = 0; i_ < n_; i_++) \
196 t_[i_] = s_[i_]; \
197 } while (0)
198#else
199#define Py_MEMCPY memcpy
200#endif
201
202#include <stdlib.h>
203
204#include <math.h> /* Moved here from the math section, before extern "C" */
205
206/********************************************
207 * WRAPPER FOR <time.h> and/or <sys/time.h> *
208 ********************************************/
209
210#ifdef TIME_WITH_SYS_TIME
211#include <sys/time.h>
212#include <time.h>
213#else /* !TIME_WITH_SYS_TIME */
214#ifdef HAVE_SYS_TIME_H
215#include <sys/time.h>
216#else /* !HAVE_SYS_TIME_H */
217#include <time.h>
218#endif /* !HAVE_SYS_TIME_H */
219#endif /* !TIME_WITH_SYS_TIME */
220
221
222/******************************
223 * WRAPPER FOR <sys/select.h> *
224 ******************************/
225
226/* NB caller must include <sys/types.h> */
227
228#ifdef HAVE_SYS_SELECT_H
229
230#include <sys/select.h>
231
232#endif /* !HAVE_SYS_SELECT_H */
233
234/*******************************
235 * stat() and fstat() fiddling *
236 *******************************/
237
238/* We expect that stat and fstat exist on most systems.
239 * It's confirmed on Unix, Mac and Windows.
240 * If you don't have them, add
241 * #define DONT_HAVE_STAT
242 * and/or
243 * #define DONT_HAVE_FSTAT
244 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
245 * HAVE_FSTAT instead.
246 * Also
247 * #define HAVE_SYS_STAT_H
248 * if <sys/stat.h> exists on your platform, and
249 * #define HAVE_STAT_H
250 * if <stat.h> does.
251 */
252#ifndef DONT_HAVE_STAT
253#define HAVE_STAT
254#endif
255
256#ifndef DONT_HAVE_FSTAT
257#define HAVE_FSTAT
258#endif
259
260#ifdef RISCOS
261#include <sys/types.h>
262#include "unixstuff.h"
263#endif
264
265#ifdef HAVE_SYS_STAT_H
266#if defined(PYOS_OS2) && defined(PYCC_GCC)
267#include <sys/types.h>
268#endif
269#include <sys/stat.h>
270#elif defined(HAVE_STAT_H)
271#include <stat.h>
272#endif
273
274#if defined(PYCC_VACPP)
275/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
276#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
277#endif
278
279#ifndef S_ISREG
280#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
281#endif
282
283#ifndef S_ISDIR
284#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
285#endif
286
287
288#ifdef __cplusplus
289/* Move this down here since some C++ #include's don't like to be included
290 inside an extern "C" */
291extern "C" {
292#endif
293
294
295/* Py_ARITHMETIC_RIGHT_SHIFT
296 * C doesn't define whether a right-shift of a signed integer sign-extends
297 * or zero-fills. Here a macro to force sign extension:
298 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
299 * Return I >> J, forcing sign extension.
300 * Requirements:
301 * I is of basic signed type TYPE (char, short, int, long, or long long).
302 * TYPE is one of char, short, int, long, or long long, although long long
303 * must not be used except on platforms that support it.
304 * J is an integer >= 0 and strictly less than the number of bits in TYPE
305 * (because C doesn't define what happens for J outside that range either).
306 * Caution:
307 * I may be evaluated more than once.
308 */
309#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
310#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
311 ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J))
312#else
313#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
314#endif
315
316/* Py_FORCE_EXPANSION(X)
317 * "Simply" returns its argument. However, macro expansions within the
318 * argument are evaluated. This unfortunate trickery is needed to get
319 * token-pasting to work as desired in some cases.
320 */
321#define Py_FORCE_EXPANSION(X) X
322
323/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
324 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
325 * assert-fails if any information is lost.
326 * Caution:
327 * VALUE may be evaluated more than once.
328 */
329#ifdef Py_DEBUG
330#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
331 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
332#else
333#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
334#endif
335
336/* Py_IS_NAN(X)
337 * Return 1 if float or double arg is a NaN, else 0.
338 * Caution:
339 * X is evaluated more than once.
340 * This may not work on all platforms. Each platform has *some*
341 * way to spell this, though -- override in pyconfig.h if you have
342 * a platform where it doesn't work.
343 */
344#ifndef Py_IS_NAN
345#define Py_IS_NAN(X) ((X) != (X))
346#endif
347
348/* Py_IS_INFINITY(X)
349 * Return 1 if float or double arg is an infinity, else 0.
350 * Caution:
351 * X is evaluated more than once.
352 * This implementation may set the underflow flag if |X| is very small;
353 * it really can't be implemented correctly (& easily) before C99.
354 * Override in pyconfig.h if you have a better spelling on your platform.
355 */
356#ifndef Py_IS_INFINITY
357#define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X))
358#endif
359
360/* Py_IS_FINITE(X)
361 * Return 1 if float or double arg is neither infinite nor NAN, else 0.
362 * Some compilers (e.g. VisualStudio) have intrisics for this, so a special
363 * macro for this particular test is useful
364 */
365#ifndef Py_IS_FINITE
366#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
367#endif
368
369/* HUGE_VAL is supposed to expand to a positive double infinity. Python
370 * uses Py_HUGE_VAL instead because some platforms are broken in this
371 * respect. We used to embed code in pyport.h to try to worm around that,
372 * but different platforms are broken in conflicting ways. If you're on
373 * a platform where HUGE_VAL is defined incorrectly, fiddle your Python
374 * config to #define Py_HUGE_VAL to something that works on your platform.
375 */
376#ifndef Py_HUGE_VAL
377#define Py_HUGE_VAL HUGE_VAL
378#endif
379
380/* Py_OVERFLOWED(X)
381 * Return 1 iff a libm function overflowed. Set errno to 0 before calling
382 * a libm function, and invoke this macro after, passing the function
383 * result.
384 * Caution:
385 * This isn't reliable. C99 no longer requires libm to set errno under
386 * any exceptional condition, but does require +- HUGE_VAL return
387 * values on overflow. A 754 box *probably* maps HUGE_VAL to a
388 * double infinity, and we're cool if that's so, unless the input
389 * was an infinity and an infinity is the expected result. A C89
390 * system sets errno to ERANGE, so we check for that too. We're
391 * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or
392 * if the returned result is a NaN, or if a C89 box returns HUGE_VAL
393 * in non-overflow cases.
394 * X is evaluated more than once.
395 * Some platforms have better way to spell this, so expect some #ifdef'ery.
396 *
397 * OpenBSD uses 'isinf()' because a compiler bug on that platform causes
398 * the longer macro version to be mis-compiled. This isn't optimal, and
399 * should be removed once a newer compiler is available on that platform.
400 * The system that had the failure was running OpenBSD 3.2 on Intel, with
401 * gcc 2.95.3.
402 *
403 * According to Tim's checkin, the FreeBSD systems use isinf() to work
404 * around a FPE bug on that platform.
405 */
406#if defined(__FreeBSD__) || defined(__OpenBSD__)
407#define Py_OVERFLOWED(X) isinf(X)
408#else
409#define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \
410 (X) == Py_HUGE_VAL || \
411 (X) == -Py_HUGE_VAL))
412#endif
413
414/* Py_SET_ERRNO_ON_MATH_ERROR(x)
415 * If a libm function did not set errno, but it looks like the result
416 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
417 * to 0 before calling a libm function, and invoke this macro after,
418 * passing the function result.
419 * Caution:
420 * This isn't reliable. See Py_OVERFLOWED comments.
421 * X is evaluated more than once.
422 */
423#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
424#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
425#else
426#define _Py_SET_EDOM_FOR_NAN(X) ;
427#endif
428#define Py_SET_ERRNO_ON_MATH_ERROR(X) \
429 do { \
430 if (errno == 0) { \
431 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
432 errno = ERANGE; \
433 else _Py_SET_EDOM_FOR_NAN(X) \
434 } \
435 } while(0)
436
437/* Py_SET_ERANGE_ON_OVERFLOW(x)
438 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
439 */
440#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
441
442/* Py_ADJUST_ERANGE1(x)
443 * Py_ADJUST_ERANGE2(x, y)
444 * Set errno to 0 before calling a libm function, and invoke one of these
445 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
446 * for functions returning complex results). This makes two kinds of
447 * adjustments to errno: (A) If it looks like the platform libm set
448 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
449 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
450 * effect, we're trying to force a useful implementation of C89 errno
451 * behavior.
452 * Caution:
453 * This isn't reliable. See Py_OVERFLOWED comments.
454 * X and Y may be evaluated more than once.
455 */
456#define Py_ADJUST_ERANGE1(X) \
457 do { \
458 if (errno == 0) { \
459 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
460 errno = ERANGE; \
461 } \
462 else if (errno == ERANGE && (X) == 0.0) \
463 errno = 0; \
464 } while(0)
465
466#define Py_ADJUST_ERANGE2(X, Y) \
467 do { \
468 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
469 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
470 if (errno == 0) \
471 errno = ERANGE; \
472 } \
473 else if (errno == ERANGE) \
474 errno = 0; \
475 } while(0)
476
477/* Py_DEPRECATED(version)
478 * Declare a variable, type, or function deprecated.
479 * Usage:
480 * extern int old_var Py_DEPRECATED(2.3);
481 * typedef int T1 Py_DEPRECATED(2.4);
482 * extern int x() Py_DEPRECATED(2.5);
483 */
484#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
485 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
486#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
487#else
488#define Py_DEPRECATED(VERSION_UNUSED)
489#endif
490
491/**************************************************************************
492Prototypes that are missing from the standard include files on some systems
493(and possibly only some versions of such systems.)
494
495Please be conservative with adding new ones, document them and enclose them
496in platform-specific #ifdefs.
497**************************************************************************/
498
499#ifdef SOLARIS
500/* Unchecked */
501extern int gethostname(char *, int);
502#endif
503
504#ifdef __BEOS__
505/* Unchecked */
506/* It's in the libs, but not the headers... - [cjh] */
507int shutdown( int, int );
508#endif
509
510#ifdef HAVE__GETPTY
511#include <sys/types.h> /* we need to import mode_t */
512extern char * _getpty(int *, int, mode_t, int);
513#endif
514
515#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
516#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
517/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
518 functions, even though they are included in libutil. */
519#include <termios.h>
520extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
521extern int forkpty(int *, char *, struct termios *, struct winsize *);
522#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
523#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
524
525
526/* These are pulled from various places. It isn't obvious on what platforms
527 they are necessary, nor what the exact prototype should look like (which
528 is likely to vary between platforms!) If you find you need one of these
529 declarations, please move them to a platform-specific block and include
530 proper prototypes. */
531#if 0
532
533/* From Modules/resource.c */
534extern int getrusage();
535extern int getpagesize();
536
537/* From Python/sysmodule.c and Modules/posixmodule.c */
538extern int fclose(FILE *);
539
540/* From Modules/posixmodule.c */
541extern int fdatasync(int);
542#endif /* 0 */
543
544
545/************************
546 * WRAPPER FOR <math.h> *
547 ************************/
548
549#ifndef HAVE_HYPOT
550extern double hypot(double, double);
551#endif
552
553
554/* On 4.4BSD-descendants, ctype functions serves the whole range of
555 * wchar_t character set rather than single byte code points only.
556 * This characteristic can break some operations of string object
557 * including str.upper() and str.split() on UTF-8 locales. This
558 * workaround was provided by Tim Robbins of FreeBSD project.
559 */
560
561#ifdef __FreeBSD__
562#include <osreldate.h>
563#if __FreeBSD_version > 500039
564#include <ctype.h>
565#include <wctype.h>
566#undef isalnum
567#define isalnum(c) iswalnum(btowc(c))
568#undef isalpha
569#define isalpha(c) iswalpha(btowc(c))
570#undef islower
571#define islower(c) iswlower(btowc(c))
572#undef isspace
573#define isspace(c) iswspace(btowc(c))
574#undef isupper
575#define isupper(c) iswupper(btowc(c))
576#undef tolower
577#define tolower(c) towlower(btowc(c))
578#undef toupper
579#define toupper(c) towupper(btowc(c))
580#endif
581#endif
582
583
584/* Declarations for symbol visibility.
585
586 PyAPI_FUNC(type): Declares a public Python API function and return type
587 PyAPI_DATA(type): Declares public Python data and its type
588 PyMODINIT_FUNC: A Python module init function. If these functions are
589 inside the Python core, they are private to the core.
590 If in an extension module, it may be declared with
591 external linkage depending on the platform.
592
593 As a number of platforms support/require "__declspec(dllimport/dllexport)",
594 we support a HAVE_DECLSPEC_DLL macro to save duplication.
595*/
596
597/*
598 All windows ports, except cygwin, are handled in PC/pyconfig.h.
599
600 BeOS and cygwin are the only other autoconf platform requiring special
601 linkage handling and both of these use __declspec().
602*/
603#if defined(__CYGWIN__) || defined(__BEOS__)
604# define HAVE_DECLSPEC_DLL
605#endif
606
607/* only get special linkage if built as shared or platform is Cygwin */
608#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
609# if defined(HAVE_DECLSPEC_DLL)
610# ifdef Py_BUILD_CORE
611# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
612# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
613 /* module init functions inside the core need no external linkage */
614 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
615# if defined(__CYGWIN__)
616# define PyMODINIT_FUNC __declspec(dllexport) void
617# else /* __CYGWIN__ */
618# define PyMODINIT_FUNC void
619# endif /* __CYGWIN__ */
620# else /* Py_BUILD_CORE */
621 /* Building an extension module, or an embedded situation */
622 /* public Python functions and data are imported */
623 /* Under Cygwin, auto-import functions to prevent compilation */
624 /* failures similar to http://python.org/doc/FAQ.html#3.24 */
625# if !defined(__CYGWIN__)
626# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
627# endif /* !__CYGWIN__ */
628# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
629 /* module init functions outside the core must be exported */
630# if defined(__cplusplus)
631# define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
632# else /* __cplusplus */
633# define PyMODINIT_FUNC __declspec(dllexport) void
634# endif /* __cplusplus */
635# endif /* Py_BUILD_CORE */
636# endif /* HAVE_DECLSPEC */
637#endif /* Py_ENABLE_SHARED */
638
639/* If no external linkage macros defined by now, create defaults */
640#ifndef PyAPI_FUNC
641# define PyAPI_FUNC(RTYPE) RTYPE
642#endif
643#ifndef PyAPI_DATA
644# define PyAPI_DATA(RTYPE) extern RTYPE
645#endif
646#ifndef PyMODINIT_FUNC
647# if defined(__cplusplus)
648# define PyMODINIT_FUNC extern "C" void
649# else /* __cplusplus */
650# define PyMODINIT_FUNC void
651# endif /* __cplusplus */
652#endif
653
654/* Deprecated DL_IMPORT and DL_EXPORT macros */
655#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
656# if defined(Py_BUILD_CORE)
657# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
658# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
659# else
660# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
661# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
662# endif
663#endif
664#ifndef DL_EXPORT
665# define DL_EXPORT(RTYPE) RTYPE
666#endif
667#ifndef DL_IMPORT
668# define DL_IMPORT(RTYPE) RTYPE
669#endif
670/* End of deprecated DL_* macros */
671
672/* If the fd manipulation macros aren't defined,
673 here is a set that should do the job */
674
675#if 0 /* disabled and probably obsolete */
676
677#ifndef FD_SETSIZE
678#define FD_SETSIZE 256
679#endif
680
681#ifndef FD_SET
682
683typedef long fd_mask;
684
685#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
686#ifndef howmany
687#define howmany(x, y) (((x)+((y)-1))/(y))
688#endif /* howmany */
689
690typedef struct fd_set {
691 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
692} fd_set;
693
694#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
695#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
696#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
697#define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
698
699#endif /* FD_SET */
700
701#endif /* fd manipulation macros */
702
703
704/* limits.h constants that may be missing */
705
706#ifndef INT_MAX
707#define INT_MAX 2147483647
708#endif
709
710#ifndef LONG_MAX
711#if SIZEOF_LONG == 4
712#define LONG_MAX 0X7FFFFFFFL
713#elif SIZEOF_LONG == 8
714#define LONG_MAX 0X7FFFFFFFFFFFFFFFL
715#else
716#error "could not set LONG_MAX in pyport.h"
717#endif
718#endif
719
720#ifndef LONG_MIN
721#define LONG_MIN (-LONG_MAX-1)
722#endif
723
724#ifndef LONG_BIT
725#define LONG_BIT (8 * SIZEOF_LONG)
726#endif
727
728#if LONG_BIT != 8 * SIZEOF_LONG
729/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
730 * 32-bit platforms using gcc. We try to catch that here at compile-time
731 * rather than waiting for integer multiplication to trigger bogus
732 * overflows.
733 */
734#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
735#endif
736
737#ifdef __cplusplus
738}
739#endif
740
741/*
742 * Hide GCC attributes from compilers that don't support them.
743 */
744#if (!defined(__GNUC__) || __GNUC__ < 2 || \
745 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
746 !defined(RISCOS)
747#define Py_GCC_ATTRIBUTE(x)
748#else
749#define Py_GCC_ATTRIBUTE(x) __attribute__(x)
750#endif
751
752/* Eliminate end-of-loop code not reached warnings from SunPro C
753 * when using do{...}while(0) macros
754 */
755#ifdef __SUNPRO_C
756#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
757#endif
758
759/*
760 * Older Microsoft compilers don't support the C99 long long literal suffixes,
761 * so these will be defined in PC/pyconfig.h for those compilers.
762 */
763#ifndef Py_LL
764#define Py_LL(x) x##LL
765#endif
766
767#ifndef Py_ULL
768#define Py_ULL(x) Py_LL(x##U)
769#endif
770
771#endif /* Py_PYPORT_H */
sys/src/cmd/python/Include/pystate.h+195−0
@@ -0,0 +1,195 @@
1
2/* Thread and interpreter state structures and their interfaces */
3
4
5#ifndef Py_PYSTATE_H
6#define Py_PYSTATE_H
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11/* State shared between threads */
12
13struct _ts; /* Forward */
14struct _is; /* Forward */
15
16typedef struct _is {
17
18 struct _is *next;
19 struct _ts *tstate_head;
20
21 PyObject *modules;
22 PyObject *sysdict;
23 PyObject *builtins;
24 PyObject *modules_reloading;
25
26 PyObject *codec_search_path;
27 PyObject *codec_search_cache;
28 PyObject *codec_error_registry;
29
30#ifdef HAVE_DLOPEN
31 int dlopenflags;
32#endif
33#ifdef WITH_TSC
34 int tscdump;
35#endif
36
37} PyInterpreterState;
38
39
40/* State unique per thread */
41
42struct _frame; /* Avoid including frameobject.h */
43
44/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
45typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *);
46
47/* The following values are used for 'what' for tracefunc functions: */
48#define PyTrace_CALL 0
49#define PyTrace_EXCEPTION 1
50#define PyTrace_LINE 2
51#define PyTrace_RETURN 3
52#define PyTrace_C_CALL 4
53#define PyTrace_C_EXCEPTION 5
54#define PyTrace_C_RETURN 6
55
56typedef struct _ts {
57 /* See Python/ceval.c for comments explaining most fields */
58
59 struct _ts *next;
60 PyInterpreterState *interp;
61
62 struct _frame *frame;
63 int recursion_depth;
64 /* 'tracing' keeps track of the execution depth when tracing/profiling.
65 This is to prevent the actual trace/profile code from being recorded in
66 the trace/profile. */
67 int tracing;
68 int use_tracing;
69
70 Py_tracefunc c_profilefunc;
71 Py_tracefunc c_tracefunc;
72 PyObject *c_profileobj;
73 PyObject *c_traceobj;
74
75 PyObject *curexc_type;
76 PyObject *curexc_value;
77 PyObject *curexc_traceback;
78
79 PyObject *exc_type;
80 PyObject *exc_value;
81 PyObject *exc_traceback;
82
83 PyObject *dict; /* Stores per-thread state */
84
85 /* tick_counter is incremented whenever the check_interval ticker
86 * reaches zero. The purpose is to give a useful measure of the number
87 * of interpreted bytecode instructions in a given thread. This
88 * extremely lightweight statistic collector may be of interest to
89 * profilers (like psyco.jit()), although nothing in the core uses it.
90 */
91 int tick_counter;
92
93 int gilstate_counter;
94
95 PyObject *async_exc; /* Asynchronous exception to raise */
96 long thread_id; /* Thread id where this tstate was created */
97
98 /* XXX signal handlers should also be here */
99
100} PyThreadState;
101
102
103PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
104PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
105PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
106
107PyAPI_FUNC(PyThreadState *) PyThreadState_New(PyInterpreterState *);
108PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
109PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
110#ifdef WITH_THREAD
111PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
112#endif
113
114PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
115PyAPI_FUNC(PyThreadState *) PyThreadState_Swap(PyThreadState *);
116PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
117PyAPI_FUNC(int) PyThreadState_SetAsyncExc(long, PyObject *);
118
119
120/* Variable and macro for in-line access to current thread state */
121
122PyAPI_DATA(PyThreadState *) _PyThreadState_Current;
123
124#ifdef Py_DEBUG
125#define PyThreadState_GET() PyThreadState_Get()
126#else
127#define PyThreadState_GET() (_PyThreadState_Current)
128#endif
129
130typedef
131 enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
132 PyGILState_STATE;
133
134/* Ensure that the current thread is ready to call the Python
135 C API, regardless of the current state of Python, or of its
136 thread lock. This may be called as many times as desired
137 by a thread so long as each call is matched with a call to
138 PyGILState_Release(). In general, other thread-state APIs may
139 be used between _Ensure() and _Release() calls, so long as the
140 thread-state is restored to its previous state before the Release().
141 For example, normal use of the Py_BEGIN_ALLOW_THREADS/
142 Py_END_ALLOW_THREADS macros are acceptable.
143
144 The return value is an opaque "handle" to the thread state when
145 PyGILState_Ensure() was called, and must be passed to
146 PyGILState_Release() to ensure Python is left in the same state. Even
147 though recursive calls are allowed, these handles can *not* be shared -
148 each unique call to PyGILState_Ensure must save the handle for its
149 call to PyGILState_Release.
150
151 When the function returns, the current thread will hold the GIL.
152
153 Failure is a fatal error.
154*/
155PyAPI_FUNC(PyGILState_STATE) PyGILState_Ensure(void);
156
157/* Release any resources previously acquired. After this call, Python's
158 state will be the same as it was prior to the corresponding
159 PyGILState_Ensure() call (but generally this state will be unknown to
160 the caller, hence the use of the GILState API.)
161
162 Every call to PyGILState_Ensure must be matched by a call to
163 PyGILState_Release on the same thread.
164*/
165PyAPI_FUNC(void) PyGILState_Release(PyGILState_STATE);
166
167/* Helper/diagnostic function - get the current thread state for
168 this thread. May return NULL if no GILState API has been used
169 on the current thread. Note the main thread always has such a
170 thread-state, even if no auto-thread-state call has been made
171 on the main thread.
172*/
173PyAPI_FUNC(PyThreadState *) PyGILState_GetThisThreadState(void);
174
175/* The implementation of sys._current_frames() Returns a dict mapping
176 thread id to that thread's current frame.
177*/
178PyAPI_FUNC(PyObject *) _PyThread_CurrentFrames(void);
179
180/* Routines for advanced debuggers, requested by David Beazley.
181 Don't use unless you know what you are doing! */
182PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Head(void);
183PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_Next(PyInterpreterState *);
184PyAPI_FUNC(PyThreadState *) PyInterpreterState_ThreadHead(PyInterpreterState *);
185PyAPI_FUNC(PyThreadState *) PyThreadState_Next(PyThreadState *);
186
187typedef struct _frame *(*PyThreadFrameGetter)(PyThreadState *self_);
188
189/* hook for PyEval_GetFrame(), requested for Psyco */
190PyAPI_DATA(PyThreadFrameGetter) _PyThreadState_GetFrame;
191
192#ifdef __cplusplus
193}
194#endif
195#endif /* !Py_PYSTATE_H */
sys/src/cmd/python/Include/pystrtod.h+18−0
@@ -0,0 +1,18 @@
1#ifndef Py_STRTOD_H
2#define Py_STRTOD_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8
9PyAPI_FUNC(double) PyOS_ascii_strtod(const char *str, char **ptr);
10PyAPI_FUNC(double) PyOS_ascii_atof(const char *str);
11PyAPI_FUNC(char *) PyOS_ascii_formatd(char *buffer, size_t buf_len, const char *format, double d);
12
13
14#ifdef __cplusplus
15}
16#endif
17
18#endif /* !Py_STRTOD_H */
sys/src/cmd/python/Include/pythonrun.h+171−0
@@ -0,0 +1,171 @@
1
2/* Interfaces to parse and execute pieces of python code */
3
4#ifndef Py_PYTHONRUN_H
5#define Py_PYTHONRUN_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
11 CO_FUTURE_WITH_STATEMENT)
12#define PyCF_MASK_OBSOLETE (CO_NESTED)
13#define PyCF_SOURCE_IS_UTF8 0x0100
14#define PyCF_DONT_IMPLY_DEDENT 0x0200
15#define PyCF_ONLY_AST 0x0400
16
17typedef struct {
18 int cf_flags; /* bitmask of CO_xxx flags relevant to future */
19} PyCompilerFlags;
20
21PyAPI_FUNC(void) Py_SetProgramName(char *);
22PyAPI_FUNC(char *) Py_GetProgramName(void);
23
24PyAPI_FUNC(void) Py_SetPythonHome(char *);
25PyAPI_FUNC(char *) Py_GetPythonHome(void);
26
27PyAPI_FUNC(void) Py_Initialize(void);
28PyAPI_FUNC(void) Py_InitializeEx(int);
29PyAPI_FUNC(void) Py_Finalize(void);
30PyAPI_FUNC(int) Py_IsInitialized(void);
31PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
32PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
33
34PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
35PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
36PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
37PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
38PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
39PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
40
41PyAPI_FUNC(struct _mod *) PyParser_ASTFromString(const char *, const char *,
42 int, PyCompilerFlags *flags,
43 PyArena *);
44PyAPI_FUNC(struct _mod *) PyParser_ASTFromFile(FILE *, const char *, int,
45 char *, char *,
46 PyCompilerFlags *, int *,
47 PyArena *);
48#define PyParser_SimpleParseString(S, B) \
49 PyParser_SimpleParseStringFlags(S, B, 0)
50#define PyParser_SimpleParseFile(FP, S, B) \
51 PyParser_SimpleParseFileFlags(FP, S, B, 0)
52PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int,
53 int);
54PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
55 int, int);
56
57PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *,
58 PyObject *, PyCompilerFlags *);
59
60PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int,
61 PyObject *, PyObject *, int,
62 PyCompilerFlags *);
63
64#define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
65PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
66 PyCompilerFlags *);
67PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
68
69PyAPI_FUNC(void) PyErr_Print(void);
70PyAPI_FUNC(void) PyErr_PrintEx(int);
71PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
72
73PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
74
75PyAPI_FUNC(void) Py_Exit(int);
76
77PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
78
79/* Bootstrap */
80PyAPI_FUNC(int) Py_Main(int argc, char **argv);
81
82/* Use macros for a bunch of old variants */
83#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
84#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
85#define PyRun_AnyFileEx(fp, name, closeit) \
86 PyRun_AnyFileExFlags(fp, name, closeit, NULL)
87#define PyRun_AnyFileFlags(fp, name, flags) \
88 PyRun_AnyFileExFlags(fp, name, 0, flags)
89#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
90#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
91#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
92#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
93#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
94#define PyRun_File(fp, p, s, g, l) \
95 PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
96#define PyRun_FileEx(fp, p, s, g, l, c) \
97 PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
98#define PyRun_FileFlags(fp, p, s, g, l, flags) \
99 PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
100
101/* In getpath.c */
102PyAPI_FUNC(char *) Py_GetProgramFullPath(void);
103PyAPI_FUNC(char *) Py_GetPrefix(void);
104PyAPI_FUNC(char *) Py_GetExecPrefix(void);
105PyAPI_FUNC(char *) Py_GetPath(void);
106
107/* In their own files */
108PyAPI_FUNC(const char *) Py_GetVersion(void);
109PyAPI_FUNC(const char *) Py_GetPlatform(void);
110PyAPI_FUNC(const char *) Py_GetCopyright(void);
111PyAPI_FUNC(const char *) Py_GetCompiler(void);
112PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
113PyAPI_FUNC(const char *) _Py_svnversion(void);
114PyAPI_FUNC(const char *) Py_SubversionRevision(void);
115PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
116
117/* Internal -- various one-time initializations */
118PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
119PyAPI_FUNC(PyObject *) _PySys_Init(void);
120PyAPI_FUNC(void) _PyImport_Init(void);
121PyAPI_FUNC(void) _PyExc_Init(void);
122PyAPI_FUNC(void) _PyImportHooks_Init(void);
123PyAPI_FUNC(int) _PyFrame_Init(void);
124PyAPI_FUNC(int) _PyInt_Init(void);
125PyAPI_FUNC(void) _PyFloat_Init(void);
126
127/* Various internal finalizers */
128PyAPI_FUNC(void) _PyExc_Fini(void);
129PyAPI_FUNC(void) _PyImport_Fini(void);
130PyAPI_FUNC(void) PyMethod_Fini(void);
131PyAPI_FUNC(void) PyFrame_Fini(void);
132PyAPI_FUNC(void) PyCFunction_Fini(void);
133PyAPI_FUNC(void) PyTuple_Fini(void);
134PyAPI_FUNC(void) PyList_Fini(void);
135PyAPI_FUNC(void) PySet_Fini(void);
136PyAPI_FUNC(void) PyString_Fini(void);
137PyAPI_FUNC(void) PyInt_Fini(void);
138PyAPI_FUNC(void) PyFloat_Fini(void);
139PyAPI_FUNC(void) PyOS_FiniInterrupts(void);
140
141/* Stuff with no proper home (yet) */
142PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *);
143PyAPI_DATA(int) (*PyOS_InputHook)(void);
144PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *);
145PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
146
147/* Stack size, in "pointers" (so we get extra safety margins
148 on 64-bit platforms). On a 32-bit platform, this translates
149 to a 8k margin. */
150#define PYOS_STACK_MARGIN 2048
151
152#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER)
153/* Enable stack checking under Microsoft C */
154#define USE_STACKCHECK
155#endif
156
157#ifdef USE_STACKCHECK
158/* Check that we aren't overflowing our stack */
159PyAPI_FUNC(int) PyOS_CheckStack(void);
160#endif
161
162/* Signals */
163typedef void (*PyOS_sighandler_t)(int);
164PyAPI_FUNC(PyOS_sighandler_t) PyOS_getsig(int);
165PyAPI_FUNC(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
166
167
168#ifdef __cplusplus
169}
170#endif
171#endif /* !Py_PYTHONRUN_H */
sys/src/cmd/python/Include/pythread.h+47−0
@@ -0,0 +1,47 @@
1
2#ifndef Py_PYTHREAD_H
3#define Py_PYTHREAD_H
4
5#define NO_EXIT_PROG /* don't define PyThread_exit_prog() */
6 /* (the result is no use of signals on SGI) */
7
8typedef void *PyThread_type_lock;
9typedef void *PyThread_type_sema;
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15PyAPI_FUNC(void) PyThread_init_thread(void);
16PyAPI_FUNC(long) PyThread_start_new_thread(void (*)(void *), void *);
17PyAPI_FUNC(void) PyThread_exit_thread(void);
18PyAPI_FUNC(void) PyThread__PyThread_exit_thread(void);
19PyAPI_FUNC(long) PyThread_get_thread_ident(void);
20
21PyAPI_FUNC(PyThread_type_lock) PyThread_allocate_lock(void);
22PyAPI_FUNC(void) PyThread_free_lock(PyThread_type_lock);
23PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
24#define WAIT_LOCK 1
25#define NOWAIT_LOCK 0
26PyAPI_FUNC(void) PyThread_release_lock(PyThread_type_lock);
27
28PyAPI_FUNC(size_t) PyThread_get_stacksize(void);
29PyAPI_FUNC(int) PyThread_set_stacksize(size_t);
30
31#ifndef NO_EXIT_PROG
32PyAPI_FUNC(void) PyThread_exit_prog(int);
33PyAPI_FUNC(void) PyThread__PyThread_exit_prog(int);
34#endif
35
36/* Thread Local Storage (TLS) API */
37PyAPI_FUNC(int) PyThread_create_key(void);
38PyAPI_FUNC(void) PyThread_delete_key(int);
39PyAPI_FUNC(int) PyThread_set_key_value(int, void *);
40PyAPI_FUNC(void *) PyThread_get_key_value(int);
41PyAPI_FUNC(void) PyThread_delete_key_value(int key);
42
43#ifdef __cplusplus
44}
45#endif
46
47#endif /* !Py_PYTHREAD_H */
sys/src/cmd/python/Include/rangeobject.h+28−0
@@ -0,0 +1,28 @@
1
2/* Range object interface */
3
4#ifndef Py_RANGEOBJECT_H
5#define Py_RANGEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/* This is about the type 'xrange', not the built-in function range(), which
11 returns regular lists. */
12
13/*
14A range object represents an integer range. This is an immutable object;
15a range cannot change its value after creation.
16
17Range objects behave like the corresponding tuple objects except that
18they are represented by a start, stop, and step datamembers.
19*/
20
21PyAPI_DATA(PyTypeObject) PyRange_Type;
22
23#define PyRange_Check(op) ((op)->ob_type == &PyRange_Type)
24
25#ifdef __cplusplus
26}
27#endif
28#endif /* !Py_RANGEOBJECT_H */
sys/src/cmd/python/Include/setobject.h+93−0
@@ -0,0 +1,93 @@
1/* Set object interface */
2
3#ifndef Py_SETOBJECT_H
4#define Py_SETOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9
10/*
11There are three kinds of slots in the table:
12
131. Unused: key == NULL
142. Active: key != NULL and key != dummy
153. Dummy: key == dummy
16
17Note: .pop() abuses the hash field of an Unused or Dummy slot to
18hold a search finger. The hash field of Unused or Dummy slots has
19no meaning otherwise.
20*/
21
22#define PySet_MINSIZE 8
23
24typedef struct {
25 long hash; /* cached hash code for the entry key */
26 PyObject *key;
27} setentry;
28
29
30/*
31This data structure is shared by set and frozenset objects.
32*/
33
34typedef struct _setobject PySetObject;
35struct _setobject {
36 PyObject_HEAD
37
38 Py_ssize_t fill; /* # Active + # Dummy */
39 Py_ssize_t used; /* # Active */
40
41 /* The table contains mask + 1 slots, and that's a power of 2.
42 * We store the mask instead of the size because the mask is more
43 * frequently needed.
44 */
45 Py_ssize_t mask;
46
47 /* table points to smalltable for small tables, else to
48 * additional malloc'ed memory. table is never NULL! This rule
49 * saves repeated runtime null-tests.
50 */
51 setentry *table;
52 setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);
53 setentry smalltable[PySet_MINSIZE];
54
55 long hash; /* only used by frozenset objects */
56 PyObject *weakreflist; /* List of weak references */
57};
58
59PyAPI_DATA(PyTypeObject) PySet_Type;
60PyAPI_DATA(PyTypeObject) PyFrozenSet_Type;
61
62/* Invariants for frozensets:
63 * data is immutable.
64 * hash is the hash of the frozenset or -1 if not computed yet.
65 * Invariants for sets:
66 * hash is -1
67 */
68
69#define PyFrozenSet_CheckExact(ob) ((ob)->ob_type == &PyFrozenSet_Type)
70#define PyAnySet_CheckExact(ob) \
71 ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type)
72#define PyAnySet_Check(ob) \
73 ((ob)->ob_type == &PySet_Type || (ob)->ob_type == &PyFrozenSet_Type || \
74 PyType_IsSubtype((ob)->ob_type, &PySet_Type) || \
75 PyType_IsSubtype((ob)->ob_type, &PyFrozenSet_Type))
76
77PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
78PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);
79PyAPI_FUNC(Py_ssize_t) PySet_Size(PyObject *anyset);
80#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)
81PyAPI_FUNC(int) PySet_Clear(PyObject *set);
82PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
83PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
84PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key);
85PyAPI_FUNC(int) _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **key);
86PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash);
87PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
88PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
89
90#ifdef __cplusplus
91}
92#endif
93#endif /* !Py_SETOBJECT_H */
sys/src/cmd/python/Include/sliceobject.h+43−0
@@ -0,0 +1,43 @@
1#ifndef Py_SLICEOBJECT_H
2#define Py_SLICEOBJECT_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7/* The unique ellipsis object "..." */
8
9PyAPI_DATA(PyObject) _Py_EllipsisObject; /* Don't use this directly */
10
11#define Py_Ellipsis (&_Py_EllipsisObject)
12
13/* Slice object interface */
14
15/*
16
17A slice object containing start, stop, and step data members (the
18names are from range). After much talk with Guido, it was decided to
19let these be any arbitrary python type. Py_None stands for omitted values.
20*/
21
22typedef struct {
23 PyObject_HEAD
24 PyObject *start, *stop, *step; /* not NULL */
25} PySliceObject;
26
27PyAPI_DATA(PyTypeObject) PySlice_Type;
28
29#define PySlice_Check(op) ((op)->ob_type == &PySlice_Type)
30
31PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop,
32 PyObject* step);
33PyAPI_FUNC(PyObject *) _PySlice_FromIndices(Py_ssize_t start, Py_ssize_t stop);
34PyAPI_FUNC(int) PySlice_GetIndices(PySliceObject *r, Py_ssize_t length,
35 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step);
36PyAPI_FUNC(int) PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
37 Py_ssize_t *start, Py_ssize_t *stop,
38 Py_ssize_t *step, Py_ssize_t *slicelength);
39
40#ifdef __cplusplus
41}
42#endif
43#endif /* !Py_SLICEOBJECT_H */
sys/src/cmd/python/Include/stringobject.h+183−0
@@ -0,0 +1,183 @@
1
2/* String object interface */
3
4#ifndef Py_STRINGOBJECT_H
5#define Py_STRINGOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#include <stdarg.h>
11
12/*
13Type PyStringObject represents a character string. An extra zero byte is
14reserved at the end to ensure it is zero-terminated, but a size is
15present so strings with null bytes in them can be represented. This
16is an immutable object type.
17
18There are functions to create new string objects, to test
19an object for string-ness, and to get the
20string value. The latter function returns a null pointer
21if the object is not of the proper type.
22There is a variant that takes an explicit size as well as a
23variant that assumes a zero-terminated string. Note that none of the
24functions should be applied to nil objects.
25*/
26
27/* Caching the hash (ob_shash) saves recalculation of a string's hash value.
28 Interning strings (ob_sstate) tries to ensure that only one string
29 object with a given value exists, so equality tests can be one pointer
30 comparison. This is generally restricted to strings that "look like"
31 Python identifiers, although the intern() builtin can be used to force
32 interning of any string.
33 Together, these sped the interpreter by up to 20%. */
34
35typedef struct {
36 PyObject_VAR_HEAD
37 long ob_shash;
38 int ob_sstate;
39 char ob_sval[1];
40
41 /* Invariants:
42 * ob_sval contains space for 'ob_size+1' elements.
43 * ob_sval[ob_size] == 0.
44 * ob_shash is the hash of the string or -1 if not computed yet.
45 * ob_sstate != 0 iff the string object is in stringobject.c's
46 * 'interned' dictionary; in this case the two references
47 * from 'interned' to this object are *not counted* in ob_refcnt.
48 */
49} PyStringObject;
50
51#define SSTATE_NOT_INTERNED 0
52#define SSTATE_INTERNED_MORTAL 1
53#define SSTATE_INTERNED_IMMORTAL 2
54
55PyAPI_DATA(PyTypeObject) PyBaseString_Type;
56PyAPI_DATA(PyTypeObject) PyString_Type;
57
58#define PyString_Check(op) PyObject_TypeCheck(op, &PyString_Type)
59#define PyString_CheckExact(op) ((op)->ob_type == &PyString_Type)
60
61PyAPI_FUNC(PyObject *) PyString_FromStringAndSize(const char *, Py_ssize_t);
62PyAPI_FUNC(PyObject *) PyString_FromString(const char *);
63PyAPI_FUNC(PyObject *) PyString_FromFormatV(const char*, va_list)
64 Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
65PyAPI_FUNC(PyObject *) PyString_FromFormat(const char*, ...)
66 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
67PyAPI_FUNC(Py_ssize_t) PyString_Size(PyObject *);
68PyAPI_FUNC(char *) PyString_AsString(PyObject *);
69PyAPI_FUNC(PyObject *) PyString_Repr(PyObject *, int);
70PyAPI_FUNC(void) PyString_Concat(PyObject **, PyObject *);
71PyAPI_FUNC(void) PyString_ConcatAndDel(PyObject **, PyObject *);
72PyAPI_FUNC(int) _PyString_Resize(PyObject **, Py_ssize_t);
73PyAPI_FUNC(int) _PyString_Eq(PyObject *, PyObject*);
74PyAPI_FUNC(PyObject *) PyString_Format(PyObject *, PyObject *);
75PyAPI_FUNC(PyObject *) _PyString_FormatLong(PyObject*, int, int,
76 int, char**, int*);
77PyAPI_FUNC(PyObject *) PyString_DecodeEscape(const char *, Py_ssize_t,
78 const char *, Py_ssize_t,
79 const char *);
80
81PyAPI_FUNC(void) PyString_InternInPlace(PyObject **);
82PyAPI_FUNC(void) PyString_InternImmortal(PyObject **);
83PyAPI_FUNC(PyObject *) PyString_InternFromString(const char *);
84PyAPI_FUNC(void) _Py_ReleaseInternedStrings(void);
85
86/* Use only if you know it's a string */
87#define PyString_CHECK_INTERNED(op) (((PyStringObject *)(op))->ob_sstate)
88
89/* Macro, trading safety for speed */
90#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
91#define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size)
92
93/* _PyString_Join(sep, x) is like sep.join(x). sep must be PyStringObject*,
94 x must be an iterable object. */
95PyAPI_FUNC(PyObject *) _PyString_Join(PyObject *sep, PyObject *x);
96
97/* --- Generic Codecs ----------------------------------------------------- */
98
99/* Create an object by decoding the encoded string s of the
100 given size. */
101
102PyAPI_FUNC(PyObject*) PyString_Decode(
103 const char *s, /* encoded string */
104 Py_ssize_t size, /* size of buffer */
105 const char *encoding, /* encoding */
106 const char *errors /* error handling */
107 );
108
109/* Encodes a char buffer of the given size and returns a
110 Python object. */
111
112PyAPI_FUNC(PyObject*) PyString_Encode(
113 const char *s, /* string char buffer */
114 Py_ssize_t size, /* number of chars to encode */
115 const char *encoding, /* encoding */
116 const char *errors /* error handling */
117 );
118
119/* Encodes a string object and returns the result as Python
120 object. */
121
122PyAPI_FUNC(PyObject*) PyString_AsEncodedObject(
123 PyObject *str, /* string object */
124 const char *encoding, /* encoding */
125 const char *errors /* error handling */
126 );
127
128/* Encodes a string object and returns the result as Python string
129 object.
130
131 If the codec returns an Unicode object, the object is converted
132 back to a string using the default encoding.
133
134 DEPRECATED - use PyString_AsEncodedObject() instead. */
135
136PyAPI_FUNC(PyObject*) PyString_AsEncodedString(
137 PyObject *str, /* string object */
138 const char *encoding, /* encoding */
139 const char *errors /* error handling */
140 );
141
142/* Decodes a string object and returns the result as Python
143 object. */
144
145PyAPI_FUNC(PyObject*) PyString_AsDecodedObject(
146 PyObject *str, /* string object */
147 const char *encoding, /* encoding */
148 const char *errors /* error handling */
149 );
150
151/* Decodes a string object and returns the result as Python string
152 object.
153
154 If the codec returns an Unicode object, the object is converted
155 back to a string using the default encoding.
156
157 DEPRECATED - use PyString_AsDecodedObject() instead. */
158
159PyAPI_FUNC(PyObject*) PyString_AsDecodedString(
160 PyObject *str, /* string object */
161 const char *encoding, /* encoding */
162 const char *errors /* error handling */
163 );
164
165/* Provides access to the internal data buffer and size of a string
166 object or the default encoded version of an Unicode object. Passing
167 NULL as *len parameter will force the string buffer to be
168 0-terminated (passing a string with embedded NULL characters will
169 cause an exception). */
170
171PyAPI_FUNC(int) PyString_AsStringAndSize(
172 register PyObject *obj, /* string or Unicode object */
173 register char **s, /* pointer to buffer variable */
174 register Py_ssize_t *len /* pointer to length variable or NULL
175 (only possible for 0-terminated
176 strings) */
177 );
178
179
180#ifdef __cplusplus
181}
182#endif
183#endif /* !Py_STRINGOBJECT_H */
sys/src/cmd/python/Include/structmember.h+93−0
@@ -0,0 +1,93 @@
1#ifndef Py_STRUCTMEMBER_H
2#define Py_STRUCTMEMBER_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8/* Interface to map C struct members to Python object attributes */
9
10#include <stddef.h> /* For offsetof */
11
12/* The offsetof() macro calculates the offset of a structure member
13 in its structure. Unfortunately this cannot be written down
14 portably, hence it is provided by a Standard C header file.
15 For pre-Standard C compilers, here is a version that usually works
16 (but watch out!): */
17
18#ifndef offsetof
19#define offsetof(type, member) ( (int) & ((type*)0) -> member )
20#endif
21
22/* An array of memberlist structures defines the name, type and offset
23 of selected members of a C structure. These can be read by
24 PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
25 is set). The array must be terminated with an entry whose name
26 pointer is NULL. */
27
28struct memberlist {
29 /* Obsolete version, for binary backwards compatibility */
30 char *name;
31 int type;
32 int offset;
33 int flags;
34};
35
36typedef struct PyMemberDef {
37 /* Current version, use this */
38 char *name;
39 int type;
40 Py_ssize_t offset;
41 int flags;
42 char *doc;
43} PyMemberDef;
44
45/* Types */
46#define T_SHORT 0
47#define T_INT 1
48#define T_LONG 2
49#define T_FLOAT 3
50#define T_DOUBLE 4
51#define T_STRING 5
52#define T_OBJECT 6
53/* XXX the ordering here is weird for binary compatibility */
54#define T_CHAR 7 /* 1-character string */
55#define T_BYTE 8 /* 8-bit signed int */
56/* unsigned variants: */
57#define T_UBYTE 9
58#define T_USHORT 10
59#define T_UINT 11
60#define T_ULONG 12
61
62/* Added by Jack: strings contained in the structure */
63#define T_STRING_INPLACE 13
64
65#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
66 when the value is NULL, instead of
67 converting to None. */
68#ifdef HAVE_LONG_LONG
69#define T_LONGLONG 17
70#define T_ULONGLONG 18
71#endif /* HAVE_LONG_LONG */
72
73/* Flags */
74#define READONLY 1
75#define RO READONLY /* Shorthand */
76#define READ_RESTRICTED 2
77#define WRITE_RESTRICTED 4
78#define RESTRICTED (READ_RESTRICTED | WRITE_RESTRICTED)
79
80
81/* Obsolete API, for binary backwards compatibility */
82PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
83PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
84
85/* Current API, use this */
86PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
87PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
88
89
90#ifdef __cplusplus
91}
92#endif
93#endif /* !Py_STRUCTMEMBER_H */
sys/src/cmd/python/Include/structseq.h+41−0
@@ -0,0 +1,41 @@
1
2/* Tuple object interface */
3
4#ifndef Py_STRUCTSEQ_H
5#define Py_STRUCTSEQ_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct PyStructSequence_Field {
11 char *name;
12 char *doc;
13} PyStructSequence_Field;
14
15typedef struct PyStructSequence_Desc {
16 char *name;
17 char *doc;
18 struct PyStructSequence_Field *fields;
19 int n_in_sequence;
20} PyStructSequence_Desc;
21
22extern char* PyStructSequence_UnnamedField;
23
24PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type,
25 PyStructSequence_Desc *desc);
26
27PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type);
28
29typedef struct {
30 PyObject_VAR_HEAD
31 PyObject *ob_item[1];
32} PyStructSequence;
33
34/* Macro, *only* to be used to fill in brand new objects */
35#define PyStructSequence_SET_ITEM(op, i, v) \
36 (((PyStructSequence *)(op))->ob_item[i] = v)
37
38#ifdef __cplusplus
39}
40#endif
41#endif /* !Py_STRUCTSEQ_H */
sys/src/cmd/python/Include/symtable.h+103−0
@@ -0,0 +1,103 @@
1#ifndef Py_SYMTABLE_H
2#define Py_SYMTABLE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8typedef enum _block_type { FunctionBlock, ClassBlock, ModuleBlock }
9 _Py_block_ty;
10
11struct _symtable_entry;
12
13struct symtable {
14 const char *st_filename; /* name of file being compiled */
15 struct _symtable_entry *st_cur; /* current symbol table entry */
16 struct _symtable_entry *st_top; /* module entry */
17 PyObject *st_symbols; /* dictionary of symbol table entries */
18 PyObject *st_stack; /* stack of namespace info */
19 PyObject *st_global; /* borrowed ref to MODULE in st_symbols */
20 int st_nblocks; /* number of blocks */
21 PyObject *st_private; /* name of current class or NULL */
22 int st_tmpname; /* temporary name counter */
23 PyFutureFeatures *st_future; /* module's future features */
24};
25
26typedef struct _symtable_entry {
27 PyObject_HEAD
28 PyObject *ste_id; /* int: key in st_symbols */
29 PyObject *ste_symbols; /* dict: name to flags */
30 PyObject *ste_name; /* string: name of block */
31 PyObject *ste_varnames; /* list of variable names */
32 PyObject *ste_children; /* list of child ids */
33 _Py_block_ty ste_type; /* module, class, or function */
34 int ste_unoptimized; /* false if namespace is optimized */
35 unsigned ste_nested : 1; /* true if block is nested */
36 unsigned ste_free : 1; /* true if block has free variables */
37 unsigned ste_child_free : 1; /* true if a child block has free vars,
38 including free refs to globals */
39 unsigned ste_generator : 1; /* true if namespace is a generator */
40 unsigned ste_varargs : 1; /* true if block has varargs */
41 unsigned ste_varkeywords : 1; /* true if block has varkeywords */
42 unsigned ste_returns_value : 1; /* true if namespace uses return with
43 an argument */
44 int ste_lineno; /* first line of block */
45 int ste_opt_lineno; /* lineno of last exec or import * */
46 int ste_tmpname; /* counter for listcomp temp vars */
47 struct symtable *ste_table;
48} PySTEntryObject;
49
50PyAPI_DATA(PyTypeObject) PySTEntry_Type;
51
52#define PySTEntry_Check(op) ((op)->ob_type == &PySTEntry_Type)
53
54PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *);
55
56PyAPI_FUNC(struct symtable *) PySymtable_Build(mod_ty, const char *,
57 PyFutureFeatures *);
58PyAPI_FUNC(PySTEntryObject *) PySymtable_Lookup(struct symtable *, void *);
59
60PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
61
62/* Flags for def-use information */
63
64#define DEF_GLOBAL 1 /* global stmt */
65#define DEF_LOCAL 2 /* assignment in code block */
66#define DEF_PARAM 2<<1 /* formal parameter */
67#define USE 2<<2 /* name is used */
68#define DEF_STAR 2<<3 /* parameter is star arg */
69#define DEF_DOUBLESTAR 2<<4 /* parameter is star-star arg */
70#define DEF_INTUPLE 2<<5 /* name defined in tuple in parameters */
71#define DEF_FREE 2<<6 /* name used but not defined in nested block */
72#define DEF_FREE_GLOBAL 2<<7 /* free variable is actually implicit global */
73#define DEF_FREE_CLASS 2<<8 /* free variable from class's method */
74#define DEF_IMPORT 2<<9 /* assignment occurred via import */
75
76#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
77
78/* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
79 table. GLOBAL is returned from PyST_GetScope() for either of them.
80 It is stored in ste_symbols at bits 12-14.
81*/
82#define SCOPE_OFF 11
83#define SCOPE_MASK 7
84
85#define LOCAL 1
86#define GLOBAL_EXPLICIT 2
87#define GLOBAL_IMPLICIT 3
88#define FREE 4
89#define CELL 5
90
91/* The following three names are used for the ste_unoptimized bit field */
92#define OPT_IMPORT_STAR 1
93#define OPT_EXEC 2
94#define OPT_BARE_EXEC 4
95#define OPT_TOPLEVEL 8 /* top-level names, including eval and exec */
96
97#define GENERATOR 1
98#define GENERATOR_EXPRESSION 2
99
100#ifdef __cplusplus
101}
102#endif
103#endif /* !Py_SYMTABLE_H */
sys/src/cmd/python/Include/sysmodule.h+30−0
@@ -0,0 +1,30 @@
1
2/* System module interface */
3
4#ifndef Py_SYSMODULE_H
5#define Py_SYSMODULE_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10PyAPI_FUNC(PyObject *) PySys_GetObject(char *);
11PyAPI_FUNC(int) PySys_SetObject(char *, PyObject *);
12PyAPI_FUNC(FILE *) PySys_GetFile(char *, FILE *);
13PyAPI_FUNC(void) PySys_SetArgv(int, char **);
14PyAPI_FUNC(void) PySys_SetPath(char *);
15
16PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...)
17 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
18PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...)
19 Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
20
21PyAPI_DATA(PyObject *) _PySys_TraceFunc, *_PySys_ProfileFunc;
22PyAPI_DATA(int) _PySys_CheckInterval;
23
24PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
25PyAPI_FUNC(void) PySys_AddWarnOption(char *);
26
27#ifdef __cplusplus
28}
29#endif
30#endif /* !Py_SYSMODULE_H */
sys/src/cmd/python/Include/timefuncs.h+23−0
@@ -0,0 +1,23 @@
1/* timefuncs.h
2 */
3
4/* Utility function related to timemodule.c. */
5
6#ifndef TIMEFUNCS_H
7#define TIMEFUNCS_H
8#ifdef __cplusplus
9extern "C" {
10#endif
11
12
13/* Cast double x to time_t, but raise ValueError if x is too large
14 * to fit in a time_t. ValueError is set on return iff the return
15 * value is (time_t)-1 and PyErr_Occurred().
16 */
17PyAPI_FUNC(time_t) _PyTime_DoubleToTimet(double x);
18
19
20#ifdef __cplusplus
21}
22#endif
23#endif /* TIMEFUNCS_H */
sys/src/cmd/python/Include/token.h+83−0
@@ -0,0 +1,83 @@
1
2/* Token types */
3
4#ifndef Py_TOKEN_H
5#define Py_TOKEN_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10#define ENDMARKER 0
11#define NAME 1
12#define NUMBER 2
13#define STRING 3
14#define NEWLINE 4
15#define INDENT 5
16#define DEDENT 6
17#define LPAR 7
18#define RPAR 8
19#define LSQB 9
20#define RSQB 10
21#define COLON 11
22#define COMMA 12
23#define SEMI 13
24#define PLUS 14
25#define MINUS 15
26#define STAR 16
27#define SLASH 17
28#define VBAR 18
29#define AMPER 19
30#define LESS 20
31#define GREATER 21
32#define EQUAL 22
33#define DOT 23
34#define PERCENT 24
35#define BACKQUOTE 25
36#define LBRACE 26
37#define RBRACE 27
38#define EQEQUAL 28
39#define NOTEQUAL 29
40#define LESSEQUAL 30
41#define GREATEREQUAL 31
42#define TILDE 32
43#define CIRCUMFLEX 33
44#define LEFTSHIFT 34
45#define RIGHTSHIFT 35
46#define DOUBLESTAR 36
47#define PLUSEQUAL 37
48#define MINEQUAL 38
49#define STAREQUAL 39
50#define SLASHEQUAL 40
51#define PERCENTEQUAL 41
52#define AMPEREQUAL 42
53#define VBAREQUAL 43
54#define CIRCUMFLEXEQUAL 44
55#define LEFTSHIFTEQUAL 45
56#define RIGHTSHIFTEQUAL 46
57#define DOUBLESTAREQUAL 47
58#define DOUBLESLASH 48
59#define DOUBLESLASHEQUAL 49
60#define AT 50
61/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
62#define OP 51
63#define ERRORTOKEN 52
64#define N_TOKENS 53
65
66/* Special definitions for cooperation with parser */
67
68#define NT_OFFSET 256
69
70#define ISTERMINAL(x) ((x) < NT_OFFSET)
71#define ISNONTERMINAL(x) ((x) >= NT_OFFSET)
72#define ISEOF(x) ((x) == ENDMARKER)
73
74
75PyAPI_DATA(char *) _PyParser_TokenNames[]; /* Token names */
76PyAPI_FUNC(int) PyToken_OneChar(int);
77PyAPI_FUNC(int) PyToken_TwoChars(int, int);
78PyAPI_FUNC(int) PyToken_ThreeChars(int, int, int);
79
80#ifdef __cplusplus
81}
82#endif
83#endif /* !Py_TOKEN_H */
sys/src/cmd/python/Include/traceback.h+30−0
@@ -0,0 +1,30 @@
1
2#ifndef Py_TRACEBACK_H
3#define Py_TRACEBACK_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8struct _frame;
9
10/* Traceback interface */
11
12typedef struct _traceback {
13 PyObject_HEAD
14 struct _traceback *tb_next;
15 struct _frame *tb_frame;
16 int tb_lasti;
17 int tb_lineno;
18} PyTracebackObject;
19
20PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
21PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
22
23/* Reveal traceback type so we can typecheck traceback objects */
24PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
25#define PyTraceBack_Check(v) ((v)->ob_type == &PyTraceBack_Type)
26
27#ifdef __cplusplus
28}
29#endif
30#endif /* !Py_TRACEBACK_H */
sys/src/cmd/python/Include/tupleobject.h+57−0
@@ -0,0 +1,57 @@
1
2/* Tuple object interface */
3
4#ifndef Py_TUPLEOBJECT_H
5#define Py_TUPLEOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/*
11Another generally useful object type is a tuple of object pointers.
12For Python, this is an immutable type. C code can change the tuple items
13(but not their number), and even use tuples are general-purpose arrays of
14object references, but in general only brand new tuples should be mutated,
15not ones that might already have been exposed to Python code.
16
17*** WARNING *** PyTuple_SetItem does not increment the new item's reference
18count, but does decrement the reference count of the item it replaces,
19if not nil. It does *decrement* the reference count if it is *not*
20inserted in the tuple. Similarly, PyTuple_GetItem does not increment the
21returned item's reference count.
22*/
23
24typedef struct {
25 PyObject_VAR_HEAD
26 PyObject *ob_item[1];
27
28 /* ob_item contains space for 'ob_size' elements.
29 * Items must normally not be NULL, except during construction when
30 * the tuple is not yet visible outside the function that builds it.
31 */
32} PyTupleObject;
33
34PyAPI_DATA(PyTypeObject) PyTuple_Type;
35
36#define PyTuple_Check(op) PyObject_TypeCheck(op, &PyTuple_Type)
37#define PyTuple_CheckExact(op) ((op)->ob_type == &PyTuple_Type)
38
39PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size);
40PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *);
41PyAPI_FUNC(PyObject *) PyTuple_GetItem(PyObject *, Py_ssize_t);
42PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
43PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
44PyAPI_FUNC(int) _PyTuple_Resize(PyObject **, Py_ssize_t);
45PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);
46
47/* Macro, trading safety for speed */
48#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
49#define PyTuple_GET_SIZE(op) (((PyTupleObject *)(op))->ob_size)
50
51/* Macro, *only* to be used to fill in brand new tuples */
52#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
53
54#ifdef __cplusplus
55}
56#endif
57#endif /* !Py_TUPLEOBJECT_H */
sys/src/cmd/python/Include/ucnhash.h+31−0
@@ -0,0 +1,31 @@
1/* Unicode name database interface */
2
3#ifndef Py_UCNHASH_H
4#define Py_UCNHASH_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9/* revised ucnhash CAPI interface (exported through a PyCObject) */
10
11typedef struct {
12
13 /* Size of this struct */
14 int size;
15
16 /* Get name for a given character code. Returns non-zero if
17 success, zero if not. Does not set Python exceptions.
18 If self is NULL, data come from the default version of the database.
19 If it is not NULL, it should be a unicodedata.ucd_X_Y_Z object */
20 int (*getname)(PyObject *self, Py_UCS4 code, char* buffer, int buflen);
21
22 /* Get character code for a given name. Same error handling
23 as for getname. */
24 int (*getcode)(PyObject *self, const char* name, int namelen, Py_UCS4* code);
25
26} _PyUnicode_Name_CAPI;
27
28#ifdef __cplusplus
29}
30#endif
31#endif /* !Py_UCNHASH_H */
sys/src/cmd/python/Include/unicodeobject.h+1265−0
@@ -0,0 +1,1265 @@
1#ifndef Py_UNICODEOBJECT_H
2#define Py_UNICODEOBJECT_H
3
4/*
5
6Unicode implementation based on original code by Fredrik Lundh,
7modified by Marc-Andre Lemburg (mal@lemburg.com) according to the
8Unicode Integration Proposal (see file Misc/unicode.txt).
9
10Copyright (c) Corporation for National Research Initiatives.
11
12
13 Original header:
14 --------------------------------------------------------------------
15
16 * Yet another Unicode string type for Python. This type supports the
17 * 16-bit Basic Multilingual Plane (BMP) only.
18 *
19 * Written by Fredrik Lundh, January 1999.
20 *
21 * Copyright (c) 1999 by Secret Labs AB.
22 * Copyright (c) 1999 by Fredrik Lundh.
23 *
24 * fredrik@pythonware.com
25 * http://www.pythonware.com
26 *
27 * --------------------------------------------------------------------
28 * This Unicode String Type is
29 *
30 * Copyright (c) 1999 by Secret Labs AB
31 * Copyright (c) 1999 by Fredrik Lundh
32 *
33 * By obtaining, using, and/or copying this software and/or its
34 * associated documentation, you agree that you have read, understood,
35 * and will comply with the following terms and conditions:
36 *
37 * Permission to use, copy, modify, and distribute this software and its
38 * associated documentation for any purpose and without fee is hereby
39 * granted, provided that the above copyright notice appears in all
40 * copies, and that both that copyright notice and this permission notice
41 * appear in supporting documentation, and that the name of Secret Labs
42 * AB or the author not be used in advertising or publicity pertaining to
43 * distribution of the software without specific, written prior
44 * permission.
45 *
46 * SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO
47 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
48 * FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR
49 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
50 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
51 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
52 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
53 * -------------------------------------------------------------------- */
54
55#include <ctype.h>
56
57/* === Internal API ======================================================= */
58
59/* --- Internal Unicode Format -------------------------------------------- */
60
61#ifndef Py_USING_UNICODE
62
63#define PyUnicode_Check(op) 0
64#define PyUnicode_CheckExact(op) 0
65
66#else
67
68/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
69 properly set, but the default rules below doesn't set it. I'll
70 sort this out some other day -- fredrik@pythonware.com */
71
72#ifndef Py_UNICODE_SIZE
73#error Must define Py_UNICODE_SIZE
74#endif
75
76/* Setting Py_UNICODE_WIDE enables UCS-4 storage. Otherwise, Unicode
77 strings are stored as UCS-2 (with limited support for UTF-16) */
78
79#if Py_UNICODE_SIZE >= 4
80#define Py_UNICODE_WIDE
81#endif
82
83/* Set these flags if the platform has "wchar.h", "wctype.h" and the
84 wchar_t type is a 16-bit unsigned type */
85/* #define HAVE_WCHAR_H */
86/* #define HAVE_USABLE_WCHAR_T */
87
88/* Defaults for various platforms */
89#ifndef PY_UNICODE_TYPE
90
91/* Windows has a usable wchar_t type (unless we're using UCS-4) */
92# if defined(MS_WIN32) && Py_UNICODE_SIZE == 2
93# define HAVE_USABLE_WCHAR_T
94# define PY_UNICODE_TYPE wchar_t
95# endif
96
97# if defined(Py_UNICODE_WIDE)
98# define PY_UNICODE_TYPE Py_UCS4
99# endif
100
101#endif
102
103/* If the compiler provides a wchar_t type we try to support it
104 through the interface functions PyUnicode_FromWideChar() and
105 PyUnicode_AsWideChar(). */
106
107#ifdef HAVE_USABLE_WCHAR_T
108# ifndef HAVE_WCHAR_H
109# define HAVE_WCHAR_H
110# endif
111#endif
112
113#ifdef HAVE_WCHAR_H
114/* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */
115# ifdef _HAVE_BSDI
116# include <time.h>
117# endif
118# include <wchar.h>
119#endif
120
121/*
122 * Use this typedef when you need to represent a UTF-16 surrogate pair
123 * as single unsigned integer.
124 */
125#if SIZEOF_INT >= 4
126typedef unsigned int Py_UCS4;
127#elif SIZEOF_LONG >= 4
128typedef unsigned long Py_UCS4;
129#endif
130
131typedef PY_UNICODE_TYPE Py_UNICODE;
132
133/* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */
134
135/* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds
136 produce different external names and thus cause import errors in
137 case Python interpreters and extensions with mixed compiled in
138 Unicode width assumptions are combined. */
139
140#ifndef Py_UNICODE_WIDE
141
142# define PyUnicode_AsASCIIString PyUnicodeUCS2_AsASCIIString
143# define PyUnicode_AsCharmapString PyUnicodeUCS2_AsCharmapString
144# define PyUnicode_AsEncodedObject PyUnicodeUCS2_AsEncodedObject
145# define PyUnicode_AsEncodedString PyUnicodeUCS2_AsEncodedString
146# define PyUnicode_AsLatin1String PyUnicodeUCS2_AsLatin1String
147# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS2_AsRawUnicodeEscapeString
148# define PyUnicode_AsUTF16String PyUnicodeUCS2_AsUTF16String
149# define PyUnicode_AsUTF8String PyUnicodeUCS2_AsUTF8String
150# define PyUnicode_AsUnicode PyUnicodeUCS2_AsUnicode
151# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS2_AsUnicodeEscapeString
152# define PyUnicode_AsWideChar PyUnicodeUCS2_AsWideChar
153# define PyUnicode_Compare PyUnicodeUCS2_Compare
154# define PyUnicode_Concat PyUnicodeUCS2_Concat
155# define PyUnicode_Contains PyUnicodeUCS2_Contains
156# define PyUnicode_Count PyUnicodeUCS2_Count
157# define PyUnicode_Decode PyUnicodeUCS2_Decode
158# define PyUnicode_DecodeASCII PyUnicodeUCS2_DecodeASCII
159# define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap
160# define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1
161# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape
162# define PyUnicode_DecodeUTF16 PyUnicodeUCS2_DecodeUTF16
163# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS2_DecodeUTF16Stateful
164# define PyUnicode_DecodeUTF8 PyUnicodeUCS2_DecodeUTF8
165# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS2_DecodeUTF8Stateful
166# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS2_DecodeUnicodeEscape
167# define PyUnicode_Encode PyUnicodeUCS2_Encode
168# define PyUnicode_EncodeASCII PyUnicodeUCS2_EncodeASCII
169# define PyUnicode_EncodeCharmap PyUnicodeUCS2_EncodeCharmap
170# define PyUnicode_EncodeDecimal PyUnicodeUCS2_EncodeDecimal
171# define PyUnicode_EncodeLatin1 PyUnicodeUCS2_EncodeLatin1
172# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS2_EncodeRawUnicodeEscape
173# define PyUnicode_EncodeUTF16 PyUnicodeUCS2_EncodeUTF16
174# define PyUnicode_EncodeUTF8 PyUnicodeUCS2_EncodeUTF8
175# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS2_EncodeUnicodeEscape
176# define PyUnicode_Find PyUnicodeUCS2_Find
177# define PyUnicode_Format PyUnicodeUCS2_Format
178# define PyUnicode_FromEncodedObject PyUnicodeUCS2_FromEncodedObject
179# define PyUnicode_FromObject PyUnicodeUCS2_FromObject
180# define PyUnicode_FromOrdinal PyUnicodeUCS2_FromOrdinal
181# define PyUnicode_FromUnicode PyUnicodeUCS2_FromUnicode
182# define PyUnicode_FromWideChar PyUnicodeUCS2_FromWideChar
183# define PyUnicode_GetDefaultEncoding PyUnicodeUCS2_GetDefaultEncoding
184# define PyUnicode_GetMax PyUnicodeUCS2_GetMax
185# define PyUnicode_GetSize PyUnicodeUCS2_GetSize
186# define PyUnicode_Join PyUnicodeUCS2_Join
187# define PyUnicode_Partition PyUnicodeUCS2_Partition
188# define PyUnicode_RPartition PyUnicodeUCS2_RPartition
189# define PyUnicode_RSplit PyUnicodeUCS2_RSplit
190# define PyUnicode_Replace PyUnicodeUCS2_Replace
191# define PyUnicode_Resize PyUnicodeUCS2_Resize
192# define PyUnicode_RichCompare PyUnicodeUCS2_RichCompare
193# define PyUnicode_SetDefaultEncoding PyUnicodeUCS2_SetDefaultEncoding
194# define PyUnicode_Split PyUnicodeUCS2_Split
195# define PyUnicode_Splitlines PyUnicodeUCS2_Splitlines
196# define PyUnicode_Tailmatch PyUnicodeUCS2_Tailmatch
197# define PyUnicode_Translate PyUnicodeUCS2_Translate
198# define PyUnicode_TranslateCharmap PyUnicodeUCS2_TranslateCharmap
199# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS2_AsDefaultEncodedString
200# define _PyUnicode_Fini _PyUnicodeUCS2_Fini
201# define _PyUnicode_Init _PyUnicodeUCS2_Init
202# define _PyUnicode_IsAlpha _PyUnicodeUCS2_IsAlpha
203# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS2_IsDecimalDigit
204# define _PyUnicode_IsDigit _PyUnicodeUCS2_IsDigit
205# define _PyUnicode_IsLinebreak _PyUnicodeUCS2_IsLinebreak
206# define _PyUnicode_IsLowercase _PyUnicodeUCS2_IsLowercase
207# define _PyUnicode_IsNumeric _PyUnicodeUCS2_IsNumeric
208# define _PyUnicode_IsTitlecase _PyUnicodeUCS2_IsTitlecase
209# define _PyUnicode_IsUppercase _PyUnicodeUCS2_IsUppercase
210# define _PyUnicode_IsWhitespace _PyUnicodeUCS2_IsWhitespace
211# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS2_ToDecimalDigit
212# define _PyUnicode_ToDigit _PyUnicodeUCS2_ToDigit
213# define _PyUnicode_ToLowercase _PyUnicodeUCS2_ToLowercase
214# define _PyUnicode_ToNumeric _PyUnicodeUCS2_ToNumeric
215# define _PyUnicode_ToTitlecase _PyUnicodeUCS2_ToTitlecase
216# define _PyUnicode_ToUppercase _PyUnicodeUCS2_ToUppercase
217
218#else
219
220# define PyUnicode_AsASCIIString PyUnicodeUCS4_AsASCIIString
221# define PyUnicode_AsCharmapString PyUnicodeUCS4_AsCharmapString
222# define PyUnicode_AsEncodedObject PyUnicodeUCS4_AsEncodedObject
223# define PyUnicode_AsEncodedString PyUnicodeUCS4_AsEncodedString
224# define PyUnicode_AsLatin1String PyUnicodeUCS4_AsLatin1String
225# define PyUnicode_AsRawUnicodeEscapeString PyUnicodeUCS4_AsRawUnicodeEscapeString
226# define PyUnicode_AsUTF16String PyUnicodeUCS4_AsUTF16String
227# define PyUnicode_AsUTF8String PyUnicodeUCS4_AsUTF8String
228# define PyUnicode_AsUnicode PyUnicodeUCS4_AsUnicode
229# define PyUnicode_AsUnicodeEscapeString PyUnicodeUCS4_AsUnicodeEscapeString
230# define PyUnicode_AsWideChar PyUnicodeUCS4_AsWideChar
231# define PyUnicode_Compare PyUnicodeUCS4_Compare
232# define PyUnicode_Concat PyUnicodeUCS4_Concat
233# define PyUnicode_Contains PyUnicodeUCS4_Contains
234# define PyUnicode_Count PyUnicodeUCS4_Count
235# define PyUnicode_Decode PyUnicodeUCS4_Decode
236# define PyUnicode_DecodeASCII PyUnicodeUCS4_DecodeASCII
237# define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap
238# define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1
239# define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape
240# define PyUnicode_DecodeUTF16 PyUnicodeUCS4_DecodeUTF16
241# define PyUnicode_DecodeUTF16Stateful PyUnicodeUCS4_DecodeUTF16Stateful
242# define PyUnicode_DecodeUTF8 PyUnicodeUCS4_DecodeUTF8
243# define PyUnicode_DecodeUTF8Stateful PyUnicodeUCS4_DecodeUTF8Stateful
244# define PyUnicode_DecodeUnicodeEscape PyUnicodeUCS4_DecodeUnicodeEscape
245# define PyUnicode_Encode PyUnicodeUCS4_Encode
246# define PyUnicode_EncodeASCII PyUnicodeUCS4_EncodeASCII
247# define PyUnicode_EncodeCharmap PyUnicodeUCS4_EncodeCharmap
248# define PyUnicode_EncodeDecimal PyUnicodeUCS4_EncodeDecimal
249# define PyUnicode_EncodeLatin1 PyUnicodeUCS4_EncodeLatin1
250# define PyUnicode_EncodeRawUnicodeEscape PyUnicodeUCS4_EncodeRawUnicodeEscape
251# define PyUnicode_EncodeUTF16 PyUnicodeUCS4_EncodeUTF16
252# define PyUnicode_EncodeUTF8 PyUnicodeUCS4_EncodeUTF8
253# define PyUnicode_EncodeUnicodeEscape PyUnicodeUCS4_EncodeUnicodeEscape
254# define PyUnicode_Find PyUnicodeUCS4_Find
255# define PyUnicode_Format PyUnicodeUCS4_Format
256# define PyUnicode_FromEncodedObject PyUnicodeUCS4_FromEncodedObject
257# define PyUnicode_FromObject PyUnicodeUCS4_FromObject
258# define PyUnicode_FromOrdinal PyUnicodeUCS4_FromOrdinal
259# define PyUnicode_FromUnicode PyUnicodeUCS4_FromUnicode
260# define PyUnicode_FromWideChar PyUnicodeUCS4_FromWideChar
261# define PyUnicode_GetDefaultEncoding PyUnicodeUCS4_GetDefaultEncoding
262# define PyUnicode_GetMax PyUnicodeUCS4_GetMax
263# define PyUnicode_GetSize PyUnicodeUCS4_GetSize
264# define PyUnicode_Join PyUnicodeUCS4_Join
265# define PyUnicode_Partition PyUnicodeUCS4_Partition
266# define PyUnicode_RPartition PyUnicodeUCS4_RPartition
267# define PyUnicode_RSplit PyUnicodeUCS4_RSplit
268# define PyUnicode_Replace PyUnicodeUCS4_Replace
269# define PyUnicode_Resize PyUnicodeUCS4_Resize
270# define PyUnicode_RichCompare PyUnicodeUCS4_RichCompare
271# define PyUnicode_SetDefaultEncoding PyUnicodeUCS4_SetDefaultEncoding
272# define PyUnicode_Split PyUnicodeUCS4_Split
273# define PyUnicode_Splitlines PyUnicodeUCS4_Splitlines
274# define PyUnicode_Tailmatch PyUnicodeUCS4_Tailmatch
275# define PyUnicode_Translate PyUnicodeUCS4_Translate
276# define PyUnicode_TranslateCharmap PyUnicodeUCS4_TranslateCharmap
277# define _PyUnicode_AsDefaultEncodedString _PyUnicodeUCS4_AsDefaultEncodedString
278# define _PyUnicode_Fini _PyUnicodeUCS4_Fini
279# define _PyUnicode_Init _PyUnicodeUCS4_Init
280# define _PyUnicode_IsAlpha _PyUnicodeUCS4_IsAlpha
281# define _PyUnicode_IsDecimalDigit _PyUnicodeUCS4_IsDecimalDigit
282# define _PyUnicode_IsDigit _PyUnicodeUCS4_IsDigit
283# define _PyUnicode_IsLinebreak _PyUnicodeUCS4_IsLinebreak
284# define _PyUnicode_IsLowercase _PyUnicodeUCS4_IsLowercase
285# define _PyUnicode_IsNumeric _PyUnicodeUCS4_IsNumeric
286# define _PyUnicode_IsTitlecase _PyUnicodeUCS4_IsTitlecase
287# define _PyUnicode_IsUppercase _PyUnicodeUCS4_IsUppercase
288# define _PyUnicode_IsWhitespace _PyUnicodeUCS4_IsWhitespace
289# define _PyUnicode_ToDecimalDigit _PyUnicodeUCS4_ToDecimalDigit
290# define _PyUnicode_ToDigit _PyUnicodeUCS4_ToDigit
291# define _PyUnicode_ToLowercase _PyUnicodeUCS4_ToLowercase
292# define _PyUnicode_ToNumeric _PyUnicodeUCS4_ToNumeric
293# define _PyUnicode_ToTitlecase _PyUnicodeUCS4_ToTitlecase
294# define _PyUnicode_ToUppercase _PyUnicodeUCS4_ToUppercase
295
296
297#endif
298
299/* --- Internal Unicode Operations ---------------------------------------- */
300
301/* If you want Python to use the compiler's wctype.h functions instead
302 of the ones supplied with Python, define WANT_WCTYPE_FUNCTIONS or
303 configure Python using --with-wctype-functions. This reduces the
304 interpreter's code size. */
305
306#if defined(HAVE_USABLE_WCHAR_T) && defined(WANT_WCTYPE_FUNCTIONS)
307
308#include <wctype.h>
309
310#define Py_UNICODE_ISSPACE(ch) iswspace(ch)
311
312#define Py_UNICODE_ISLOWER(ch) iswlower(ch)
313#define Py_UNICODE_ISUPPER(ch) iswupper(ch)
314#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
315#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
316
317#define Py_UNICODE_TOLOWER(ch) towlower(ch)
318#define Py_UNICODE_TOUPPER(ch) towupper(ch)
319#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
320
321#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
322#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
323#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
324
325#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
326#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
327#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
328
329#define Py_UNICODE_ISALPHA(ch) iswalpha(ch)
330
331#else
332
333#define Py_UNICODE_ISSPACE(ch) _PyUnicode_IsWhitespace(ch)
334
335#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
336#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
337#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
338#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
339
340#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
341#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
342#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
343
344#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
345#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
346#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
347
348#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
349#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
350#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
351
352#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
353
354#endif
355
356#define Py_UNICODE_ISALNUM(ch) \
357 (Py_UNICODE_ISALPHA(ch) || \
358 Py_UNICODE_ISDECIMAL(ch) || \
359 Py_UNICODE_ISDIGIT(ch) || \
360 Py_UNICODE_ISNUMERIC(ch))
361
362#define Py_UNICODE_COPY(target, source, length) \
363 Py_MEMCPY((target), (source), (length)*sizeof(Py_UNICODE))
364
365#define Py_UNICODE_FILL(target, value, length) do\
366 {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
367 for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
368 } while (0)
369
370/* check if substring matches at given offset. the offset must be
371 valid, and the substring must not be empty */
372#define Py_UNICODE_MATCH(string, offset, substring) \
373 ((*((string)->str + (offset)) == *((substring)->str)) && \
374 ((*((string)->str + (offset) + (substring)->length-1) == *((substring)->str + (substring)->length-1))) && \
375 !memcmp((string)->str + (offset), (substring)->str, (substring)->length*sizeof(Py_UNICODE)))
376
377#ifdef __cplusplus
378extern "C" {
379#endif
380
381/* --- Unicode Type ------------------------------------------------------- */
382
383typedef struct {
384 PyObject_HEAD
385 Py_ssize_t length; /* Length of raw Unicode data in buffer */
386 Py_UNICODE *str; /* Raw Unicode buffer */
387 long hash; /* Hash value; -1 if not set */
388 PyObject *defenc; /* (Default) Encoded version as Python
389 string, or NULL; this is used for
390 implementing the buffer protocol */
391} PyUnicodeObject;
392
393PyAPI_DATA(PyTypeObject) PyUnicode_Type;
394
395#define PyUnicode_Check(op) PyObject_TypeCheck(op, &PyUnicode_Type)
396#define PyUnicode_CheckExact(op) ((op)->ob_type == &PyUnicode_Type)
397
398/* Fast access macros */
399#define PyUnicode_GET_SIZE(op) \
400 (((PyUnicodeObject *)(op))->length)
401#define PyUnicode_GET_DATA_SIZE(op) \
402 (((PyUnicodeObject *)(op))->length * sizeof(Py_UNICODE))
403#define PyUnicode_AS_UNICODE(op) \
404 (((PyUnicodeObject *)(op))->str)
405#define PyUnicode_AS_DATA(op) \
406 ((const char *)((PyUnicodeObject *)(op))->str)
407
408/* --- Constants ---------------------------------------------------------- */
409
410/* This Unicode character will be used as replacement character during
411 decoding if the errors argument is set to "replace". Note: the
412 Unicode character U+FFFD is the official REPLACEMENT CHARACTER in
413 Unicode 3.0. */
414
415#define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD)
416
417/* === Public API ========================================================= */
418
419/* --- Plain Py_UNICODE --------------------------------------------------- */
420
421/* Create a Unicode Object from the Py_UNICODE buffer u of the given
422 size.
423
424 u may be NULL which causes the contents to be undefined. It is the
425 user's responsibility to fill in the needed data afterwards. Note
426 that modifying the Unicode object contents after construction is
427 only allowed if u was set to NULL.
428
429 The buffer is copied into the new object. */
430
431PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
432 const Py_UNICODE *u, /* Unicode buffer */
433 Py_ssize_t size /* size of buffer */
434 );
435
436/* Return a read-only pointer to the Unicode object's internal
437 Py_UNICODE buffer. */
438
439PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
440 PyObject *unicode /* Unicode object */
441 );
442
443/* Get the length of the Unicode object. */
444
445PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(
446 PyObject *unicode /* Unicode object */
447 );
448
449/* Get the maximum ordinal for a Unicode character. */
450PyAPI_FUNC(Py_UNICODE) PyUnicode_GetMax(void);
451
452/* Resize an already allocated Unicode object to the new size length.
453
454 *unicode is modified to point to the new (resized) object and 0
455 returned on success.
456
457 This API may only be called by the function which also called the
458 Unicode constructor. The refcount on the object must be 1. Otherwise,
459 an error is returned.
460
461 Error handling is implemented as follows: an exception is set, -1
462 is returned and *unicode left untouched.
463
464*/
465
466PyAPI_FUNC(int) PyUnicode_Resize(
467 PyObject **unicode, /* Pointer to the Unicode object */
468 Py_ssize_t length /* New length */
469 );
470
471/* Coerce obj to an Unicode object and return a reference with
472 *incremented* refcount.
473
474 Coercion is done in the following way:
475
476 1. String and other char buffer compatible objects are decoded
477 under the assumptions that they contain data using the current
478 default encoding. Decoding is done in "strict" mode.
479
480 2. All other objects (including Unicode objects) raise an
481 exception.
482
483 The API returns NULL in case of an error. The caller is responsible
484 for decref'ing the returned objects.
485
486*/
487
488PyAPI_FUNC(PyObject*) PyUnicode_FromEncodedObject(
489 register PyObject *obj, /* Object */
490 const char *encoding, /* encoding */
491 const char *errors /* error handling */
492 );
493
494/* Coerce obj to an Unicode object and return a reference with
495 *incremented* refcount.
496
497 Unicode objects are passed back as-is (subclasses are converted to
498 true Unicode objects), all other objects are delegated to
499 PyUnicode_FromEncodedObject(obj, NULL, "strict") which results in
500 using the default encoding as basis for decoding the object.
501
502 The API returns NULL in case of an error. The caller is responsible
503 for decref'ing the returned objects.
504
505*/
506
507PyAPI_FUNC(PyObject*) PyUnicode_FromObject(
508 register PyObject *obj /* Object */
509 );
510
511/* --- wchar_t support for platforms which support it --------------------- */
512
513#ifdef HAVE_WCHAR_H
514
515/* Create a Unicode Object from the whcar_t buffer w of the given
516 size.
517
518 The buffer is copied into the new object. */
519
520PyAPI_FUNC(PyObject*) PyUnicode_FromWideChar(
521 register const wchar_t *w, /* wchar_t buffer */
522 Py_ssize_t size /* size of buffer */
523 );
524
525/* Copies the Unicode Object contents into the wchar_t buffer w. At
526 most size wchar_t characters are copied.
527
528 Note that the resulting wchar_t string may or may not be
529 0-terminated. It is the responsibility of the caller to make sure
530 that the wchar_t string is 0-terminated in case this is required by
531 the application.
532
533 Returns the number of wchar_t characters copied (excluding a
534 possibly trailing 0-termination character) or -1 in case of an
535 error. */
536
537PyAPI_FUNC(Py_ssize_t) PyUnicode_AsWideChar(
538 PyUnicodeObject *unicode, /* Unicode object */
539 register wchar_t *w, /* wchar_t buffer */
540 Py_ssize_t size /* size of buffer */
541 );
542
543#endif
544
545/* --- Unicode ordinals --------------------------------------------------- */
546
547/* Create a Unicode Object from the given Unicode code point ordinal.
548
549 The ordinal must be in range(0x10000) on narrow Python builds
550 (UCS2), and range(0x110000) on wide builds (UCS4). A ValueError is
551 raised in case it is not.
552
553*/
554
555PyAPI_FUNC(PyObject*) PyUnicode_FromOrdinal(int ordinal);
556
557/* === Builtin Codecs =====================================================
558
559 Many of these APIs take two arguments encoding and errors. These
560 parameters encoding and errors have the same semantics as the ones
561 of the builtin unicode() API.
562
563 Setting encoding to NULL causes the default encoding to be used.
564
565 Error handling is set by errors which may also be set to NULL
566 meaning to use the default handling defined for the codec. Default
567 error handling for all builtin codecs is "strict" (ValueErrors are
568 raised).
569
570 The codecs all use a similar interface. Only deviation from the
571 generic ones are documented.
572
573*/
574
575/* --- Manage the default encoding ---------------------------------------- */
576
577/* Return a Python string holding the default encoded value of the
578 Unicode object.
579
580 The resulting string is cached in the Unicode object for subsequent
581 usage by this function. The cached version is needed to implement
582 the character buffer interface and will live (at least) as long as
583 the Unicode object itself.
584
585 The refcount of the string is *not* incremented.
586
587 *** Exported for internal use by the interpreter only !!! ***
588
589*/
590
591PyAPI_FUNC(PyObject *) _PyUnicode_AsDefaultEncodedString(
592 PyObject *, const char *);
593
594/* Returns the currently active default encoding.
595
596 The default encoding is currently implemented as run-time settable
597 process global. This may change in future versions of the
598 interpreter to become a parameter which is managed on a per-thread
599 basis.
600
601 */
602
603PyAPI_FUNC(const char*) PyUnicode_GetDefaultEncoding(void);
604
605/* Sets the currently active default encoding.
606
607 Returns 0 on success, -1 in case of an error.
608
609 */
610
611PyAPI_FUNC(int) PyUnicode_SetDefaultEncoding(
612 const char *encoding /* Encoding name in standard form */
613 );
614
615/* --- Generic Codecs ----------------------------------------------------- */
616
617/* Create a Unicode object by decoding the encoded string s of the
618 given size. */
619
620PyAPI_FUNC(PyObject*) PyUnicode_Decode(
621 const char *s, /* encoded string */
622 Py_ssize_t size, /* size of buffer */
623 const char *encoding, /* encoding */
624 const char *errors /* error handling */
625 );
626
627/* Encodes a Py_UNICODE buffer of the given size and returns a
628 Python string object. */
629
630PyAPI_FUNC(PyObject*) PyUnicode_Encode(
631 const Py_UNICODE *s, /* Unicode char buffer */
632 Py_ssize_t size, /* number of Py_UNICODE chars to encode */
633 const char *encoding, /* encoding */
634 const char *errors /* error handling */
635 );
636
637/* Encodes a Unicode object and returns the result as Python
638 object. */
639
640PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject(
641 PyObject *unicode, /* Unicode object */
642 const char *encoding, /* encoding */
643 const char *errors /* error handling */
644 );
645
646/* Encodes a Unicode object and returns the result as Python string
647 object. */
648
649PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
650 PyObject *unicode, /* Unicode object */
651 const char *encoding, /* encoding */
652 const char *errors /* error handling */
653 );
654
655PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap(
656 PyObject* string /* 256 character map */
657 );
658
659
660/* --- UTF-7 Codecs ------------------------------------------------------- */
661
662PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF7(
663 const char *string, /* UTF-7 encoded string */
664 Py_ssize_t length, /* size of string */
665 const char *errors /* error handling */
666 );
667
668PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF7(
669 const Py_UNICODE *data, /* Unicode char buffer */
670 Py_ssize_t length, /* number of Py_UNICODE chars to encode */
671 int encodeSetO, /* force the encoder to encode characters in
672 Set O, as described in RFC2152 */
673 int encodeWhiteSpace, /* force the encoder to encode space, tab,
674 carriage return and linefeed characters */
675 const char *errors /* error handling */
676 );
677
678/* --- UTF-8 Codecs ------------------------------------------------------- */
679
680PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8(
681 const char *string, /* UTF-8 encoded string */
682 Py_ssize_t length, /* size of string */
683 const char *errors /* error handling */
684 );
685
686PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF8Stateful(
687 const char *string, /* UTF-8 encoded string */
688 Py_ssize_t length, /* size of string */
689 const char *errors, /* error handling */
690 Py_ssize_t *consumed /* bytes consumed */
691 );
692
693PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String(
694 PyObject *unicode /* Unicode object */
695 );
696
697PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF8(
698 const Py_UNICODE *data, /* Unicode char buffer */
699 Py_ssize_t length, /* number of Py_UNICODE chars to encode */
700 const char *errors /* error handling */
701 );
702
703/* --- UTF-16 Codecs ------------------------------------------------------ */
704
705/* Decodes length bytes from a UTF-16 encoded buffer string and returns
706 the corresponding Unicode object.
707
708 errors (if non-NULL) defines the error handling. It defaults
709 to "strict".
710
711 If byteorder is non-NULL, the decoder starts decoding using the
712 given byte order:
713
714 *byteorder == -1: little endian
715 *byteorder == 0: native order
716 *byteorder == 1: big endian
717
718 In native mode, the first two bytes of the stream are checked for a
719 BOM mark. If found, the BOM mark is analysed, the byte order
720 adjusted and the BOM skipped. In the other modes, no BOM mark
721 interpretation is done. After completion, *byteorder is set to the
722 current byte order at the end of input data.
723
724 If byteorder is NULL, the codec starts in native order mode.
725
726*/
727
728PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16(
729 const char *string, /* UTF-16 encoded string */
730 Py_ssize_t length, /* size of string */
731 const char *errors, /* error handling */
732 int *byteorder /* pointer to byteorder to use
733 0=native;-1=LE,1=BE; updated on
734 exit */
735 );
736
737PyAPI_FUNC(PyObject*) PyUnicode_DecodeUTF16Stateful(
738 const char *string, /* UTF-16 encoded string */
739 Py_ssize_t length, /* size of string */
740 const char *errors, /* error handling */
741 int *byteorder, /* pointer to byteorder to use
742 0=native;-1=LE,1=BE; updated on
743 exit */
744 Py_ssize_t *consumed /* bytes consumed */
745 );
746
747/* Returns a Python string using the UTF-16 encoding in native byte
748 order. The string always starts with a BOM mark. */
749
750PyAPI_FUNC(PyObject*) PyUnicode_AsUTF16String(
751 PyObject *unicode /* Unicode object */
752 );
753
754/* Returns a Python string object holding the UTF-16 encoded value of
755 the Unicode data.
756
757 If byteorder is not 0, output is written according to the following
758 byte order:
759
760 byteorder == -1: little endian
761 byteorder == 0: native byte order (writes a BOM mark)
762 byteorder == 1: big endian
763
764 If byteorder is 0, the output string will always start with the
765 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is
766 prepended.
767
768 Note that Py_UNICODE data is being interpreted as UTF-16 reduced to
769 UCS-2. This trick makes it possible to add full UTF-16 capabilities
770 at a later point without compromising the APIs.
771
772*/
773
774PyAPI_FUNC(PyObject*) PyUnicode_EncodeUTF16(
775 const Py_UNICODE *data, /* Unicode char buffer */
776 Py_ssize_t length, /* number of Py_UNICODE chars to encode */
777 const char *errors, /* error handling */
778 int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */
779 );
780
781/* --- Unicode-Escape Codecs ---------------------------------------------- */
782
783PyAPI_FUNC(PyObject*) PyUnicode_DecodeUnicodeEscape(
784 const char *string, /* Unicode-Escape encoded string */
785 Py_ssize_t length, /* size of string */
786 const char *errors /* error handling */
787 );
788
789PyAPI_FUNC(PyObject*) PyUnicode_AsUnicodeEscapeString(
790 PyObject *unicode /* Unicode object */
791 );
792
793PyAPI_FUNC(PyObject*) PyUnicode_EncodeUnicodeEscape(
794 const Py_UNICODE *data, /* Unicode char buffer */
795 Py_ssize_t length /* Number of Py_UNICODE chars to encode */
796 );
797
798/* --- Raw-Unicode-Escape Codecs ------------------------------------------ */
799
800PyAPI_FUNC(PyObject*) PyUnicode_DecodeRawUnicodeEscape(
801 const char *string, /* Raw-Unicode-Escape encoded string */
802 Py_ssize_t length, /* size of string */
803 const char *errors /* error handling */
804 );
805
806PyAPI_FUNC(PyObject*) PyUnicode_AsRawUnicodeEscapeString(
807 PyObject *unicode /* Unicode object */
808 );
809
810PyAPI_FUNC(PyObject*) PyUnicode_EncodeRawUnicodeEscape(
811 const Py_UNICODE *data, /* Unicode char buffer */
812 Py_ssize_t length /* Number of Py_UNICODE chars to encode */
813 );
814
815/* --- Unicode Internal Codec ---------------------------------------------
816
817 Only for internal use in _codecsmodule.c */
818
819PyObject *_PyUnicode_DecodeUnicodeInternal(
820 const char *string,
821 Py_ssize_t length,
822 const char *errors
823 );
824
825/* --- Latin-1 Codecs -----------------------------------------------------
826
827 Note: Latin-1 corresponds to the first 256 Unicode ordinals.
828
829*/
830
831PyAPI_FUNC(PyObject*) PyUnicode_DecodeLatin1(
832 const char *string, /* Latin-1 encoded string */
833 Py_ssize_t length, /* size of string */
834 const char *errors /* error handling */
835 );
836
837PyAPI_FUNC(PyObject*) PyUnicode_AsLatin1String(
838 PyObject *unicode /* Unicode object */
839 );
840
841PyAPI_FUNC(PyObject*) PyUnicode_EncodeLatin1(
842 const Py_UNICODE *data, /* Unicode char buffer */
843 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
844 const char *errors /* error handling */
845 );
846
847/* --- ASCII Codecs -------------------------------------------------------
848
849 Only 7-bit ASCII data is excepted. All other codes generate errors.
850
851*/
852
853PyAPI_FUNC(PyObject*) PyUnicode_DecodeASCII(
854 const char *string, /* ASCII encoded string */
855 Py_ssize_t length, /* size of string */
856 const char *errors /* error handling */
857 );
858
859PyAPI_FUNC(PyObject*) PyUnicode_AsASCIIString(
860 PyObject *unicode /* Unicode object */
861 );
862
863PyAPI_FUNC(PyObject*) PyUnicode_EncodeASCII(
864 const Py_UNICODE *data, /* Unicode char buffer */
865 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
866 const char *errors /* error handling */
867 );
868
869/* --- Character Map Codecs -----------------------------------------------
870
871 This codec uses mappings to encode and decode characters.
872
873 Decoding mappings must map single string characters to single
874 Unicode characters, integers (which are then interpreted as Unicode
875 ordinals) or None (meaning "undefined mapping" and causing an
876 error).
877
878 Encoding mappings must map single Unicode characters to single
879 string characters, integers (which are then interpreted as Latin-1
880 ordinals) or None (meaning "undefined mapping" and causing an
881 error).
882
883 If a character lookup fails with a LookupError, the character is
884 copied as-is meaning that its ordinal value will be interpreted as
885 Unicode or Latin-1 ordinal resp. Because of this mappings only need
886 to contain those mappings which map characters to different code
887 points.
888
889*/
890
891PyAPI_FUNC(PyObject*) PyUnicode_DecodeCharmap(
892 const char *string, /* Encoded string */
893 Py_ssize_t length, /* size of string */
894 PyObject *mapping, /* character mapping
895 (char ordinal -> unicode ordinal) */
896 const char *errors /* error handling */
897 );
898
899PyAPI_FUNC(PyObject*) PyUnicode_AsCharmapString(
900 PyObject *unicode, /* Unicode object */
901 PyObject *mapping /* character mapping
902 (unicode ordinal -> char ordinal) */
903 );
904
905PyAPI_FUNC(PyObject*) PyUnicode_EncodeCharmap(
906 const Py_UNICODE *data, /* Unicode char buffer */
907 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
908 PyObject *mapping, /* character mapping
909 (unicode ordinal -> char ordinal) */
910 const char *errors /* error handling */
911 );
912
913/* Translate a Py_UNICODE buffer of the given length by applying a
914 character mapping table to it and return the resulting Unicode
915 object.
916
917 The mapping table must map Unicode ordinal integers to Unicode
918 ordinal integers or None (causing deletion of the character).
919
920 Mapping tables may be dictionaries or sequences. Unmapped character
921 ordinals (ones which cause a LookupError) are left untouched and
922 are copied as-is.
923
924*/
925
926PyAPI_FUNC(PyObject *) PyUnicode_TranslateCharmap(
927 const Py_UNICODE *data, /* Unicode char buffer */
928 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
929 PyObject *table, /* Translate table */
930 const char *errors /* error handling */
931 );
932
933#ifdef MS_WIN32
934
935/* --- MBCS codecs for Windows -------------------------------------------- */
936
937PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCS(
938 const char *string, /* MBCS encoded string */
939 Py_ssize_t length, /* size of string */
940 const char *errors /* error handling */
941 );
942
943PyAPI_FUNC(PyObject*) PyUnicode_DecodeMBCSStateful(
944 const char *string, /* MBCS encoded string */
945 Py_ssize_t length, /* size of string */
946 const char *errors, /* error handling */
947 Py_ssize_t *consumed /* bytes consumed */
948 );
949
950PyAPI_FUNC(PyObject*) PyUnicode_AsMBCSString(
951 PyObject *unicode /* Unicode object */
952 );
953
954PyAPI_FUNC(PyObject*) PyUnicode_EncodeMBCS(
955 const Py_UNICODE *data, /* Unicode char buffer */
956 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
957 const char *errors /* error handling */
958 );
959
960#endif /* MS_WIN32 */
961
962/* --- Decimal Encoder ---------------------------------------------------- */
963
964/* Takes a Unicode string holding a decimal value and writes it into
965 an output buffer using standard ASCII digit codes.
966
967 The output buffer has to provide at least length+1 bytes of storage
968 area. The output string is 0-terminated.
969
970 The encoder converts whitespace to ' ', decimal characters to their
971 corresponding ASCII digit and all other Latin-1 characters except
972 \0 as-is. Characters outside this range (Unicode ordinals 1-256)
973 are treated as errors. This includes embedded NULL bytes.
974
975 Error handling is defined by the errors argument:
976
977 NULL or "strict": raise a ValueError
978 "ignore": ignore the wrong characters (these are not copied to the
979 output buffer)
980 "replace": replaces illegal characters with '?'
981
982 Returns 0 on success, -1 on failure.
983
984*/
985
986PyAPI_FUNC(int) PyUnicode_EncodeDecimal(
987 Py_UNICODE *s, /* Unicode buffer */
988 Py_ssize_t length, /* Number of Py_UNICODE chars to encode */
989 char *output, /* Output buffer; must have size >= length */
990 const char *errors /* error handling */
991 );
992
993/* --- Methods & Slots ----------------------------------------------------
994
995 These are capable of handling Unicode objects and strings on input
996 (we refer to them as strings in the descriptions) and return
997 Unicode objects or integers as apporpriate. */
998
999/* Concat two strings giving a new Unicode string. */
1000
1001PyAPI_FUNC(PyObject*) PyUnicode_Concat(
1002 PyObject *left, /* Left string */
1003 PyObject *right /* Right string */
1004 );
1005
1006/* Split a string giving a list of Unicode strings.
1007
1008 If sep is NULL, splitting will be done at all whitespace
1009 substrings. Otherwise, splits occur at the given separator.
1010
1011 At most maxsplit splits will be done. If negative, no limit is set.
1012
1013 Separators are not included in the resulting list.
1014
1015*/
1016
1017PyAPI_FUNC(PyObject*) PyUnicode_Split(
1018 PyObject *s, /* String to split */
1019 PyObject *sep, /* String separator */
1020 Py_ssize_t maxsplit /* Maxsplit count */
1021 );
1022
1023/* Dito, but split at line breaks.
1024
1025 CRLF is considered to be one line break. Line breaks are not
1026 included in the resulting list. */
1027
1028PyAPI_FUNC(PyObject*) PyUnicode_Splitlines(
1029 PyObject *s, /* String to split */
1030 int keepends /* If true, line end markers are included */
1031 );
1032
1033/* Partition a string using a given separator. */
1034
1035PyAPI_FUNC(PyObject*) PyUnicode_Partition(
1036 PyObject *s, /* String to partition */
1037 PyObject *sep /* String separator */
1038 );
1039
1040/* Partition a string using a given separator, searching from the end of the
1041 string. */
1042
1043PyAPI_FUNC(PyObject*) PyUnicode_RPartition(
1044 PyObject *s, /* String to partition */
1045 PyObject *sep /* String separator */
1046 );
1047
1048/* Split a string giving a list of Unicode strings.
1049
1050 If sep is NULL, splitting will be done at all whitespace
1051 substrings. Otherwise, splits occur at the given separator.
1052
1053 At most maxsplit splits will be done. But unlike PyUnicode_Split
1054 PyUnicode_RSplit splits from the end of the string. If negative,
1055 no limit is set.
1056
1057 Separators are not included in the resulting list.
1058
1059*/
1060
1061PyAPI_FUNC(PyObject*) PyUnicode_RSplit(
1062 PyObject *s, /* String to split */
1063 PyObject *sep, /* String separator */
1064 Py_ssize_t maxsplit /* Maxsplit count */
1065 );
1066
1067/* Translate a string by applying a character mapping table to it and
1068 return the resulting Unicode object.
1069
1070 The mapping table must map Unicode ordinal integers to Unicode
1071 ordinal integers or None (causing deletion of the character).
1072
1073 Mapping tables may be dictionaries or sequences. Unmapped character
1074 ordinals (ones which cause a LookupError) are left untouched and
1075 are copied as-is.
1076
1077*/
1078
1079PyAPI_FUNC(PyObject *) PyUnicode_Translate(
1080 PyObject *str, /* String */
1081 PyObject *table, /* Translate table */
1082 const char *errors /* error handling */
1083 );
1084
1085/* Join a sequence of strings using the given separator and return
1086 the resulting Unicode string. */
1087
1088PyAPI_FUNC(PyObject*) PyUnicode_Join(
1089 PyObject *separator, /* Separator string */
1090 PyObject *seq /* Sequence object */
1091 );
1092
1093/* Return 1 if substr matches str[start:end] at the given tail end, 0
1094 otherwise. */
1095
1096PyAPI_FUNC(Py_ssize_t) PyUnicode_Tailmatch(
1097 PyObject *str, /* String */
1098 PyObject *substr, /* Prefix or Suffix string */
1099 Py_ssize_t start, /* Start index */
1100 Py_ssize_t end, /* Stop index */
1101 int direction /* Tail end: -1 prefix, +1 suffix */
1102 );
1103
1104/* Return the first position of substr in str[start:end] using the
1105 given search direction or -1 if not found. -2 is returned in case
1106 an error occurred and an exception is set. */
1107
1108PyAPI_FUNC(Py_ssize_t) PyUnicode_Find(
1109 PyObject *str, /* String */
1110 PyObject *substr, /* Substring to find */
1111 Py_ssize_t start, /* Start index */
1112 Py_ssize_t end, /* Stop index */
1113 int direction /* Find direction: +1 forward, -1 backward */
1114 );
1115
1116/* Count the number of occurrences of substr in str[start:end]. */
1117
1118PyAPI_FUNC(Py_ssize_t) PyUnicode_Count(
1119 PyObject *str, /* String */
1120 PyObject *substr, /* Substring to count */
1121 Py_ssize_t start, /* Start index */
1122 Py_ssize_t end /* Stop index */
1123 );
1124
1125/* Replace at most maxcount occurrences of substr in str with replstr
1126 and return the resulting Unicode object. */
1127
1128PyAPI_FUNC(PyObject *) PyUnicode_Replace(
1129 PyObject *str, /* String */
1130 PyObject *substr, /* Substring to find */
1131 PyObject *replstr, /* Substring to replace */
1132 Py_ssize_t maxcount /* Max. number of replacements to apply;
1133 -1 = all */
1134 );
1135
1136/* Compare two strings and return -1, 0, 1 for less than, equal,
1137 greater than resp. */
1138
1139PyAPI_FUNC(int) PyUnicode_Compare(
1140 PyObject *left, /* Left string */
1141 PyObject *right /* Right string */
1142 );
1143
1144/* Rich compare two strings and return one of the following:
1145
1146 - NULL in case an exception was raised
1147 - Py_True or Py_False for successfuly comparisons
1148 - Py_NotImplemented in case the type combination is unknown
1149
1150 Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in
1151 case the conversion of the arguments to Unicode fails with a
1152 UnicodeDecodeError.
1153
1154 Possible values for op:
1155
1156 Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE
1157
1158*/
1159
1160PyAPI_FUNC(PyObject *) PyUnicode_RichCompare(
1161 PyObject *left, /* Left string */
1162 PyObject *right, /* Right string */
1163 int op /* Operation: Py_EQ, Py_NE, Py_GT, etc. */
1164 );
1165
1166/* Apply a argument tuple or dictionary to a format string and return
1167 the resulting Unicode string. */
1168
1169PyAPI_FUNC(PyObject *) PyUnicode_Format(
1170 PyObject *format, /* Format string */
1171 PyObject *args /* Argument tuple or dictionary */
1172 );
1173
1174/* Checks whether element is contained in container and return 1/0
1175 accordingly.
1176
1177 element has to coerce to an one element Unicode string. -1 is
1178 returned in case of an error. */
1179
1180PyAPI_FUNC(int) PyUnicode_Contains(
1181 PyObject *container, /* Container string */
1182 PyObject *element /* Element string */
1183 );
1184
1185/* Externally visible for str.strip(unicode) */
1186PyAPI_FUNC(PyObject *) _PyUnicode_XStrip(
1187 PyUnicodeObject *self,
1188 int striptype,
1189 PyObject *sepobj
1190 );
1191
1192/* === Characters Type APIs =============================================== */
1193
1194/* These should not be used directly. Use the Py_UNICODE_IS* and
1195 Py_UNICODE_TO* macros instead.
1196
1197 These APIs are implemented in Objects/unicodectype.c.
1198
1199*/
1200
1201PyAPI_FUNC(int) _PyUnicode_IsLowercase(
1202 Py_UNICODE ch /* Unicode character */
1203 );
1204
1205PyAPI_FUNC(int) _PyUnicode_IsUppercase(
1206 Py_UNICODE ch /* Unicode character */
1207 );
1208
1209PyAPI_FUNC(int) _PyUnicode_IsTitlecase(
1210 Py_UNICODE ch /* Unicode character */
1211 );
1212
1213PyAPI_FUNC(int) _PyUnicode_IsWhitespace(
1214 const Py_UNICODE ch /* Unicode character */
1215 );
1216
1217PyAPI_FUNC(int) _PyUnicode_IsLinebreak(
1218 const Py_UNICODE ch /* Unicode character */
1219 );
1220
1221PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToLowercase(
1222 Py_UNICODE ch /* Unicode character */
1223 );
1224
1225PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToUppercase(
1226 Py_UNICODE ch /* Unicode character */
1227 );
1228
1229PyAPI_FUNC(Py_UNICODE) _PyUnicode_ToTitlecase(
1230 Py_UNICODE ch /* Unicode character */
1231 );
1232
1233PyAPI_FUNC(int) _PyUnicode_ToDecimalDigit(
1234 Py_UNICODE ch /* Unicode character */
1235 );
1236
1237PyAPI_FUNC(int) _PyUnicode_ToDigit(
1238 Py_UNICODE ch /* Unicode character */
1239 );
1240
1241PyAPI_FUNC(double) _PyUnicode_ToNumeric(
1242 Py_UNICODE ch /* Unicode character */
1243 );
1244
1245PyAPI_FUNC(int) _PyUnicode_IsDecimalDigit(
1246 Py_UNICODE ch /* Unicode character */
1247 );
1248
1249PyAPI_FUNC(int) _PyUnicode_IsDigit(
1250 Py_UNICODE ch /* Unicode character */
1251 );
1252
1253PyAPI_FUNC(int) _PyUnicode_IsNumeric(
1254 Py_UNICODE ch /* Unicode character */
1255 );
1256
1257PyAPI_FUNC(int) _PyUnicode_IsAlpha(
1258 Py_UNICODE ch /* Unicode character */
1259 );
1260
1261#ifdef __cplusplus
1262}
1263#endif
1264#endif /* Py_USING_UNICODE */
1265#endif /* !Py_UNICODEOBJECT_H */
sys/src/cmd/python/Include/weakrefobject.h+75−0
@@ -0,0 +1,75 @@
1/* Weak references objects for Python. */
2
3#ifndef Py_WEAKREFOBJECT_H
4#define Py_WEAKREFOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9
10typedef struct _PyWeakReference PyWeakReference;
11
12/* PyWeakReference is the base struct for the Python ReferenceType, ProxyType,
13 * and CallableProxyType.
14 */
15struct _PyWeakReference {
16 PyObject_HEAD
17
18 /* The object to which this is a weak reference, or Py_None if none.
19 * Note that this is a stealth reference: wr_object's refcount is
20 * not incremented to reflect this pointer.
21 */
22 PyObject *wr_object;
23
24 /* A callable to invoke when wr_object dies, or NULL if none. */
25 PyObject *wr_callback;
26
27 /* A cache for wr_object's hash code. As usual for hashes, this is -1
28 * if the hash code isn't known yet.
29 */
30 long hash;
31
32 /* If wr_object is weakly referenced, wr_object has a doubly-linked NULL-
33 * terminated list of weak references to it. These are the list pointers.
34 * If wr_object goes away, wr_object is set to Py_None, and these pointers
35 * have no meaning then.
36 */
37 PyWeakReference *wr_prev;
38 PyWeakReference *wr_next;
39};
40
41PyAPI_DATA(PyTypeObject) _PyWeakref_RefType;
42PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType;
43PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType;
44
45#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType)
46#define PyWeakref_CheckRefExact(op) \
47 ((op)->ob_type == &_PyWeakref_RefType)
48#define PyWeakref_CheckProxy(op) \
49 (((op)->ob_type == &_PyWeakref_ProxyType) || \
50 ((op)->ob_type == &_PyWeakref_CallableProxyType))
51
52/* This macro calls PyWeakref_CheckRef() last since that can involve a
53 function call; this makes it more likely that the function call
54 will be avoided. */
55#define PyWeakref_Check(op) \
56 (PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op))
57
58
59PyAPI_FUNC(PyObject *) PyWeakref_NewRef(PyObject *ob,
60 PyObject *callback);
61PyAPI_FUNC(PyObject *) PyWeakref_NewProxy(PyObject *ob,
62 PyObject *callback);
63PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref);
64
65PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
66
67PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
68
69#define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object)
70
71
72#ifdef __cplusplus
73}
74#endif
75#endif /* !Py_WEAKREFOBJECT_H */