drift icon indicating copy to clipboard operation
drift copied to clipboard

[Question] Is ffi's triginometric functions supported on isolate?

Open andreystavitsky opened this issue 5 years ago • 4 comments

Is trigonometric functions such as sin, cos etc. supported in background isolate mode?

andreystavitsky avatar May 19 '20 15:05 andreystavitsky

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?

simolus3 avatar May 19 '20 17:05 simolus3

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

andreystavitsky avatar May 19 '20 18:05 andreystavitsky

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!

simolus3 avatar May 19 '20 19:05 simolus3

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.

andreystavitsky avatar May 19 '20 19:05 andreystavitsky