/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2004 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_0.txt. | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: | +----------------------------------------------------------------------+ */ /* $Id: header,v 1.15 2004/01/08 16:46:52 sniper Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_tcc.h" /* If you declare any globals in php_tcc.h uncomment this: */ ZEND_DECLARE_MODULE_GLOBALS(tcc) /* True global resources - no need for thread safety here */ static int le_tcc; /* {{{ tcc_functions[] * * Every user visible function must have an entry in tcc_functions[]. */ function_entry tcc_functions[] = { PHP_FE(tcc_compile_string, NULL) PHP_FE(tcc_call_function, NULL) PHP_FE(tcc_call_phpfunction, NULL) PHP_FE(tcc_add_file, NULL) PHP_FE(tcc_add_library, NULL) PHP_FE(tcc_add_library_path, NULL) PHP_FE(tcc_add_include_path, NULL) {NULL, NULL, NULL} /* Must be the last line in tcc_functions[] */ }; /* }}} */ /* {{{ tcc_module_entry */ zend_module_entry tcc_module_entry = { #if ZEND_MODULE_API_NO >= 20010901 STANDARD_MODULE_HEADER, #endif "tcc", tcc_functions, PHP_MINIT(tcc), PHP_MSHUTDOWN(tcc), PHP_RINIT(tcc), /* Replace with NULL if there's nothing to do at request start */ PHP_RSHUTDOWN(tcc), /* Replace with NULL if there's nothing to do at request end */ PHP_MINFO(tcc), #if ZEND_MODULE_API_NO >= 20010901 "0.1", /* Replace with version number for your extension */ #endif STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_TCC ZEND_GET_MODULE(tcc) #endif /* {{{ PHP_INI */ /* Remove comments and fill if you need to have entries in php.ini PHP_INI_BEGIN() STD_PHP_INI_ENTRY("tcc.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_tcc_globals, tcc_globals) STD_PHP_INI_ENTRY("tcc.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_tcc_globals, tcc_globals) PHP_INI_END() */ /* }}} */ /* {{{ php_tcc_init_globals */ /* Uncomment this function if you have INI entries static void php_tcc_init_globals(zend_tcc_globals *tcc_globals) { tcc_globals->global_value = 0; tcc_globals->global_string = NULL; } */ /* }}} */ void php_tcc_return_value(zval * ret_value); /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(tcc) { /* If you have INI entries, uncomment these lines ZEND_INIT_MODULE_GLOBALS(tcc, php_tcc_init_globals, NULL); REGISTER_INI_ENTRIES(); */ TCC_G(state) = tcc_new(); tcc_set_output_type(TCC_G(state), TCC_OUTPUT_MEMORY); tcc_add_symbol(TCC_G(state), "_estrdup", (unsigned long)&_estrdup); tcc_add_symbol(TCC_G(state), "php_tcc_return_value", (unsigned long)&php_tcc_return_value); /* now try and add some usefull stuff??? */ return SUCCESS; } /* }}} */ /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(tcc) { /* uncomment this line if you have INI entries UNREGISTER_INI_ENTRIES(); */ tcc_delete(TCC_G(state)); return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request start */ /* {{{ PHP_RINIT_FUNCTION */ PHP_RINIT_FUNCTION(tcc) { return SUCCESS; } /* }}} */ /* Remove if there's nothing to do at request end */ /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(tcc) { return SUCCESS; } /* }}} */ /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(tcc) { php_info_print_table_start(); php_info_print_table_header(2, "tcc support", "enabled"); php_info_print_table_end(); /* Remove comments if you have entries in php.ini DISPLAY_INI_ENTRIES(); */ } /* }}} */ /* {{{ proto string tcc_compile_string(string cstring) Compile some C code.. */ PHP_FUNCTION(tcc_compile_string) { char *cstr = NULL; int cstr_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cstr, &cstr_len) == FAILURE) { return; } /* no idea if it works? */ RETURN_LONG(tcc_compile_string(TCC_G(state),cstr)); } /* }}} */ /* {{{ proto string tcc_compile_string(string cstring) Compile some C code.. */ PHP_FUNCTION(tcc_call_function) { char *fname = NULL; int fname_len; unsigned long val; void (*func)(); /* we can only call functions without arguments.. */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } tcc_relocate(TCC_G(state)); tcc_get_symbol(TCC_G(state),&val,fname); func = (void *)val; func(); RETURN_TRUE; } void php_tcc_return_value(zval * ret_value) { printf("RETURNED TYPE: %d\n", ret_value->type); } PHP_FUNCTION(tcc_call_phpfunction) { char *fname = NULL; int fname_len; unsigned long val; void (*func)(int num_params, zval** params); /* we can only call functions without arguments.. */ zval **args, **got_args; zval *ret_value; int i; if (zend_parse_parameters(1 TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } tcc_relocate(TCC_G(state)); tcc_get_symbol(TCC_G(state),&val,fname); args = (zval **)emalloc(sizeof(zval *) * ZEND_NUM_ARGS()); /* maybe -1 */ got_args = (zval **)safe_emalloc(sizeof(zval *), ZEND_NUM_ARGS(), 0); zend_get_parameters_array(ht, ZEND_NUM_ARGS(), got_args); for (i =1; i < ZEND_NUM_ARGS(); i++ ) { args[i-1] = got_args[i]; } func = (void *)val; func(ZEND_NUM_ARGS(), args); //efree(args); //efree(got_args); RETURN_FALSE; } /* }}} */ /* standard calls from library */ PHP_FUNCTION(tcc_add_file) { char *fname = NULL; int fname_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } RETURN_LONG(tcc_add_file(TCC_G(state), (const char *) fname)); } /* include path*/ PHP_FUNCTION(tcc_add_include_path) { char *fname = NULL; int fname_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } RETURN_LONG(tcc_add_include_path(TCC_G(state), (const char *) fname)); } /* the library name is the same as the argument of the '-l' option */ PHP_FUNCTION(tcc_add_library) { char *fname = NULL; int fname_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } RETURN_LONG(tcc_add_library(TCC_G(state), (const char *) fname)); } /* equivalent to -Lpath option */ PHP_FUNCTION(tcc_add_library_path) { char *fname = NULL; int fname_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) { return; } RETURN_LONG(tcc_add_library_path(TCC_G(state), (const char *) fname)); } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */