summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/_warnings.c3
-rw-r--r--Python/import.c25
-rw-r--r--Python/sysmodule.c17
-rw-r--r--Python/traceback.c4
4 files changed, 26 insertions, 23 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index e9384ca..cb81b07 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -266,7 +266,8 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
PyFile_WriteString("\n", f_stderr);
}
else
- Py_DisplaySourceLine(f_stderr, PyUnicode_AsString(filename), lineno, 2);
+ _Py_DisplaySourceLine(f_stderr, PyUnicode_AsString(filename),
+ lineno, 2);
PyErr_Clear();
}
diff --git a/Python/import.c b/Python/import.c
index 14cda6e..7ad3bf9 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2162,6 +2162,7 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
static PyObject *pathstr = NULL;
static PyObject *pkgstr = NULL;
PyObject *pkgname, *modname, *modpath, *modules, *parent;
+ int orig_level = level;
if (globals == NULL || !PyDict_Check(globals) || !level)
return Py_None;
@@ -2292,9 +2293,27 @@ get_parent(PyObject *globals, char *buf, Py_ssize_t *p_buflen, int level)
modules = PyImport_GetModuleDict();
parent = PyDict_GetItemString(modules, buf);
- if (parent == NULL)
- PyErr_Format(PyExc_SystemError,
- "Parent module '%.200s' not loaded", buf);
+ if (parent == NULL) {
+ if (orig_level < 1) {
+ PyObject *err_msg = PyBytes_FromFormat(
+ "Parent module '%.200s' not found "
+ "while handling absolute import", buf);
+ if (err_msg == NULL) {
+ return NULL;
+ }
+ if (!PyErr_WarnEx(PyExc_RuntimeWarning,
+ PyBytes_AsString(err_msg), 1)) {
+ *buf = '\0';
+ *p_buflen = 0;
+ parent = Py_None;
+ }
+ Py_DECREF(err_msg);
+ } else {
+ PyErr_Format(PyExc_SystemError,
+ "Parent module '%.200s' not loaded, "
+ "cannot perform relative import", buf);
+ }
+ }
return parent;
/* We expect, but can't guarantee, if parent != None, that:
- parent.__name__ == buf
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 4017ac2..f4118d6 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -824,29 +824,12 @@ PyDoc_STRVAR(sys_clear_type_cache__doc__,
Clear the internal type lookup cache.");
-static PyObject *
-sys_compact_freelists(PyObject* self, PyObject* args)
-{
- size_t fsum, fbc, fbf;
-
- PyFloat_CompactFreeList(&fbc, &fbf, &fsum);
-
- return Py_BuildValue("((kkk))", fsum, fbc, fbf);
-
-}
-
-PyDoc_STRVAR(sys_compact_freelists__doc__,
-"_compact_freelists() -> ((remaing_objects, total_blocks, freed_blocks),)\n\
-Compact the free lists of floats.");
-
static PyMethodDef sys_methods[] = {
/* Might as well keep this in alphabetic order */
{"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS,
callstats_doc},
{"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,
sys_clear_type_cache__doc__},
- {"_compact_freelists", sys_compact_freelists, METH_NOARGS,
- sys_compact_freelists__doc__},
{"_current_frames", sys_current_frames, METH_NOARGS,
current_frames_doc},
{"displayhook", sys_displayhook, METH_O, displayhook_doc},
diff --git a/Python/traceback.c b/Python/traceback.c
index 55300fc..d569a18 100644
--- a/Python/traceback.c
+++ b/Python/traceback.c
@@ -129,7 +129,7 @@ PyTraceBack_Here(PyFrameObject *frame)
}
int
-Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)
+_Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)
{
int err = 0;
FILE *xfp = NULL;
@@ -241,7 +241,7 @@ tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)
err = PyFile_WriteString(linebuf, f);
if (err != 0)
return err;
- return Py_DisplaySourceLine(f, filename, lineno, 4);
+ return _Py_DisplaySourceLine(f, filename, lineno, 4);
}
static int