From 84d7e09ce6e1e702b42975b94883e87cf1282ba7 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Fri, 7 Nov 2014 18:40:12 +0000 Subject: [PATCH 01/13] saving changes, still 3 failing tests --- php_uv.c | 284 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 164 insertions(+), 120 deletions(-) diff --git a/php_uv.c b/php_uv.c index 6d82127..e330391 100644 --- a/php_uv.c +++ b/php_uv.c @@ -56,7 +56,7 @@ zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 RETURN_FALSE; \ } \ r = uv_timer_init(loop, &uv->uv.timer); \ - if (r) { \ + if (r < 0) { \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "uv_timer_init failed");\ RETURN_FALSE;\ } \ @@ -257,6 +257,9 @@ char *php_uv_resource_map[IS_UV_MAX] = { /* TODO: fix this */ static char uv_fs_read_buf[8192]; +/* TODO: unsure about this! */ +static uv_buf_t uv_fs_read_buf_t; + /* declarations */ static inline uv_stream_t* php_uv_get_current_stream(php_uv_t *uv); @@ -285,17 +288,17 @@ static void php_uv_close_cb2(uv_handle_t *handle); static void php_uv_shutdown_cb(uv_shutdown_t* req, int status); -static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf); +static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread,const uv_buf_t* buf); static void php_uv_read2_cb(uv_pipe_t* handle, ssize_t nread, uv_buf_t buf, uv_handle_type pending); -static uv_buf_t php_uv_read_alloc(uv_handle_t* handle, size_t suggested_size); +static void php_uv_read_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf); static void php_uv_close_cb(uv_handle_t *handle); -static void php_uv_timer_cb(uv_timer_t *handle, int status); +static void php_uv_timer_cb(uv_timer_t *handle); -static void php_uv_idle_cb(uv_timer_t *handle, int status); +static void php_uv_idle_cb(uv_timer_t *handle); static void php_uv_signal_cb(uv_signal_t *handle, int sig_num); @@ -356,11 +359,8 @@ static php_socket_t php_uv_zval_to_fd(zval *ptr TSRMLS_DC) static const char* php_uv_strerror(long error_code) { - uv_err_t error; - error.code = error_code; - /* Note: uv_strerror doesn't use assert. we don't need check value here */ - return uv_strerror(error); + return uv_strerror(error_code); } /** @@ -388,7 +388,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_TCP: { r = uv_tcp_init(loop, &uv->uv.tcp); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_tcp_init failed"); goto cleanup; } @@ -399,7 +399,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_IDLE: { r = uv_idle_init(loop, &uv->uv.idle); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_idle_init failed"); goto cleanup; } @@ -410,7 +410,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_UDP: { r = uv_udp_init(loop, &uv->uv.udp); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_udp_init failed"); goto cleanup; } @@ -421,7 +421,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_PREPARE: { r = uv_prepare_init(loop, &uv->uv.prepare); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_prepare_init failed"); goto cleanup; } @@ -432,7 +432,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_CHECK: { r = uv_check_init(loop, &uv->uv.check); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_check_init failed"); goto cleanup; } @@ -953,9 +953,11 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS) PHP_UV_FS_PARSE_PARAMETERS("zzlf", &zloop, &zstream, &length, &fci, &fcc); memset(uv_fs_read_buf, 0, length); + uv_fs_read_buf_t = uv_buf_init(uv_fs_read_buf, length); + PHP_UV_FS_SETUP() PHP_UV_ZVAL_TO_FD(fd, zstream); - PHP_UV_FS_ASYNC(loop, read, fd, uv_fs_read_buf, length, -1); + PHP_UV_FS_ASYNC(loop, read, fd, &uv_fs_read_buf_t, 1, -1); break; } case UV_FS_SENDFILE: @@ -979,12 +981,16 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS) char *buffer; int buffer_len = 0; long fd, offset = -1; - + uv_buf_t uv_fs_write_buf_t; + PHP_UV_FS_PARSE_PARAMETERS("zzslf", &zloop, &zstream, &buffer, &buffer_len, &offset, &fci, &fcc); PHP_UV_FS_SETUP(); PHP_UV_ZVAL_TO_FD(fd, zstream); uv->buffer = estrndup(buffer, buffer_len); - PHP_UV_FS_ASYNC(loop, write, fd, uv->buffer, buffer_len, offset); + + /* TODO: is this right?! */ + uv_fs_write_buf_t = uv_buf_init(uv->buffer, buffer_len); + PHP_UV_FS_ASYNC(loop, write, fd, &uv_fs_write_buf_t, 1, offset); break; } case UV_FS_UNKNOWN: @@ -1043,7 +1049,7 @@ static zval *php_uv_address_to_zval(const struct sockaddr *addr) return tmp; } -static zval *php_uv_make_stat(const uv_statbuf_t *s) +static zval *php_uv_make_stat(const uv_stat_t *s) { zval *tmp; MAKE_STD_ZVAL(tmp); @@ -1342,7 +1348,8 @@ static void php_uv_tcp_connect_cb(uv_connect_t *req, int status) efree(req); } -static void php_uv_process_close_cb(uv_process_t* process, int exit_status, int term_signal) +/* TODO: Not sure how PHP will deal with int64_t */ +static void php_uv_process_close_cb(uv_process_t* process, int64_t exit_status, int term_signal) { zval *retval_ptr, *signal, *stat, *proc= NULL; zval **params[3]; @@ -1554,7 +1561,7 @@ static void php_uv_shutdown_cb(uv_shutdown_t* handle, int status) efree(handle); } -static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) +static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { zval *rsc, *buffer, *err, *retval_ptr = NULL; zval **params[3]; @@ -1565,7 +1572,7 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) MAKE_STD_ZVAL(buffer); if (nread > 0) { - ZVAL_STRINGL(buffer,buf.base,nread, 1); + ZVAL_STRINGL(buffer,buf->base,nread, 1); } else { ZVAL_NULL(buffer); } @@ -1591,8 +1598,8 @@ static void php_uv_read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) zval_ptr_dtor(&retval_ptr); } - if (buf.base) { - efree(buf.base); + if (buf->base) { + efree(buf->base); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read_cb, uv->resource_id); @@ -1645,60 +1652,50 @@ static void php_uv_read2_cb(uv_pipe_t* handle, ssize_t nread, uv_buf_t buf, uv_h PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read2_cb, uv->resource_id); } -static void php_uv_prepare_cb(uv_prepare_t* handle, int status) +static void php_uv_prepare_cb(uv_prepare_t* handle) { zval *retval_ptr = NULL; - zval **params[2]; - zval *rsc, *zstat; + zval **params[1]; + zval *rsc; php_uv_t *uv = (php_uv_t*)handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); PHP_UV_DEBUG_PRINT("prepare_cb\n"); - MAKE_STD_ZVAL(zstat); - ZVAL_LONG(zstat, status); - MAKE_STD_ZVAL(rsc); ZVAL_RESOURCE(rsc, uv->resource_id); zend_list_addref(uv->resource_id); params[0] = &rsc; - params[1] = &zstat; - php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_PREPARE_CB TSRMLS_CC); + php_uv_do_callback2(&retval_ptr, uv, params, 1, PHP_UV_PREPARE_CB TSRMLS_CC); zval_ptr_dtor(&rsc); - zval_ptr_dtor(&zstat); if (retval_ptr != NULL) { zval_ptr_dtor(&retval_ptr); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_prepare_cb, uv->resource_id); } -static void php_uv_check_cb(uv_check_t* handle, int status) +static void php_uv_check_cb(uv_check_t* handle) { zval *retval_ptr = NULL; - zval **params[2]; - zval *rsc, *zstat; + zval **params[1]; + zval *rsc; php_uv_t *uv = (php_uv_t*)handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); PHP_UV_DEBUG_PRINT("check_cb\n"); - MAKE_STD_ZVAL(zstat); - ZVAL_LONG(zstat, status); - MAKE_STD_ZVAL(rsc); ZVAL_RESOURCE(rsc, uv->resource_id); zend_list_addref(uv->resource_id); params[0] = &rsc; - params[1] = &zstat; - php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_CHECK_CB TSRMLS_CC); + php_uv_do_callback2(&retval_ptr, uv, params, 1, PHP_UV_CHECK_CB TSRMLS_CC); zval_ptr_dtor(&rsc); - zval_ptr_dtor(&zstat); if (retval_ptr != NULL) { zval_ptr_dtor(&retval_ptr); } @@ -1706,29 +1703,25 @@ static void php_uv_check_cb(uv_check_t* handle, int status) } -static void php_uv_async_cb(uv_async_t* handle, int status) +static void php_uv_async_cb(uv_async_t* handle) { zval *retval_ptr = NULL; - zval **params[2]; - zval *zstat, *resource; + zval **params[1]; + zval *resource; php_uv_t *uv = (php_uv_t*)handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); PHP_UV_DEBUG_PRINT("async_cb\n"); - MAKE_STD_ZVAL(zstat); - ZVAL_LONG(zstat, status); MAKE_STD_ZVAL(resource); ZVAL_RESOURCE(resource, uv->resource_id); zend_list_addref(uv->resource_id); params[0] = &resource; - params[1] = &zstat; - php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_ASYNC_CB TSRMLS_CC); + php_uv_do_callback2(&retval_ptr, uv, params, 1, PHP_UV_ASYNC_CB TSRMLS_CC); zval_ptr_dtor(&resource); - zval_ptr_dtor(&zstat); if (retval_ptr != NULL) { zval_ptr_dtor(&retval_ptr); } @@ -1829,7 +1822,7 @@ static void php_uv_fs_cb(uv_fs_t* req) { zval *buffer; if (Z_LVAL_P(result) >= 0) { - buffer = php_uv_make_stat((const uv_statbuf_t*)req->ptr); + buffer = php_uv_make_stat((const uv_stat_t*)req->ptr); } else { MAKE_STD_ZVAL(buffer); ZVAL_NULL(buffer); @@ -1956,7 +1949,7 @@ static void php_uv_fs_event_cb(uv_fs_event_t* req, const char* filename, int eve zval_ptr_dtor(params[3]); } -static void php_uv_statbuf_to_zval(zval *result, const uv_statbuf_t *stat) +static void php_uv_stat_to_zval(zval *result, const uv_stat_t *stat) { array_init(result); @@ -1981,7 +1974,7 @@ static void php_uv_statbuf_to_zval(zval *result, const uv_statbuf_t *stat) } -static void php_uv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_statbuf_t* prev, const uv_statbuf_t* curr) +static void php_uv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr) { zval **params[4], *retval_ptr, *rsc, *stat, *p, *c = NULL; php_uv_t *uv = (php_uv_t*)handle->data; @@ -1995,9 +1988,9 @@ static void php_uv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_statbuf ZVAL_LONG(stat, status); MAKE_STD_ZVAL(p); - php_uv_statbuf_to_zval(p, prev); + php_uv_stat_to_zval(p, prev); MAKE_STD_ZVAL(c); - php_uv_statbuf_to_zval(c, curr); + php_uv_stat_to_zval(c, curr); params[0] = &rsc; params[1] = &stat; @@ -2057,7 +2050,7 @@ static void php_uv_poll_cb(uv_poll_t* handle, int status, int events) } -static void php_uv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, uv_buf_t buf, struct sockaddr* addr, unsigned flags) +static void php_uv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf, const struct sockaddr* addr, unsigned flags) { /* TODO: is this implment correct? */ zval *retval_ptr = NULL; @@ -2067,7 +2060,7 @@ static void php_uv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, uv_buf_t buf, st TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); MAKE_STD_ZVAL(buffer); - ZVAL_STRINGL(buffer,buf.base,nread, 1); + ZVAL_STRINGL(buffer,buf->base,nread, 1); MAKE_STD_ZVAL(rsc); ZVAL_RESOURCE(rsc, uv->resource_id); @@ -2089,14 +2082,16 @@ static void php_uv_udp_recv_cb(uv_udp_t* handle, ssize_t nread, uv_buf_t buf, st zval_ptr_dtor(&retval_ptr); } - if (buf.base) { - efree(buf.base); + if (buf->base) { + efree(buf->base); } } -static uv_buf_t php_uv_read_alloc(uv_handle_t* handle, size_t suggested_size) +static void php_uv_read_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - return uv_buf_init(emalloc(suggested_size), suggested_size); + buf->base = emalloc(suggested_size); + buf->len = suggested_size; + //return uv_buf_init(emalloc(suggested_size), suggested_size); } @@ -2124,10 +2119,10 @@ static void php_uv_close_cb(uv_handle_t *handle) } -static void php_uv_idle_cb(uv_timer_t *handle, int status) +static void php_uv_idle_cb(uv_timer_t *handle) { - zval *retval_ptr, *idle, *stat = NULL; - zval **params[2]; + zval *retval_ptr, *idle; + zval **params[1]; php_uv_t *uv = (php_uv_t*)handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); @@ -2136,11 +2131,7 @@ static void php_uv_idle_cb(uv_timer_t *handle, int status) ZVAL_RESOURCE(idle, uv->resource_id); zend_list_addref(uv->resource_id); - MAKE_STD_ZVAL(stat); - ZVAL_LONG(stat, status); - params[0] = &idle; - params[1] = &stat; php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_IDLE_CB TSRMLS_CC); @@ -2149,7 +2140,6 @@ static void php_uv_idle_cb(uv_timer_t *handle, int status) zval_ptr_dtor(&retval_ptr); } zval_ptr_dtor(&idle); - zval_ptr_dtor(&stat); } static void php_uv_getaddrinfo_cb(uv_getaddrinfo_t* handle, int status, struct addrinfo* res) @@ -2210,28 +2200,24 @@ static void php_uv_getaddrinfo_cb(uv_getaddrinfo_t* handle, int status, struct a uv_freeaddrinfo(res); } -static void php_uv_timer_cb(uv_timer_t *handle, int status) +static void php_uv_timer_cb(uv_timer_t *handle) { - zval *retval_ptr, *stat, *client= NULL; + zval *retval_ptr, *client= NULL; zval **params[2]; php_uv_t *uv = (php_uv_t*)handle->data; TSRMLS_FETCH_FROM_CTX(uv->thread_ctx); - MAKE_STD_ZVAL(stat); - ZVAL_LONG(stat, status); MAKE_STD_ZVAL(client); ZVAL_RESOURCE(client, uv->resource_id); zend_list_addref(uv->resource_id); params[0] = &client; - params[1] = &stat; - php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_TIMER_CB TSRMLS_CC); + php_uv_do_callback2(&retval_ptr, uv, params, 1, PHP_UV_TIMER_CB TSRMLS_CC); if (retval_ptr != NULL) { zval_ptr_dtor(&retval_ptr); } - zval_ptr_dtor(&stat); zval_ptr_dtor(&client); } @@ -2404,16 +2390,16 @@ static void php_uv_socket_bind(enum php_uv_socket_type ip_type, INTERNAL_FUNCTIO switch (ip_type) { case PHP_UV_TCP_IPV4: - r = uv_tcp_bind((uv_tcp_t*)&uv->uv.tcp, PHP_UV_SOCKADDR_IPV4(addr)); + r = uv_tcp_bind((uv_tcp_t*)&uv->uv.tcp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV4(addr), 0); break; case PHP_UV_TCP_IPV6: - r = uv_tcp_bind6((uv_tcp_t*)&uv->uv.tcp, PHP_UV_SOCKADDR_IPV6(addr)); + r = uv_tcp_bind((uv_tcp_t*)&uv->uv.tcp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV6(addr), 0); break; case PHP_UV_UDP_IPV4: - r = uv_udp_bind((uv_udp_t*)&uv->uv.udp, PHP_UV_SOCKADDR_IPV4(addr), flags); + r = uv_udp_bind((uv_udp_t*)&uv->uv.udp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV4(addr), flags); break; case PHP_UV_UDP_IPV6: - r = uv_udp_bind6((uv_udp_t*)&uv->uv.udp, PHP_UV_SOCKADDR_IPV6(addr), flags); + r = uv_udp_bind((uv_udp_t*)&uv->uv.udp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV6(addr), flags); break; case PHP_UV_TCP: case PHP_UV_UDP: @@ -2422,7 +2408,7 @@ static void php_uv_socket_bind(enum php_uv_socket_type ip_type, INTERNAL_FUNCTIO break; } - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "bind failed"); RETURN_FALSE; } @@ -2503,9 +2489,9 @@ static void php_uv_udp_send(int type, INTERNAL_FUNCTION_PARAMETERS) php_uv_cb_init(&cb, client, &fci, &fcc, PHP_UV_SEND_CB); if (type == 1) { - uv_udp_send(&w->req, &client->uv.udp, &w->buf, 1, PHP_UV_SOCKADDR_IPV4(addr), php_uv_udp_send_cb); + uv_udp_send(&w->req, &client->uv.udp, &w->buf, 1, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV4(addr), php_uv_udp_send_cb); } else if (type == 2) { - uv_udp_send6(&w->req, &client->uv.udp, &w->buf, 1, PHP_UV_SOCKADDR_IPV6(addr), php_uv_udp_send_cb); + uv_udp_send(&w->req, &client->uv.udp, &w->buf, 1, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV6(addr), php_uv_udp_send_cb); } } @@ -2542,14 +2528,14 @@ static void php_uv_tcp_connect(enum php_uv_socket_type type, INTERNAL_FUNCTION_P goto clean; } - uv_tcp_connect(req, &uv->uv.tcp, PHP_UV_SOCKADDR_IPV4(addr), php_uv_tcp_connect_cb); + uv_tcp_connect(req, &uv->uv.tcp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV4(addr), php_uv_tcp_connect_cb); } else { if (!PHP_UV_SOCKADDR_IS_IPV6(addr)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed uv sockaddr resource is not initialized for ipv6"); goto clean; } - uv_tcp_connect6(req, &uv->uv.tcp, PHP_UV_SOCKADDR_IPV6(addr), php_uv_tcp_connect_cb); + uv_tcp_connect(req, &uv->uv.tcp, (const struct sockaddr*)&PHP_UV_SOCKADDR_IPV6(addr), php_uv_tcp_connect_cb); } return; @@ -2863,6 +2849,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_pipe_connect, 0, 0, 3) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_pipe_pending_count, 0, 0, 1) + ZEND_ARG_INFO(0, handle) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_pipe_pending_type, 0, 0, 1) + ZEND_ARG_INFO(0, handle) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_pipe_pending_instances, 0, 0, 2) ZEND_ARG_INFO(0, handle) ZEND_ARG_INFO(0, count) @@ -3293,7 +3287,7 @@ PHP_FUNCTION(uv_unref) PHP_FUNCTION(uv_last_error) { uv_loop_t *loop; - uv_err_t err; + int err; zval *zloop = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, @@ -3303,7 +3297,7 @@ PHP_FUNCTION(uv_last_error) PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop); err = uv_last_error(loop); - RETVAL_LONG(err.code); + RETVAL_LONG(err); } /* }}} */ @@ -3313,20 +3307,18 @@ PHP_FUNCTION(uv_err_name) { long error_code; const char *error_msg; - uv_err_t error; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) { return; } - if (error_code > UV_MAX_ERRORS || error_code < -1) { + if (error_code < UV_ERRNO_MAX || error_code > 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "passes unexpected value."); RETURN_FALSE; } - error.code = error_code; - error_msg = uv_err_name(error); + error_msg = uv_err_name(error_code); RETVAL_STRING(error_msg, 1); } @@ -3612,7 +3604,7 @@ PHP_FUNCTION(uv_write) PHP_UV_INIT_WRITE_REQ(w, uv, data, data_len) r = uv_write(&w->req, (uv_stream_t*)php_uv_get_current_stream(uv), &w->buf, 1, php_uv_write_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "write failed"); } @@ -3652,7 +3644,7 @@ PHP_FUNCTION(uv_write2) PHP_UV_INIT_WRITE_REQ(w, uv, data, data_len) r = uv_write2(&w->req, (uv_stream_t*)php_uv_get_current_stream(uv), &w->buf, 1, (uv_stream_t*)php_uv_get_current_stream(send), php_uv_write_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "write2 failed"); } @@ -3705,7 +3697,7 @@ PHP_FUNCTION(uv_accept) } r = uv_accept((uv_stream_t *)php_uv_get_current_stream(server), (uv_stream_t *)php_uv_get_current_stream(client)); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); RETURN_FALSE; } @@ -3746,7 +3738,7 @@ PHP_FUNCTION(uv_shutdown) shutdown->data = uv; r = uv_shutdown(shutdown, (uv_stream_t*)php_uv_get_current_stream(uv), (uv_shutdown_cb)php_uv_shutdown_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); } @@ -3841,7 +3833,7 @@ PHP_FUNCTION(uv_read_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_READ_CB); r = uv_read_start((uv_stream_t*)php_uv_get_current_stream(uv), php_uv_read_alloc, php_uv_read_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read failed"); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read_start, uv->resource_id); @@ -3887,7 +3879,7 @@ PHP_FUNCTION(uv_read2_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_READ2_CB); r = uv_read2_start((uv_stream_t*)php_uv_get_current_stream(uv), php_uv_read_alloc, php_uv_read2_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read2 failed"); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read2_start, uv->resource_id); @@ -3933,8 +3925,10 @@ PHP_FUNCTION(uv_ip4_addr) } PHP_UV_SOCKADDR_INIT(sockaddr, 1); - PHP_UV_SOCKADDR_IPV4(sockaddr) = uv_ip4_addr(address, port); - + //PHP_UV_SOCKADDR_IPV4(sockaddr) = uv_ip4_addr(address, port); + /* TODO: is this right?! */ + uv_ip4_addr(address, port, &PHP_UV_SOCKADDR_IPV4(sockaddr)); + ZEND_REGISTER_RESOURCE(return_value, sockaddr, uv_sockaddr_handle); sockaddr->resource_id = Z_RESVAL_P(return_value); } @@ -3955,7 +3949,9 @@ PHP_FUNCTION(uv_ip6_addr) } PHP_UV_SOCKADDR_INIT(sockaddr, 0); - PHP_UV_SOCKADDR_IPV6(sockaddr) = uv_ip6_addr(address, port); + //PHP_UV_SOCKADDR_IPV6(sockaddr) = uv_ip6_addr(address, port); + /* TODO: is this right?! */ + uv_ip6_addr(address, port, &PHP_UV_SOCKADDR_IPV6(sockaddr)); ZEND_REGISTER_RESOURCE(return_value, sockaddr, uv_sockaddr_handle); sockaddr->resource_id = Z_RESVAL_P(return_value); @@ -3995,7 +3991,7 @@ PHP_FUNCTION(uv_listen) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_LISTEN_CB); r = uv_listen((uv_stream_t*)php_uv_get_current_stream(uv), backlog, php_uv_listen_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); } } @@ -4417,7 +4413,7 @@ PHP_FUNCTION(uv_udp_recv_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_RECV_CB); r = uv_udp_recv_start((uv_udp_t*)&uv->uv.udp, php_uv_read_alloc, php_uv_udp_recv_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read failed"); } } @@ -4452,9 +4448,9 @@ PHP_FUNCTION(uv_udp_set_membership) { zval *client; php_uv_t *uv; - char *multicast_addr, interface_addr; + char *multicast_addr, *interface_addr; int error, multicast_addr_len, interface_addr_len = 0; - long membership; + int membership; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &client, &multicast_addr, &multicast_addr_len, &interface_addr, &interface_addr_len, &membership) == FAILURE) { @@ -4489,7 +4485,7 @@ PHP_FUNCTION(uv_udp_set_multicast_loop) PHP_UV_TYPE_CHECK(uv, IS_UV_UDP); r = uv_udp_set_multicast_loop((uv_udp_t*)&uv->uv.udp, enabled); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_loop failed"); } } @@ -4521,7 +4517,7 @@ PHP_FUNCTION(uv_udp_set_multicast_ttl) } r = uv_udp_set_multicast_ttl((uv_udp_t*)&uv->uv.udp, ttl); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_ttl failed"); } } @@ -4545,7 +4541,7 @@ PHP_FUNCTION(uv_udp_set_broadcast) PHP_UV_TYPE_CHECK(uv, IS_UV_UDP); r = uv_udp_set_broadcast((uv_udp_t*)&uv->uv.udp, enabled); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_loop failed"); } } @@ -4719,7 +4715,7 @@ PHP_FUNCTION(uv_pipe_init) uv->type = IS_UV_PIPE; r = uv_pipe_init(loop, &uv->uv.pipe, (int)ipc); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_pipe_init failed"); return; } @@ -4837,6 +4833,43 @@ PHP_FUNCTION(uv_pipe_pending_instances) } /* }}} */ +/* {{{ proto void uv_pipe_pending_count(resource $handle) +*/ +PHP_FUNCTION(uv_pipe_pending_count) +{ + php_uv_t *uv; + zval *handle; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z",&handle) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(uv, php_uv_t *, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle); + + PHP_UV_TYPE_CHECK(uv, IS_UV_PIPE); + + uv_pipe_pending_count(&uv->uv.pipe); +} +/* }}} */ + +/* {{{ proto void uv_pipe_pending_type(resource $handle) +*/ +PHP_FUNCTION(uv_pipe_pending_type) +{ + php_uv_t *uv; + zval *handle; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, + "z",&handle) == FAILURE) { + return; + } + ZEND_FETCH_RESOURCE(uv, php_uv_t *, &handle, -1, PHP_UV_RESOURCE_NAME, uv_resource_handle); + + PHP_UV_TYPE_CHECK(uv, IS_UV_PIPE); + + uv_pipe_pending_type(&uv->uv.pipe); +} +/* }}} */ #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3) /* {{{ proto void uv_stdio_new(zval $fd, long $flags) @@ -4915,7 +4948,7 @@ PHP_FUNCTION(uv_loadavg) */ PHP_FUNCTION(uv_uptime) { - uv_err_t error; + int error; double uptime; error = uv_uptime(&uptime); @@ -4969,12 +5002,13 @@ PHP_FUNCTION(uv_exepath) PHP_FUNCTION(uv_cwd) { char buffer[MAXPATHLEN]; + size_t buffer_sz = sizeof(buffer) / sizeof(buffer[0]); if (zend_parse_parameters_none() == FAILURE) { return; } - uv_cwd(buffer, MAXPATHLEN); + uv_cwd(buffer, &buffer_sz); RETURN_STRING(buffer, 1); } @@ -4986,11 +5020,11 @@ PHP_FUNCTION(uv_cpu_info) { zval *retval; uv_cpu_info_t *cpus; - uv_err_t error; + int error; int i, count; error = uv_cpu_info(&cpus, &count); - if (UV_OK == error.code) { + if (0 == error) { MAKE_STD_ZVAL(retval); array_init(retval); @@ -5028,12 +5062,12 @@ PHP_FUNCTION(uv_interface_addresses) { zval *retval; uv_interface_address_t *interfaces; - uv_err_t error; + int error; char buffer[512]; int i, count; error = uv_interface_addresses(&interfaces, &count); - if (UV_OK == error.code) { + if (0 == error) { MAKE_STD_ZVAL(retval); array_init(retval); @@ -5231,7 +5265,7 @@ PHP_FUNCTION(uv_spawn) proc->resource_id = Z_RESVAL_P(return_value); zval_copy_ctor(return_value); - r = uv_spawn(loop, &proc->uv.process, options); + r = uv_spawn(loop, &proc->uv.process, &options); if (zenv != NULL) { char **p = zenv; @@ -5291,7 +5325,7 @@ PHP_FUNCTION(uv_kill) */ PHP_FUNCTION(uv_chdir) { - uv_err_t error; + int error; char *directory; int directory_len; @@ -5300,7 +5334,7 @@ PHP_FUNCTION(uv_chdir) return; } error = uv_chdir(directory); - if (error.code == UV_OK) { + if (error == 0) { RETURN_TRUE; } else { RETURN_FALSE; @@ -5633,7 +5667,7 @@ PHP_FUNCTION(uv_async_init) PHP_UV_INIT_UV(uv, IS_UV_ASYNC); r = uv_async_init(loop, &uv->uv.async, php_uv_async_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_async_init failed"); return; } @@ -5694,7 +5728,7 @@ PHP_FUNCTION(uv_queue_work) r = uv_queue_work(loop, (uv_work_t*)&uv->uv.work, php_uv_work_cb, php_uv_after_work_cb); - if (r) { + if (r < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_queue_work failed"); return; } @@ -5938,11 +5972,19 @@ PHP_FUNCTION(uv_fs_event_init) uv->uv.fs_event.data = uv; - error = uv_fs_event_init(loop, (uv_fs_event_t*)&uv->uv.fs_event, path, php_uv_fs_event_cb, flags); - if (error) { + /* TODO: is this right?! */ + //error = uv_fs_event_init(loop, (uv_fs_event_t*)&uv->uv.fs_event, path, php_uv_fs_event_cb, flags); + error = uv_fs_event_init(loop, (uv_fs_event_t*)&uv->uv.fs_event); + if (error < 0) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_fs_event_init failed"); \ return; } + + error = uv_fs_event_start((uv_fs_event_t*)&uv->uv.fs_event, php_uv_fs_event_cb, path, flags); + if(error < 0) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_fs_event_start failed"); \ + return; + } } /* }}} */ @@ -6423,6 +6465,8 @@ static zend_function_entry uv_functions[] = { PHP_FE(uv_pipe_open, arginfo_uv_pipe_open) PHP_FE(uv_pipe_connect, arginfo_uv_pipe_connect) PHP_FE(uv_pipe_pending_instances, arginfo_uv_pipe_pending_instances) + PHP_FE(uv_pipe_pending_count, arginfo_uv_pipe_pending_count) + PHP_FE(uv_pipe_pending_type, arginfo_uv_pipe_pending_type) #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3) PHP_FE(uv_stdio_new, NULL) #endif From 1ea6c5aca4d300a2c8afce66ca9b6779ad2ef488 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Fri, 7 Nov 2014 21:42:17 +0000 Subject: [PATCH 02/13] update for libuv 1.0.0rc2, updated tests for api changes --- php_uv.c | 26 +++++++++++++++------ tests/100-uv_async.phpt | 4 ++-- tests/100-uv_check.phpt | 4 ++-- tests/100-uv_prepare.phpt | 4 ++-- tests/100-uv_timer.phpt | 4 ++-- tests/399-fs-stat-regression-no14.phpt | 32 +++++++++++++++++++++++--- tests/400-tcp_bind.phpt | 2 +- tests/800-uv_spawn.phpt | 4 ++-- tests/999-uv_chdir.phpt | 8 ++++++- tests/fixtures/poll | 1 + uv.c | 2 +- 11 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 tests/fixtures/poll diff --git a/php_uv.c b/php_uv.c index e330391..e3dc0a3 100644 --- a/php_uv.c +++ b/php_uv.c @@ -875,14 +875,14 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS) PHP_UV_FS_SETUP_AND_EXECUTE(open, path, flag, mode); break; } - case UV_FS_READDIR: + case UV_FS_SCANDIR: { char *path; int path_len = 0; long flags; PHP_UV_FS_PARSE_PARAMETERS("zslf!", &zloop, &path, &path_len, &flags, &fci, &fcc); - PHP_UV_FS_SETUP_AND_EXECUTE(readdir, path, flags); + PHP_UV_FS_SETUP_AND_EXECUTE(scandir, path, flags); break; } case UV_FS_LSTAT: @@ -1798,7 +1798,7 @@ static void php_uv_fs_cb(uv_fs_t* req) argc = 1; break; } - case UV_FS_READDIR: + case UV_FS_SCANDIR: { zval *dirent; int nnames, i = 0; @@ -2133,7 +2133,7 @@ static void php_uv_idle_cb(uv_timer_t *handle) params[0] = &idle; - php_uv_do_callback2(&retval_ptr, uv, params, 2, PHP_UV_IDLE_CB TSRMLS_CC); + php_uv_do_callback2(&retval_ptr, uv, params, 1, PHP_UV_IDLE_CB TSRMLS_CC); if (retval_ptr != NULL) { @@ -4839,6 +4839,7 @@ PHP_FUNCTION(uv_pipe_pending_count) { php_uv_t *uv; zval *handle; + int count; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&handle) == FAILURE) { @@ -4848,7 +4849,8 @@ PHP_FUNCTION(uv_pipe_pending_count) PHP_UV_TYPE_CHECK(uv, IS_UV_PIPE); - uv_pipe_pending_count(&uv->uv.pipe); + count = uv_pipe_pending_count(&uv->uv.pipe); + RETURN_LONG(count); } /* }}} */ @@ -4858,6 +4860,7 @@ PHP_FUNCTION(uv_pipe_pending_type) { php_uv_t *uv; zval *handle; + uv_handle_type ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&handle) == FAILURE) { @@ -4867,7 +4870,8 @@ PHP_FUNCTION(uv_pipe_pending_type) PHP_UV_TYPE_CHECK(uv, IS_UV_PIPE); - uv_pipe_pending_type(&uv->uv.pipe); + ret = uv_pipe_pending_type(&uv->uv.pipe); + RETURN_LONG(ret); } /* }}} */ @@ -5934,7 +5938,15 @@ PHP_FUNCTION(uv_fs_fstat) */ PHP_FUNCTION(uv_fs_readdir) { - php_uv_fs_common(UV_FS_READDIR, INTERNAL_FUNCTION_PARAM_PASSTHRU); + php_uv_fs_common(UV_FS_SCANDIR, INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto uv_fs_scandir(resource $loop, string $path, long $flags, callable $callback) + * */ +PHP_FUNCTION(uv_fs_scandir) +{ + php_uv_fs_common(UV_FS_SCANDIR, INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ diff --git a/tests/100-uv_async.phpt b/tests/100-uv_async.phpt index 9dc8d03..a750d2f 100644 --- a/tests/100-uv_async.phpt +++ b/tests/100-uv_async.phpt @@ -3,7 +3,7 @@ Check for uv_async --FILE-- Date: Mon, 10 Nov 2014 04:30:57 +0000 Subject: [PATCH 03/13] fix issue with uv_loop_new based on 1.0 migration guide, add additional tests --- php_uv.c | 62 +++++++++++++++++++++++--------------- tests/010-uv_loop_new.phpt | 15 +++++++++ tests/330-poll-fd.phpt | 20 ++++++++++++ 3 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 tests/010-uv_loop_new.phpt create mode 100644 tests/330-poll-fd.phpt diff --git a/php_uv.c b/php_uv.c index e3dc0a3..9eb05cc 100644 --- a/php_uv.c +++ b/php_uv.c @@ -56,7 +56,7 @@ zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 RETURN_FALSE; \ } \ r = uv_timer_init(loop, &uv->uv.timer); \ - if (r < 0) { \ + if (r) { \ php_error_docref(NULL TSRMLS_CC, E_WARNING, "uv_timer_init failed");\ RETURN_FALSE;\ } \ @@ -388,7 +388,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_TCP: { r = uv_tcp_init(loop, &uv->uv.tcp); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_tcp_init failed"); goto cleanup; } @@ -399,7 +399,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_IDLE: { r = uv_idle_init(loop, &uv->uv.idle); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_idle_init failed"); goto cleanup; } @@ -410,7 +410,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_UDP: { r = uv_udp_init(loop, &uv->uv.udp); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_udp_init failed"); goto cleanup; } @@ -421,7 +421,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_PREPARE: { r = uv_prepare_init(loop, &uv->uv.prepare); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_prepare_init failed"); goto cleanup; } @@ -432,7 +432,7 @@ static inline int php_uv_common_init(php_uv_t **result, uv_loop_t *loop, enum ph case IS_UV_CHECK: { r = uv_check_init(loop, &uv->uv.check); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_check_init failed"); goto cleanup; } @@ -1117,7 +1117,10 @@ void static destruct_uv_loop(zend_rsrc_list_entry *rsrc TSRMLS_DC) { uv_loop_t *loop = (uv_loop_t *)rsrc->ptr; if (loop != _php_uv_default_loop) { - uv_loop_delete(loop); + //uv_loop_delete(loop); + /* updated for libuv 1.0 as uv_loop_delete is deprecated */ + uv_loop_close(loop); + efree(loop); } } @@ -2408,7 +2411,7 @@ static void php_uv_socket_bind(enum php_uv_socket_type ip_type, INTERNAL_FUNCTIO break; } - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "bind failed"); RETURN_FALSE; } @@ -3530,7 +3533,10 @@ PHP_FUNCTION(uv_loop_delete) PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop); if (loop != _php_uv_default_loop) { - uv_loop_delete(loop); + //uv_loop_delete(loop); + /* uv_loop_delete deprecated with libuv 1.0 */ + uv_loop_close(loop); + efree(loop); } } /* }}} */ @@ -3604,7 +3610,7 @@ PHP_FUNCTION(uv_write) PHP_UV_INIT_WRITE_REQ(w, uv, data, data_len) r = uv_write(&w->req, (uv_stream_t*)php_uv_get_current_stream(uv), &w->buf, 1, php_uv_write_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "write failed"); } @@ -3644,7 +3650,7 @@ PHP_FUNCTION(uv_write2) PHP_UV_INIT_WRITE_REQ(w, uv, data, data_len) r = uv_write2(&w->req, (uv_stream_t*)php_uv_get_current_stream(uv), &w->buf, 1, (uv_stream_t*)php_uv_get_current_stream(send), php_uv_write_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "write2 failed"); } @@ -3697,7 +3703,7 @@ PHP_FUNCTION(uv_accept) } r = uv_accept((uv_stream_t *)php_uv_get_current_stream(server), (uv_stream_t *)php_uv_get_current_stream(client)); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); RETURN_FALSE; } @@ -3738,7 +3744,7 @@ PHP_FUNCTION(uv_shutdown) shutdown->data = uv; r = uv_shutdown(shutdown, (uv_stream_t*)php_uv_get_current_stream(uv), (uv_shutdown_cb)php_uv_shutdown_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); } @@ -3833,7 +3839,7 @@ PHP_FUNCTION(uv_read_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_READ_CB); r = uv_read_start((uv_stream_t*)php_uv_get_current_stream(uv), php_uv_read_alloc, php_uv_read_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read failed"); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read_start, uv->resource_id); @@ -3844,6 +3850,9 @@ PHP_FUNCTION(uv_read_start) */ PHP_FUNCTION(uv_read2_start) { + /* TODO: determine how to make this backwards compatible? */ + php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_read2_start is no longer supported."); + /* zval *client; php_uv_t *uv; int r; @@ -3879,10 +3888,11 @@ PHP_FUNCTION(uv_read2_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_READ2_CB); r = uv_read2_start((uv_stream_t*)php_uv_get_current_stream(uv), php_uv_read_alloc, php_uv_read2_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read2 failed"); } PHP_UV_DEBUG_RESOURCE_REFCOUNT(uv_read2_start, uv->resource_id); + */ } /* }}} */ @@ -3991,7 +4001,7 @@ PHP_FUNCTION(uv_listen) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_LISTEN_CB); r = uv_listen((uv_stream_t*)php_uv_get_current_stream(uv), backlog, php_uv_listen_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_uv_strerror(r)); } } @@ -4342,9 +4352,11 @@ PHP_FUNCTION(uv_default_loop) */ PHP_FUNCTION(uv_loop_new) { - uv_loop_t *loop; + uv_loop_t *loop = emalloc(sizeof(*loop)); + uv_loop_init(loop); - loop = uv_loop_new(); + //loop = uv_loop_new(); + ZEND_REGISTER_RESOURCE(return_value, loop, uv_loop_handle); } /* }}} */ @@ -4413,7 +4425,7 @@ PHP_FUNCTION(uv_udp_recv_start) php_uv_cb_init(&cb, uv, &fci, &fcc, PHP_UV_RECV_CB); r = uv_udp_recv_start((uv_udp_t*)&uv->uv.udp, php_uv_read_alloc, php_uv_udp_recv_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "read failed"); } } @@ -4485,7 +4497,7 @@ PHP_FUNCTION(uv_udp_set_multicast_loop) PHP_UV_TYPE_CHECK(uv, IS_UV_UDP); r = uv_udp_set_multicast_loop((uv_udp_t*)&uv->uv.udp, enabled); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_loop failed"); } } @@ -4517,7 +4529,7 @@ PHP_FUNCTION(uv_udp_set_multicast_ttl) } r = uv_udp_set_multicast_ttl((uv_udp_t*)&uv->uv.udp, ttl); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_ttl failed"); } } @@ -4541,7 +4553,7 @@ PHP_FUNCTION(uv_udp_set_broadcast) PHP_UV_TYPE_CHECK(uv, IS_UV_UDP); r = uv_udp_set_broadcast((uv_udp_t*)&uv->uv.udp, enabled); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "uv_udp_set_muticast_loop failed"); } } @@ -4715,7 +4727,7 @@ PHP_FUNCTION(uv_pipe_init) uv->type = IS_UV_PIPE; r = uv_pipe_init(loop, &uv->uv.pipe, (int)ipc); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_pipe_init failed"); return; } @@ -5671,7 +5683,7 @@ PHP_FUNCTION(uv_async_init) PHP_UV_INIT_UV(uv, IS_UV_ASYNC); r = uv_async_init(loop, &uv->uv.async, php_uv_async_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_async_init failed"); return; } @@ -5732,7 +5744,7 @@ PHP_FUNCTION(uv_queue_work) r = uv_queue_work(loop, (uv_work_t*)&uv->uv.work, php_uv_work_cb, php_uv_after_work_cb); - if (r < 0) { + if (r) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "uv_queue_work failed"); return; } diff --git a/tests/010-uv_loop_new.phpt b/tests/010-uv_loop_new.phpt new file mode 100644 index 0000000..a0813e6 --- /dev/null +++ b/tests/010-uv_loop_new.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check to make sure uv_loop_new can be used +--SKIPIF-- + +--FILE-- + Date: Mon, 10 Nov 2014 15:46:49 +0000 Subject: [PATCH 04/13] add test for fs_close issue described in #36, updating travis build --- .travis.yml | 10 ++++------ tests/300-fs_close.phpt | 19 +++++++++++++++++++ travis-install.sh | 13 +++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 tests/300-fs_close.phpt create mode 100644 travis-install.sh diff --git a/.travis.yml b/.travis.yml index 14e70fa..7f906e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,10 @@ php: - 5.5 - 5.6 -before_script: - - sudo apt-add-repository -y ppa:linuxjedi/ppa - - sudo apt-get update -qq - - sudo apt-get -y install libuv-dev - - phpize && ./configure --with-uv --enable-httpparser && make && sudo make install - - echo "extension=uv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` +before_install: + - chmod +x travis-install.sh + +install: ./travis-install.sh notifications: email: false diff --git a/tests/300-fs_close.phpt b/tests/300-fs_close.phpt new file mode 100644 index 0000000..5407f87 --- /dev/null +++ b/tests/300-fs_close.phpt @@ -0,0 +1,19 @@ +--TEST-- +Check for fs read and close +--FILE-- +> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"` From a25595f43a0d2541b44ce4713833dcf4cf13dd1e Mon Sep 17 00:00:00 2001 From: Daniel Lowrey Date: Tue, 11 Nov 2014 10:36:22 -0500 Subject: [PATCH 05/13] Add $offset param to uv_fs_read() to allow seeking on open handles This change modifies the uv_fs_read() function signature slightly by adding a new $offset parameter. This allows the same file handle to be reused for multiple reads. Previously the only way to access a section of a file that had already been read was to open a new handle. Old: uv_fs_read(resoruce $loop, zval $fd, long $length, callable $callback) New: uv_fs_read(resoruce $loop, zval $fd, long $offest, long $length, callable $callback) This change represents a minor BC break for existing code using uv_fs_read(). --- README.md | 6 +++++- php_uv.c | 10 ++++++---- tests/300-fs.phpt | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 20d28a3..a5dac3e 100644 --- a/README.md +++ b/README.md @@ -2180,7 +2180,7 @@ uv_run(); -### void uv_fs_read(resource $loop, zval $fd, long $length, callable $callback) +### void uv_fs_read(resource $loop, zval $fd, long $offset, long $length, callable $callback) ##### *Description* @@ -2192,6 +2192,10 @@ async read. *zval $fd*: this expects long $fd, resource $php_stream or resource $php_socket. +*long $offset*: the offset position in the file at which reading should commence. + +*long $length*: the length in bytes that should be read starting at position *$offset*. + *resource $callback*: this callback parameter expects (zval $fd, long $nread, string $buffer). ##### *Return Value* diff --git a/php_uv.c b/php_uv.c index 6d82127..2466790 100644 --- a/php_uv.c +++ b/php_uv.c @@ -950,12 +950,13 @@ static void php_uv_fs_common(uv_fs_type fs_type, INTERNAL_FUNCTION_PARAMETERS) zval *zstream = NULL; unsigned long fd; unsigned long length; - - PHP_UV_FS_PARSE_PARAMETERS("zzlf", &zloop, &zstream, &length, &fci, &fcc); + unsigned long offset; + + PHP_UV_FS_PARSE_PARAMETERS("zzllf", &zloop, &zstream, &offset, &length, &fci, &fcc); memset(uv_fs_read_buf, 0, length); PHP_UV_FS_SETUP() PHP_UV_ZVAL_TO_FD(fd, zstream); - PHP_UV_FS_ASYNC(loop, read, fd, uv_fs_read_buf, length, -1); + PHP_UV_FS_ASYNC(loop, read, fd, uv_fs_read_buf, length, offset); break; } case UV_FS_SENDFILE: @@ -3023,6 +3024,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_fs_read, 0, 0, 3) ZEND_ARG_INFO(0, loop) ZEND_ARG_INFO(0, fd) + ZEND_ARG_INFO(0, offset) ZEND_ARG_INFO(0, size) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() @@ -5713,7 +5715,7 @@ PHP_FUNCTION(uv_fs_open) /* }}} */ -/* {{{ proto void uv_fs_read(resoruce $loop, zval $fd, callable $callback) +/* {{{ proto void uv_fs_read(resoruce $loop, zval $fd, long $offset, long $length, callable $callback) */ PHP_FUNCTION(uv_fs_read) { diff --git a/tests/300-fs.phpt b/tests/300-fs.phpt index 81a94c0..cdca52b 100644 --- a/tests/300-fs.phpt +++ b/tests/300-fs.phpt @@ -5,7 +5,7 @@ Check for fs read and close define("FIXTURE_PATH", dirname(__FILE__) . "/fixtures/hello.data"); uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){ - uv_fs_read(uv_default_loop(),$r,32,function($stream, $nread, $data) { + uv_fs_read(uv_default_loop(),$r, $offset=0, $len=32,function($stream, $nread, $data) { if ($nread <= 0) { if ($nread < 0) { throw new Exception("read error"); From 459b61462a1030430c768fc7852fb34be47ec7f4 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Wed, 12 Nov 2014 15:49:12 +0000 Subject: [PATCH 06/13] fix uv_fs_scandir --- php_uv.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/php_uv.c b/php_uv.c index 9eb05cc..9822f97 100644 --- a/php_uv.c +++ b/php_uv.c @@ -1806,15 +1806,13 @@ static void php_uv_fs_cb(uv_fs_t* req) zval *dirent; int nnames, i = 0; char *namebuf = (char *)req->ptr; - + uv_dirent_t dent; + MAKE_STD_ZVAL(dirent); array_init(dirent); - - nnames = req->result; - for (i = 0; i < nnames; i++) { - add_next_index_string(dirent, namebuf, 1); - namebuf += strlen(namebuf) + 1; - } + while (UV_EOF != uv_fs_scandir_next(req, &dent)) { + add_next_index_string(dirent, dent.name, 1); + } params[1] = &dirent; break; @@ -2924,6 +2922,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_fs_readdir, 0, 0, 4) ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_fs_scandir, 0, 0, 4) + ZEND_ARG_INFO(0, loop) + ZEND_ARG_INFO(0, path) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, callback) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_uv_fs_fstat, 0, 0, 3) ZEND_ARG_INFO(0, loop) ZEND_ARG_INFO(0, fd) @@ -6556,6 +6561,7 @@ static zend_function_entry uv_functions[] = { PHP_FE(uv_fs_lstat, arginfo_uv_fs_lstat) PHP_FE(uv_fs_fstat, arginfo_uv_fs_fstat) PHP_FE(uv_fs_readdir, arginfo_uv_fs_readdir) + PHP_FE(uv_fs_scandir, arginfo_uv_fs_scandir) PHP_FE(uv_fs_sendfile, arginfo_uv_fs_sendfile) PHP_FE(uv_fs_event_init, arginfo_uv_fs_event_init) /* tty */ From 73a295abc998fdc61ef749b558f802e8e2cc6720 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Wed, 12 Nov 2014 15:52:08 +0000 Subject: [PATCH 07/13] cleanup uv_fs_scandir --- php_uv.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/php_uv.c b/php_uv.c index 9822f97..a4cc5b1 100644 --- a/php_uv.c +++ b/php_uv.c @@ -1804,8 +1804,6 @@ static void php_uv_fs_cb(uv_fs_t* req) case UV_FS_SCANDIR: { zval *dirent; - int nnames, i = 0; - char *namebuf = (char *)req->ptr; uv_dirent_t dent; MAKE_STD_ZVAL(dirent); From dd9aac9abbaeb1be871a2f1d0e121645beae91de Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Thu, 13 Nov 2014 02:20:21 +0000 Subject: [PATCH 08/13] Fix Issue #59 segfault on null passed as handle to uv_stdio_new --- php_uv.c | 14 ++++++++------ tests/800-uv_spawn-issue59.phpt | 9 +++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 tests/800-uv_spawn-issue59.phpt diff --git a/php_uv.c b/php_uv.c index a4cc5b1..2be7416 100644 --- a/php_uv.c +++ b/php_uv.c @@ -4908,11 +4908,10 @@ PHP_FUNCTION(uv_stdio_new) return; } - stdio = (php_uv_stdio_t*)emalloc(sizeof(php_uv_stdio_t)); - stdio->flags = flags; - stdio->stream = NULL; - - if (Z_TYPE_P(handle) == IS_LONG) { + if(Z_TYPE_P(handle) == IS_NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed unexpected resource"); + RETURN_FALSE; + } else if (Z_TYPE_P(handle) == IS_LONG) { fd = Z_LVAL_P(handle); } else if (Z_TYPE_P(handle) == IS_RESOURCE) { if (ZEND_FETCH_RESOURCE_NO_RETURN(stream, php_stream*, &handle, -1, NULL, php_file_le_stream())) { @@ -4929,7 +4928,10 @@ PHP_FUNCTION(uv_stdio_new) } } - + stdio = (php_uv_stdio_t*)emalloc(sizeof(php_uv_stdio_t)); + stdio->flags = flags; + stdio->stream = NULL; + stdio->fd = fd; if (Z_TYPE_P(handle) == IS_RESOURCE) { diff --git a/tests/800-uv_spawn-issue59.phpt b/tests/800-uv_spawn-issue59.phpt new file mode 100644 index 0000000..c817d0d --- /dev/null +++ b/tests/800-uv_spawn-issue59.phpt @@ -0,0 +1,9 @@ +--TEST-- +Test uv_spawn doesn't cause segfault #56 +--FILE-- + Date: Fri, 14 Nov 2014 02:01:07 +0000 Subject: [PATCH 09/13] Fix issue #36, Fix issue #56, uv_poll no longer allows plainfiles or php related streams resolving a SIGABRT as epoll doesn't support those stream types --- php_uv.c | 67 +++++++++++++++++++++++++++++++++++++++- tests/300-fs_close.phpt | 4 +-- tests/330-poll-fd.phpt | 4 +-- tests/330-poll-pipe.phpt | 20 ++++++++++++ tests/fixtures/proc.php | 3 ++ 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 tests/330-poll-pipe.phpt create mode 100644 tests/fixtures/proc.php diff --git a/php_uv.c b/php_uv.c index 2be7416..cbd6c7b 100644 --- a/php_uv.c +++ b/php_uv.c @@ -110,6 +110,18 @@ zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 lock->type = lock_type; \ lock->locked = 0; \ +#define PHP_UV_ZVAL_TO_VALID_POLL_FD(fd, zstream) \ +{ \ + fd = php_uv_zval_to_valid_poll_fd(zstream TSRMLS_CC); \ + if (fd < 0) { \ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid variable passed. can't convert to fd."); \ + RETURN_FALSE; \ + } \ + if (uv->fs_fd == NULL) { \ + uv->fs_fd = zstream;\ + Z_ADDREF_P(zstream);\ + }\ +} #define PHP_UV_ZVAL_TO_FD(fd, zstream) \ { \ @@ -318,6 +330,51 @@ static char *php_uv_map_resource_name(enum php_uv_resource_type type) RETURN_FALSE; \ } \ +#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3) +static php_socket_t php_uv_zval_to_valid_poll_fd(zval *ptr TSRMLS_DC) +{ + php_socket_t fd = -1; + php_stream *stream; + php_uv_t *uv; + + /* Validate Checks */ + const char check_php[] = "PHP"; + const char check_file[] = "plainfile"; + +#ifndef PHP_WIN32 + php_socket *socket; +#endif + /* TODO: is this correct on windows platform? */ + if (Z_TYPE_P(ptr) == IS_RESOURCE) { + if (ZEND_FETCH_RESOURCE_NO_RETURN(stream, php_stream *, &ptr, -1, NULL, php_file_le_stream())) { + /* make sure only valid resource streams are passed - plainfiles and php streams are invalid */ + if (stream->wrapper) { + if ( (strcmp((char *)stream->wrapper->wops->label, check_file) == 0) || (strcmp((char *)stream->wrapper->wops->label, check_php) == 0) ) { + php_error_docref(NULL TSRMLS_CC, E_ERROR, "invalid resource passed, this resource is not supported"); + return -1; + } + } + + if (php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&fd, 1) != SUCCESS || fd < 0) { + fd = -1; + } + } else if (ZEND_FETCH_RESOURCE_NO_RETURN(uv, php_uv_t*, &ptr, -1, NULL, uv_resource_handle)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "uv resource does not support yet"); + fd = -1; +#ifndef PHP_WIN32 + } else if (ZEND_FETCH_RESOURCE_NO_RETURN(socket, php_socket *, &ptr, -1, NULL, php_sockets_le_socket())) { + /* TODO: is this correct on windows platform? */ + fd = socket->bsd_socket; +#endif + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unhandled resource type detected."); + fd = -1; + } + } + + return fd; +} +#endif #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3) static php_socket_t php_uv_zval_to_fd(zval *ptr TSRMLS_DC) @@ -351,6 +408,14 @@ static php_socket_t php_uv_zval_to_fd(zval *ptr TSRMLS_DC) if (fd < 0) { fd = -1; } + + /* make sure that a valid resource handle was passed - issue #36 */ + int err; + err = uv_guess_handle((uv_file) fd); + if(err == UV_UNKNOWN_HANDLE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid resource type detected"); + fd = -1; + } } return fd; @@ -6210,7 +6275,7 @@ PHP_FUNCTION(uv_poll_init) PHP_UV_INIT_UV(uv, IS_UV_POLL); PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop); - PHP_UV_ZVAL_TO_FD(fd, zstream); + PHP_UV_ZVAL_TO_VALID_POLL_FD(fd, zstream); error = uv_poll_init(loop, &uv->uv.poll, fd); if (error) { diff --git a/tests/300-fs_close.phpt b/tests/300-fs_close.phpt index 5407f87..1ab1cda 100644 --- a/tests/300-fs_close.phpt +++ b/tests/300-fs_close.phpt @@ -15,5 +15,5 @@ uv_fs_open(uv_default_loop(),FIXTURE_PATH, UV::O_RDONLY, 0, function($r){ }); uv_run(); ---EXPECT-- -OK +--EXPECTF-- +Warning: uv_fs_close(): invalid resource type detected in %s on line %d diff --git a/tests/330-poll-fd.phpt b/tests/330-poll-fd.phpt index 56f6675..37142af 100644 --- a/tests/330-poll-fd.phpt +++ b/tests/330-poll-fd.phpt @@ -16,5 +16,5 @@ uv_run($loop); fwrite($fd, 'hello'); ---EXPECT-- -OK +--EXPECTF-- +Fatal error: uv_poll_init(): invalid resource passed, this resource is not supported in %s on line %d diff --git a/tests/330-poll-pipe.phpt b/tests/330-poll-pipe.phpt new file mode 100644 index 0000000..37a8a8f --- /dev/null +++ b/tests/330-poll-pipe.phpt @@ -0,0 +1,20 @@ +--TEST-- +Check poll of a pipe works +--FILE-- + Date: Fri, 14 Nov 2014 02:05:44 +0000 Subject: [PATCH 10/13] fix notice --- tests/330-poll-pipe.phpt | 1 - tests/fixtures/proc.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/330-poll-pipe.phpt b/tests/330-poll-pipe.phpt index 37a8a8f..cd6a648 100644 --- a/tests/330-poll-pipe.phpt +++ b/tests/330-poll-pipe.phpt @@ -4,7 +4,6 @@ Check poll of a pipe works Date: Fri, 14 Nov 2014 02:26:36 +0000 Subject: [PATCH 11/13] update test, just checking for no segfault --- tests/330-poll-pipe.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/330-poll-pipe.phpt b/tests/330-poll-pipe.phpt index cd6a648..36fabca 100644 --- a/tests/330-poll-pipe.phpt +++ b/tests/330-poll-pipe.phpt @@ -2,18 +2,18 @@ Check poll of a pipe works --FILE-- &1", "w"); stream_set_blocking($fd, 0); $loop = uv_loop_new(); $poll = uv_poll_init($loop, $fd); uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $fd) { - echo "OK"; + echo "\nOK"; uv_poll_stop($poll); pclose($fd); }); uv_run($loop); - --EXPECT-- +hello OK From 42361ad0c5a7baf1f84956aa44b77228618e4b48 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Mon, 17 Nov 2014 16:48:57 +0000 Subject: [PATCH 12/13] fix segfault issue caused by uv_unref deleting resource, resource is freed by destruct_uv --- php_uv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/php_uv.c b/php_uv.c index cbd6c7b..0a0bc02 100644 --- a/php_uv.c +++ b/php_uv.c @@ -1178,12 +1178,19 @@ void static destruct_uv_lock(zend_rsrc_list_entry *rsrc TSRMLS_DC) efree(lock); } +static void destruct_uv_loop_walk_cb(uv_handle_t* handle, void* arg) +{ + if (!uv_is_closing(handle)) { + uv_close(handle, NULL); + } +} + void static destruct_uv_loop(zend_rsrc_list_entry *rsrc TSRMLS_DC) { uv_loop_t *loop = (uv_loop_t *)rsrc->ptr; if (loop != _php_uv_default_loop) { - //uv_loop_delete(loop); /* updated for libuv 1.0 as uv_loop_delete is deprecated */ + uv_walk(loop, destruct_uv_loop_walk_cb, NULL); uv_loop_close(loop); efree(loop); } @@ -1226,8 +1233,8 @@ void static destruct_uv(zend_rsrc_list_entry *rsrc TSRMLS_DC) } obj->in_free = 1; - - /* for now */ + + /* for now */ for (i = 0; i < PHP_UV_CB_MAX; i++) { php_uv_cb_t *cb = obj->callback[i]; if (cb != NULL) { @@ -3343,10 +3350,8 @@ PHP_FUNCTION(uv_unref) if (ZEND_FETCH_RESOURCE_NO_RETURN(loop, uv_loop_t*, &handle, -1, NULL, uv_loop_handle)) { uv_unref((uv_handle_t *)loop); - zend_list_delete(Z_RESVAL_P(handle)); } else if (ZEND_FETCH_RESOURCE_NO_RETURN(uv, php_uv_t*, &handle, -1, NULL, uv_resource_handle)) { uv_unref((uv_handle_t *)php_uv_get_current_stream(uv)); - zend_list_delete(uv->resource_id); } else { php_error_docref(NULL TSRMLS_CC, E_ERROR, "passes unexpected resource."); } @@ -4111,6 +4116,7 @@ PHP_FUNCTION(uv_timer_init) PHP_UV_INIT_TIMER(uv, IS_UV_TIMER) uv->uv.timer.data = uv; + PHP_UV_DEBUG_PRINT("uv_timer_init: resource: %d\n", uv->resource_id); ZVAL_RESOURCE(return_value, uv->resource_id); } @@ -4180,7 +4186,7 @@ PHP_FUNCTION(uv_timer_stop) php_error_docref(NULL TSRMLS_CC, E_NOTICE, "passed uv timer resource has been stopped. you don't have to call this method"); RETURN_FALSE; } - + PHP_UV_DEBUG_PRINT("uv_timer_stop: resource: %d\n", uv->resource_id); r = uv_timer_stop((uv_timer_t*)&uv->uv.timer); RETURN_LONG(r); From 99791cf3b4193e5fdf24b2889687812a8830d918 Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Thu, 20 Nov 2014 19:47:35 +0000 Subject: [PATCH 13/13] updating to libuv 1.0 release --- travis-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/travis-install.sh b/travis-install.sh index 577879b..bbf155b 100644 --- a/travis-install.sh +++ b/travis-install.sh @@ -3,7 +3,7 @@ set -e set -o pipefail # install 'libuv' -git clone --recursive --branch v1.0.0-rc2 --depth 1 https://github.com/joyent/libuv.git +git clone --recursive --branch v1.0.0 --depth 1 https://github.com/joyent/libuv.git pushd libuv ./autogen.sh && ./configure && make && sudo make install popd