2017-12-27 4 views
-3

Sincerelly 그래서 C++ RAII 기능을 갖춘 전문가가 아니에요. 나는 결코 전에 사용하지 않았다. 어쨌든 나는 그것에 대해 공부하기 시작했다. ("커널 패닉"에서). 나는 다음과 같은 오류가있는 모듈을 컴파일 :Unique_ptr의 C++ 사용

In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’: 
/usr/include/c++/6/bits/unique_ptr.h:539:9: required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’ 
java/rocksjni/compaction_filter_factory_jnicallback.cc:33:58: required from here 
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0, 
       from /usr/include/c++/6/bits/stl_algobase.h:64, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&) 
    swap(_Tp& __a, _Tp& __b) 
    ^~~~ 
/usr/include/c++/6/bits/move.h:179:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’) 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0, 
       from /usr/include/c++/6/bits/stl_algobase.h:64, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm]) 
    swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) 
    ^~~~ 
/usr/include/c++/6/bits/move.h:202:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&) 
    swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 
    ^~~~ 
/usr/include/c++/6/bits/stl_pair.h:471:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/string:52:0, 
       from /usr/include/c++/6/stdexcept:39, 
       from /usr/include/c++/6/array:39, 
       from /usr/include/c++/6/tuple:39, 
       from /usr/include/c++/6/functional:55, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) 
    swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, 
    ^~~~ 
/usr/include/c++/6/bits/basic_string.h:5287:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/tuple:39:0, 
       from /usr/include/c++/6/functional:55, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&) 
    swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) 
    ^~~~ 
/usr/include/c++/6/array:275:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/functional:55:0, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&) 
    swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) 
    ^~~~ 
/usr/include/c++/6/tuple:1546:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/memory:79:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&) 
    swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) 
    ^~~~ 
/usr/include/c++/6/functional:2238:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13, 
       from java/rocksjni/compaction_filter_factory_jnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’: 
/usr/include/c++/6/bits/unique_ptr.h:539:9: required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’ 
java/rocksjni/comparatorjnicallback.cc:34:21: required from here 
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0, 
       from /usr/include/c++/6/bits/stl_algobase.h:64, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&) 
    swap(_Tp& __a, _Tp& __b) 
    ^~~~ 
/usr/include/c++/6/bits/move.h:179:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’) 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0, 
       from /usr/include/c++/6/bits/stl_algobase.h:64, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm]) 
    swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) 
    ^~~~ 
/usr/include/c++/6/bits/move.h:202:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0, 
       from /usr/include/c++/6/memory:62, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&) 
    swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 
    ^~~~ 
/usr/include/c++/6/bits/stl_pair.h:471:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/string:52:0, 
       from /usr/include/c++/6/stdexcept:39, 
       from /usr/include/c++/6/array:39, 
       from /usr/include/c++/6/tuple:39, 
       from /usr/include/c++/6/functional:55, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) 
    swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, 
    ^~~~ 
/usr/include/c++/6/bits/basic_string.h:5287:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/tuple:39:0, 
       from /usr/include/c++/6/functional:55, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&) 
    swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two) 
    ^~~~ 
/usr/include/c++/6/array:275:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/functional:55:0, 
       from /usr/include/c++/6/memory:79, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&) 
    swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y) 
    ^~~~ 
/usr/include/c++/6/tuple:1546:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 
    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ 
In file included from /usr/include/c++/6/memory:79:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&) 
    swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) 
    ^~~~ 
/usr/include/c++/6/functional:2238:5: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/6/memory:81:0, 
       from ./java/./rocksjni/comparatorjnicallback.h:13, 
       from java/rocksjni/comparatorjnicallback.cc:9: 
/usr/include/c++/6/bits/unique_ptr.h:614:6: note: mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’ 
    swap(std::get<0>(_M_t), __p); 

나는이 스택 트레이스를 이해하기 모르겠어요하지만 unique_ptr에 일치하지 않는 솔기. 어쩌면 const char *와 char *.

버그가있는 클래스입니다 :

CompactionFilterFactoryJniCallback::CompactionFilterFactoryJniCallback(
    JNIEnv* env, jobject jcompaction_filter_factory) 
    : JniCallback(env, jcompaction_filter_factory) { 

    // Note: The name of a CompactionFilterFactory will not change during 
    // it's lifetime, so we cache it in a global var 
    jmethodID jname_method_id = 
     AbstractCompactionFilterFactoryJni::getNameMethodId(env); 
    if(jname_method_id == nullptr) { 
    // exception thrown: NoSuchMethodException or OutOfMemoryError 
    return; 
    } 

    jstring jname = 
     (jstring)env->CallObjectMethod(m_jcallback_obj, jname_method_id); 
    if(env->ExceptionCheck()) { 
    // exception thrown 
    return; 
    } 
    jboolean has_exception = JNI_FALSE; 
// line 33 
    m_name = JniUtil::copyString(env, jname, &has_exception); // also releases jname 
    if (has_exception == JNI_TRUE) { 
    // exception thrown 
    return; 
    } 

    m_jcreate_compaction_filter_methodid = 
     AbstractCompactionFilterFactoryJni::getCreateCompactionFilterMethodId(env); 
    if(m_jcreate_compaction_filter_methodid == nullptr) { 
    // exception thrown: NoSuchMethodException or OutOfMemoryError 
    return; 
    } 
} 

const char* CompactionFilterFactoryJniCallback::Name() const { 
    return m_name.get(); 
} 

std::unique_ptr<CompactionFilter> CompactionFilterFactoryJniCallback::CreateCompactionFilter(
    const CompactionFilter::Context& context) { 
    jboolean attached_thread = JNI_FALSE; 
    JNIEnv* env = getJniEnv(&attached_thread); 
    assert(env != nullptr); 

    jlong addr_compaction_filter = env->CallLongMethod(m_jcallback_obj, 
     m_jcreate_compaction_filter_methodid, 
     static_cast<jboolean>(context.is_full_compaction), 
     static_cast<jboolean>(context.is_manual_compaction)); 

    if(env->ExceptionCheck()) { 
    // exception thrown from CallLongMethod 
    env->ExceptionDescribe(); // print out exception to stderr 
    releaseJniEnv(attached_thread); 
    return nullptr; 
    } 

    auto* const cff = reinterpret_cast<CompactionFilter*>(addr_compaction_filter); 

    releaseJniEnv(attached_thread); 

    return std::unique_ptr<CompactionFilter>(cff); 
} 

문제를 식별하기위한이 스택 트레이스를 읽는 방법을 명확하지 않다. 문제를 수정하고 스택 추적을 읽는 방법에 대한 약간의 제안을 보내 주시면 감사하겠습니다.

+2

라인은 라인 33을? 'm_name'의 타입은 무엇입니까? – cpplearner

+0

'CompactionFilter' 클래스의 정의는 무엇입니까? 'unique_ptr'을 사용하지 않고이 방법으로 만든'CompactionFilter' 사용을 마쳤 으면, 어떻게 제거 할 수 있습니까? –

+0

코드를 [mcve]로 좁히십시오. –

답변

0

오류는 사용자가 reset을 호출하려고 시도한 std::unique_ptr<char const[]> 개체를 가지고 있으며 char*을 인수로 전달합니다.

글쎄, 그 인수는이 const_cast 달성 할 수 컴파일 할 char const*, 할 필요가 예 :

std::unique_ptr<char const[]> p; 
char* q = new char[1]{}; 
p.reset(const_cast<char const*>(q)); 

JniUtil::copyString 반환 std::unique_ptr<char[]> 같은데 및 일으키는 당신은 std::unique_ptr<char const[]>에 할당 오류. std::unique_ptr<char[]>을 할

한 수정 m_name의 유형을 변경하는 것입니다.

또 다른 수동 const와를 추가하는 것입니다 (추가 const와 안전하고 암시 적 변환이지만, std::unique_ptr<>::reset의 올바른 과부하 선택하려면 여기를 필요) :

m_name.reset(const_cast<char const*>(JniUtil::copyString(...).release())); 
+0

'const_cast'는 매우, 아주 * 아주 드물게 정확한 해결책입니다. –

+0

@JesperJuhl 당신은 오히려 완벽하게 안전하고 암시 적 변환 인을 제거하는 것보다, const와를 추가하고, 여기에'const_cast'에 대해 생각합니다. –

+0

m_name.reset (const_cast (JniUtil :: copyString (env, jname, & has_exception)))); // 또한 출시 jname ---> 자바/rocksjni/compaction_filter_factory_jnicallback.cc : 34 : 90 : 오류 : 타입 '표준 : unique_ptr'에서 무효에 const_cast는 '숯불 *의 CONST' m_name.reset (에 const_cast <문자를 입력합니다 * const> (JniUtil :: copyString (env, jname, & has_exception)))); // 또한 jname을 해제합니다. –

관련 문제