Skip to content

Document lifetime of pm_options_t #3066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/prism.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ PRISM_EXPORTED_FUNCTION const char * pm_version(void);

/**
* Initialize a parser with the given start and end pointers.
* The resulting parser must eventually be freed with `pm_parser_free()`.
*
* @param parser The parser to initialize.
* @param source The source to parse.
* @param size The size of the source.
* @param options The optional options to use when parsing.
* These options must live for the whole lifetime of this parser.
*/
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options);

Expand All @@ -68,6 +70,9 @@ PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_par
/**
* Free any memory associated with the given parser.
*
* Note: this does not free the `pm_options_t` object that was used to initialize the parser.
* See \ref pm_options_t::pm_options_free() "pm_options_free()".
*
* @param parser The parser to free.
*/
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
Expand Down
4 changes: 4 additions & 0 deletions include/prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_
/**
* Free the internal memory associated with the options.
*
* Must be called after the parser was freed with \ref pm_parser::pm_parser_free() "pm_parser_free()".
* If multiple parsers are created with the same options object, they must all be freed first,
* before it is safe to free the options object.
*
* @param options The options struct whose internal memory should be freed.
*/
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
Expand Down
Loading