Repository navigation
fix(flutter): SIGSEGV crash on macOS — missing fields in Dart FFI bindings - #3186
Conversation
…nAsrNano Add fields to Dart FFI structs that were added to the C API but missing from the Flutter bindings, causing a struct layout mismatch and SIGSEGV crash when creating an OfflineRecognizer. SherpaOnnxOfflineWhisperModelConfig: - enableTokenTimestamps (int32) - enableSegmentTimestamps (int32) SherpaOnnxOfflineFunAsrNanoModelConfig: - language (Pointer<Utf8>) - itn (int32) - hotwords (Pointer<Utf8>)
📝 WalkthroughWalkthroughThis PR extends Flutter FFI bindings for offline speech recognition by adding configuration fields to FunASR Nano (language, itn, hotwords) and Whisper (enableTokenTimestamps, enableSegmentTimestamps) models. Changes include updates to Dart config classes, native struct definitions, serialization/deserialization methods, FFI wire-up, and memory cleanup. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @ayoubamine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical SIGSEGV crash on macOS by updating the Flutter Dart FFI bindings for Sherpa Onnx. The changes ensure that the Dart configuration structures accurately reflect the underlying C API, preventing runtime errors due to mismatched data structures. This significantly improves the stability and reliability of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a SIGSEGV crash on macOS by adding missing fields to the Dart FFI structs to match the C API. The changes in sherpa_onnx_bindings.dart and offline_recognizer.dart are well-implemented, ensuring the new configuration properties are handled correctly, including memory management. The fix appears solid. I've added a couple of suggestions to improve code readability by formatting long toString() methods to adhere to the Dart style guide.
| @override | ||
| String toString() { | ||
| return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed)'; | ||
| return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed, language: $language, itn: $itn, hotwords: $hotwords)'; |
There was a problem hiding this comment.
This line is very long (over 300 characters), which harms readability. The Dart style guide recommends a maximum line length of 80 characters. Please format this string literal across multiple lines for better readability and maintainability.
| return 'OfflineFunAsrNanoModelConfig(encoderAdaptor: $encoderAdaptor, llm: $llm, embedding: $embedding, tokenizer: $tokenizer, systemPrompt: $systemPrompt, userPrompt: $userPrompt, maxNewTokens: $maxNewTokens, temperature: $temperature, topP: $topP, seed: $seed, language: $language, itn: $itn, hotwords: $hotwords)'; | |
| return 'OfflineFunAsrNanoModelConfig(' 'encoderAdaptor: $encoderAdaptor, ' 'llm: $llm, ' 'embedding: $embedding, ' 'tokenizer: $tokenizer, ' 'systemPrompt: $systemPrompt, ' 'userPrompt: $userPrompt, ' 'maxNewTokens: $maxNewTokens, ' 'temperature: $temperature, ' 'topP: $topP, ' 'seed: $seed, ' 'language: $language, ' 'itn: $itn, ' 'hotwords: $hotwords)'; |
References
- The Dart style guide recommends a line length of 80 characters. Long lines should be split for better readability. (link)
| @override | ||
| String toString() { | ||
| return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings)'; | ||
| return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings, enableTokenTimestamps: $enableTokenTimestamps, enableSegmentTimestamps: $enableSegmentTimestamps)'; |
There was a problem hiding this comment.
Similar to the toString() method in OfflineFunAsrNanoModelConfig, this line is very long (over 200 characters). Please format it to adhere to the 80-character line limit for better readability.
| return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings, enableTokenTimestamps: $enableTokenTimestamps, enableSegmentTimestamps: $enableSegmentTimestamps)'; | |
| return 'OfflineWhisperModelConfig(' 'encoder: $encoder, ' 'decoder: $decoder, ' 'language: $language, ' 'task: $task, ' 'tailPaddings: $tailPaddings, ' 'enableTokenTimestamps: $enableTokenTimestamps, ' 'enableSegmentTimestamps: $enableSegmentTimestamps)'; |
References
- The Dart style guide recommends a line length of 80 characters. Long lines should be split for better readability. (link)
csukuangfj
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
Summary
The Flutter Dart FFI structs are missing fields that exist in the C API, causing a crash (SIGSEGV) when creating an
OfflineRecognizeron macOS.Missing fields
SherpaOnnxOfflineWhisperModelConfig:enableTokenTimestampsenableSegmentTimestampsSherpaOnnxOfflineFunAsrNanoModelConfig:languageitnhotwordsChanges
sherpa_onnx_bindings.dart— added missing FFI struct fields to matchc-api.hoffline_recognizer.dart— added Dart config properties,convertConfig()pass-through, andfreeConfig()cleanupCrash
macOS 15.7.3 / Flutter 3.38.5 / sherpa_onnx 1.12.24
Summary by CodeRabbit