简体   繁体   English

分配 std::function 导致段错误

[英]Assigning std::function causes segfault

I have a strange segmentation fault I am unable to properly understand.我有一个奇怪的分段错误,我无法正确理解。 I am creating a function object with std::bind, then assign this to a std::function object, this apparently results in a segfault.我正在使用 std::bind 创建一个函数对象,然后将它分配给一个 std::function 对象,这显然会导致段错误。

std::function<ara::com::Future<SetShapeOutput>(const 
                    messages::test::SetShapeParams&)> SetShape_callback_;

void set_SetShape_callback(const std::function<ara::com::Future<SetShapeOutput>(
        const messages::test::SetShapeParams&)>& callback) {
    SetShape_callback_ = callback;
}

[somewhere else] [别的地方]

algo_service_.GetshapeServiceSkeleton()->set_SetShape_callback(
                            std::bind(&ShapeServerAraBinding::on_call_serviceshapeService_methodSetShape,
                                    this, std::placeholders::_1));



// definition
ara::com::Future<adaptiveautosarapplication::shapeServiceSkeleton::SetShapeOutput>
                on_call_serviceshapeService_methodSetShape(
                    const messages::test::SetShapeParams& araSetShapeParams);

And the stacktrace from gdb showing the assignment causes a segfault:来自 gdb 的堆栈跟踪显示分配会导致段错误:

#0  0x000055c45c268839 in std::swap<std::_Any_data> (__a=..., __b=...) at /usr/include/c++/6/bits/move.h:191
#1  0x000055c45c267781 in std::function<ara::com::Future<serviceInterfaces::test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)>::swap(s
td::function<ara::com::Future<serviceInterfaces::test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)>&) (this=0x7fffea5d6be0, __x=...)
    at /usr/include/c++/6/functional:2016
#2  0x000055c45c263934 in std::function<ara::com::Future<serviceInterfaces::test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)>::operat
or=(std::function<ara::com::Future<serviceInterfaces::test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)> const&) (this=0x58, __x=...)
    at /usr/include/c++/6/functional:1931
#3  0x000055c45c26009f in shapeServer::adaptiveautosarapplication::shapeServiceSkeleton::set_SetShape_callback(std::function<ara::com::Future<serviceInterfaces:
:test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)> const&) (this=0x0, callback=...)
    at /app/tests/eclipseProject/projects/shapeRPC/build/autogen/algos/shape/server/ara/include/shapeServer_service.h:40
#4  0x000055c45c260508 in shapeServer::ShapeServerAraBinding::Initialize (this=0x7fffea5d6dd0)
    at /app/tests/eclipseProject/projects/shapeRPC/build/autogen/algos/shape/server/ara/include/shapeServerAraBinding.h:69
#5  0x000055c45c25854c in main (argc=1, argv=0x7fffea5d6fd8)
    at /app/tests/eclipseProject/projects/shapeRPC/build/autogen/algos/shape/server/ara/src/shapeServerAraMain.cpp:108

The problem cause is shown in the following line:问题原因显示在以下行中:

#3  0x000055c45c26009f in shapeServer::adaptiveautosarapplication::shapeServiceSkeleton::set_SetShape_callback(std::function<ara::com::Future<serviceInterfaces:
:test::shapeService::SetShapeOutput> (messages::test::SetShapeParams const&)> const&) (this=0x0, callback=...)

Note shapeServiceSkeleton this=0x0 .注意shapeServiceSkeleton this=0x0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM