Re: [LyX/master] Do not return copies of string members
On Fri, May 12, 2023 at 09:22:03AM +0200, Jean-Marc Lasgouttes wrote: Le 11/05/2023 à 23:04, Enrico Forestieri a écrit : Anyway, I don't think the autoconf test is broken because: From what I read here: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html this define is merely a default. It looks like one can choose to change it, as long as all the libraries you use (e.g. Qt) do the same. I found the attached test for COW on stackoverflow. I first tried it on Solaris 10 with the following results: $ /opt/csw/bin/g++ -dumpversion 5.5.0 $ /opt/csw/bin/g++ cow.cpp -o cow $ ./cow std::string is NOT COW. $ /usr/sfw/bin/g++ -dumpversion 3.4.3 $ /usr/sfw/bin/g++ cow.cpp -o cow $ ./cow std::string is COW. Then I tried it on cygwin: $ g++ cow.cpp -o cow $ ./cow std::string is NOT COW. and all of this despite the fact that _GLIBCXX_USE_CXX11_ABI=0 on cygwin. I am very confused, but the build I obtained by manually commenting out STD_STRING_USES_COW in config.h (and changing nothing else, e.g., leaving USE_GLIBCXX_CXX11_ABI commented out) is working fine until now. So, maybe the define for STD_STRING_USES_COW should be performed by actually directly testing for it (as in the attached) rather than inferring it from _GLIBCXX_USE_CXX11_ABI? -- Enrico // https://stackoverflow.com/questions/4496150/programmatically-determine-if-stdstring-uses-copy-on-write-cow-mechanism #include #include bool stdstring_supports_cow() { //make sure the string is longer than the size of potential //implementation of small-string. std::string s1 = "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789"; std::string s2 = s1; std::string s3 = s2; bool result1 = s1.data() == s2.data(); bool result2 = s1.data() == s3.data(); s2[0] = 'X'; bool result3 = s1.data() != s2.data(); bool result4 = s1.data() == s3.data(); s3[0] = 'X'; bool result5 = s1.data() != s3.data(); return result1 && result2 && result3 && result4 && result5; } int main() { if (stdstring_supports_cow()) std::cout << "std::string is COW." << std::endl; else std::cout << "std::string is NOT COW." << std::endl; return 0; } -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
Le 11/05/2023 à 23:04, Enrico Forestieri a écrit : Anyway, I don't think the autoconf test is broken because: From what I read here: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html this define is merely a default. It looks like one can choose to change it, as long as all the libraries you use (e.g. Qt) do the same. I have not been able to find the relevant git commit explining why this was done. JMarc $ diff -up /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/c++config.h /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/c++config.h | grep -C1 _GLIBCXX_USE_CXX11_ABI #ifndef _GLIBCXX_USE_CXX11_ABI -# define _GLIBCXX_USE_CXX11_ABI 0 +# define _GLIBCXX_USE_CXX11_ABI 1 #endif -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
Le 11/05/2023 à 19:59, Enrico Forestieri a écrit : Is this somthing special about cygwin or is our autoconf test broken? The former, I think. This is what I get when comparing cygwin and native windows configuration: $ diff -up build-cygwin/config.h build-win32/config.h | grep -B1 STD_STRING /* std::string uses copy-on-write */ -#define STD_STRING_USES_COW 1 +/* #undef STD_STRING_USES_COW */ So, cygwin is using COW in the std::string implementation... Or our test is broken on cywin... I think the new thread-safe string type is required for C++11 compliance. JMarc -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
On Thu, May 11, 2023 at 08:51:13PM +0200, Enrico Forestieri wrote: On Thu, May 11, 2023 at 07:59:48PM +0200, Enrico Forestieri wrote: On Thu, May 11, 2023 at 04:32:45PM +0200, Jean-Marc Lasgouttes wrote: Is this somthing special about cygwin or is our autoconf test broken? The former, I think. Or not, maybe, see below. This is what I get when comparing cygwin and native windows configuration: $ diff -up build-cygwin/config.h build-win32/config.h | grep -B1 STD_STRING /* std::string uses copy-on-write */ -#define STD_STRING_USES_COW 1 +/* #undef STD_STRING_USES_COW */ So, cygwin is using COW in the std::string implementation... I hacked config.h by undefining STD_STRING_USES_COW and recompiled. LyX does not crash anymore and works fine, seemingly... Anyway, I don't think the autoconf test is broken because: $ diff -up /usr/lib/gcc/x86_64-pc-cygwin/11/include/c++/x86_64-pc-cygwin/bits/c++config.h /usr/lib/gcc/x86_64-w64-mingw32/11/include/c++/x86_64-w64-mingw32/bits/c++config.h | grep -C1 _GLIBCXX_USE_CXX11_ABI #ifndef _GLIBCXX_USE_CXX11_ABI -# define _GLIBCXX_USE_CXX11_ABI 0 +# define _GLIBCXX_USE_CXX11_ABI 1 #endif -- Enrico -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
On Thu, May 11, 2023 at 07:59:48PM +0200, Enrico Forestieri wrote: On Thu, May 11, 2023 at 04:32:45PM +0200, Jean-Marc Lasgouttes wrote: Is this somthing special about cygwin or is our autoconf test broken? The former, I think. Or not, maybe, see below. This is what I get when comparing cygwin and native windows configuration: $ diff -up build-cygwin/config.h build-win32/config.h | grep -B1 STD_STRING /* std::string uses copy-on-write */ -#define STD_STRING_USES_COW 1 +/* #undef STD_STRING_USES_COW */ So, cygwin is using COW in the std::string implementation... I hacked config.h by undefining STD_STRING_USES_COW and recompiled. LyX does not crash anymore and works fine, seemingly... -- Enrico -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
On Thu, May 11, 2023 at 04:32:45PM +0200, Jean-Marc Lasgouttes wrote: Le 11/05/2023 à 15:26, Jean-Marc Lasgouttes a écrit : In file included from ../../../../src/frontends/qt/Toolbars.cpp:15: ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::from() const’: ../../../../src/Converter.h:55:51: warning: returning reference to temporary [-Wreturn-local-addr] 55 | std::string const & from() const { return from_; } | ^ Does this warning make any sense to you? What do I miss? I get no warning here. OK, I get it now this happens when using trivstring instead of plain std:string. I do not understand why this happens for you with gcc 11. I thought the new ABI wa savailable with gcc 5? Is this somthing special about cygwin or is our autoconf test broken? The former, I think. This is what I get when comparing cygwin and native windows configuration: $ diff -up build-cygwin/config.h build-win32/config.h | grep -B1 STD_STRING /* std::string uses copy-on-write */ -#define STD_STRING_USES_COW 1 +/* #undef STD_STRING_USES_COW */ So, cygwin is using COW in the std::string implementation... -- Enrico -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
Le 11/05/2023 à 15:26, Jean-Marc Lasgouttes a écrit : In file included from ../../../../src/frontends/qt/Toolbars.cpp:15: ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::from() const’: ../../../../src/Converter.h:55:51: warning: returning reference to temporary [-Wreturn-local-addr] 55 | std::string const & from() const { return from_; } | ^ Does this warning make any sense to you? What do I miss? I get no warning here. OK, I get it now this happens when using trivstring instead of plain std:string. I do not understand why this happens for you with gcc 11. I thought the new ABI wa savailable with gcc 5? Is this somthing special about cygwin or is our autoconf test broken? Anyway the patch should remain reverted until we remove support for gcc 4.9 (which we could IMO). JMarc -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
Le 10/05/2023 à 23:19, Enrico Forestieri a écrit : After this commit my cygwin build crashes badly at startup. I can't even get a backtrace. What is strange is that a native Windows build works fine, instead. Both builds use the same version of gcc: OK, I'll revert for now. However I get a lot of warnings like the following: In file included from ../../../../src/frontends/qt/Toolbars.cpp:15: ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::from() const’: ../../../../src/Converter.h:55:51: warning: returning reference to temporary [-Wreturn-local-addr] 55 | std::string const & from() const { return from_; } | ^ Does this warning make any sense to you? What do I miss? I get no warning here. JMarc -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
On Wed, May 10, 2023 at 11:21:04AM +0200, Jean-Marc Lasgouttes wrote: Le 09/05/2023 à 22:08, Enrico Forestieri a écrit : On Fri, May 05, 2023 at 07:28:59PM +0200, Jean-Marc Lasgouttes wrote: commit 3ae5d6bdec1df23cc0d848b2d8bf6b09323b Author: Jean-Marc Lasgouttes Date: Fri May 5 20:35:23 2023 +0200 Do not return copies of string members This fixes the g++ 12 warnings below. After this commit my cygwin build crashes badly at startup. I can't even get a backtrace. What is strange is that a native Windows build works fine, instead. Both builds use the same version of gcc: Strange... Did you try to run it under valgrind or something similar? Unfortunately valgrind is not available on cygwin and I don't know of any other similar software. I do not see that. Valgrind output horrors (more on that later), but not related to this. Did you check whether a full rebuild helps? No, it does not. Simply reverting the commit solves the issue. However I get a lot of warnings like the following: In file included from ../../../../src/frontends/qt/Toolbars.cpp:15: ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::from() const’: ../../../../src/Converter.h:55:51: warning: returning reference to temporary [-Wreturn-local-addr] 55 | std::string const & from() const { return from_; } | ^ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::to() const’: ../../../../src/Converter.h:57:49: warning: returning reference to temporary [-Wreturn-local-addr] 57 | std::string const & to() const { return to_; } | ^~~ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::command() const’: ../../../../src/Converter.h:59:54: warning: returning reference to temporary [-Wreturn-local-addr] 59 | std::string const & command() const { return command_; } | ^~~~ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::flags() const’: ../../../../src/Converter.h:63:52: warning: returning reference to temporary [-Wreturn-local-addr] 63 | std::string const & flags() const { return flags_; } |^~ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::latex_flavor() const’: ../../../../src/Converter.h:77:59: warning: returning reference to temporary [-Wreturn-local-addr] 77 | std::string const & latex_flavor() const { return latex_flavor_; } | ^ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::result_dir() const’: ../../../../src/Converter.h:87:57: warning: returning reference to temporary [-Wreturn-local-addr] 87 | std::string const & result_dir() const { return result_dir_; } | ^~~ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::result_file() const’: ../../../../src/Converter.h:89:58: warning: returning reference to temporary [-Wreturn-local-addr] 89 | std::string const & result_file() const { return result_file_; } | ^~~~ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::parselog() const’: ../../../../src/Converter.h:91:55: warning: returning reference to temporary [-Wreturn-local-addr] 91 | std::string const & parselog() const { return parselog_; } | ^ ../../../../src/Converter.h: In member function ‘const string& lyx::Converter::hyperref_driver() const’: ../../../../src/Converter.h:93:62: warning: returning reference to temporary [-Wreturn-local-addr] 93 | std::string const & hyperref_driver() const { return href_driver_; } | ^~~~ -- Enrico -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
Le 09/05/2023 à 22:08, Enrico Forestieri a écrit : On Fri, May 05, 2023 at 07:28:59PM +0200, Jean-Marc Lasgouttes wrote: commit 3ae5d6bdec1df23cc0d848b2d8bf6b09323b Author: Jean-Marc Lasgouttes Date: Fri May 5 20:35:23 2023 +0200 Do not return copies of string members This fixes the g++ 12 warnings below. After this commit my cygwin build crashes badly at startup. I can't even get a backtrace. What is strange is that a native Windows build works fine, instead. Both builds use the same version of gcc: Strange... Did you try to run it under valgrind or something similar? I do not see that. Valgrind output horrors (more on that later), but not related to this. Did you check whether a full rebuild helps? JMarc -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: [LyX/master] Do not return copies of string members
On Fri, May 05, 2023 at 07:28:59PM +0200, Jean-Marc Lasgouttes wrote: commit 3ae5d6bdec1df23cc0d848b2d8bf6b09323b Author: Jean-Marc Lasgouttes Date: Fri May 5 20:35:23 2023 +0200 Do not return copies of string members This fixes the g++ 12 warnings below. After this commit my cygwin build crashes badly at startup. I can't even get a backtrace. What is strange is that a native Windows build works fine, instead. Both builds use the same version of gcc: $ g++ -dumpfullversion 11.3.0 $ x86_64-w64-mingw32-g++ -dumpfullversion 11.3.0 I am baffled. ../../master/src/Converter.cpp:714:55: warning: possibly dangling reference to a temporary [-Wdangling-reference] 714 | Mover const & mover = getMover(conv.to()); | ^ ../../master/src/Converter.cpp:714:71: note: the temporary was destroyed at the end of the full expression ‘lyx::getMover(lyx::Converter::to() const())’ 714 | Mover const & mover = getMover(conv.to()); | ^~~ ../../master/src/Converter.cpp:786:39: warning: possibly dangling reference to a temporary [-Wdangling-reference] 786 | Mover const & mover = getMover(conv.from()); | ^ ../../master/src/Converter.cpp:786:55: note: the temporary was destroyed at the end of the full expression ‘lyx::getMover(lyx::Converter::from() const())’ 786 | Mover const & mover = getMover(conv.from()); --- src/Converter.h | 18 +- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Converter.h b/src/Converter.h index 091dbcd..9e8249d 100644 --- a/src/Converter.h +++ b/src/Converter.h @@ -52,15 +52,15 @@ public: /// void readFlags(); /// - std::string const from() const { return from_; } + std::string const & from() const { return from_; } /// - std::string const to() const { return to_; } + std::string const & to() const { return to_; } /// - std::string const command() const { return command_; } + std::string const & command() const { return command_; } /// void setCommand(std::string const & command); /// - std::string const flags() const { return flags_; } + std::string const & flags() const { return flags_; } /// void setFlags(std::string const & flags) { flags_ = flags; } /// @@ -74,7 +74,7 @@ public: /// bool latex() const { return latex_; } /// - std::string const latex_flavor() const { return latex_flavor_; } + std::string const & latex_flavor() const { return latex_flavor_; } /// bool docbook() const { return docbook_; } /// @@ -84,13 +84,13 @@ public: /// bool nice() const { return nice_; } /// - std::string const result_dir() const { return result_dir_; } + std::string const & result_dir() const { return result_dir_; } /// - std::string const result_file() const { return result_file_; } + std::string const & result_file() const { return result_file_; } /// - std::string const parselog() const { return parselog_; } + std::string const & parselog() const { return parselog_; } /// - std::string const hyperref_driver() const { return href_driver_; } + std::string const & hyperref_driver() const { return href_driver_; } private: /// -- lyx-cvs mailing list lyx-...@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs -- Enrico -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel