mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Expose the CO_xxx flags via the "new" module (re-solving a problem "the
right way"). Fiddle __future__.py to use them. Jeremy's pyassem.py may also want to use them (by-hand duplication of magic numbers is brittle), but leaving that to his judgment. Beef up __future__'s test to verify the exported feature names appear correct.
This commit is contained in:
parent
95618b5bc9
commit
aa32070f4d
3 changed files with 48 additions and 13 deletions
|
|
@ -220,9 +220,38 @@ char new_doc[] =
|
|||
\n\
|
||||
You need to know a great deal about the interpreter to use this!";
|
||||
|
||||
static void
|
||||
insertint(PyObject *d, char *name, int value)
|
||||
{
|
||||
PyObject *v = PyInt_FromLong((long) value);
|
||||
if (v == NULL) {
|
||||
/* Don't bother reporting this error */
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
PyDict_SetItemString(d, name, v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
}
|
||||
|
||||
DL_EXPORT(void)
|
||||
initnew(void)
|
||||
{
|
||||
Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
PyObject *m;
|
||||
PyObject *d;
|
||||
|
||||
m = Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
#define ADDSYM(TOKEN) insertint(d, #TOKEN, TOKEN)
|
||||
ADDSYM(CO_OPTIMIZED);
|
||||
ADDSYM(CO_NEWLOCALS);
|
||||
ADDSYM(CO_VARARGS);
|
||||
ADDSYM(CO_VARKEYWORDS);
|
||||
ADDSYM(CO_NESTED);
|
||||
ADDSYM(CO_GENERATOR);
|
||||
ADDSYM(CO_GENERATOR_ALLOWED);
|
||||
ADDSYM(CO_FUTURE_DIVISION);
|
||||
#undef ADDSYM
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue