@@ -47,6 +47,14 @@ namespace sqlite {
47
47
WrapIntoFunctor (ReturnType(*ptr)(Arguments...)): ptr(ptr) {}
48
48
ReturnType operator ()(Arguments... arguments) { return (*ptr)(std::forward<Arguments>(arguments)...); }
49
49
};
50
+ inline void store_error_log_data_pointer (std::shared_ptr<void > ptr) {
51
+ static std::shared_ptr<void > stored;
52
+ stored = std::move (ptr);
53
+ }
54
+ template <class T >
55
+ std::shared_ptr<typename std::decay<T>::type> make_shared_inferred (T &&t) {
56
+ return std::make_shared<typename std::decay<T>::type>(std::forward<T>(t));
57
+ }
50
58
}
51
59
template <class Handler >
52
60
typename std::enable_if<!detail::is_callable<Handler(const sqlite_exception&)>::value>::type
@@ -67,7 +75,7 @@ namespace sqlite {
67
75
template <class Handler >
68
76
typename std::enable_if<detail::is_callable<Handler(const sqlite_exception&)>::value>::type
69
77
error_log (Handler &&handler) {
70
- auto ptr = new auto ([handler = std::forward<Handler>(handler)](int error_code, const char *errstr) mutable {
78
+ auto ptr = detail::make_shared_inferred ([handler = std::forward<Handler>(handler)](int error_code, const char *errstr) mutable {
71
79
switch (error_code & 0xFF ) {
72
80
#define SQLITE_MODERN_CPP_ERROR_CODE (NAME,name,derived ) \
73
81
case SQLITE_ ## NAME: switch (error_code) { \
@@ -84,8 +92,10 @@ namespace sqlite {
84
92
default : handler (sqlite_exception (errstr, " " , error_code)); \
85
93
}
86
94
});
95
+
87
96
sqlite3_config (SQLITE_CONFIG_LOG, (void (*)(void *,int ,const char *))[](void *functor, int error_code, const char *errstr) {
88
- (*static_cast <decltype (ptr)>(functor))(error_code, errstr);
89
- }, ptr);
97
+ (*static_cast <decltype (ptr.get ())>(functor))(error_code, errstr);
98
+ }, ptr.get ());
99
+ detail::store_error_log_data_pointer (std::move (ptr));
90
100
}
91
101
}
0 commit comments