1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Bug 880: Prevent SIGSEGV in init_python when -no-home is used.

Before this patch, init_python would crash trying to set up elinks.home
at the Python side.  Now it uses None as the value in that case.
Also, init_python no longer adds "(null)" to $PYTHONPATH.
This commit is contained in:
M. Levinson 2006-12-07 23:56:00 +01:00 committed by Kalle Olavi Niemitalo
parent 1442f551aa
commit 78bd416dc0
3 changed files with 25 additions and 12 deletions

View File

@ -221,6 +221,9 @@ class feedreader:
def __init__(self, feeds=my_favorite_feeds): def __init__(self, feeds=my_favorite_feeds):
"""Constructor.""" """Constructor."""
if elinks.home is None:
raise elinks.error("Cannot identify unread entries without "
"a ~/.elinks configuration directory.")
self._results = {} self._results = {}
self._feeds = feeds self._feeds = feeds
for feed in feeds: for feed in feeds:

View File

@ -112,7 +112,8 @@ DESCRIPTION
Other public objects: Other public objects:
home -- A string containing the pathname of the ~/.elinks directory. home -- A string containing the pathname of the ~/.elinks directory, or
None if ELinks has no configuration directory.
FUNCTIONS FUNCTIONS
bind_key(...) bind_key(...)

View File

@ -96,21 +96,27 @@ end:
static int static int
set_python_search_path(void) set_python_search_path(void)
{ {
struct string new_python_path, *okay; struct string new_python_path;
unsigned char *old_python_path; unsigned char *old_python_path;
int result = -1; int result = -1;
if (!init_string(&new_python_path)) return result; if (!init_string(&new_python_path)) return result;
if (elinks_home && !add_format_to_string(&new_python_path, "%s%c",
elinks_home, DELIM))
goto end;
if (!add_to_string(&new_python_path, CONFDIR))
goto end;
old_python_path = (unsigned char *) getenv("PYTHONPATH"); old_python_path = (unsigned char *) getenv("PYTHONPATH");
if (old_python_path) if (old_python_path && !add_format_to_string(&new_python_path, "%c%s",
okay = add_format_to_string(&new_python_path, "%s%c%s%c%s", DELIM, old_python_path))
elinks_home, DELIM, CONFDIR, goto end;
DELIM, old_python_path);
else result = env_set("PYTHONPATH", new_python_path.source, -1);
okay = add_format_to_string(&new_python_path, "%s%c%s",
elinks_home, DELIM, CONFDIR); end:
if (okay) result = env_set("PYTHONPATH", new_python_path.source, -1);
done_string(&new_python_path); done_string(&new_python_path);
return result; return result;
} }
@ -140,7 +146,8 @@ error -- Errors internal to ELinks.\n\
\n\ \n\
Other public objects:\n\ Other public objects:\n\
\n\ \n\
home -- A string containing the pathname of the ~/.elinks directory.\n"); home -- A string containing the pathname of the ~/.elinks directory, or\n\
None if ELinks has no configuration directory.\n");
void void
init_python(struct module *module) init_python(struct module *module)
@ -165,7 +172,9 @@ init_python(struct module *module)
elinks_module = Py_InitModule3("elinks", NULL, module_doc); elinks_module = Py_InitModule3("elinks", NULL, module_doc);
if (!elinks_module) goto python_error; if (!elinks_module) goto python_error;
if (PyModule_AddStringConstant(elinks_module, "home", elinks_home) != 0) /* If @elinks_home is NULL, Py_BuildValue() returns a None reference. */
if (PyModule_AddObject(elinks_module, "home",
Py_BuildValue("s", elinks_home)) != 0)
goto python_error; goto python_error;
python_elinks_err = PyErr_NewException("elinks.error", NULL, NULL); python_elinks_err = PyErr_NewException("elinks.error", NULL, NULL);