comparison Python/pythonrun.c @ 66685:713c6b6ca5ce

Add an "optimize" parameter to compile() to control the optimization level, and provide an interface to it in py_compile, compileall and PyZipFile.
author Georg Brandl <georg@python.org>
date Sat, 04 Dec 2010 10:26:46 +0000
parents 62b61abd02b8
children b7be652daf6e
comparison
equal deleted inserted replaced
66684:893b098929e7 66685:713c6b6ca5ce
1791 Py_DECREF(co); 1791 Py_DECREF(co);
1792 return v; 1792 return v;
1793 } 1793 }
1794 1794
1795 PyObject * 1795 PyObject *
1796 Py_CompileStringFlags(const char *str, const char *filename, int start, 1796 Py_CompileStringExFlags(const char *str, const char *filename, int start,
1797 PyCompilerFlags *flags) 1797 PyCompilerFlags *flags, int optimize)
1798 { 1798 {
1799 PyCodeObject *co; 1799 PyCodeObject *co;
1800 mod_ty mod; 1800 mod_ty mod;
1801 PyArena *arena = PyArena_New(); 1801 PyArena *arena = PyArena_New();
1802 if (arena == NULL) 1802 if (arena == NULL)
1810 if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { 1810 if (flags && (flags->cf_flags & PyCF_ONLY_AST)) {
1811 PyObject *result = PyAST_mod2obj(mod); 1811 PyObject *result = PyAST_mod2obj(mod);
1812 PyArena_Free(arena); 1812 PyArena_Free(arena);
1813 return result; 1813 return result;
1814 } 1814 }
1815 co = PyAST_Compile(mod, filename, flags, arena); 1815 co = PyAST_CompileEx(mod, filename, flags, optimize, arena);
1816 PyArena_Free(arena); 1816 PyArena_Free(arena);
1817 return (PyObject *)co; 1817 return (PyObject *)co;
1818 } 1818 }
1819 1819
1820 /* For use in Py_LIMITED_API */ 1820 /* For use in Py_LIMITED_API */
2448 2448
2449 #undef Py_CompileString 2449 #undef Py_CompileString
2450 PyAPI_FUNC(PyObject *) 2450 PyAPI_FUNC(PyObject *)
2451 Py_CompileString(const char *str, const char *p, int s) 2451 Py_CompileString(const char *str, const char *p, int s)
2452 { 2452 {
2453 return Py_CompileStringFlags(str, p, s, NULL); 2453 return Py_CompileStringExFlags(str, p, s, NULL, -1);
2454 }
2455
2456 #undef Py_CompileStringFlags
2457 PyAPI_FUNC(PyObject *)
2458 Py_CompileStringFlags(const char *str, const char *p, int s,
2459 PyCompilerFlags *flags)
2460 {
2461 return Py_CompileStringExFlags(str, p, s, flags, -1);
2454 } 2462 }
2455 2463
2456 #undef PyRun_InteractiveOne 2464 #undef PyRun_InteractiveOne
2457 PyAPI_FUNC(int) 2465 PyAPI_FUNC(int)
2458 PyRun_InteractiveOne(FILE *f, const char *p) 2466 PyRun_InteractiveOne(FILE *f, const char *p)