fix: replace global serd_output buffer with a local string via stream pointer#114
Open
SoundMatt wants to merge 1 commit into
Open
fix: replace global serd_output buffer with a local string via stream pointer#114SoundMatt wants to merge 1 commit into
SoundMatt wants to merge 1 commit into
Conversation
… pointer The file-scope serd_output string was shared across all calls to generateTripleOutput, meaning concurrent or reentrant calls could corrupt each other's output. The Serd write callback already receives a void* stream pointer for exactly this purpose. Replace the global with a local std::string in generateTripleOutput, pass its address as the stream argument, and update the callback to cast and append through it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
serd_outputis a file-scopestd::stringthatgenerateTripleOutputclears at the top and reads at the end. Concurrent or reentrant calls corrupt each other's output, and the global state makes the function non-reentrant by design.Root cause
The write callback
write_serd_output_to_stringignores thevoid* streamparameter and instead appends directly to the global. The Serd API provides the stream pointer precisely so that callers can supply per-call buffers without shared state.Fix
Remove the global
serd_output. Declarestd::string local_outputinsidegenerateTripleOutput, pass&local_outputas the stream argument toserd_writer_new, and update the callback tostatic_cast<std::string*>(stream)->append(...). ReturnHelper::trimTrailingNewlines(local_output)at the end.