RSQLite
RSQLite copied to clipboard
Crash after including cpp11 headers
This PR is based on a state before we used the cpp11 package.
The first commit adds a test script. The second commit includes a single file from cpp11 and leads to a segmentation fault in the test script. Why?
Downstream issue: dm tests on my machine not stopping (or segfaulting) for the RSQLite variant.
The backtrace in the debugger shows an interaction between duckdb and RSQLite that I can't quite fully grasp:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xffff11000000)
frame #0: 0x000000012cb90344 RSQLite.so`std::__1::__tuple_leaf<0ul, SEXPREC*&, false>::get[abi:v15006](this=0x0000ffff11000000) at tuple:358:102
355 return 0;
356 }
357
-> 358 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
359 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
360 };
361
Target 0: (R) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xffff11000000)
* frame #0: 0x000000012cb90344 RSQLite.so`std::__1::__tuple_leaf<0ul, SEXPREC*&, false>::get[abi:v15006](this=0x0000ffff11000000) at tuple:358:102
frame #1: 0x000000012cb90304 RSQLite.so`std::__1::tuple_element<0ul, std::__1::tuple<SEXPREC*&, char const*&> >::type&& std::__1::get[abi:v15006]<0ul, SEXPREC*&, char const*&>(__t=size=2) at tuple:1375:66
frame #2: 0x000000012cb902ec RSQLite.so`decltype(f=0x000000016fdfe7d0, a=size=2, (null)=0x000000016fdfe42f)(SEXPREC*, char const*, ...)>()(std::declval<SEXPREC*&>(), std::declval<char const*&>())) cpp11::detail::apply<void (*&)(SEXPREC*, char const*, ...), SEXPREC*&, char const*&, 0ul, 1ul>(void (*&)(SEXPREC*, char const*, ...), std::__1::tuple<SEXPREC*&, char const*&>&&, cpp11::detail::index_sequence<0ul, 1ul> const&) at protect.hpp:194:10
frame #3: 0x000000012cb90290 RSQLite.so`decltype(f=0x000000016fdfe7d0, a=size=2)(SEXPREC*, char const*, ...)>()(std::declval<SEXPREC*&>(), std::declval<char const*&>())) cpp11::detail::apply<void (*&)(SEXPREC*, char const*, ...), SEXPREC*&, char const*&>(void (*&)(SEXPREC*, char const*, ...), std::__1::tuple<SEXPREC*&, char const*&>&&) at protect.hpp:200:10
frame #4: 0x000000012cb90260 RSQLite.so`cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>::operator(this=0x000000016fdfe7d0)() && at protect.hpp:213:12
frame #5: 0x000000012cb901c8 RSQLite.so`void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(this=0x000000016fdfe7e8), SEXPREC*&, char const*&>&&)::'lambda'()::operator()() const at protect.hpp:145:5
frame #6: 0x000000012cb903b4 RSQLite.so`SEXPREC* cpp11::unwind_protect<void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(), void>(this=0x000000016fdfe7e8, data=0x000000016fdfe7e8), SEXPREC*&, char const*&>&&)::'lambda'(void*)::operator()(void*) const at protect.hpp:118:16
frame #7: 0x000000012cb90384 RSQLite.so`SEXPREC* cpp11::unwind_protect<void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(), void>(data=0x000000016fdfe7e8), SEXPREC*&, char const*&>&&)::'lambda'(void*)::__invoke(void*) at protect.hpp:116:7
frame #8: 0x0000000100498cf8 libR.dylib`R_UnwindProtect(fun=(RSQLite.so`SEXPREC* cpp11::unwind_protect<void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(), void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(void*)::__invoke(void*) at protect.hpp:116), data=0x000000016fdfe7e8, cleanfun=(RSQLite.so`SEXPREC* cpp11::unwind_protect<void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(), void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(void*, Rboolean)::__invoke(void*, Rboolean) at protect.hpp:121), cleandata=0x000000016fdfe6c8, cont=0x000000012d166548) at context.c:944:11 [opt]
frame #9: 0x0000000130a2e214 duckdb.so`SEXPREC* cpp11::unwind_protect<void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>&&)::'lambda'(), void>(code=0x000000016fdfe7e8), SEXPREC*&, char const*&>&&) at protect.hpp:104:14 [opt]
frame #10: 0x0000000130a2f970 duckdb.so`cpp11::external_pointer<duckdb::ConnWrapper, &duckdb::ConnDeleter(duckdb::ConnWrapper*)>::r_deleter(SEXPREC*) [inlined] void cpp11::unwind_protect<cpp11::detail::closure<void (SEXPREC*, char const*, ...), SEXPREC*&, char const*&>, void>(code=0x000000016fdfe7d0), SEXPREC*&, char const*&>&&) at protect.hpp:133:9 [opt]
frame #11: 0x0000000130a2f964 duckdb.so`cpp11::external_pointer<duckdb::ConnWrapper, &duckdb::ConnDeleter(duckdb::ConnWrapper*)>::r_deleter(SEXPREC*) [inlined] decltype(this=<unavailable>, a=<unavailable>, a=0x000000016fdfe7c8)(SEXPREC*, char const*, ...)>(0)) std::__1::declval<void (*)(SEXPREC*, char const*, ...)>()()(std::declval<SEXPREC*&>(), std::declval<char const*&>())) cpp11::protect::function<void (SEXPREC*, char const*, ...)>::operator()<SEXPREC*&, char const*&>(SEXPREC*&, char const*&) const at protect.hpp:216:14 [opt]
frame #12: 0x0000000130a2f944 duckdb.so`cpp11::external_pointer<duckdb::ConnWrapper, &duckdb::ConnDeleter(duckdb::ConnWrapper*)>::r_deleter(SEXPREC*) [inlined] void cpp11::warning<>(fmt="Connection is garbage-collected, use dbDisconnect() to avoid this.") at protect.hpp:292:3 [opt]
frame #13: 0x0000000130a2f944 duckdb.so`cpp11::external_pointer<duckdb::ConnWrapper, &duckdb::ConnDeleter(duckdb::ConnWrapper*)>::r_deleter(SEXPREC*) [inlined] duckdb::ConnDeleter(conn=0x00006000002203c0) at connection.cpp:6:2 [opt]
frame #14: 0x0000000130a2f944 duckdb.so`cpp11::external_pointer<duckdb::ConnWrapper, &duckdb::ConnDeleter(duckdb::ConnWrapper*)>::r_deleter(p=0x000000012b1502b0) at external_pointer.hpp:49:5 [opt]
frame #15: 0x0000000100534280 libR.dylib`R_RunWeakRefFinalizer(w=<unavailable>) at memory.c:1498:2 [opt]
frame #16: 0x00000001005347c0 libR.dylib`RunFinalizers at memory.c:1565:3 [opt]
frame #17: 0x0000000100534524 libR.dylib`R_RunExitFinalizers at memory.c:1595:5 [opt] [artificial]
frame #18: 0x00000001006116e0 libR.dylib`Rstd_CleanUp(saveact=SA_NOSAVE, status=0, runLast=<unavailable>) at sys-std.c:1233:5 [opt]
frame #19: 0x00000001006144e0 libR.dylib`R_CleanUp(saveact=<unavailable>, status=0, runLast=<unavailable>) at system.c:87:5 [opt]
frame #20: 0x00000001005301b0 libR.dylib`end_Rmainloop at main.c:1127:5 [opt]
frame #21: 0x0000000100530028 libR.dylib`run_Rmainloop at main.c:1138:5 [opt]
frame #22: 0x00000001005301d0 libR.dylib`Rf_mainloop at main.c:1144:5 [opt]
frame #23: 0x0000000100003ea0 R`main + 32
frame #24: 0x00000001ab75ff28 dyld`start + 2236
@Antonov548: Can you please take a look? What other info do you need?
This only seems to happen on macOS arm64, I don't see the failure in a Linux container.