diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 15 | ||||
-rw-r--r-- | Python/errors.c | 16 | ||||
-rw-r--r-- | Python/import.c | 8 | ||||
-rw-r--r-- | Python/marshal.c | 8 | ||||
-rw-r--r-- | Python/pystrtod.c | 7 | ||||
-rw-r--r-- | Python/pythonrun.c | 28 | ||||
-rw-r--r-- | Python/sysmodule.c | 4 |
7 files changed, 55 insertions, 31 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 80adc30ed4..e35680005f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1829,15 +1829,26 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) long hash = ((PyStringObject *)w)->ob_shash; if (hash != -1) { PyDictObject *d; + PyDictEntry *e; d = (PyDictObject *)(f->f_globals); - x = d->ma_lookup(d, w, hash)->me_value; + e = d->ma_lookup(d, w, hash); + if (e == NULL) { + x = NULL; + break; + } + x = e->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); continue; } d = (PyDictObject *)(f->f_builtins); - x = d->ma_lookup(d, w, hash)->me_value; + e = d->ma_lookup(d, w, hash); + if (e == NULL) { + x = NULL; + break; + } + x = e->me_value; if (x != NULL) { Py_INCREF(x); PUSH(x); diff --git a/Python/errors.c b/Python/errors.c index c391d3389a..d99f261e18 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -597,13 +597,16 @@ PyErr_WriteUnraisable(PyObject *obj) if (f != NULL) { PyFile_WriteString("Exception ", f); if (t) { - char* className = PyExceptionClass_Name(t); PyObject* moduleName; - char *dot = strrchr(className, '.'); - if (dot != NULL) - className = dot+1; - moduleName = PyObject_GetAttrString(t, "__module__"); + char* className = PyExceptionClass_Name(t); + if (className != NULL) { + char *dot = strrchr(className, '.'); + if (dot != NULL) + className = dot+1; + } + + moduleName = PyObject_GetAttrString(t, "__module__"); if (moduleName == NULL) PyFile_WriteString("<unknown>", f); else { @@ -734,7 +737,8 @@ PyErr_SyntaxLocation(const char *filename, int lineno) tmp = PyErr_ProgramText(filename, lineno); if (tmp) { - PyObject_SetAttrString(v, "text", tmp); + if (PyObject_SetAttrString(v, "text", tmp)) + PyErr_Clear(); Py_DECREF(tmp); } } diff --git a/Python/import.c b/Python/import.c index 094e4fd00a..c14e8cd0f2 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1252,9 +1252,11 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf, } else if (importer == Py_None) { /* No importer was found, so it has to be a file. - * Check if the directory is valid. */ + * Check if the directory is valid. + * Note that the empty string is a valid path, but + * not stat'able, hence the check for len. */ #ifdef HAVE_STAT - if (stat(buf, &statbuf) != 0) { + if (len && stat(buf, &statbuf) != 0) { /* Directory does not exist. */ PyDict_SetItem(path_importer_cache, v, Py_False); @@ -2058,7 +2060,7 @@ PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, /* Return the package that an import is being performed in. If globals comes from the module foo.bar.bat (not itself a package), this returns the sys.modules entry for foo.bar. If globals is from a package's __init__.py, - the package's entry in sys.modules is returned. + the package's entry in sys.modules is returned, as a borrowed reference. The *name* of the returned package is returned in buf, with the length of the name in *p_buflen. diff --git a/Python/marshal.c b/Python/marshal.c index c5d5b72f7d..10a6c0c1d7 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1073,12 +1073,10 @@ marshal_dump(PyObject *self, PyObject *args) } static PyObject * -marshal_load(PyObject *self, PyObject *args) +marshal_load(PyObject *self, PyObject *f) { RFILE rf; - PyObject *f, *result; - if (!PyArg_ParseTuple(args, "O:load", &f)) - return NULL; + PyObject *result; if (!PyFile_Check(f)) { PyErr_SetString(PyExc_TypeError, "marshal.load() arg must be file"); @@ -1121,7 +1119,7 @@ marshal_loads(PyObject *self, PyObject *args) static PyMethodDef marshal_methods[] = { {"dump", marshal_dump, METH_VARARGS}, - {"load", marshal_load, METH_VARARGS}, + {"load", marshal_load, METH_O}, {"dumps", marshal_dumps, METH_VARARGS}, {"loads", marshal_loads, METH_VARARGS}, {NULL, NULL} /* sentinel */ diff --git a/Python/pystrtod.c b/Python/pystrtod.c index 8a71c285a9..e1c84ea03e 100644 --- a/Python/pystrtod.c +++ b/Python/pystrtod.c @@ -31,6 +31,7 @@ * is returned (according to the sign of the value), and %ERANGE is * stored in %errno. If the correct value would cause underflow, * zero is returned and %ERANGE is stored in %errno. + * If memory allocation fails, %ENOMEM is stored in %errno. * * This function resets %errno before calling strtod() so that * you can reliably detect overflow and underflow. @@ -102,6 +103,12 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) /* We need to convert the '.' to the locale specific decimal point */ copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len); + if (copy == NULL) { + if (endptr) + *endptr = (char *)nptr; + errno = ENOMEM; + return val; + } c = copy; memcpy(c, nptr, decimal_point_pos - nptr); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 8283fc5c98..2dbcf75ac9 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -659,7 +659,7 @@ initsite(void) /* Parse input from a file and execute it */ int -PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, +PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) { if (filename == NULL) @@ -738,7 +738,7 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags ps2 = PyString_AsString(w); } arena = PyArena_New(); - mod = PyParser_ASTFromFile(fp, filename, + mod = PyParser_ASTFromFile(fp, filename, Py_single_input, ps1, ps2, flags, &errcode, arena); Py_XDECREF(v); @@ -1126,13 +1126,15 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) /* Don't do anything else */ } else if (PyExceptionClass_Check(exception)) { - char* className = PyExceptionClass_Name(exception); - char *dot = strrchr(className, '.'); PyObject* moduleName; - if (dot != NULL) - className = dot+1; - moduleName = PyObject_GetAttrString(exception, "__module__"); + char* className = PyExceptionClass_Name(exception); + if (className != NULL) { + char *dot = strrchr(className, '.'); + if (dot != NULL) + className = dot+1; + } + moduleName = PyObject_GetAttrString(exception, "__module__"); if (moduleName == NULL) err = PyFile_WriteString("<unknown>", f); else { @@ -1178,7 +1180,7 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) } PyObject * -PyRun_StringFlags(const char *str, int start, PyObject *globals, +PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) { PyObject *ret = NULL; @@ -1225,7 +1227,7 @@ run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, } static PyObject * -run_pyc_file(FILE *fp, const char *filename, PyObject *globals, +run_pyc_file(FILE *fp, const char *filename, PyObject *globals, PyObject *locals, PyCompilerFlags *flags) { PyCodeObject *co; @@ -1294,13 +1296,13 @@ Py_SymtableString(const char *str, const char *filename, int start) /* Preferred access to parser is through AST. */ mod_ty -PyParser_ASTFromString(const char *s, const char *filename, int start, +PyParser_ASTFromString(const char *s, const char *filename, int start, PyCompilerFlags *flags, PyArena *arena) { mod_ty mod; perrdetail err; node *n = PyParser_ParseStringFlagsFilename(s, filename, - &_PyParser_Grammar, start, &err, + &_PyParser_Grammar, start, &err, PARSER_FLAGS(flags)); if (n) { mod = PyAST_FromNode(n, flags, filename, arena); @@ -1314,7 +1316,7 @@ PyParser_ASTFromString(const char *s, const char *filename, int start, } mod_ty -PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, +PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, char *ps2, PyCompilerFlags *flags, int *errcode, PyArena *arena) { @@ -1345,7 +1347,7 @@ PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int fla start, NULL, NULL, &err, flags); if (n == NULL) err_input(&err); - + return n; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c6eb91fc6f..4c92a90210 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -196,7 +196,7 @@ static PyObject * sys_exit(PyObject *self, PyObject *args) { PyObject *exit_code = 0; - if (!PyArg_ParseTuple(args, "|O:exit", &exit_code)) + if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code)) return NULL; /* Raise SystemExit so callers may catch it or clean up. */ PyErr_SetObject(PyExc_SystemExit, exit_code); @@ -668,7 +668,7 @@ static PyObject * sys_call_tracing(PyObject *self, PyObject *args) { PyObject *func, *funcargs; - if (!PyArg_ParseTuple(args, "OO:call_tracing", &func, &funcargs)) + if (!PyArg_UnpackTuple(args, "call_tracing", 2, 2, &func, &funcargs)) return NULL; return _PyEval_CallTracing(func, funcargs); } |