[LyX/master] Add move constructor and move assignment operator for FileName class
Stephan Witt
st.witt at gmx.net
Thu Jan 14 18:02:48 UTC 2021
Am 14.01.2021 um 17:57 schrieb Stephan Witt <st.witt at gmx.net>:
>
> Am 14.01.2021 um 17:09 schrieb Stephan Witt <st.witt at gmx.net>:
>>
>> Am 14.01.2021 um 09:30 schrieb Yuriy Skalko <yuriy.skalko at gmail.com>:
>>>
>>>> Sorry, I’ve reverted the change for now locally. I can answer your questions later…
>>>> Perhaps the compiler flags of the autotools build are of interest (but cmake build crashes either):
>>>> Configuration
>>>> Host type: x86_64-apple-darwin18.7.0
>>>> Special build flags: build=release warnings callback-printing use-hunspell use-aspell
>>>> Bundled libraries: nod boost mythes
>>>> C++ Compiler: c++ -stdlib=libc++ (11.0.0)
>>>> C++ Compiler flags: -Wall -Wextra -fPIC -Os -std=c++17 -Wno-deprecated-register
>>>> C++ Compiler user flags: -I/Users/Shared/LyX/utilities/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
>>>> -arch x86_64 -mmacosx-version-min=10.10 -std=c++17 -std=c++11
>>>> Linker flags: -rdynamic
>>>> Linker user flags: -L/Users/Shared/LyX/utilities/lib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
>>>> -arch x86_64 -mmacosx-version-min=10.10
>>>> Qt Frontend:
>>>> Qt version: 5.12.9
>>>> Packaging: macosx
>>>> Are all these library and compiler standard choice switches compatible and correct?
>>>> Stephan
>>>
>>>
>>> Thanks for testing Stephan and Scott.
>>> So seems like it is macos-only issue. I see nothing suspicious in your compiler flags (are you manually override default C++17 to C++11?).
>>
>> Yes, in the past I was forced to do so. I’ll try to work with consistent compiler switches.
>>
>> Should it work w/o -std=c++17? What do expect to happen with different compiler switches for build of Qt-libs and LyX?
>
> Ok, it doesn’t work on Apple with c++17 w/o loosing backwards compatibility and many warnings about deprecated classes:
>
> Configuration
> Host type: x86_64-apple-darwin18.7.0
> Special build flags: build=release warnings callback-printing use-hunspell use-aspell
> Bundled libraries: nod boost mythes
> C++ Compiler: c++ -stdlib=libc++ (11.0.0)
> C++ Compiler flags: -Wall -Wextra -fPIC -Os -std=c++17 -Wno-deprecated-register
> C++ Compiler user flags: -I/Users/Shared/LyX/utilities/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -arch x86_64 -mmacosx-version-min=10.10 -std=c++17 -std=c++17
> Linker flags: -rdynamic
> Linker user flags: -L/Users/Shared/LyX/utilities/lib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -arch x86_64 -mmacosx-version-min=10.10
>
> The show stopper with -mmacosx-version-min=10.10 is:
>
> /Users/stephan/git/lyx/src/insets/ExternalTransforms.cpp:334:20: error: 'any_cast<std::__1::function<std::__1::unique_ptr<const lyx::external::TransformCommand, std::__1::default_delete<const
> lyx::external::TransformCommand> > (lyx::external::RotationData)> >' is unavailable: introduced in macOS 10.14
> Factory factory = any_cast<Factory>(any_factory);
>
> Using -mmacosx-version-min=10.14 as suggested I’m able to build LyX - but after revert of the revert (add move constructor again) it crashes again.
>
> Using -mmacosx-version-min=10.10 and c++11 consistently it crashes too.
I used the debugger to bring some light into it.
The crash is at lastfiles.insert:
========================
void LastFilesSection::add(FileName const & file)
{
// If file already exist, delete it and reinsert at front.
LastFiles::iterator it = find(lastfiles.begin(), lastfiles.end(), file);
if (it != lastfiles.end())
lastfiles.erase(it);
lastfiles.insert(lastfiles.begin(), file);
if (lastfiles.size() > num_lastfiles)
lastfiles.pop_back();
}
========================
This is the implementation of vector::insert()
========================
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
__RAII_IncreaseAnnotator __annotator(*this);
if (__p == this->__end_)
{
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_raw_pointer(this->__end_), __x);
++this->__end_;
}
else
{
__move_range(__p, this->__end_, __p + 1);
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
if (__p <= __xr && __xr < this->__end_)
++__xr;
*__p = *__xr; <====== here it crashes
}
__annotator.__done();
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
__v.push_back(__x);
__p = __swap_out_circular_buffer(__v, __p);
}
return __make_iter(__p);
}
========================
And this is the __move_range allocator:
========================
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
{
pointer __old_last = this->__end_;
difference_type __n = __old_last - __to;
for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_raw_pointer(this->__end_),
_VSTD::move(*__i));
_VSTD::move_backward(__from_s, __from_s + __n, __old_last);
}
========================
Here the member d is a nullptr:
========================
FileName & FileName::operator=(FileName const & rhs)
{
if (&rhs == this)
return *this;
d->name = rhs.d->name;
d->fi = rhs.d->fi;
return *this;
}
========================
I don’t know if this is helpful.
Stephan
More information about the lyx-devel
mailing list