cpython/Modules/symtablemodule.c
Benjamin Peterson 78565b2216 Merged revisions 73376,73393,73398,73400,73404-73405,73409,73419-73421,73432,73457,73460,73485-73486,73488-73489,73501-73502,73513-73514 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73376 | benjamin.peterson | 2009-06-11 17:29:23 -0500 (Thu, 11 Jun 2009) | 1 line

  remove check for case handled in sub-function
........
  r73393 | alexandre.vassalotti | 2009-06-12 13:56:57 -0500 (Fri, 12 Jun 2009) | 2 lines

  Clear reference to the static PyExc_RecursionErrorInst in _PyExc_Fini.
........
  r73398 | alexandre.vassalotti | 2009-06-12 15:57:12 -0500 (Fri, 12 Jun 2009) | 3 lines

  Add const qualifier to PyErr_SetFromErrnoWithFilename and to
  PyErr_SetFromErrnoWithUnicodeFilename.
........
  r73400 | alexandre.vassalotti | 2009-06-12 16:43:47 -0500 (Fri, 12 Jun 2009) | 2 lines

  Delete outdated make file for building the parser with MSVC 6.
........
  r73404 | benjamin.peterson | 2009-06-12 20:40:00 -0500 (Fri, 12 Jun 2009) | 1 line

  keep the slice.step field as NULL if no step expression is given
........
  r73405 | benjamin.peterson | 2009-06-12 22:46:30 -0500 (Fri, 12 Jun 2009) | 1 line

  prevent import statements from assigning to None
........
  r73409 | benjamin.peterson | 2009-06-13 08:06:21 -0500 (Sat, 13 Jun 2009) | 1 line

  allow importing from a module named None if it has an 'as' clause
........
  r73419 | benjamin.peterson | 2009-06-13 11:19:19 -0500 (Sat, 13 Jun 2009) | 1 line

  set Print.values to NULL if there are no values
........
  r73420 | benjamin.peterson | 2009-06-13 12:08:53 -0500 (Sat, 13 Jun 2009) | 1 line

  give a better error message when deleting ()
........
  r73421 | benjamin.peterson | 2009-06-13 15:23:33 -0500 (Sat, 13 Jun 2009) | 1 line

  when no module is given in a 'from' relative import, make ImportFrom.module NULL
........
  r73432 | amaury.forgeotdarc | 2009-06-14 16:20:40 -0500 (Sun, 14 Jun 2009) | 3 lines

  #6227: Because of a wrong indentation, the test was not testing what it should.
  Ensure that the snippet in doctest_aliases actually contains aliases.
........
  r73457 | benjamin.peterson | 2009-06-16 18:13:09 -0500 (Tue, 16 Jun 2009) | 1 line

  add underscores
........
  r73460 | benjamin.peterson | 2009-06-16 22:23:04 -0500 (Tue, 16 Jun 2009) | 1 line

  remove unused 'encoding' member from the compiler struct
........
  r73485 | benjamin.peterson | 2009-06-19 17:07:47 -0500 (Fri, 19 Jun 2009) | 1 line

  remove duplicate test
........
  r73486 | benjamin.peterson | 2009-06-19 17:09:17 -0500 (Fri, 19 Jun 2009) | 1 line

  add missing assertion #6313
........
  r73488 | benjamin.peterson | 2009-06-19 17:16:28 -0500 (Fri, 19 Jun 2009) | 1 line

  show that this one isn't used
........
  r73489 | benjamin.peterson | 2009-06-19 17:21:12 -0500 (Fri, 19 Jun 2009) | 1 line

  use closures
........
  r73501 | benjamin.peterson | 2009-06-21 18:01:07 -0500 (Sun, 21 Jun 2009) | 1 line

  don't need to add the name 'lambda' as assigned
........
  r73502 | benjamin.peterson | 2009-06-21 18:03:36 -0500 (Sun, 21 Jun 2009) | 1 line

  remove tmpname support since it's no longer used
........
  r73513 | benjamin.peterson | 2009-06-22 20:18:57 -0500 (Mon, 22 Jun 2009) | 1 line

  fix grammar
........
  r73514 | benjamin.peterson | 2009-06-22 22:01:56 -0500 (Mon, 22 Jun 2009) | 1 line

  remove some unused symtable constants
........
2009-06-28 19:19:51 +00:00

101 lines
2.5 KiB
C

#include "Python.h"
#include "code.h"
#include "compile.h"
#include "Python-ast.h"
#include "symtable.h"
static PyObject *
symtable_symtable(PyObject *self, PyObject *args)
{
struct symtable *st;
PyObject *t;
char *str;
char *filename;
char *startstr;
int start;
if (!PyArg_ParseTuple(args, "sss:symtable", &str, &filename,
&startstr))
return NULL;
if (strcmp(startstr, "exec") == 0)
start = Py_file_input;
else if (strcmp(startstr, "eval") == 0)
start = Py_eval_input;
else if (strcmp(startstr, "single") == 0)
start = Py_single_input;
else {
PyErr_SetString(PyExc_ValueError,
"symtable() arg 3 must be 'exec' or 'eval' or 'single'");
return NULL;
}
st = Py_SymtableString(str, filename, start);
if (st == NULL)
return NULL;
t = st->st_blocks;
Py_INCREF(t);
PyMem_Free((void *)st->st_future);
PySymtable_Free(st);
return t;
}
static PyMethodDef symtable_methods[] = {
{"symtable", symtable_symtable, METH_VARARGS,
PyDoc_STR("Return symbol and scope dictionaries"
" used internally by compiler.")},
{NULL, NULL} /* sentinel */
};
static struct PyModuleDef symtablemodule = {
PyModuleDef_HEAD_INIT,
"_symtable",
NULL,
-1,
symtable_methods,
NULL,
NULL,
NULL,
NULL
};
PyMODINIT_FUNC
PyInit__symtable(void)
{
PyObject *m;
m = PyModule_Create(&symtablemodule);
if (m == NULL)
return NULL;
PyModule_AddIntConstant(m, "USE", USE);
PyModule_AddIntConstant(m, "DEF_GLOBAL", DEF_GLOBAL);
PyModule_AddIntConstant(m, "DEF_LOCAL", DEF_LOCAL);
PyModule_AddIntConstant(m, "DEF_PARAM", DEF_PARAM);
PyModule_AddIntConstant(m, "DEF_FREE", DEF_FREE);
PyModule_AddIntConstant(m, "DEF_FREE_CLASS", DEF_FREE_CLASS);
PyModule_AddIntConstant(m, "DEF_IMPORT", DEF_IMPORT);
PyModule_AddIntConstant(m, "DEF_BOUND", DEF_BOUND);
PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock);
PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock);
PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock);
PyModule_AddIntConstant(m, "OPT_IMPORT_STAR", OPT_IMPORT_STAR);
PyModule_AddIntConstant(m, "OPT_TOPLEVEL", OPT_TOPLEVEL);
PyModule_AddIntConstant(m, "LOCAL", LOCAL);
PyModule_AddIntConstant(m, "GLOBAL_EXPLICIT", GLOBAL_EXPLICIT);
PyModule_AddIntConstant(m, "GLOBAL_IMPLICIT", GLOBAL_IMPLICIT);
PyModule_AddIntConstant(m, "FREE", FREE);
PyModule_AddIntConstant(m, "CELL", CELL);
PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFFSET);
PyModule_AddIntConstant(m, "SCOPE_MASK", SCOPE_MASK);
if (PyErr_Occurred()) {
Py_DECREF(m);
m = 0;
}
return m;
}