Refactor getter functions to caller-provided output pattern#55
Merged
Conversation
All eight getter functions now return OkjError and write results into a caller-supplied struct pointer instead of returning a pointer to a static file-scope variable. This makes the library fully thread-safe and reentrant, and aligns getters with the okj_parse() error-code convention. New signatures: OkjError okj_get_string(parser, key, OkJsonString *out_str); OkjError okj_get_number(parser, key, OkJsonNumber *out_num); OkjError okj_get_boolean(parser, key, OkJsonBoolean *out_bool); OkjError okj_get_array(parser, key, OkJsonArray *out_arr); OkjError okj_get_object(parser, key, OkJsonObject *out_obj); OkjError okj_get_token(parser, key, OkJsonToken *out_tok); OkjError okj_get_array_raw(parser, key, OkJsonArray *out_arr); OkjError okj_get_object_raw(parser, key, OkJsonObject *out_obj); NULL parser/key/output returns OKJ_ERROR_BAD_POINTER; type mismatch or key-not-found returns the type-specific error code (BAD_STRING, BAD_NUMBER, BAD_BOOLEAN, BAD_ARRAY, BAD_OBJECT). The seven static file-scope result structs (s_string_result etc.) are removed entirely. All unit tests updated to use value-type locals, dot-operator member access, and assert-on-error-code patterns. All 230 tests pass. https://claude.ai/code/session_017TcSrEaHq4Wg57Qq8wvFzM
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.
All eight getter functions now return OkjError and write results into a caller-supplied struct pointer instead of returning a pointer to a static file-scope variable. This makes the library fully thread-safe and reentrant, and aligns getters with the okj_parse() error-code convention.
New signatures:
OkjError okj_get_string(parser, key, OkJsonString *out_str);
OkjError okj_get_number(parser, key, OkJsonNumber *out_num);
OkjError okj_get_boolean(parser, key, OkJsonBoolean *out_bool);
OkjError okj_get_array(parser, key, OkJsonArray *out_arr);
OkjError okj_get_object(parser, key, OkJsonObject *out_obj);
OkjError okj_get_token(parser, key, OkJsonToken *out_tok);
OkjError okj_get_array_raw(parser, key, OkJsonArray *out_arr);
OkjError okj_get_object_raw(parser, key, OkJsonObject *out_obj);
NULL parser/key/output returns OKJ_ERROR_BAD_POINTER; type mismatch or key-not-found returns the type-specific error code (BAD_STRING, BAD_NUMBER, BAD_BOOLEAN, BAD_ARRAY, BAD_OBJECT). The seven static file-scope result structs (s_string_result etc.) are removed entirely.
All unit tests updated to use value-type locals, dot-operator member access, and assert-on-error-code patterns. All 230 tests pass.
https://claude.ai/code/session_017TcSrEaHq4Wg57Qq8wvFzM