drift
drift copied to clipboard
[Question] Is ffi's triginometric functions supported on isolate?
Is trigonometric functions such as sin, cos etc. supported in background isolate mode?
I think they should be supported, yes. We call Pointer.fromFunction on the same isolate where we send the queries.
Did you run into any issues with them on a background isolate?
Yes, there's assertion in void resultNum(num value) from moor_ffi-0.5.0\lib\src\bindings\types.dart
void resultNum(num value) {
if (value is int) {
resultInt(value);
} else if (value is double) {
resultDouble(value);
}
throw AssertionError();
}
value is 0.6427862172391164
It's true that that function is obviously broken and throws an assertion error each time. But I don't think that should have much of an impact, since tests pass and all Dart errors are silently swallowed in a ffi callback.
I've fixed that problem on develop, but did you really get a stacktrace on resultNum? If so, do you have a small repro for me to try out? Thanks!
Stack traces
SqliteFunctionContextPointer.resultNum (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\bindings\types.dart:123)
_unaryNumFunction (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:29)
_cosImpl (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:42)
PreparedStatement._step (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:148)
PreparedStatement.select (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:49)
_VmDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\vm_database.dart:97)
_ExecutorWithQueryDelegate.runSelect.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:41)
BasicLock.synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\synchronized-2.2.0\lib\src\basic_lock.dart:32)
_ExecutorWithQueryDelegate._synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:22)
_ExecutorWithQueryDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:39)
_MoorServer._runQuery (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:89)
<asynchronous gap> (Unknown Source:0)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:57)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:0)
IsolateCommunication.setRequestHandler.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\communication.dart:163)
_RootZone.runUnaryGuarded (dart:async/zone.dart:1374)
_BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
_DelayedData.perform (dart:async/stream_impl.dart:594)
_StreamImplEvents.handleNext (dart:async/stream_impl.dart:710)
_PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670)
SqliteFunctionContextPointer.resultNum (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\bindings\types.dart:123)
_unaryNumFunction (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:29)
_sinImpl (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:37)
PreparedStatement._step (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:148)
PreparedStatement.select (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:49)
_VmDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\vm_database.dart:97)
_ExecutorWithQueryDelegate.runSelect.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:41)
BasicLock.synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\synchronized-2.2.0\lib\src\basic_lock.dart:32)
_ExecutorWithQueryDelegate._synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:22)
_ExecutorWithQueryDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:39)
_MoorServer._runQuery (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:89)
<asynchronous gap> (Unknown Source:0)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:57)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:0)
IsolateCommunication.setRequestHandler.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\communication.dart:163)
_RootZone.runUnaryGuarded (dart:async/zone.dart:1374)
_BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
_DelayedData.perform (dart:async/stream_impl.dart:594)
_StreamImplEvents.handleNext (dart:async/stream_impl.dart:710)
_PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670)
_microtaskLoop (dart:async/schedule_microtask.dart:43)
_startMicrotaskLoop (dart:async/schedule_microtask.dart:52)
_startMicrotaskLoop (dart:async/schedule_microtask.dart:0)
_runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118)
_RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169)
SqliteFunctionContextPointer.resultNum (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\bindings\types.dart:123)
_unaryNumFunction (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:29)
_acosImpl (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\moor_functions.dart:62)
PreparedStatement._step (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:148)
PreparedStatement.select (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\impl\prepared_statement.dart:49)
_VmDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor_ffi-0.6.0\lib\src\vm_database.dart:97)
_ExecutorWithQueryDelegate.runSelect.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:41)
BasicLock.synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\synchronized-2.2.0\lib\src\basic_lock.dart:32)
_ExecutorWithQueryDelegate._synchronized (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:22)
_ExecutorWithQueryDelegate.runSelect (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\executor\helpers\engines.dart:39)
_MoorServer._runQuery (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:89)
<asynchronous gap> (Unknown Source:0)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:57)
_MoorServer._handleRequest (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\server.dart:0)
IsolateCommunication.setRequestHandler.<anonymous closure> (e:\Projects\_Flutter\.pub-cache\hosted\pub.dartlang.org\moor-3.1.0\lib\src\runtime\isolate\communication.dart:163)
_RootZone.runUnaryGuarded (dart:async/zone.dart:1374)
_BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339)
_DelayedData.perform (dart:async/stream_impl.dart:594)
_StreamImplEvents.handleNext (dart:async/stream_impl.dart:710)
_PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670)
_microtaskLoop (dart:async/schedule_microtask.dart:43)
_startMicrotaskLoop (dart:async/schedule_microtask.dart:52)
_startMicrotaskLoop (dart:async/schedule_microtask.dart:0)
_runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118)
_RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169)
I`ll try to create repo for reproduction, but there will be some delay.