<commit_before>/* {{{ macros */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <signal.h>

#include "xcache.h"

#ifdef HAVE_XCACHE_OPTIMIZER
#	include "mod_optimizer/xc_optimizer.h"
#endif
#ifdef HAVE_XCACHE_CACHER
#	include "mod_cacher/xc_cacher.h"
#endif
#ifdef HAVE_XCACHE_COVERAGER
#	include "mod_coverager/xc_coverager.h"
#endif
#ifdef HAVE_XCACHE_DISASSEMBLER
#	include "mod_disassembler/xc_disassembler.h"
#endif

#include "xcache_globals.h"
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_const_string.h"
#include "xcache/xc_opcode_spec.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"

#include "php.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "SAPI.h"
/* }}} */

/* {{{ globals */
static char *xc_coredump_dir = NULL;
#ifdef ZEND_WIN32
static zend_ulong xc_coredump_type = 0;
#endif
static zend_bool xc_disable_on_crash = 0;

static zend_compile_file_t *old_compile_file = NULL;

zend_bool xc_test = 0;

ZEND_DECLARE_MODULE_GLOBALS(xcache)

/* }}} */

static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
{
	XG(initial_compile_file_called) = 1;
	return old_compile_file(h, type TSRMLS_CC);
}
/* }}} */

/* devel helper function */
#if 0
static void xc_list_extensions() /* {{{ */
{
	zend_llist_element *element;
	zend_extension *ext;
	fprintf(stderr, "extensions:\n");
	for (element = zend_extensions.head; element; element = element->next) {
		ext = (zend_extension *) element->data;
		fprintf(stderr, " - %s\n", ext->name);
	}
}
/* }}} */
#endif

/* module helper function */
static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */
{
	typedef struct {
		const char *prefix;
		zend_uchar (*getsize)();
		const char *(*get)(zend_uchar i);
	} xc_nameinfo_t;
	xc_nameinfo_t nameinfos[] = {
		{ "",        xc_get_op_type_count,   xc_get_op_type   },
		{ "",        xc_get_data_type_count, xc_get_data_type },
		{ "",        xc_get_opcode_count,    xc_get_opcode    },
		{ "OPSPEC_", xc_get_op_spec_count,   xc_get_op_spec   },
		{ NULL, NULL, NULL }
	};
	int undefdone = 0;
	xc_nameinfo_t *p;

	for (p = nameinfos; p->getsize; p ++) {
		zend_uchar i, count;
		char const_name[96];
		int const_name_len;

		count = p->getsize();
		for (i = 0; i < count; i ++) {
			const char *name = p->get(i);
			if (!name) continue;
			if (strcmp(name, "UNDEF") == 0) {
				if (undefdone) continue;
				undefdone = 1;
			}
			const_name_len = snprintf(const_name, sizeof(const_name), "XC_%s%s", p->prefix, name);
			zend_register_long_constant(const_name, const_name_len+1, i, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
		}
	}

	zend_register_long_constant(XCACHE_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	zend_register_stringl_constant(XCACHE_STRS("XCACHE_VERSION"), XCACHE_STRL(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	zend_register_stringl_constant(XCACHE_STRS("XCACHE_MODULES"), XCACHE_STRL(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	return 0;
}
/* }}} */
/* {{{ PHP_GINIT_FUNCTION(xcache) */
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wshadow"

#ifdef PHP_GINIT_FUNCTION
static PHP_GINIT_FUNCTION(xcache)
#else
static void xc_init_globals(zend_xcache_globals* xcache_globals TSRMLS_DC)
#endif
{
#pragma GCC pop_options

	memset(xcache_globals, 0, sizeof(zend_xcache_globals));

#ifdef HAVE_XCACHE_CONSTANT
	zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0);
#endif
	zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0);
	zend_hash_init_ex(&xcache_globals->internal_class_table,    1, NULL, NULL, 1, 0);
}
/* }}} */
/* {{{ PHP_GSHUTDOWN_FUNCTION(xcache) */
static
#ifdef PHP_GSHUTDOWN_FUNCTION
PHP_GSHUTDOWN_FUNCTION(xcache)<commit_msg>fixed #320: void warning for gcc only pragma<commit_after>/* {{{ macros */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <signal.h>

#include "xcache.h"

#ifdef HAVE_XCACHE_OPTIMIZER
#	include "mod_optimizer/xc_optimizer.h"
#endif
#ifdef HAVE_XCACHE_CACHER
#	include "mod_cacher/xc_cacher.h"
#endif
#ifdef HAVE_XCACHE_COVERAGER
#	include "mod_coverager/xc_coverager.h"
#endif
#ifdef HAVE_XCACHE_DISASSEMBLER
#	include "mod_disassembler/xc_disassembler.h"
#endif

#include "xcache_globals.h"
#include "xcache/xc_extension.h"
#include "xcache/xc_ini.h"
#include "xcache/xc_const_string.h"
#include "xcache/xc_opcode_spec.h"
#include "xcache/xc_utils.h"
#include "util/xc_stack.h"

#include "php.h"
#include "ext/standard/info.h"
#include "ext/standard/php_string.h"
#include "SAPI.h"
/* }}} */

/* {{{ globals */
static char *xc_coredump_dir = NULL;
#ifdef ZEND_WIN32
static zend_ulong xc_coredump_type = 0;
#endif
static zend_bool xc_disable_on_crash = 0;

static zend_compile_file_t *old_compile_file = NULL;

zend_bool xc_test = 0;

ZEND_DECLARE_MODULE_GLOBALS(xcache)

/* }}} */

static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */
{
	XG(initial_compile_file_called) = 1;
	return old_compile_file(h, type TSRMLS_CC);
}
/* }}} */

/* devel helper function */
#if 0
static void xc_list_extensions() /* {{{ */
{
	zend_llist_element *element;
	zend_extension *ext;
	fprintf(stderr, "extensions:\n");
	for (element = zend_extensions.head; element; element = element->next) {
		ext = (zend_extension *) element->data;
		fprintf(stderr, " - %s\n", ext->name);
	}
}
/* }}} */
#endif

/* module helper function */
static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */
{
	typedef struct {
		const char *prefix;
		zend_uchar (*getsize)();
		const char *(*get)(zend_uchar i);
	} xc_nameinfo_t;
	xc_nameinfo_t nameinfos[] = {
		{ "",        xc_get_op_type_count,   xc_get_op_type   },
		{ "",        xc_get_data_type_count, xc_get_data_type },
		{ "",        xc_get_opcode_count,    xc_get_opcode    },
		{ "OPSPEC_", xc_get_op_spec_count,   xc_get_op_spec   },
		{ NULL, NULL, NULL }
	};
	int undefdone = 0;
	xc_nameinfo_t *p;

	for (p = nameinfos; p->getsize; p ++) {
		zend_uchar i, count;
		char const_name[96];
		int const_name_len;

		count = p->getsize();
		for (i = 0; i < count; i ++) {
			const char *name = p->get(i);
			if (!name) continue;
			if (strcmp(name, "UNDEF") == 0) {
				if (undefdone) continue;
				undefdone = 1;
			}
			const_name_len = snprintf(const_name, sizeof(const_name), "XC_%s%s", p->prefix, name);
			zend_register_long_constant(const_name, const_name_len+1, i, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
		}
	}

	zend_register_long_constant(XCACHE_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	zend_register_stringl_constant(XCACHE_STRS("XCACHE_VERSION"), XCACHE_STRL(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	zend_register_stringl_constant(XCACHE_STRS("XCACHE_MODULES"), XCACHE_STRL(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);
	return 0;
}
/* }}} */
/* {{{ PHP_GINIT_FUNCTION(xcache) */
#ifdef __GNUC__
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wshadow"
#endif

#ifdef PHP_GINIT_FUNCTION
static PHP_GINIT_FUNCTION(xcache)
#else
static void xc_init_globals(zend_xcache_globals* xcache_globals TSRMLS_DC)
#endif
{
#ifdef __GNUC__
#pragma GCC pop_options
#endif

	memset(xcache_globals, 0, sizeof(zend_xcache_globals));

#ifdef HAVE_XCACHE_CONSTANT
	zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0);
#endif
	zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0);
	zend_hash_init_ex(&xcache_globals->internal_class_table,    1, NULL, NULL, 1, 0);
}
/* }}} */
/* {{{ PHP_GSHUTDOWN_FUNCTION(xcache) */
static
#ifdef PHP_GSHUTDOWN_FUNCTION
PHP_GSHUTDOWN_FUNCTION(xcache)
{'fraction_non_alphanumeric': 0.13616379851777416, 'fraction_numerical': 0.006657455093581208, 'mean_word_length': 5.536945812807882, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, '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': '270946', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3253, 'n_words': 570}