chewing / libchewing

libchewing - The intelligent phonetic input method library
https://chewing.im/
GNU Lesser General Public License v2.1
357 stars 89 forks source link

Guarantee that *_static output will not be modified until next handle_* API call #511

Closed kanru closed 2 months ago

kanru commented 2 months ago

Is your feature request related to a problem? Please describe.

It was discovered via fcitx5-chewing integration that C and Rust version used different strategy to maintain internal buffers. We should be able to make a stronger guarantee for the *_static APIs to make them safer to use.

Describe the solution you'd like

Copy the outputs to per-context-method internal buffer. Poison previously returned buffers so it's easier to discover misuse.

Describe alternatives you've considered

Deprecate *_static functions. Although they might seem convenient to use due to lack of memory management, they are a footgun for the same reason.

Additional context

https://github.com/fcitx/fcitx5-chewing/issues/18