<commit_before>/**
 *    Copyright(c) 2016-2018 rryqszq4
 *
 *
 */

#include "ngx_php_debug.h"
#include "ngx_http_php_coroutine.h"

ngx_php_coroutine_t *
ngx_http_php_coroutine_alloc(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;
	ngx_php_coroutine_t *coro;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);
	if (ctx == NULL) {
		return NULL;
	}

	coro = ctx->coro;
	if (coro == NULL) {
		coro = ngx_pcalloc(r->pool, sizeof(ngx_php_coroutine_t));
		if (coro == NULL) {
			return NULL;
		}
		
		if (!coro->stack) {
			coro->stack = ngx_palloc(r->pool, PHP_COROUTINE_STACK_SIZE);
		}
	}

	return coro;
}

ngx_int_t 
ngx_http_php_coroutine_run(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	if (ngx_php_coroutine_create(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	return NGX_OK;
}

ngx_int_t 
ngx_http_php_coroutine_yield(ngx_http_request_t *r)
{
	ngx_php_request = r;

	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	zend_execute_data *current_execute_data = EG(current_execute_data);
    zend_op **opline_ptr;
    opline_ptr = EG(opline_ptr);
    zend_vm_stack current_stack = EG(argument_stack);
    //ctx->op_array = (zend_op_array*)emalloc(sizeof(zend_op_array));
    ctx->op_array = EG(active_op_array);
    ngx_php_debug("%p\n", ctx->op_array);
    ctx->return_value_ptr_ptr = EG(return_value_ptr_ptr);

    ctx->op_array->fn_flags |= ZEND_ACC_GENERATOR;
    ctx->execute_data = zend_create_execute_data_from_op_array(ctx->op_array, 0 TSRMLS_CC);
    EG(current_execute_data) = current_execute_data;
    EG(opline_ptr) = opline_ptr;
    ctx->argument_stack = EG(argument_stack);
    EG(argument_stack) = current_stack;
    ctx->opline_ptr = *EG(opline_ptr);
    EG(opline_ptr) = opline_ptr;
    ctx->op_array->fn_flags &= ~ZEND_ACC_GENERATOR;

	if (ngx_php_coroutine_yield(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	r = ngx_php_request;

    ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

    //ctx->execute_data->opline++;
    EG(current_execute_data) = ctx->execute_data;
    EG(argument_stack) = ctx->argument_stack;
    EG(opline_ptr) = &(ctx->opline_ptr);
    EG(return_value_ptr_ptr) = ctx->return_value_ptr_ptr;
    //ctx->op_array->fn_flags &= ~ZEND_ACC_GENERATOR;
    EG(active_op_array) = ctx->op_array;

	return NGX_OK;
}

ngx_int_t 
ngx_http_php_coroutine_resume(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	if (ngx_php_coroutine_resume(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	return NGX_OK;
}


<commit_msg>[src] Fixed core dump in function, zend_do_fcall_common_helper_SPEC zend_vm_stack_clear_multiple<commit_after>/**
 *    Copyright(c) 2016-2018 rryqszq4
 *
 *
 */

#include "ngx_php_debug.h"
#include "ngx_http_php_coroutine.h"

ngx_php_coroutine_t *
ngx_http_php_coroutine_alloc(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;
	ngx_php_coroutine_t *coro;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);
	if (ctx == NULL) {
		return NULL;
	}

	coro = ctx->coro;
	if (coro == NULL) {
		coro = ngx_pcalloc(r->pool, sizeof(ngx_php_coroutine_t));
		if (coro == NULL) {
			return NULL;
		}
		
		if (!coro->stack) {
			coro->stack = ngx_palloc(r->pool, PHP_COROUTINE_STACK_SIZE);
		}
	}

	return coro;
}

ngx_int_t 
ngx_http_php_coroutine_run(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	if (ngx_php_coroutine_create(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	return NGX_OK;
}

ngx_int_t 
ngx_http_php_coroutine_yield(ngx_http_request_t *r)
{
	ngx_php_request = r;

	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	zend_execute_data *current_execute_data = EG(current_execute_data);
    zend_op **opline_ptr;
    opline_ptr = EG(opline_ptr);
    zend_vm_stack current_stack = EG(argument_stack);
    //ctx->op_array = (zend_op_array*)emalloc(sizeof(zend_op_array));
    ctx->op_array = EG(active_op_array);
    ngx_php_debug("%p\n", ctx->op_array);
    ctx->return_value_ptr_ptr = EG(return_value_ptr_ptr);

    ctx->op_array->fn_flags |= ZEND_ACC_GENERATOR;
    ctx->execute_data = zend_create_execute_data_from_op_array(ctx->op_array, 0 TSRMLS_CC);
    EG(current_execute_data) = current_execute_data;
    EG(opline_ptr) = opline_ptr;
    *(EG(argument_stack)->top-1) = NULL;
    ctx->argument_stack = EG(argument_stack);
    EG(argument_stack) = current_stack;
    ctx->opline_ptr = *EG(opline_ptr);
    EG(opline_ptr) = opline_ptr;
    ctx->op_array->fn_flags &= ~ZEND_ACC_GENERATOR;

	if (ngx_php_coroutine_yield(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	r = ngx_php_request;

    ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

    //ctx->execute_data->opline++;
    EG(current_execute_data) = ctx->execute_data;
    EG(argument_stack) = ctx->argument_stack;
    EG(opline_ptr) = &(ctx->opline_ptr);
    EG(return_value_ptr_ptr) = ctx->return_value_ptr_ptr;
    //ctx->op_array->fn_flags &= ~ZEND_ACC_GENERATOR;
    EG(active_op_array) = ctx->op_array;

	return NGX_OK;
}

ngx_int_t 
ngx_http_php_coroutine_resume(ngx_http_request_t *r)
{
	ngx_http_php_ctx_t *ctx;

	ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

	if (ngx_php_coroutine_resume(ctx->coro) != 0) {
		return NGX_ERROR;
	}

	return NGX_OK;
}



{'fraction_non_alphanumeric': 0.1235052316890882, 'fraction_numerical': 0.005044843049327354, 'mean_word_length': 5.021372328458942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 62, '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': '7221620', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2369, 'n_words': 301}