Mercurial > cpython-lru_cache-weakref
annotate Modules/symtablemodule.c @ 58973:db86bf39ccaa legacy-trunk
Issue 7970: When email.Parser.Parser parses a MIME message of type
message/rfc822 it turns it into an object whose body consists of
a list containing a single Message object. HeaderParser, on the
other hand, just copies the body as a string. Generator.flatten
has a special handler for the message mime type that expected the
body to be the one item list. This fails if the message was parsed
by HeaderParser. So we now check to see if the body is a string
first, and if so just we just emit it.
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Sun, 21 Feb 2010 04:23:00 +0000 |
| parents | 514fc9366f2d |
| children | fd25030223b0 |
| 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_FREE", DEF_FREE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 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
|
64 PyModule_AddIntConstant(m, "DEF_IMPORT", DEF_IMPORT); |
|
17159
10940561e891
add DEF_BOUND constant
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
65 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
|
66 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
67 PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
68 PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
30683
diff
changeset
|
69 PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock); |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
70 |
|
17551
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
71 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
|
72 PyModule_AddIntConstant(m, "OPT_EXEC", OPT_EXEC); |
|
cbc9f8865595
Export three optimization (fast locals) flags
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
17159
diff
changeset
|
73 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
|
74 |
|
16422
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
75 PyModule_AddIntConstant(m, "LOCAL", LOCAL); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
76 PyModule_AddIntConstant(m, "GLOBAL_EXPLICIT", GLOBAL_EXPLICIT); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
77 PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
78 PyModule_AddIntConstant(m, "FREE", FREE); |
|
8b318b8d78c9
Add minimal interface to symtable: _symtable module.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 PyModule_AddIntConstant(m, "CELL", CELL); |
|
48269
c36ccf2a71e1
get the symtable module back in working order
Benjamin Peterson <benjamin@python.org>
parents:
36324
diff
changeset
|
80 |
|
c36ccf2a71e1
get the symtable module back in working order
Benjamin Peterson <benjamin@python.org>
parents:
36324
diff
changeset
|
81 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
|
82 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
|
83 } |
