Boost logo

Boost Users :

Subject: [Boost-users] Convert boost::shared_ptr to std::shared_ptr for boost::dll::import
From: David Demelier (markand_at_[hidden])
Date: 2018-04-12 19:48:24


Hello,

In my application I use std::shared_ptr in the public API for loading
plugins. I wanted to use boost::dll to import dynamically plugins as
well.

It looks like for some reasons that it still use boost::shared_ptr
instead of std::shared_ptr even though C++11 is 7 years old.

I wanted to convert the boost shared_ptr to std with the following
function:

std::shared_ptr<plugin> load(boost::shared_ptr<plugin> ptr)
{
    return std::shared_ptr<plugin>(ptr.get(), [ptr] (auto) {});
}

It works at perfectly at runtime, however my application segfaults at
end, when destroying objects. I suspect that it's because the internal
boost::dll shared_library is destroyed **before** my own shared_ptr.

The backtrace:

(gdb) bt
#0 0x00007ffff3f054d8 in ?? ()
#1 0x00007fffffffdb80 in ?? ()
#2 0x00007ffff4109400 in ?? ()
#3 0x00007ffff4add6f8 in _nl_current_default_domain () from
/lib64/libc.so.6
#4 0x00007ffff47641d8 in __run_exit_handlers () from /lib64/libc.so.6
#5 0x00007ffff476422a in exit () from /lib64/libc.so.6
#6 0x00007ffff474df31 in __libc_start_main () from /lib64/libc.so.6
#7 0x0000000000413c1a in _start ()

Is there any chance I can safely convert the smart pointer?

Regards,

-- 
David

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net