Hi,

There is a bug in module Readline. The string that function `readline'
returns
is deleted before you can add it to the history. So getting entries from
the
history table often results in strings that wouldn`t occur in your
wildest dreams.
This never happened under Solaris, but always under (different versions
of)
Linux whenever a string that was stored in the history is editted.
I have fixed
this by forcing the string to be copied and returning the copy before
the string
itself is deleted by free( ... ).


readline :: String ->   -- Prompt String

            IO String   -- Returned line

readline prompt =  do

--ToDo: Get the "Live register in _casm_GC_ " bug fixed

--      this stops us passing the prompt string to readline directly :-(

--    litstr <- _casm_GC_ ``%r = readline(%0);'' prompt

      _casm_ ``rl_prompt_hack = (char*)realloc(rl_prompt_hack, %1);

               strcpy (rl_prompt_hack,%0);''

               prompt (length prompt)

     litstr <- _casm_GC_ ``%r = readline (rl_prompt_hack);''

     if (litstr == ``NULL'')

     then fail (userError "Readline has read EOF")

     else do

           let str = unpackCString litstr

           str' <- copy str                               -- this line is new

           _casm_ ``free(%0);'' litstr

           return str

             where                                        -- these five lines are new, 
too

               copy []     = return []

               copy (a:as) = do

                               as' <- copy as

                               return (a:as')

Martin


Reply via email to