Mercurial > cpython-lru_cache-weakref
annotate Modules/symtablemodule.c @ 49955:878d40468c4e legacy-trunk
Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
| author | Vinay Sajip <vinay_sajip@yahoo.co.uk> |
|---|---|
| date | Wed, 03 Dec 2008 23:22:58 +0000 |
| parents | c36ccf2a71e1 |
| children | e38335d4df91 514fc9366f2d |
| rev | line source |
|---|---|
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1 #include "Python.h" |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
3 #include "code.h" |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
4 #include "compile.h" |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
5 #include "Python-ast.h" |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
6 #include "symtable.h" |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
7 |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
8 static PyObject * |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 symtable_symtable(PyObject *self, PyObject *args) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
10 { |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
11 struct symtable *st; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
12 PyObject *t; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 char *str; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 char *filename; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 char *startstr; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 int start; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
19 if (!PyArg_ParseTuple(args, "sss:symtable", &str, &filename, |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 &startstr)) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
21 return NULL; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
22 if (strcmp(startstr, "exec") == 0) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 start = Py_file_input; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
24 else if (strcmp(startstr, "eval") == 0) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
25 start = Py_eval_input; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
26 else if (strcmp(startstr, "single") == 0) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
27 start = Py_single_input; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
28 else { |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
29 PyErr_SetString(PyExc_ValueError, |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
30 "symtable() arg 3 must be 'exec' or 'eval' or 'single'"); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
31 return NULL; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
32 } |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 st = Py_SymtableString(str, filename, start); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 if (st == NULL) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
35 return NULL; |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
36 t = st->st_symbols; |
|
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
37 Py_INCREF(t); |
|
21253
d024a5c72cb5
Fix [ #489673 ] memory leak in test_symtable: Free the st_future slot.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17551
diff
changeset
|
38 PyMem_Free((void *)st->st_future); |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
39 PySymtable_Free(st); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
40 return t; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
41 } |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
42 |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
43 static PyMethodDef symtable_methods[] = { |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
44 {"symtable", symtable_symtable, METH_VARARGS, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
45 PyDoc_STR("Return symbol and scope dictionaries" |
|
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
46 " used internally by compiler.")}, |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
47 {NULL, NULL} /* sentinel */ |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
48 }; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
49 |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
21253
diff
changeset
|
50 PyMODINIT_FUNC |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
51 init_symtable(void) |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
52 { |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
53 PyObject *m; |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
54 |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
55 m = Py_InitModule("_symtable", symtable_methods); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
56 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35742
diff
changeset
|
57 return; |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
58 PyModule_AddIntConstant(m, "USE", USE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
59 PyModule_AddIntConstant(m, "DEF_GLOBAL", DEF_GLOBAL); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
60 PyModule_AddIntConstant(m, "DEF_LOCAL", DEF_LOCAL); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
61 PyModule_AddIntConstant(m, "DEF_PARAM", DEF_PARAM); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
62 PyModule_AddIntConstant(m, "DEF_STAR", DEF_STAR); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 PyModule_AddIntConstant(m, "DEF_DOUBLESTAR", DEF_DOUBLESTAR); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
64 PyModule_AddIntConstant(m, "DEF_INTUPLE", DEF_INTUPLE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
65 PyModule_AddIntConstant(m, "DEF_FREE", DEF_FREE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
66 PyModule_AddIntConstant(m, "DEF_FREE_GLOBAL", DEF_FREE_GLOBAL); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
67 PyModule_AddIntConstant(m, "DEF_FREE_CLASS", DEF_FREE_CLASS); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
68 PyModule_AddIntConstant(m, "DEF_IMPORT", DEF_IMPORT); |
|
17159
10940561e891
add DEF_BOUND constant
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
69 PyModule_AddIntConstant(m, "DEF_BOUND", DEF_BOUND); |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
70 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
71 PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
72 PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
73 PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock); |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
74 |
|
17551
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
75 PyModule_AddIntConstant(m, "OPT_IMPORT_STAR", OPT_IMPORT_STAR); |
|
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
76 PyModule_AddIntConstant(m, "OPT_EXEC", OPT_EXEC); |
|
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
77 PyModule_AddIntConstant(m, "OPT_BARE_EXEC", OPT_BARE_EXEC); |
|
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
78 |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 PyModule_AddIntConstant(m, "LOCAL", LOCAL); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
80 PyModule_AddIntConstant(m, "GLOBAL_EXPLICIT", GLOBAL_EXPLICIT); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
81 PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
82 PyModule_AddIntConstant(m, "FREE", FREE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
83 PyModule_AddIntConstant(m, "CELL", CELL); |
|
48269
c36ccf2a71e1
get the symtable module back in working order
Benjamin Peterson <benjamin@python.org>
parents:
36324
diff
changeset
|
84 |
|
c36ccf2a71e1
get the symtable module back in working order
Benjamin Peterson <benjamin@python.org>
parents:
36324
diff
changeset
|
85 PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFF); |
|
c36ccf2a71e1
get the symtable module back in working order
Benjamin Peterson <benjamin@python.org>
parents:
36324
diff
changeset
|
86 PyModule_AddIntConstant(m, "SCOPE_MASK", SCOPE_MASK); |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
87 } |
