Index: tcc.c =================================================================== RCS file: /repository/pecl/tcc/tcc.c,v retrieving revision 1.2 diff -u -p -r1.2 tcc.c --- tcc.c 25 Apr 2008 04:09:47 -0000 1.2 +++ tcc.c 25 Apr 2008 07:19:39 -0000 @@ -25,16 +25,9 @@ #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[]. */ zend_function_entry tcc_functions[] = { PHP_FE(tcc_new, NULL) @@ -48,7 +41,7 @@ zend_function_entry tcc_functions[] = { PHP_FE(tcc_set_output_type, NULL) PHP_FE(tcc_output_file, NULL) PHP_FE(tcc_run, NULL) - {NULL, NULL, NULL} /* Must be the last line in tcc_functions[] */ + {NULL, NULL, NULL} }; /* }}} */ @@ -66,7 +59,7 @@ zend_module_entry tcc_module_entry = { NULL, PHP_MINFO(tcc), #if ZEND_MODULE_API_NO >= 20010901 - "0.1.2", /* Replace with version number for your extension */ + PHP_TCC_VERSION, #endif STANDARD_MODULE_PROPERTIES }; @@ -107,9 +100,6 @@ void php_tcc_error(void *opaque, const c */ PHP_MINIT_FUNCTION(tcc) { - /* If you have INI entries, uncomment these lines - REGISTER_INI_ENTRIES(); - */ le_tcc = zend_register_list_destructors_ex(php_tcc_dtor, NULL, PHP_TCC_RES_NAME, module_number); REGISTER_LONG_CONSTANT("TCC_OUTPUT_MEMORY", TCC_OUTPUT_MEMORY, @@ -148,6 +138,8 @@ PHP_MINFO_FUNCTION(tcc) { php_info_print_table_start(); php_info_print_table_header(2, "tcc support", "enabled"); + php_info_print_table_row(2, "Version", PHP_TCC_VERSION); + php_info_print_table_row(2, "Revision", "$Revision: 1.99 $"); php_info_print_table_end(); } /* }}} */ @@ -157,14 +149,17 @@ PHP_MINFO_FUNCTION(tcc) PHP_FUNCTION(tcc_new) { php_tcc *tcc; + tcc = emalloc(sizeof(php_tcc)); tcc->argc = 0; tcc->argv = NULL; tcc->state = tcc_new(); - if(!tcc->state){ + + if(!tcc->state) { efree(tcc); RETURN_FALSE; } + tcc_set_error_func(tcc->state, NULL, php_tcc_error); ZEND_REGISTER_RESOURCE(return_value, tcc, le_tcc); } @@ -177,14 +172,13 @@ PHP_FUNCTION(tcc_delete) zval *ztcc; php_tcc *tcc; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ztcc) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &ztcc) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); tcc_delete(tcc->state); tcc->state = NULL; - return; } /* }}} */ @@ -198,11 +192,10 @@ PHP_FUNCTION(tcc_add_include_path) int pathname_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &pathname, &pathname_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &pathname, &pathname_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_add_include_path(tcc->state, pathname); RETURN_LONG(ret); @@ -219,11 +212,10 @@ PHP_FUNCTION(tcc_add_sysinclude_path) int pathname_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &pathname, &pathname_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &pathname, &pathname_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_add_sysinclude_path(tcc->state, pathname); RETURN_LONG(ret); @@ -242,14 +234,12 @@ PHP_FUNCTION(tcc_define_symbol) int value_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rss", &ztcc, &sym, &sym_len, &value, &value_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &ztcc, &sym, &sym_len, &value, &value_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); tcc_define_symbol(tcc->state, sym, value); - return; } /* }}} */ @@ -262,14 +252,12 @@ PHP_FUNCTION(tcc_undefine_symbol) char *sym; int sym_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &sym, &sym_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &sym, &sym_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); tcc_undefine_symbol(tcc->state, sym); - return; } /* }}} */ @@ -283,11 +271,10 @@ PHP_FUNCTION(tcc_add_file) int filename_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &filename, &filename_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &filename, &filename_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_add_file(tcc->state, filename); RETURN_LONG(ret); @@ -304,11 +291,10 @@ PHP_FUNCTION(tcc_compile_string) int buf_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &buf, &buf_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &buf, &buf_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_compile_string(tcc->state, buf); RETURN_LONG(ret); @@ -324,11 +310,10 @@ PHP_FUNCTION(tcc_set_output_type) long output_type; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rl", &ztcc, &output_type) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &ztcc, &output_type) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_set_output_type(tcc->state, output_type); RETURN_LONG(ret); @@ -345,18 +330,17 @@ PHP_FUNCTION(tcc_output_file) int filename_len; int ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, - "rs", &ztcc, &filename, &filename_len) - == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &ztcc, &filename, &filename_len) == FAILURE) { + return; } + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); ret = tcc_output_file(tcc->state, filename); RETURN_LONG(ret); } /* }}} */ -/* {{{ proto int tcc_run(resource tcc) +/* {{{ proto int tcc_run(resource tcc[, array args]) */ PHP_FUNCTION(tcc_run) { @@ -364,42 +348,34 @@ PHP_FUNCTION(tcc_run) zval *ztcc; int ret; int i; - zval *zargv; + zval *zargv = NULL; zval **arg; HashTable *hash; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, - ZEND_NUM_ARGS() TSRMLS_CC, "r", &ztcc) - == SUCCESS) { - ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, - PHP_TCC_RES_NAME, le_tcc); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|a", &ztcc, &zargv) != SUCCESS) { + return; + } + + ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, PHP_TCC_RES_NAME, le_tcc); + + if (!zargv) { tcc->argc = 0; tcc->argv = NULL; - }else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, - ZEND_NUM_ARGS() TSRMLS_CC, - "ra", &ztcc, &zargv) - == SUCCESS) { - ZEND_FETCH_RESOURCE(tcc, php_tcc*, &ztcc, -1, - PHP_TCC_RES_NAME, le_tcc); + } else { hash = Z_ARRVAL_P(zargv); tcc->argc = zend_hash_num_elements(hash); tcc->argv = emalloc(sizeof(char*) * tcc->argc); + for(i=0; i < tcc->argc; i++){ if(zend_hash_get_current_data(hash, (void **)&arg) == FAILURE) { - php_error(E_WARNING, - "%s() takes tcc reference", - get_active_function_name(TSRMLS_C)); + php_error(E_WARNING, "%s() takes tcc reference", get_active_function_name(TSRMLS_C)); RETURN_FALSE; } tcc->argv[i] = Z_STRVAL_PP(arg); zend_hash_move_forward(hash); } - }else{ - php_error(E_WARNING, - "%s() takes tcc reference", - get_active_function_name(TSRMLS_C)); - RETURN_FALSE; } + ret = tcc_run(tcc->state, tcc->argc, tcc->argv); RETURN_LONG(ret); } Index: php_tcc.h =================================================================== RCS file: /repository/pecl/tcc/php_tcc.h,v retrieving revision 1.1 diff -u -p -r1.1 php_tcc.h --- php_tcc.h 24 Apr 2008 17:25:41 -0000 1.1 +++ php_tcc.h 25 Apr 2008 07:19:39 -0000 @@ -21,17 +21,12 @@ #include +#define PHP_TCC_VERSION "0.1.3-dev" #define PHP_TCC_RES_NAME "TCC State" extern zend_module_entry tcc_module_entry; #define phpext_tcc_ptr &tcc_module_entry -#ifdef PHP_WIN32 -#define PHP_TCC_API __declspec(dllexport) -#else -#define PHP_TCC_API -#endif - #ifdef ZTS #include "TSRM.h" #endif @@ -60,15 +55,8 @@ PHP_FUNCTION(tcc_set_output_type); PHP_FUNCTION(tcc_output_file); PHP_FUNCTION(tcc_run); -#ifdef ZTS -#define TCC_G(v) TSRMG(tcc_globals_id, zend_tcc_globals *, v) -#else -#define TCC_G(v) (tcc_globals.v) -#endif - #endif /* PHP_TCC_H */ - /* * Local variables: * tab-width: 4