<commit_before>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_bitcoinconsensus.h"

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_version, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_version, IS_LONG, 0)
#endif
ZEND_END_ARG_INFO();

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script, IS_LONG, 0)
#endif
    ZEND_ARG_TYPE_INFO(0, scriptPubKey, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, transaction, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, nInput, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(1, errorFlag, IS_LONG, 1)
ZEND_END_ARG_INFO();

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script_with_amount, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script_with_amount, IS_LONG, 0)
#endif
    ZEND_ARG_TYPE_INFO(0, scriptPubKey, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, amount, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, transaction, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, nInput, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(1, errorFlag, IS_LONG, 1)
ZEND_END_ARG_INFO();


/* {{{ proto int bitcoinconsensus_version();
 * Return the version of libbitcoinconsensus */
PHP_FUNCTION(bitcoinconsensus_version)
{
    unsigned int version = bitcoinconsensus_version();
    RETURN_LONG(version);
}
/* }}} */

/* {{{ proto int bitcoinconsensus_verify_script(string scriptPubKey, string transaction, int nInput, int flags, int error);
 * Return true or false for a given scriptPubKey / transaction / nInput */
PHP_FUNCTION(bitcoinconsensus_verify_script)
{
    unsigned char *scriptPubKey, *transaction;
    int scriptPubKeyLen, transactionLen;
    unsigned int nInput, flags;
    zval *scriptErr;
    bitcoinconsensus_error error;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssllz", &scriptPubKey, &scriptPubKeyLen, &transaction, &transactionLen, &nInput, &flags, &scriptErr) == FAILURE) {
        return;
    }

    int result = bitcoinconsensus_verify_script(scriptPubKey, scriptPubKeyLen, transaction, transactionLen, nInput, flags, &error);
    if (result != bitcoinconsensus_ERR_OK) {
        ZVAL_LONG(scriptErr, error);
    }
    RETURN_LONG(result);
}
/* }}} */

/* {{{ proto int bitcoinconsensus_verify_script(string scriptPubKey, string transaction, int nInput, int flags, int error);
 * Return true or false for a given scriptPubKey / transaction / nInput */
PHP_FUNCTION(bitcoinconsensus_verify_script_with_amount)
{
    unsigned char *scriptPubKey, *transaction;
    int scriptPubKeyLen, transactionLen;
    unsigned int nInput, flags;
    int64_t amount;
    zval *scriptErr;
    bitcoinconsensus_error error;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slsllz", &scriptPubKey, &scriptPubKeyLen, &amount, &transaction, &transactionLen, &nInput, &flags, &scriptErr) == FAILURE) {
        return;
    }

    int result = bitcoinconsensus_verify_script_with_amount(scriptPubKey, scriptPubKeyLen, amount, transaction, transactionLen, nInput, flags, &error);
    if (result != bitcoinconsensus_ERR_OK) {
        ZVAL_LONG(scriptErr, error);
    }
    RETURN_LONG(result);
}
/* }}} */

PHP_MINIT_FUNCTION(bitcoinconsensus)
{
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_NONE", 0, CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_P2SH", (1U << 0), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_DERSIG", (1U << 2), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY", (1U << 9), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY", (1U << 10), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_WITNESS", (1U << 11), CONST_CS | CONST_PERSISTENT);
<commit_msg>use zend_string over unsigned char*<commit_after>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_bitcoinconsensus.h"

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_version, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_version, IS_LONG, 0)
#endif
ZEND_END_ARG_INFO();

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script, IS_LONG, 0)
#endif
    ZEND_ARG_TYPE_INFO(0, scriptPubKey, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, transaction, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, nInput, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(1, errorFlag, IS_LONG, 1)
ZEND_END_ARG_INFO();

#if (PHP_VERSION_ID >= 70000 && PHP_VERSION_ID <= 70200)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script_with_amount, IS_LONG, NULL, 0)
#else
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(arginfo_bitcoinconsensus_verify_script_with_amount, IS_LONG, 0)
#endif
    ZEND_ARG_TYPE_INFO(0, scriptPubKey, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, amount, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, transaction, IS_STRING, 0)
    ZEND_ARG_TYPE_INFO(0, nInput, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
    ZEND_ARG_TYPE_INFO(1, errorFlag, IS_LONG, 1)
ZEND_END_ARG_INFO();


/* {{{ proto int bitcoinconsensus_version();
 * Return the version of libbitcoinconsensus */
PHP_FUNCTION(bitcoinconsensus_version)
{
    unsigned int version = bitcoinconsensus_version();
    RETURN_LONG(version);
}
/* }}} */

/* {{{ proto int bitcoinconsensus_verify_script(string scriptPubKey, string transaction, int nInput, int flags, int error);
 * Return true or false for a given scriptPubKey / transaction / nInput */
PHP_FUNCTION(bitcoinconsensus_verify_script)
{
    zend_string *tx, *scriptPubKey;
    unsigned int nInput, flags;
    int result = 0;
    zval *scriptErr;
    bitcoinconsensus_error error;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SSllz", &scriptPubKey, &tx, &nInput, &flags, &scriptErr) == FAILURE) {
        return;
    }

    result = bitcoinconsensus_verify_script(scriptPubKey->val, scriptPubKey->len, tx->val, tx->len, nInput, flags, &error);
    if (result != bitcoinconsensus_ERR_OK) {
        ZVAL_LONG(scriptErr, error);
    }
    RETURN_LONG(result);
}
/* }}} */

/* {{{ proto int bitcoinconsensus_verify_script(string scriptPubKey, string transaction, int nInput, int flags, int error);
 * Return true or false for a given scriptPubKey / transaction / nInput */
PHP_FUNCTION(bitcoinconsensus_verify_script_with_amount)
{
    zend_string *scriptPubKey, *transaction;
    unsigned int nInput, flags;
    int64_t amount;
    int result = 0;
    zval *scriptErr;
    bitcoinconsensus_error error;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SlSllz", &scriptPubKey, &amount, &transaction, &nInput, &flags, &scriptErr) == FAILURE) {
        return;
    }

    result = bitcoinconsensus_verify_script_with_amount(scriptPubKey->val, scriptPubKey->len, amount, transaction->val, transaction->len, nInput, flags, &error);
    if (result != bitcoinconsensus_ERR_OK) {
        ZVAL_LONG(scriptErr, error);
    }
    RETURN_LONG(result);
}
/* }}} */

PHP_MINIT_FUNCTION(bitcoinconsensus)
{
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_NONE", 0, CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_P2SH", (1U << 0), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_DERSIG", (1U << 2), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY", (1U << 9), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_CHECKSEQUENCEVERIFY", (1U << 10), CONST_CS | CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("BITCOINCONSENSUS_SCRIPT_FLAGS_VERIFY_WITNESS", (1U << 11), CONST_CS | CONST_PERSISTENT);

{'fraction_non_alphanumeric': 0.1028178854215184, 'fraction_numerical': 0.017466231951560315, 'mean_word_length': 6.260355029585799, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 17, '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': '5033873', 'n_tokens_mistral': 3303, 'n_tokens_neox': 3142, 'n_words': 562}