Index: setup.py =================================================================== --- setup.py (revision 74738) +++ setup.py (working copy) @@ -546,16 +546,16 @@ # readline do_readline = self.compiler_obj.find_library_file(lib_dirs, 'readline') - if platform == 'darwin': # and os.uname()[2] < '9.': + # Mac OS X 10.5 and 10.6 (Darwin 9 and 10) are OK. + os_release = int(os.uname()[2].split('.')[0]) + if platform == 'darwin' and os_release < 9: # MacOSX 10.4 has a broken readline. Don't try to build # the readline module unless the user has installed a fixed # readline package - # FIXME: The readline emulation on 10.5 is better, but the - # readline module doesn't compile out of the box. if find_file('readline/rlconf.h', inc_dirs, []) is None: do_readline = False if do_readline: - if sys.platform == 'darwin': + if sys.platform == 'darwin' and os_release < 9: # In every directory on the search path search for a dynamic # library and then a static library, instead of first looking # for dynamic libraries on the entiry path. Index: Modules/readline.c =================================================================== --- Modules/readline.c (revision 74738) +++ Modules/readline.c (working copy) @@ -6,6 +6,7 @@ /* Standard definitions */ #include "Python.h" +#include #include #include #include @@ -976,10 +977,23 @@ n = strlen(p); if (n > 0) { char *line; + char *e = "EditLine wrapper"; HISTORY_STATE *state = history_get_history_state(); - if (state->length > 0) - line = history_get(state->length)->line; - else + if (state->length > 0) { + /* + * On Mac OS X 10.5, readline is emulated. + * When there's only one line in history, the + * original statement (in the "else" part below) + * causes out-of-bounds access and BusError. + * The fix is applied only if r_library_version + * is "EditLine wrapper" because the original + * statement works for GNU readline. + */ + if (strncmp(rl_library_version, e, strlen(e)) == 0) + line = history_get(state->length - 1)->line; + else + line = history_get(state->length)->line; + } else line = ""; if (strcmp(p, line)) add_history(p);