Skip to content

Commit

Permalink
New method simdjson_cleanup
Browse files Browse the repository at this point in the history
This method will cleanup allocated buffers by simdjson parser
  • Loading branch information
JakubOnderka committed Nov 26, 2024
1 parent 9a27456 commit dd3a890
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions php_simdjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ SIMDJSON_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(simdjson_key_count_arginfo, 0,
ZEND_ARG_TYPE_INFO(0, throw_if_uncountable, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

SIMDJSON_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(simdjson_cleanup_arginfo, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

#define SIMDJSON_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(simdjson, v)
static simdjson_php_parser *simdjson_get_parser() {
simdjson_php_parser *parser = SIMDJSON_G(parser);
Expand Down Expand Up @@ -221,6 +224,17 @@ PHP_FUNCTION (simdjson_key_exists) {
}
}

PHP_FUNCTION (simdjson_cleanup) {
ZEND_PARSE_PARAMETERS_NONE();

simdjson_php_parser *parser = SIMDJSON_G(parser);
if (EXPECTED(parser != NULL)) {
php_simdjson_free_parser(parser);
SIMDJSON_G(parser) = NULL;
}
RETURN_TRUE;
}

/* {{{ simdjson_functions[]
*/
zend_function_entry simdjson_functions[] = {
Expand All @@ -229,6 +243,7 @@ zend_function_entry simdjson_functions[] = {
PHP_FE(simdjson_key_value, simdjson_key_value_arginfo)
PHP_FE(simdjson_key_exists, simdjson_key_exists_arginfo)
PHP_FE(simdjson_key_count, simdjson_key_count_arginfo)
PHP_FE(simdjson_cleanup, simdjson_cleanup_arginfo)
{NULL, NULL, NULL}
};
/* }}} */
Expand Down

0 comments on commit dd3a890

Please sign in to comment.