<commit_before>#include "php_git2.h"
#include "php_git2_priv.h"
#include "revwalk.h"

static int php_git2_treebuilder_filter_cb(const git_tree_entry *entry, void *payload)
{
	php_git2_t *result;
	zval *param_tree_entry, *retval_ptr = NULL;
	php_git2_cb_t *p = (php_git2_cb_t*)payload;
	long retval = 0;
	GIT2_TSRMLS_SET(p->tsrm_ls)

	MAKE_STD_ZVAL(param_tree_entry);
	if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, entry, 0 TSRMLS_CC)) {
		return 0;
	}
	ZVAL_RESOURCE(param_tree_entry, GIT2_RVAL_P(result));
	zend_list_addref(GIT2_RVAL_P(result));
	Z_ADDREF_P(p->payload);

	if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, &param_tree_entry, &p->payload)) {
		zval_ptr_dtor(&param_tree_entry);
		zval_ptr_dtor(&p->payload);
		zend_list_delete(result->resource_id);
		retval = 0;
		return 0;
	}

	retval = Z_LVAL_P(retval_ptr);
	zval_ptr_dtor(&retval_ptr);
	zend_list_delete(result->resource_id);

	return retval;
}


/* {{{ proto resource git_treebuilder_create([resource $source])
 */
PHP_FUNCTION(git_treebuilder_create)
{
	php_git2_t *result = NULL, *_source = NULL;
	git_treebuilder *out = NULL;
	zval *source = NULL;
	git_tree *tree = NULL;
	int error = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"|r", &source) == FAILURE) {
		return;
	}
	if (source != NULL) {
		tree = PHP_GIT2_V(_source, tree);
	}

	ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
	error = git_treebuilder_create(&out, tree);
	if (php_git2_check_error(error, "git_treebuilder_create" TSRMLS_CC)) {
		RETURN_FALSE;
	}
	if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREEBUILDER, out, 1 TSRMLS_CC)) {
		RETURN_FALSE;
	}
	ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */

<commit_msg>Fix seg fault when calling git_treebuilder_create<commit_after>#include "php_git2.h"
#include "php_git2_priv.h"
#include "revwalk.h"

static int php_git2_treebuilder_filter_cb(const git_tree_entry *entry, void *payload)
{
	php_git2_t *result;
	zval *param_tree_entry, *retval_ptr = NULL;
	php_git2_cb_t *p = (php_git2_cb_t*)payload;
	long retval = 0;
	GIT2_TSRMLS_SET(p->tsrm_ls)

	MAKE_STD_ZVAL(param_tree_entry);
	if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREE_ENTRY, entry, 0 TSRMLS_CC)) {
		return 0;
	}
	ZVAL_RESOURCE(param_tree_entry, GIT2_RVAL_P(result));
	zend_list_addref(GIT2_RVAL_P(result));
	Z_ADDREF_P(p->payload);

	if (php_git2_call_function_v(p->fci, p->fcc TSRMLS_CC, &retval_ptr, 2, &param_tree_entry, &p->payload)) {
		zval_ptr_dtor(&param_tree_entry);
		zval_ptr_dtor(&p->payload);
		zend_list_delete(result->resource_id);
		retval = 0;
		return 0;
	}

	retval = Z_LVAL_P(retval_ptr);
	zval_ptr_dtor(&retval_ptr);
	zend_list_delete(result->resource_id);

	return retval;
}


/* {{{ proto resource git_treebuilder_create([resource $source])
 */
PHP_FUNCTION(git_treebuilder_create)
{
	php_git2_t *result = NULL, *_source = NULL;
	git_treebuilder *out = NULL;
	zval *source = NULL;
	git_tree *tree = NULL;
	int error = 0;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"|r", &source) == FAILURE) {
		return;
	}
	if (source != NULL) {
        ZEND_FETCH_RESOURCE(_source, php_git2_t*, &source, -1, PHP_GIT2_RESOURCE_NAME, git2_resource_handle);
		tree = PHP_GIT2_V(_source, tree);
	}

	error = git_treebuilder_create(&out, tree);
	if (php_git2_check_error(error, "git_treebuilder_create" TSRMLS_CC)) {
		RETURN_FALSE;
	}
	if (php_git2_make_resource(&result, PHP_GIT2_TYPE_TREEBUILDER, out, 1 TSRMLS_CC)) {
		RETURN_FALSE;
	}
	ZVAL_RESOURCE(return_value, GIT2_RVAL_P(result));
}
/* }}} */


{'fraction_non_alphanumeric': 0.130374479889043, 'fraction_numerical': 0.016643550624133148, 'mean_word_length': 6.404517453798768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4758595', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1565, 'n_words': 241}