Skip to content

Replace deprecated std::istrstream with std::istringstream - #3214

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
suykerbuyk:fix/replace-deprecated-istrstream
Feb 25, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
suykerbuyk:fix/replace-deprecated-istrstream

Conversation

@suykerbuyk

@suykerbuyk suykerbuyk commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

std::istrstream (from <strstream>) has been deprecated since C++98 and produces -Wdeprecated-declarations warnings on GCC 14+ and Clang 18+. This PR replaces all 37 usages across 23 files with std::istringstream (from <sstream>).

Changes

  • Pattern A (30 sites): std::istrstream is(buf.data(), buf.size()) → std::istringstream is(std::string(buf.data(), buf.size()))
  • Pattern B (7 sites): new std::istrstream(buf.data(), buf.size()) → new std::istringstream(std::string(buf.data(), buf.size()))
  • For files that already include <sstream>, the redundant <strstream> include is simply removed
  • For offline-tts-pocket-impl.h which used istrstream without including <strstream> (transitive include), <sstream> was added directly
  • For offline-tts-zipvoice-impl.h which includes <strstream> but never uses istrstream, replaced with <sstream>

Safety

The zero-copy property of istrstream is not needed at any of these call sites:

  • All source buffers (buf from ReadFile, data from C API) outlive the stream usage
  • Data sizes are small (symbol tables, lexicons, WAV chunks, FST rules)
  • For heap-allocated Pattern B cases, istringstream is actually safer — the stream owns its data, eliminating any dangling-pointer risk

Files changed (23)

Category Files
C API c-api/c-api.cc
Core symbol-table.cc, lexicon.cc, offline-recognizer-impl.cc, online-recognizer-impl.cc, audio-tagging-label-file.cc, keyword-spotter-transducer-impl.h, piper-phonemize-lexicon.cc
TTS offline-tts-matcha-impl.h, offline-tts-vits-impl.h, offline-tts-character-frontend.cc, offline-tts-kokoro-impl.h, offline-tts-kitten-impl.h, offline-tts-pocket-impl.h, offline-tts-zipvoice-impl.h, matcha-tts-lexicon.cc, melo-tts-lexicon.cc, character-lexicon.cc, kokoro-multi-lang-lexicon.cc, homophone-replacer.cc
RKNN rknn/keyword-spotter-transducer-rknn-impl.h
JNI jni/common.h, jni/wave-reader.cc

No functional or behavioral changes.

Summary by CodeRabbit

  • Bug Fixes

    • More robust handling of invalid/empty audio input to avoid failures when loading wave data.
  • Chores

    • Replaced deprecated C++ stream usage across multiple internal modules for improved compatibility and maintainability.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 24, 2026
@coderabbitai

coderabbitai Bot commented Feb 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbb629c and 77d6773.

📒 Files selected for processing (23)
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/csrc/audio-tagging-label-file.cc
  • sherpa-onnx/csrc/character-lexicon.cc
  • sherpa-onnx/csrc/homophone-replacer.cc
  • sherpa-onnx/csrc/keyword-spotter-transducer-impl.h
  • sherpa-onnx/csrc/kokoro-multi-lang-lexicon.cc
  • sherpa-onnx/csrc/lexicon.cc
  • sherpa-onnx/csrc/matcha-tts-lexicon.cc
  • sherpa-onnx/csrc/melo-tts-lexicon.cc
  • sherpa-onnx/csrc/offline-recognizer-impl.cc
  • sherpa-onnx/csrc/offline-tts-character-frontend.cc
  • sherpa-onnx/csrc/offline-tts-kitten-impl.h
  • sherpa-onnx/csrc/offline-tts-kokoro-impl.h
  • sherpa-onnx/csrc/offline-tts-matcha-impl.h
  • sherpa-onnx/csrc/offline-tts-pocket-impl.h
  • sherpa-onnx/csrc/offline-tts-vits-impl.h
  • sherpa-onnx/csrc/offline-tts-zipvoice-impl.h
  • sherpa-onnx/csrc/online-recognizer-impl.cc
  • sherpa-onnx/csrc/piper-phonemize-lexicon.cc
  • sherpa-onnx/csrc/rknn/keyword-spotter-transducer-rknn-impl.h
  • sherpa-onnx/csrc/symbol-table.cc
  • sherpa-onnx/jni/common.h
  • sherpa-onnx/jni/wave-reader.cc
✅ Files skipped from review due to trivial changes (1)
  • sherpa-onnx/csrc/offline-tts-zipvoice-impl.h
🚧 Files skipped from review as they are similar to previous changes (14)
  • sherpa-onnx/csrc/keyword-spotter-transducer-impl.h
  • sherpa-onnx/csrc/piper-phonemize-lexicon.cc
  • sherpa-onnx/csrc/homophone-replacer.cc
  • sherpa-onnx/csrc/offline-tts-matcha-impl.h
  • sherpa-onnx/csrc/offline-tts-kitten-impl.h
  • sherpa-onnx/csrc/online-recognizer-impl.cc
  • sherpa-onnx/csrc/offline-tts-vits-impl.h
  • sherpa-onnx/jni/common.h
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/csrc/rknn/keyword-spotter-transducer-rknn-impl.h
  • sherpa-onnx/csrc/offline-tts-pocket-impl.h
  • sherpa-onnx/csrc/melo-tts-lexicon.cc
  • sherpa-onnx/csrc/audio-tagging-label-file.cc
  • sherpa-onnx/csrc/kokoro-multi-lang-lexicon.cc

📝 Walkthrough

Walkthrough

This PR replaces deprecated std::istrstream with std::istringstream across multiple files, updates includes from <strstream> to <sstream>, and adds a null/size guard in SherpaOnnxReadWaveFromBinaryData to return nullptr for invalid input.

Changes

Cohort / File(s) Summary
C API & Wave Reading
sherpa-onnx/c-api/c-api.cc
Added null/size guard in SherpaOnnxReadWaveFromBinaryData; replaced istrstream with istringstream(std::string(data, n)).
JNI / Android bindings
sherpa-onnx/jni/common.h, sherpa-onnx/jni/wave-reader.cc
Replaced <strstream> with <sstream> and istrstream usages with istringstream constructed from std::string for asset/buffer reads.
Lexicon / Tokenization / Symbol table
sherpa-onnx/csrc/character-lexicon.cc, sherpa-onnx/csrc/kokoro-multi-lang-lexicon.cc, sherpa-onnx/csrc/lexicon.cc, sherpa-onnx/csrc/symbol-table.cc, sherpa-onnx/csrc/piper-phonemize-lexicon.cc, sherpa-onnx/csrc/audio-tagging-label-file.cc
Replaced istrstream with istringstream(std::string(...)), removed <strstream>, updated buffer-to-stream construction for token/lexicon initialization.
Keyword & Spotter Implementations
sherpa-onnx/csrc/keyword-spotter-transducer-impl.h, sherpa-onnx/csrc/rknn/keyword-spotter-transducer-rknn-impl.h
Switched to istringstream for in-memory keyword data parsing; header include updates.
Homophone / Matching / Phonemize
sherpa-onnx/csrc/homophone-replacer.cc, sherpa-onnx/csrc/matcha-tts-lexicon.cc, sherpa-onnx/csrc/melo-tts-lexicon.cc
Replaced istrstream with istringstream for buffer-driven initialization flows.
Offline/Online Recognizer & Frontend
sherpa-onnx/csrc/offline-recognizer-impl.cc, sherpa-onnx/csrc/online-recognizer-impl.cc, sherpa-onnx/csrc/offline-tts-character-frontend.cc
Updated text-normalizer and FAR input stream construction from raw buffers to istringstream(std::string(...)).
Offline TTS Implementations
sherpa-onnx/csrc/offline-tts-kitten-impl.h, sherpa-onnx/csrc/offline-tts-kokoro-impl.h, sherpa-onnx/csrc/offline-tts-matcha-impl.h, sherpa-onnx/csrc/offline-tts-pocket-impl.h, sherpa-onnx/csrc/offline-tts-vits-impl.h, sherpa-onnx/csrc/offline-tts-zipvoice-impl.h
Replaced istrstream with istringstream (including dynamic/new usages) and switched includes to <sstream> for rule-FST and FAR processing.
Other
sherpa-onnx/csrc/homophone-replacer.cc
Same istrstream → istringstream replacement for buffer parsing in homophone rules.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

size:XL

Poem

🐰 I hopped through buffers, strings in hand,
Swapped old streams for ones more grand.
Null checks added, headers neat,
Now parsing flows are tidy and fleet.
A small rabbit's code-hop, swift and planned. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: replacing deprecated std::istrstream with std::istringstream across 23 files in the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @suykerbuyk, 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 systematically updates the codebase to use std::istringstream instead of the deprecated std::istrstream. This change addresses compiler warnings and improves code modernity without introducing any functional regressions. The refactoring ensures better memory management for stream data and cleans up header includes across numerous files.

Highlights

  • Deprecation Warning Resolution: Replaced all 37 usages of the deprecated std::istrstream (from <strstream>) with std::istringstream (from <sstream>) to eliminate -Wdeprecated-declarations warnings on GCC 14+ and Clang 18+.
  • Consistent Replacement Patterns: Applied two primary replacement patterns: direct instantiation (std::istrstream is(buf.data(), buf.size()) became std::istringstream is(std::string(buf.data(), buf.size()))) and heap allocation (new std::istrstream(...) became new std::istringstream(std::string(...))).
  • Improved Safety and Code Cleanliness: The change enhances safety by making istringstream own its data, mitigating potential dangling-pointer risks, especially for heap-allocated instances. Redundant <strstream> includes were removed, and <sstream> was added where istrstream was used via transitive includes.
  • No Functional or Behavioral Changes: The modifications are purely for maintenance and compatibility, ensuring no alterations to the existing functionality or behavior of the affected components.
Changelog
  • sherpa-onnx/c-api/c-api.cc
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/csrc/audio-tagging-label-file.cc
    • Removed strstream include.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/csrc/character-lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/homophone-replacer.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/keyword-spotter-transducer-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/csrc/kokoro-multi-lang-lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/matcha-tts-lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/melo-tts-lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-recognizer-impl.cc
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-character-frontend.cc
    • Removed strstream include.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-kitten-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-kokoro-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-matcha-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-pocket-impl.h
    • Added sstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-vits-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/offline-tts-zipvoice-impl.h
    • Replaced strstream include with sstream.
  • sherpa-onnx/csrc/online-recognizer-impl.cc
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/piper-phonemize-lexicon.cc
    • Removed strstream include.
    • Updated std::istrstream instantiations to std::istringstream.
  • sherpa-onnx/csrc/rknn/keyword-spotter-transducer-rknn-impl.h
    • Replaced strstream include with sstream.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/csrc/symbol-table.cc
    • Removed strstream include.
    • Updated std::istrstream instantiation to std::istringstream.
  • sherpa-onnx/jni/common.h
    • Replaced strstream include with sstream.
  • sherpa-onnx/jni/wave-reader.cc
    • Updated std::istrstream instantiation to std::istringstream.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great pull request that addresses the use of the deprecated std::istrstream. The changes are consistent across all files, and the detailed PR description is very helpful in understanding the reasoning behind the changes and their safety. I have one suggestion to improve the robustness of the C-API.

bool is_ok = false;

std::istrstream is(data, n);
std::istringstream is(std::string(data, n));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Constructing a std::string from a null pointer with a non-zero size is undefined behavior. Since this is a C-API, it would be safer to add a check to ensure data is not null when n > 0 before this line is executed, for instance at the beginning of the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The original istrstream(data, n) had the same null-pointer UB, but since we're touching this line anyway, I've added an early if (\!data || n <= 0) return nullptr; guard at the top of the function. Updated in the force-push.

std::istrstream (from <strstream>) has been deprecated since C++98 and
produces -Wdeprecated-declarations warnings on GCC 14+ and Clang 18+.

Replace all 37 usages across 23 files with std::istringstream (from
<sstream>). The zero-copy property of istrstream is not needed at any
of these call sites — all source buffers outlive the stream and the
data sizes are small (symbol tables, lexicons, WAV chunks, FST rules).

For files that already include <sstream> (symbol-table.cc, lexicon.cc,
audio-tagging-label-file.cc, piper-phonemize-lexicon.cc,
offline-tts-character-frontend.cc, matcha-tts-lexicon.cc,
homophone-replacer.cc, melo-tts-lexicon.cc, character-lexicon.cc,
kokoro-multi-lang-lexicon.cc), the redundant <strstream> include is
simply removed.
@suykerbuyk
suykerbuyk force-pushed the fix/replace-deprecated-istrstream branch from cbb629c to 77d6773 Compare February 24, 2026 18:14
suykerbuyk pushed a commit to suykerbuyk/recmeet that referenced this pull request Feb 24, 2026
…pstream PR

Bump sherpa-onnx from v1.10.39 (73 releases behind) to v1.12.26 via
the suykerbuyk/sherpa-onnx fork's fix/replace-deprecated-istrstream
branch, which replaces all 37 deprecated std::istrstream usages across
23 sherpa-onnx source files with std::istringstream.

Upstream PR: k2-fsa/sherpa-onnx#3214

CMakeLists.txt changes:
- GIT_TAG v1.10.39 → fork branch fix/replace-deprecated-istrstream
- Removed CMAKE_MODULE_PATH workaround (fixed upstream in v1.12.26 —
  sherpa-onnx now uses CMAKE_CURRENT_SOURCE_DIR for module paths)
- Removed include_directories workaround (fixed upstream — sherpa-onnx
  now uses PROJECT_SOURCE_DIR for include paths)
- Replaced manual FetchContent_Populate + add_subdirectory with
  FetchContent_MakeAvailable(sherpa-onnx) since workarounds are gone
- Kept CMAKE_POLICY_VERSION_MINIMUM 3.5 (still needed for transitive
  dep kaldi-native-fbank)

Result: zero build warnings from sherpa-onnx (previously 10 istrstream
deprecation warnings). All 134 unit tests pass (522 assertions).

Once upstream merges the PR, switch back to k2-fsa/sherpa-onnx with
the release tag containing the fix.
suykerbuyk pushed a commit to suykerbuyk/recmeet that referenced this pull request Feb 24, 2026
…mit upstream PR #3215

Switch sherpa-onnx GIT_TAG from fix/replace-deprecated-istrstream to
fix/gcc15-deprecation-warnings, a combined fork branch that includes
both the istrstream fix (PR #3214) and the new wstring_convert fix
(PR #3215).

The wstring_convert fix replaces all std::wstring_convert / codecvt_utf8
usage across 6 sherpa-onnx source files with manual UTF-8 codec
functions implementing RFC 3629. Changes were made on the fork at
/tmp/sherpa-onnx on branch fix/replace-deprecated-wstring-convert,
then cherry-picked onto the combined branch.

Files changed in sherpa-onnx fork (PR #3215):
  text-utils.h          — Add Utf32ToUtf8(char32_t) overload
  text-utils.cc         — Remove <codecvt>, rewrite 4 functions
  kokoro-multi-lang-lexicon.cc      — Use text-utils functions
  piper-phonemize-lexicon.cc        — Use text-utils functions
  offline-tts-character-frontend.cc — Use text-utils functions
  matcha-tts-lexicon.cc — Remove local Utf32ToUtf8 (now shared)

Files changed in recmeet:
  CMakeLists.txt — GIT_TAG → fix/gcc15-deprecation-warnings

Result: zero C++ deprecation warnings from sherpa-onnx when building
recmeet with GCC 15.2. All 134 unit tests pass (522 assertions).

Upstream PRs:
  k2-fsa/sherpa-onnx#3214 (istrstream → istringstream)
  k2-fsa/sherpa-onnx#3215 (wstring_convert → manual UTF-8 codec)

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@csukuangfj
csukuangfj merged commit 0b76a7d into k2-fsa:master Feb 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants