summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-ast.c4
-rw-r--r--Python/ast.c1
-rw-r--r--Python/bltinmodule.c7
-rw-r--r--Python/ceval.c20
-rw-r--r--Python/compile.c2
-rw-r--r--Python/dtoa.c4
-rw-r--r--Python/dynload_aix.c2
-rw-r--r--Python/dynload_dl.c16
-rw-r--r--Python/dynload_hpux.c2
-rw-r--r--Python/dynload_next.c4
-rw-r--r--Python/dynload_os2.c2
-rw-r--r--Python/dynload_shlib.c2
-rw-r--r--Python/dynload_win.c2
-rw-r--r--Python/getargs.c7
-rw-r--r--Python/import.c97
-rw-r--r--Python/importdl.c5
-rw-r--r--Python/peephole.c167
-rw-r--r--Python/pystrtod.c2
-rw-r--r--Python/sysmodule.c97
19 files changed, 222 insertions, 221 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index 2c09f96..6b1ea3c 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -2,7 +2,7 @@
/*
- __version__ 82163.
+ __version__ 0daa6ba25d9b.
This module must be committed separately after each AST grammar change;
The __version__ number is set to the revision number of the commit
@@ -6739,7 +6739,7 @@ PyInit__ast(void)
NULL;
if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
return NULL;
- if (PyModule_AddStringConstant(m, "__version__", "82163") < 0)
+ if (PyModule_AddStringConstant(m, "__version__", "0daa6ba25d9b") < 0)
return NULL;
if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return
NULL;
diff --git a/Python/ast.c b/Python/ast.c
index 4edf335..e62a215 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -3231,7 +3231,6 @@ decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, cons
const char *end;
if (encoding == NULL) {
- buf = (char *)s;
u = NULL;
} else {
/* check for integer overflow */
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 2aea9f7..ca40cb0 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -37,7 +37,7 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *cell;
PyObject *cls = NULL;
- Py_ssize_t nargs, nbases;
+ Py_ssize_t nargs;
assert(args != NULL);
if (!PyTuple_Check(args)) {
@@ -61,7 +61,6 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
bases = PyTuple_GetSlice(args, 2, nargs);
if (bases == NULL)
return NULL;
- nbases = nargs - 2;
if (kwds == NULL) {
meta = NULL;
@@ -512,7 +511,7 @@ source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf)
if (PyUnicode_Check(cmd)) {
cf->cf_flags |= PyCF_IGNORE_COOKIE;
- cmd = _PyUnicode_AsDefaultEncodedString(cmd, NULL);
+ cmd = _PyUnicode_AsDefaultEncodedString(cmd);
if (cmd == NULL)
return NULL;
}
@@ -766,7 +765,6 @@ builtin_exec(PyObject *self, PyObject *args)
{
PyObject *v;
PyObject *prog, *globals = Py_None, *locals = Py_None;
- int plain = 0;
if (!PyArg_UnpackTuple(args, "exec", 1, 3, &prog, &globals, &locals))
return NULL;
@@ -775,7 +773,6 @@ builtin_exec(PyObject *self, PyObject *args)
globals = PyEval_GetGlobals();
if (locals == Py_None) {
locals = PyEval_GetLocals();
- plain = 1;
}
if (!globals || !locals) {
PyErr_SetString(PyExc_SystemError,
diff --git a/Python/ceval.c b/Python/ceval.c
index f6d4b0b..9572918 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -811,10 +811,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
unsigned char *first_instr;
PyObject *names;
PyObject *consts;
-#if defined(Py_DEBUG) || defined(LLTRACE)
- /* Make it easier to find out where we are with a debugger */
- char *filename;
-#endif
/* Computed GOTOs, or
the-optimization-commonly-but-improperly-known-as-"threaded code"
@@ -1227,18 +1223,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
#ifdef LLTRACE
lltrace = PyDict_GetItemString(f->f_globals, "__lltrace__") != NULL;
#endif
-#if defined(Py_DEBUG) || defined(LLTRACE)
- {
- PyObject *error_type, *error_value, *error_traceback;
- PyErr_Fetch(&error_type, &error_value, &error_traceback);
- filename = _PyUnicode_AsString(co->co_filename);
- if (filename == NULL && tstate->overflowed) {
- /* maximum recursion depth exceeded */
- goto exit_eval_frame;
- }
- PyErr_Restore(error_type, error_value, error_traceback);
- }
-#endif
why = WHY_NOT;
err = 0;
@@ -2706,7 +2690,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
Py_DECREF(*pfunc);
*pfunc = self;
na++;
- n++;
+ /* n++; */
} else
Py_INCREF(func);
sp = stack_pointer;
@@ -3042,7 +3026,7 @@ fast_yield:
PyTrace_RETURN, retval)) {
Py_XDECREF(retval);
retval = NULL;
- why = WHY_EXCEPTION;
+ /* why = WHY_EXCEPTION; */
}
}
}
diff --git a/Python/compile.c b/Python/compile.c
index 1d6e38c..53f5a12 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3026,7 +3026,7 @@ expr_constant(struct compiler *c, expr_ty e)
case Name_kind:
/* optimize away names that can't be reassigned */
id = PyBytes_AS_STRING(
- _PyUnicode_AsDefaultEncodedString(e->v.Name.id, NULL));
+ _PyUnicode_AsDefaultEncodedString(e->v.Name.id));
if (strcmp(id, "True") == 0) return 1;
if (strcmp(id, "False") == 0) return 0;
if (strcmp(id, "None") == 0) return 0;
diff --git a/Python/dtoa.c b/Python/dtoa.c
index 44dc01f..82b6faa 100644
--- a/Python/dtoa.c
+++ b/Python/dtoa.c
@@ -2055,7 +2055,7 @@ _Py_dg_strtod(const char *s00, char **se)
+ Exp_msk1
;
word1(&rv) = 0;
- dsign = 0;
+ /* dsign = 0; */
break;
}
}
@@ -2092,7 +2092,7 @@ _Py_dg_strtod(const char *s00, char **se)
goto undfl;
}
}
- dsign = 1 - dsign;
+ /* dsign = 1 - dsign; */
break;
}
if ((aadj = ratio(delta, bs)) <= 2.) {
diff --git a/Python/dynload_aix.c b/Python/dynload_aix.c
index 149990d..74c7b32 100644
--- a/Python/dynload_aix.c
+++ b/Python/dynload_aix.c
@@ -154,7 +154,7 @@ aix_loaderror(const char *pathname)
}
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
diff --git a/Python/dynload_dl.c b/Python/dynload_dl.c
index 2606e1e..37519b2 100644
--- a/Python/dynload_dl.c
+++ b/Python/dynload_dl.c
@@ -10,17 +10,17 @@
extern char *Py_GetProgramName(void);
const struct filedescr _PyImport_DynLoadFiletab[] = {
- {".o", "rb", C_EXTENSION},
- {"module.o", "rb", C_EXTENSION},
- {0, 0}
+ {".o", "rb", C_EXTENSION},
+ {"module.o", "rb", C_EXTENSION},
+ {0, 0}
};
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
- const char *pathname, FILE *fp)
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
+ const char *pathname, FILE *fp)
{
- char funcname[258];
+ char funcname[258];
- PyOS_snprintf(funcname, sizeof(funcname), "PyInit_%.200s", shortname);
- return dl_loadmod(Py_GetProgramName(), pathname, funcname);
+ PyOS_snprintf(funcname, sizeof(funcname), "PyInit_%.200s", shortname);
+ return dl_loadmod(Py_GetProgramName(), pathname, funcname);
}
diff --git a/Python/dynload_hpux.c b/Python/dynload_hpux.c
index 18a8137..3ebbbad 100644
--- a/Python/dynload_hpux.c
+++ b/Python/dynload_hpux.c
@@ -19,7 +19,7 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
{0, 0}
};
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
diff --git a/Python/dynload_next.c b/Python/dynload_next.c
index cabf9b9..eb17950 100644
--- a/Python/dynload_next.c
+++ b/Python/dynload_next.c
@@ -31,8 +31,8 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
#define LINKOPTIONS NSLINKMODULE_OPTION_BINDNOW| \
NSLINKMODULE_OPTION_RETURN_ON_ERROR|NSLINKMODULE_OPTION_PRIVATE
#endif
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
- const char *pathname, FILE *fp)
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
+ const char *pathname, FILE *fp)
{
dl_funcptr p = NULL;
char funcname[258];
diff --git a/Python/dynload_os2.c b/Python/dynload_os2.c
index 101c024..f7264da 100644
--- a/Python/dynload_os2.c
+++ b/Python/dynload_os2.c
@@ -15,7 +15,7 @@ const struct filedescr _PyImport_DynLoadFiletab[] = {
{0, 0}
};
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c
index 7ea510e..1c215c3 100644
--- a/Python/dynload_shlib.c
+++ b/Python/dynload_shlib.c
@@ -75,7 +75,7 @@ static struct {
static int nhandles = 0;
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
diff --git a/Python/dynload_win.c b/Python/dynload_win.c
index 73a1dcf..9c04250 100644
--- a/Python/dynload_win.c
+++ b/Python/dynload_win.c
@@ -171,7 +171,7 @@ static char *GetPythonImport (HINSTANCE hModule)
return NULL;
}
-dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp)
{
dl_funcptr p;
diff --git a/Python/getargs.c b/Python/getargs.c
index 600941d..e1cef0c 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -551,7 +551,7 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
#define UNICODE_DEFAULT_ENCODING(arg) \
- _PyUnicode_AsDefaultEncodedString(arg, NULL)
+ _PyUnicode_AsDefaultEncodedString(arg)
/* Format an error message generated by convertsimple(). */
@@ -966,9 +966,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'u': /* raw unicode buffer (Py_UNICODE *) */
case 'Z': /* raw unicode buffer or None */
{
+ Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
+
if (*format == '#') { /* any buffer-like object */
/* "s#" or "Z#" */
- Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
FETCH_SIZE;
if (c == 'Z' && arg == Py_None) {
@@ -984,8 +985,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
format++;
} else {
/* "s" or "Z" */
- Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
-
if (c == 'Z' && arg == Py_None)
*p = NULL;
else if (PyUnicode_Check(arg)) {
diff --git a/Python/import.c b/Python/import.c
index 23752ee..22a7c87 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -636,7 +636,7 @@ _PyImport_FixupBuiltin(PyObject *mod, char *name)
}
PyObject *
-_PyImport_FindExtensionUnicode(char *name, PyObject *filename)
+_PyImport_FindExtensionUnicode(const char *name, PyObject *filename)
{
PyObject *mod, *mdict;
PyModuleDef* def;
@@ -680,7 +680,7 @@ _PyImport_FindExtensionUnicode(char *name, PyObject *filename)
}
PyObject *
-_PyImport_FindBuiltin(char *name)
+_PyImport_FindBuiltin(const char *name)
{
PyObject *res, *filename;
filename = PyUnicode_FromString(name);
@@ -698,18 +698,18 @@ _PyImport_FindBuiltin(char *name)
'NEW' REFERENCE! */
PyObject *
-PyImport_AddModule(const char *name)
+PyImport_AddModuleObject(PyObject *name)
{
PyObject *modules = PyImport_GetModuleDict();
PyObject *m;
- if ((m = PyDict_GetItemString(modules, name)) != NULL &&
+ if ((m = PyDict_GetItem(modules, name)) != NULL &&
PyModule_Check(m))
return m;
- m = PyModule_New(name);
+ m = PyModule_NewObject(name);
if (m == NULL)
return NULL;
- if (PyDict_SetItemString(modules, name, m) != 0) {
+ if (PyDict_SetItem(modules, name, m) != 0) {
Py_DECREF(m);
return NULL;
}
@@ -718,14 +718,27 @@ PyImport_AddModule(const char *name)
return m;
}
+PyObject *
+PyImport_AddModule(const char *name)
+{
+ PyObject *nameobj, *module;
+ nameobj = PyUnicode_FromString(name);
+ if (nameobj == NULL)
+ return NULL;
+ module = PyImport_AddModuleObject(nameobj);
+ Py_DECREF(nameobj);
+ return module;
+}
+
+
/* Remove name from sys.modules, if it's there. */
static void
-remove_module(const char *name)
+remove_module(PyObject *name)
{
PyObject *modules = PyImport_GetModuleDict();
- if (PyDict_GetItemString(modules, name) == NULL)
+ if (PyDict_GetItem(modules, name) == NULL)
return;
- if (PyDict_DelItemString(modules, name) < 0)
+ if (PyDict_DelItem(modules, name) < 0)
Py_FatalError("import: deleting existing key in"
"sys.modules failed");
}
@@ -763,10 +776,42 @@ PyObject *
PyImport_ExecCodeModuleWithPathnames(char *name, PyObject *co, char *pathname,
char *cpathname)
{
+ PyObject *m = NULL;
+ PyObject *nameobj, *pathobj = NULL, *cpathobj = NULL;
+
+ nameobj = PyUnicode_FromString(name);
+ if (nameobj == NULL)
+ return NULL;
+
+ if (pathname != NULL) {
+ pathobj = PyUnicode_DecodeFSDefault(pathname);
+ if (pathobj == NULL)
+ goto error;
+ } else
+ pathobj = NULL;
+ if (cpathname != NULL) {
+ cpathobj = PyUnicode_DecodeFSDefault(cpathname);
+ if (cpathobj == NULL)
+ goto error;
+ } else
+ cpathobj = NULL;
+ m = PyImport_ExecCodeModuleObject(nameobj, co, pathobj, cpathobj);
+error:
+ Py_DECREF(nameobj);
+ Py_XDECREF(pathobj);
+ Py_XDECREF(cpathobj);
+ return m;
+}
+
+PyObject*
+PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname,
+ PyObject *cpathname)
+{
PyObject *modules = PyImport_GetModuleDict();
PyObject *m, *d, *v;
+ PyObject *pathbytes;
- m = PyImport_AddModule(name);
+ m = PyImport_AddModuleObject(name);
if (m == NULL)
return NULL;
/* If the module is being reloaded, we get the old module back
@@ -778,12 +823,18 @@ PyImport_ExecCodeModuleWithPathnames(char *name, PyObject *co, char *pathname,
goto error;
}
/* Remember the filename as the __file__ attribute */
- v = NULL;
if (pathname != NULL) {
- v = get_sourcefile(pathname);
+ pathbytes = PyUnicode_EncodeFSDefault(pathname);
+ if (pathbytes != NULL) {
+ v = get_sourcefile(PyBytes_AS_STRING(pathbytes));
+ Py_DECREF(pathbytes);
+ } else
+ v = NULL;
if (v == NULL)
PyErr_Clear();
}
+ else
+ v = NULL;
if (v == NULL) {
v = ((PyCodeObject *)co)->co_filename;
Py_INCREF(v);
@@ -793,27 +844,21 @@ PyImport_ExecCodeModuleWithPathnames(char *name, PyObject *co, char *pathname,
Py_DECREF(v);
/* Remember the pyc path name as the __cached__ attribute. */
- if (cpathname == NULL) {
- v = Py_None;
- Py_INCREF(v);
- }
- else if ((v = PyUnicode_FromString(cpathname)) == NULL) {
- PyErr_Clear(); /* Not important enough to report */
+ if (cpathname != NULL)
+ v = cpathname;
+ else
v = Py_None;
- Py_INCREF(v);
- }
if (PyDict_SetItemString(d, "__cached__", v) != 0)
PyErr_Clear(); /* Not important enough to report */
- Py_DECREF(v);
v = PyEval_EvalCode(co, d, d);
if (v == NULL)
goto error;
Py_DECREF(v);
- if ((m = PyDict_GetItemString(modules, name)) == NULL) {
+ if ((m = PyDict_GetItem(modules, name)) == NULL) {
PyErr_Format(PyExc_ImportError,
- "Loaded module %.200s not found in sys.modules",
+ "Loaded module %R not found in sys.modules",
name);
return NULL;
}
@@ -1547,8 +1592,8 @@ PyImport_GetImporter(PyObject *path) {
pathname and an open file. Return NULL if the module is not found. */
#ifdef MS_COREDLL
-extern FILE *PyWin_FindRegisteredModule(const char *, struct filedescr **,
- char *, Py_ssize_t);
+extern FILE *_PyWin_FindRegisteredModule(const char *, struct filedescr **,
+ char *, Py_ssize_t);
#endif
static int case_ok(char *, Py_ssize_t, Py_ssize_t, char *);
@@ -1631,7 +1676,7 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
return &fd_builtin;
}
#ifdef MS_COREDLL
- fp = PyWin_FindRegisteredModule(name, &fdp, buf, buflen);
+ fp = _PyWin_FindRegisteredModule(name, &fdp, buf, buflen);
if (fp != NULL) {
*p_fp = fp;
return fdp;
diff --git a/Python/importdl.c b/Python/importdl.c
index 9caed45..74ca8a7 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -12,8 +12,7 @@
#include "importdl.h"
-extern dl_funcptr _PyImport_GetDynLoadFunc(const char *name,
- const char *shortname,
+extern dl_funcptr _PyImport_GetDynLoadFunc(const char *shortname,
const char *pathname, FILE *fp);
@@ -48,7 +47,7 @@ _PyImport_LoadDynamicModule(char *name, char *pathname, FILE *fp)
shortname = lastdot+1;
}
- p0 = _PyImport_GetDynLoadFunc(name, shortname, pathname, fp);
+ p0 = _PyImport_GetDynLoadFunc(shortname, pathname, fp);
p = (PyObject*(*)(void))p0;
if (PyErr_Occurred())
goto error;
diff --git a/Python/peephole.c b/Python/peephole.c
index f972e16..ab96ce9 100644
--- a/Python/peephole.c
+++ b/Python/peephole.c
@@ -23,6 +23,64 @@
#define ISBASICBLOCK(blocks, start, bytes) \
(blocks[start]==blocks[start+bytes-1])
+
+#define CONST_STACK_CREATE() { \
+ const_stack_size = 256; \
+ const_stack = PyMem_New(PyObject *, const_stack_size); \
+ load_const_stack = PyMem_New(Py_ssize_t, const_stack_size); \
+ if (!const_stack || !load_const_stack) { \
+ PyErr_NoMemory(); \
+ goto exitError; \
+ } \
+ }
+
+#define CONST_STACK_DELETE() do { \
+ if (const_stack) \
+ PyMem_Free(const_stack); \
+ if (load_const_stack) \
+ PyMem_Free(load_const_stack); \
+ } while(0)
+
+#define CONST_STACK_LEN() (const_stack_top + 1)
+
+#define CONST_STACK_PUSH_OP(i) do { \
+ PyObject *_x; \
+ assert(codestr[i] == LOAD_CONST); \
+ assert(PyList_GET_SIZE(consts) > GETARG(codestr, i)); \
+ _x = PyList_GET_ITEM(consts, GETARG(codestr, i)); \
+ if (++const_stack_top >= const_stack_size) { \
+ const_stack_size *= 2; \
+ PyMem_Resize(const_stack, PyObject *, const_stack_size); \
+ PyMem_Resize(load_const_stack, Py_ssize_t, const_stack_size); \
+ if (!const_stack || !load_const_stack) { \
+ PyErr_NoMemory(); \
+ goto exitError; \
+ } \
+ } \
+ load_const_stack[const_stack_top] = i; \
+ const_stack[const_stack_top] = _x; \
+ in_consts = 1; \
+ } while(0)
+
+#define CONST_STACK_RESET() do { \
+ const_stack_top = -1; \
+ } while(0)
+
+#define CONST_STACK_TOP(x) \
+ const_stack[const_stack_top]
+
+#define CONST_STACK_LASTN(i) \
+ &const_stack[const_stack_top - i + 1]
+
+#define CONST_STACK_POP(i) do { \
+ assert(const_stack_top + 1 >= i); \
+ const_stack_top -= i; \
+ } while(0)
+
+#define CONST_STACK_OP_LASTN(i) \
+ ((const_stack_top >= i - 1) ? load_const_stack[const_stack_top - i + 1] : -1)
+
+
/* Replace LOAD_CONST c1. LOAD_CONST c2 ... LOAD_CONST cn BUILD_TUPLE n
with LOAD_CONST (c1, c2, ... cn).
The consts table must still be in list form so that the
@@ -33,17 +91,14 @@
test; for BUILD_SET it assembles a frozenset rather than a tuple.
*/
static int
-tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
+tuple_of_constants(unsigned char *codestr, Py_ssize_t n,
+ PyObject *consts, PyObject **objs)
{
PyObject *newconst, *constant;
- Py_ssize_t i, arg, len_consts;
+ Py_ssize_t i, len_consts;
/* Pre-conditions */
assert(PyList_CheckExact(consts));
- assert(codestr[n*3] == BUILD_TUPLE || codestr[n*3] == BUILD_LIST || codestr[n*3] == BUILD_SET);
- assert(GETARG(codestr, (n*3)) == n);
- for (i=0 ; i<n ; i++)
- assert(codestr[i*3] == LOAD_CONST);
/* Buildup new tuple of constants */
newconst = PyTuple_New(n);
@@ -51,16 +106,14 @@ tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
return 0;
len_consts = PyList_GET_SIZE(consts);
for (i=0 ; i<n ; i++) {
- arg = GETARG(codestr, (i*3));
- assert(arg < len_consts);
- constant = PyList_GET_ITEM(consts, arg);
+ constant = objs[i];
Py_INCREF(constant);
PyTuple_SET_ITEM(newconst, i, constant);
}
/* If it's a BUILD_SET, use the PyTuple we just built to create a
PyFrozenSet, and use that as the constant instead: */
- if (codestr[n*3] == BUILD_SET) {
+ if (codestr[0] == BUILD_SET) {
PyObject *tuple = newconst;
newconst = PyFrozenSet_New(tuple);
Py_DECREF(tuple);
@@ -77,9 +130,8 @@ tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
/* Write NOPs over old LOAD_CONSTS and
add a new LOAD_CONST newconst on top of the BUILD_TUPLE n */
- memset(codestr, NOP, n*3);
- codestr[n*3] = LOAD_CONST;
- SETARG(codestr, (n*3), len_consts);
+ codestr[0] = LOAD_CONST;
+ SETARG(codestr, 0, len_consts);
return 1;
}
@@ -87,14 +139,14 @@ tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
with LOAD_CONST binop(c1,c2)
The consts table must still be in list form so that the
new constant can be appended.
- Called with codestr pointing to the first LOAD_CONST.
+ Called with codestr pointing to the BINOP.
Abandons the transformation if the folding fails (i.e. 1+'a').
If the new constant is a sequence, only folds when the size
is below a threshold value. That keeps pyc files from
becoming large in the presence of code like: (None,)*1000.
*/
static int
-fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
+fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **objs)
{
PyObject *newconst, *v, *w;
Py_ssize_t len_consts, size;
@@ -102,13 +154,11 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
/* Pre-conditions */
assert(PyList_CheckExact(consts));
- assert(codestr[0] == LOAD_CONST);
- assert(codestr[3] == LOAD_CONST);
/* Create new constant */
- v = PyList_GET_ITEM(consts, GETARG(codestr, 0));
- w = PyList_GET_ITEM(consts, GETARG(codestr, 3));
- opcode = codestr[6];
+ v = objs[0];
+ w = objs[1];
+ opcode = codestr[0];
switch (opcode) {
case BINARY_POWER:
newconst = PyNumber_Power(v, w, Py_None);
@@ -180,16 +230,15 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
Py_DECREF(newconst);
/* Write NOP NOP NOP NOP LOAD_CONST newconst */
- memset(codestr, NOP, 4);
- codestr[4] = LOAD_CONST;
- SETARG(codestr, 4, len_consts);
+ codestr[-2] = LOAD_CONST;
+ SETARG(codestr, -2, len_consts);
return 1;
}
static int
-fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
+fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v)
{
- PyObject *newconst=NULL, *v;
+ PyObject *newconst=NULL/*, *v*/;
Py_ssize_t len_consts;
int opcode;
@@ -198,7 +247,6 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
assert(codestr[0] == LOAD_CONST);
/* Create new constant */
- v = PyList_GET_ITEM(consts, GETARG(codestr, 0));
opcode = codestr[3];
switch (opcode) {
case UNARY_NEGATIVE:
@@ -340,7 +388,11 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
unsigned char *lineno;
int *addrmap = NULL;
int new_line, cum_orig_line, last_line, tabsiz;
- int cumlc=0, lastlc=0; /* Count runs of consecutive LOAD_CONSTs */
+ PyObject **const_stack = NULL;
+ Py_ssize_t *load_const_stack = NULL;
+ Py_ssize_t const_stack_top = -1;
+ Py_ssize_t const_stack_size = 0;
+ int in_consts = 0; /* whether we are in a LOAD_CONST sequence */
unsigned int *blocks = NULL;
char *name;
@@ -386,12 +438,16 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
goto exitError;
assert(PyList_Check(consts));
+ CONST_STACK_CREATE();
+
for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) {
reoptimize_current:
opcode = codestr[i];
- lastlc = cumlc;
- cumlc = 0;
+ if (!in_consts) {
+ CONST_STACK_RESET();
+ }
+ in_consts = 0;
switch (opcode) {
/* Replace UNARY_NOT POP_JUMP_IF_FALSE
@@ -432,21 +488,21 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
goto exitError;
else if (h == 0)
continue;
- cumlc = lastlc + 1;
+ CONST_STACK_PUSH_OP(i);
break;
/* Skip over LOAD_CONST trueconst
POP_JUMP_IF_FALSE xx. This improves
"while 1" performance. */
case LOAD_CONST:
- cumlc = lastlc + 1;
+ CONST_STACK_PUSH_OP(i);
j = GETARG(codestr, i);
if (codestr[i+3] != POP_JUMP_IF_FALSE ||
!ISBASICBLOCK(blocks,i,6) ||
!PyObject_IsTrue(PyList_GET_ITEM(consts, j)))
continue;
memset(codestr+i, NOP, 6);
- cumlc = 0;
+ CONST_STACK_RESET();
break;
/* Try to fold tuples of constants (includes a case for lists and sets
@@ -458,19 +514,23 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
case BUILD_LIST:
case BUILD_SET:
j = GETARG(codestr, i);
- h = i - 3 * j;
- if (h >= 0 &&
- j <= lastlc &&
+ if (j == 0)
+ break;
+ h = CONST_STACK_OP_LASTN(j);
+ assert((h >= 0 || CONST_STACK_LEN() < j));
+ if (h >= 0 && j > 0 && j <= CONST_STACK_LEN() &&
((opcode == BUILD_TUPLE &&
- ISBASICBLOCK(blocks, h, 3*(j+1))) ||
+ ISBASICBLOCK(blocks, h, i-h+3)) ||
((opcode == BUILD_LIST || opcode == BUILD_SET) &&
codestr[i+3]==COMPARE_OP &&
- ISBASICBLOCK(blocks, h, 3*(j+2)) &&
+ ISBASICBLOCK(blocks, h, i-h+6) &&
(GETARG(codestr,i+3)==6 ||
GETARG(codestr,i+3)==7))) &&
- tuple_of_constants(&codestr[h], j, consts)) {
+ tuple_of_constants(&codestr[i], j, consts, CONST_STACK_LASTN(j))) {
assert(codestr[i] == LOAD_CONST);
- cumlc = 1;
+ memset(&codestr[h], NOP, i - h);
+ CONST_STACK_POP(j);
+ CONST_STACK_PUSH_OP(i);
break;
}
if (codestr[i+3] != UNPACK_SEQUENCE ||
@@ -482,10 +542,12 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
} else if (j == 2) {
codestr[i] = ROT_TWO;
memset(codestr+i+1, NOP, 5);
+ CONST_STACK_RESET();
} else if (j == 3) {
codestr[i] = ROT_THREE;
codestr[i+1] = ROT_TWO;
memset(codestr+i+2, NOP, 4);
+ CONST_STACK_RESET();
}
break;
@@ -504,12 +566,18 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
case BINARY_AND:
case BINARY_XOR:
case BINARY_OR:
- if (lastlc >= 2 &&
- ISBASICBLOCK(blocks, i-6, 7) &&
- fold_binops_on_constants(&codestr[i-6], consts)) {
+ /* NOTE: LOAD_CONST is saved at `i-2` since it has an arg
+ while BINOP hasn't */
+ h = CONST_STACK_OP_LASTN(2);
+ assert((h >= 0 || CONST_STACK_LEN() < 2));
+ if (h >= 0 &&
+ ISBASICBLOCK(blocks, h, i-h+1) &&
+ fold_binops_on_constants(&codestr[i], consts, CONST_STACK_LASTN(2))) {
i -= 2;
+ memset(&codestr[h], NOP, i - h);
assert(codestr[i] == LOAD_CONST);
- cumlc = 1;
+ CONST_STACK_POP(2);
+ CONST_STACK_PUSH_OP(i);
}
break;
@@ -518,12 +586,15 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
case UNARY_NEGATIVE:
case UNARY_INVERT:
case UNARY_POSITIVE:
- if (lastlc >= 1 &&
- ISBASICBLOCK(blocks, i-3, 4) &&
- fold_unaryops_on_constants(&codestr[i-3], consts)) {
+ h = CONST_STACK_OP_LASTN(1);
+ assert((h >= 0 || CONST_STACK_LEN() < 1));
+ if (h >= 0 &&
+ ISBASICBLOCK(blocks, h, i-h+1) &&
+ fold_unaryops_on_constants(&codestr[i-3], consts, CONST_STACK_TOP())) {
i -= 2;
assert(codestr[i] == LOAD_CONST);
- cumlc = 1;
+ CONST_STACK_POP(1);
+ CONST_STACK_PUSH_OP(i);
}
break;
@@ -680,6 +751,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
assert(h + nops == codelen);
code = PyBytes_FromStringAndSize((char *)codestr, h);
+ CONST_STACK_DELETE();
PyMem_Free(addrmap);
PyMem_Free(codestr);
PyMem_Free(blocks);
@@ -689,6 +761,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
code = NULL;
exitUnchanged:
+ CONST_STACK_DELETE();
if (blocks != NULL)
PyMem_Free(blocks);
if (addrmap != NULL)
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 75e3032..7bf21c0 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -954,7 +954,7 @@ format_float_short(double d, char format_code,
/* shouldn't get here: Gay's code should always return
something starting with a digit, an 'I', or 'N' */
strncpy(p, "ERR", 3);
- p += 3;
+ /* p += 3; */
assert(0);
}
goto exit;
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index ea095d2..d06adc0 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1176,7 +1176,6 @@ PySys_AddXOption(const wchar_t *s)
PyObject *opts;
PyObject *name = NULL, *value = NULL;
const wchar_t *name_end;
- int r;
opts = get_xoptions();
if (opts == NULL)
@@ -1194,7 +1193,7 @@ PySys_AddXOption(const wchar_t *s)
}
if (name == NULL || value == NULL)
goto error;
- r = PyDict_SetItem(opts, name, value);
+ PyDict_SetItem(opts, name, value);
Py_DECREF(name);
Py_DECREF(value);
return;
@@ -1256,7 +1255,6 @@ int_info -- a struct sequence with information about the int implementation.\n\
maxsize -- the largest supported length of containers.\n\
maxunicode -- the largest supported character\n\
builtin_module_names -- tuple of module names built into this interpreter\n\
-subversion -- subversion information of the build as tuple\n\
version -- the version of this interpreter as a string\n\
version_info -- version information as a named tuple\n\
hexversion -- version information encoded as a single integer\n\
@@ -1304,95 +1302,6 @@ settrace() -- set the global debug tracing function\n\
)
/* end of sys_doc */ ;
-/* Subversion branch and revision management */
-static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
-static const char headurl[] = "$HeadURL$";
-static int svn_initialized;
-static char patchlevel_revision[50]; /* Just the number */
-static char branch[50];
-static char shortbranch[50];
-static const char *svn_revision;
-
-static void
-svnversion_init(void)
-{
- const char *python, *br_start, *br_end, *br_end2, *svnversion;
- Py_ssize_t len;
- int istag = 0;
-
- if (svn_initialized)
- return;
-
- python = strstr(headurl, "/python/");
- if (!python) {
- strcpy(branch, "unknown branch");
- strcpy(shortbranch, "unknown");
- }
- else {
- br_start = python + 8;
- br_end = strchr(br_start, '/');
- assert(br_end);
-
- /* Works even for trunk,
- as we are in trunk/Python/sysmodule.c */
- br_end2 = strchr(br_end+1, '/');
-
- istag = strncmp(br_start, "tags", 4) == 0;
- if (strncmp(br_start, "trunk", 5) == 0) {
- strcpy(branch, "trunk");
- strcpy(shortbranch, "trunk");
- }
- else if (istag || strncmp(br_start, "branches", 8) == 0) {
- len = br_end2 - br_start;
- strncpy(branch, br_start, len);
- branch[len] = '\0';
-
- len = br_end2 - (br_end + 1);
- strncpy(shortbranch, br_end + 1, len);
- shortbranch[len] = '\0';
- }
- else {
- Py_FatalError("bad HeadURL");
- return;
- }
- }
-
-
- svnversion = _Py_svnversion();
- if (strcmp(svnversion, "Unversioned directory") != 0 && strcmp(svnversion, "exported") != 0)
- svn_revision = svnversion;
- else if (istag) {
- len = strlen(_patchlevel_revision);
- assert(len >= 13);
- assert(len < (sizeof(patchlevel_revision) + 13));
- strncpy(patchlevel_revision, _patchlevel_revision + 11,
- len - 13);
- patchlevel_revision[len - 13] = '\0';
- svn_revision = patchlevel_revision;
- }
- else
- svn_revision = "";
-
- svn_initialized = 1;
-}
-
-/* Return svnversion output if available.
- Else return Revision of patchlevel.h if on branch.
- Else return empty string */
-const char*
-Py_SubversionRevision()
-{
- svnversion_init();
- return svn_revision;
-}
-
-const char*
-Py_SubversionShortBranch()
-{
- svnversion_init();
- return shortbranch;
-}
-
PyDoc_STRVAR(flags__doc__,
"sys.flags\n\
@@ -1596,10 +1505,6 @@ _PySys_Init(void)
PyUnicode_FromString(Py_GetVersion()));
SET_SYS_FROM_STRING("hexversion",
PyLong_FromLong(PY_VERSION_HEX));
- svnversion_init();
- SET_SYS_FROM_STRING("subversion",
- Py_BuildValue("(sss)", "CPython", branch,
- svn_revision));
SET_SYS_FROM_STRING("_mercurial",
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
_Py_hgversion()));