From 3ea33c216b773ad773ea22d3f7741291bdb8fce6 Mon Sep 17 00:00:00 2001 From: Shuhei Tanuma Date: Mon, 25 Jun 2012 13:34:47 +0900 Subject: [PATCH] add uv_setup_args and fix uv_get_process_title. should i call uv_setup_args at RINIT phase ? --- php_uv.c | 56 ++++++++++++++++++++++++++- tests/999-uv_get_process_title.phpt | 15 +++++++ tests/999-uv_resident_set_memory.phpt | 13 +++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 tests/999-uv_get_process_title.phpt create mode 100644 tests/999-uv_resident_set_memory.phpt diff --git a/php_uv.c b/php_uv.c index 96a6759..b84bac0 100644 --- a/php_uv.c +++ b/php_uv.c @@ -2949,12 +2949,14 @@ PHP_FUNCTION(uv_uptime) PHP_FUNCTION(uv_get_process_title) { char buffer[512] = {0}; + size_t buffer_sz; uv_err_t error; - /* TODO: check behavior */ - error = uv_get_process_title(buffer,sizeof(buffer)); + error = uv_get_process_title(buffer, sizeof(buffer)); if (UV_OK == error.code) { RETURN_STRING(buffer,1); + } else { + RETURN_FALSE; } } /* }}} */ @@ -4880,6 +4882,55 @@ PHP_FUNCTION(uv_ip6_name) } /* }}} */ +/* {{{ */ +PHP_FUNCTION(uv_setup_args) +{ + long argc = 0; + zval *argv, *z_result; + char **result, **real_argv, *key, *p; + HashTable *h; + HashPosition pos; + int i, hash_len , key_type = 0; + uint guard = 255; + uint key_len; + ulong key_index; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "la", &argc, &argv) == FAILURE) { + return; + } + + h = Z_ARRVAL_P(argv); + hash_len = zend_hash_num_elements(h); + + real_argv = ecalloc(hash_len+1, sizeof(char**)); + for (zend_hash_internal_pointer_reset_ex(h, &pos); + (key_type = zend_hash_get_current_key_ex(h, &key, &key_len, &key_index, 0, &pos)) != HASH_KEY_NON_EXISTANT; + zend_hash_move_forward_ex(h, &pos)) { + zval **value; + + zend_hash_get_current_data_ex(h, (void *) &value, &pos); + real_argv[pos->h] = Z_STRVAL_PP(value); + } + + result = uv_setup_args(argc, real_argv); + + MAKE_STD_ZVAL(z_result); + array_init(z_result); + + i = 0; + p = *result; + while (p != '\0' && i < guard) { + add_next_index_string(z_result, p, 1); + p = *result++; + i++; + } + efree(real_argv); + + RETURN_ZVAL(z_result,0,1); +} +/* }}} */ + static zend_function_entry uv_functions[] = { /* general */ @@ -5027,6 +5078,7 @@ static zend_function_entry uv_functions[] = { PHP_FE(uv_cwd, NULL) PHP_FE(uv_chdir, arginfo_uv_chdir) PHP_FE(uv_resident_set_memory, NULL) + PHP_FE(uv_setup_args, NULL) {NULL, NULL, NULL} }; diff --git a/tests/999-uv_get_process_title.phpt b/tests/999-uv_get_process_title.phpt new file mode 100644 index 0000000..d83cf92 --- /dev/null +++ b/tests/999-uv_get_process_title.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check for uv_get_process_title +--FILE-- + 0) { + echo "OK"; +} else { + echo "FAILED: {$title}"; +} +--EXPECT-- +OK \ No newline at end of file diff --git a/tests/999-uv_resident_set_memory.phpt b/tests/999-uv_resident_set_memory.phpt new file mode 100644 index 0000000..45f4afd --- /dev/null +++ b/tests/999-uv_resident_set_memory.phpt @@ -0,0 +1,13 @@ +--TEST-- +Check for uv_resident_set_memory +--FILE-- + 0) { + echo "OK"; +} else { + echo "FAILED: {resident_mem} should be greater than 0 (maybe)"; +} +--EXPECT-- +OK \ No newline at end of file