Georg Baum wrote:
> Am Dienstag, 14. November 2006 19:08 schrieb Peter Kümmel:
>> Peter Kümmel wrote:
>>> Bennett Helm wrote:
>>>> Recipe for another crash (1.5 on Mac).
>>>>
>>>> Create a document with a bibliography that specifies two .bib files.
>>>> Select View > View Source, and check the "Display complete source"
>>>> option. Back in the main LyX window, start typing text in a standard
>>>> paragraph. After a few keystrokes, LyX crashes.
>>>>
>>>> As you begin typing, looking at the LaTeX Source window reveals that
> the
>>>> names of the files listed in \Bibliography change as you type.
>>>>
>>>> Here's the backtrace.
>>>>
>>>> Bennett
>>>>
>>> Similar here on Windows:
>>>
>>> 1. new document
>>> 2. insert List/TOC->Bibtex Bilio
>>> 3. add a biblio
>>> 4. view source ->crash
>>>
>>
>> This fixes the crash here:
>>
>> Index: insets/insetbibtex.C
>> ===================================================================
>> --- insets/insetbibtex.C (revision 15916)
>> +++ insets/insetbibtex.C (working copy)
>> @@ -155,7 +155,8 @@
>> typedef boost::tokenizer<Separator> Tokenizer;
>>
>> Separator const separator(",");
>> - Tokenizer const tokens(to_utf8(getParam("bibfiles")), separator);
>> + const string param(to_utf8(getParam("bibfiles")));
>> + Tokenizer const tokens(param, separator);
>> Tokenizer::const_iterator const begin = tokens.begin();
>> Tokenizer::const_iterator const end = tokens.end();
>>
>>
>> But why is it needed?
As I understand it now, to_utf8 creates a std::string which
gets destroyed after construction. And the ctor of Tokenizer
doesn't make a deep copy of the string, it only stores iterators.
>> Why is the string deconstructed while passed as parameter?
>>
>> std::string const to_utf8(docstring const & ucs4)
>> {
>> std::vector<char> const utf8 =
>> ucs4_to_utf8(ucs4.data(), ucs4.size());
>> return std::string(utf8.begin(), utf8.end());
>> }
>>
>> Isn't this deep copying?
>
> Yes, it is.
>
>> There could be hundreds of such constructs in LyX.
>> This is really a ugly bug.
>
> Indeed. Does the attached patch work for you? If yes I would prefer that,
> since we should convert all filename stuff to docstring eventually and use
> one place where that is converted to the encoding that is actually usesd
> by the file system. I don't get the crash with or without the patch.
>
Yes, your patch also works.
The crash here is produced by a check of the STL code, so if there
is no check it is possible that it doesn't hurt.
The problem is, I have no idea how we could catch such bugs, no compiler
warnings here.
>
> Georg
>
>
> ------------------------------------------------------------------------
>
> Index: src/insets/insetbibtex.C
> ===================================================================
> --- src/insets/insetbibtex.C (Revision 15927)
> +++ src/insets/insetbibtex.C (Arbeitskopie)
> @@ -151,19 +151,20 @@ int InsetBibtex::latex(Buffer const & bu
> // use such filenames.)
> // Otherwise, store the (maybe absolute) path to the original,
> // unmangled database name.
> - typedef boost::char_separator<char> Separator;
> - typedef boost::tokenizer<Separator> Tokenizer;
> + typedef boost::char_separator<char_type> Separator;
> + typedef boost::tokenizer<Separator, docstring::const_iterator,
> docstring> Tokenizer;
>
> - Separator const separator(",");
> - Tokenizer const tokens(to_utf8(getParam("bibfiles")), separator);
> + Separator const separator(from_ascii(",").c_str());
> + Tokenizer const tokens(getParam("bibfiles"), separator);
> Tokenizer::const_iterator const begin = tokens.begin();
> Tokenizer::const_iterator const end = tokens.end();
>
> - std::ostringstream dbs;
> + odocstringstream dbs;
> for (Tokenizer::const_iterator it = begin; it != end; ++it) {
> - string const input = trim(*it);
> + docstring const input = trim(*it);
> + // FIXME UNICODE
> string database =
> - normalize_name(buffer, runparams, input, ".bib");
> + normalize_name(buffer, runparams, to_utf8(input),
> ".bib");
> string const in_file = database + ".bib";
>
> if (!runparams.inComment && !runparams.dryrun &&
> !runparams.nice &&
> @@ -184,10 +185,10 @@ int InsetBibtex::latex(Buffer const & bu
>
> if (it != begin)
> dbs << ',';
> - dbs << latex_path(database);
> + // FIXME UNICODE
> + dbs << from_utf8(latex_path(database));
> }
> - // FIXME UNICODE
> - docstring const db_out = from_utf8(dbs.str());
> + docstring const db_out = dbs.str();
>
> // Post this warning only once.
> static bool warned_about_spaces = false;
--
Peter Kümmel