diff options
Diffstat (limited to 'main/streams')
| -rw-r--r-- | main/streams/filter.c | 19 | ||||
| -rw-r--r-- | main/streams/memory.c | 31 | ||||
| -rw-r--r-- | main/streams/php_stream_context.h | 10 | ||||
| -rw-r--r-- | main/streams/php_stream_filter_api.h | 2 | ||||
| -rw-r--r-- | main/streams/streams.c | 167 | ||||
| -rw-r--r-- | main/streams/transports.c | 18 | ||||
| -rw-r--r-- | main/streams/userspace.c | 748 | ||||
| -rw-r--r-- | main/streams/xp_socket.c | 10 |
8 files changed, 429 insertions, 576 deletions
diff --git a/main/streams/filter.c b/main/streams/filter.c index 71599f0d12..7a38c4fa3c 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -46,26 +46,25 @@ PHPAPI HashTable *_php_get_stream_filters_hash(TSRMLS_D) /* API for registering GLOBAL filters */ PHPAPI int php_stream_filter_register_factory(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC) { - return zend_hash_add(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); + return zend_hash_str_add_ptr(&stream_filters_hash, filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; } PHPAPI int php_stream_filter_unregister_factory(const char *filterpattern TSRMLS_DC) { - return zend_hash_del(&stream_filters_hash, (char*)filterpattern, strlen(filterpattern) + 1); + return zend_hash_str_del(&stream_filters_hash, filterpattern, strlen(filterpattern)); } /* API for registering VOLATILE wrappers */ PHPAPI int php_stream_filter_register_factory_volatile(const char *filterpattern, php_stream_filter_factory *factory TSRMLS_DC) { if (!FG(stream_filters)) { - php_stream_filter_factory tmpfactory; - ALLOC_HASHTABLE(FG(stream_filters)); zend_hash_init(FG(stream_filters), zend_hash_num_elements(&stream_filters_hash), NULL, NULL, 1); - zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory)); +//??? zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL, &tmpfactory, sizeof(php_stream_filter_factory)); + zend_hash_copy(FG(stream_filters), &stream_filters_hash, NULL); } - return zend_hash_add(FG(stream_filters), (char*)filterpattern, strlen(filterpattern) + 1, factory, sizeof(*factory), NULL); + return zend_hash_str_add_ptr(FG(stream_filters), (char*)filterpattern, strlen(filterpattern), factory) ? SUCCESS : FAILURE; } /* Buckets */ @@ -259,7 +258,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval n = strlen(filtername); - if (SUCCESS == zend_hash_find(filter_hash, (char*)filtername, n + 1, (void**)&factory)) { + if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, filtername, n))) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } else if ((period = strrchr(filtername, '.'))) { /* try a wildcard */ @@ -271,7 +270,7 @@ PHPAPI php_stream_filter *php_stream_filter_create(const char *filtername, zval while (period && !filter) { *period = '\0'; strncat(wildname, ".*", 2); - if (SUCCESS == zend_hash_find(filter_hash, wildname, strlen(wildname) + 1, (void**)&factory)) { + if (NULL != (factory = zend_hash_str_find_ptr(filter_hash, wildname, strlen(wildname)))) { filter = factory->create_filter(filtername, filterparams, persistent TSRMLS_CC); } @@ -523,8 +522,8 @@ PHPAPI php_stream_filter *php_stream_filter_remove(php_stream_filter *filter, in filter->chain->tail = filter->prev; } - if (filter->rsrc_id > 0) { - zend_list_delete(filter->rsrc_id); + if (filter->res) { + zend_list_delete(filter->res); } if (call_dtor) { diff --git a/main/streams/memory.c b/main/streams/memory.c index 854b9e2720..b13d8b62ac 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -351,7 +351,7 @@ typedef struct { php_stream *innerstream; size_t smax; int mode; - zval* meta; + zval meta; } php_stream_temp_data; @@ -416,9 +416,7 @@ static int php_stream_temp_close(php_stream *stream, int close_handle TSRMLS_DC) ret = 0; } - if (ts->meta) { - zval_ptr_dtor(&ts->meta); - } + zval_ptr_dtor(&ts->meta); efree(ts); @@ -522,8 +520,8 @@ static int php_stream_temp_set_option(php_stream *stream, int option, int value, switch(option) { case PHP_STREAM_OPTION_META_DATA_API: - if (ts->meta) { - zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL_P(ts->meta), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); + if (Z_TYPE(ts->meta) != IS_UNDEF) { + zend_hash_copy(Z_ARRVAL_P((zval*)ptrparam), Z_ARRVAL(ts->meta), zval_add_ref); } return PHP_STREAM_OPTION_RETURN_OK; default: @@ -556,7 +554,7 @@ PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STR self = ecalloc(1, sizeof(*self)); self->smax = max_memory_usage; self->mode = mode; - self->meta = NULL; + ZVAL_UNDEF(&self->meta); stream = php_stream_alloc_rel(&php_stream_temp_ops, self, 0, mode & TEMP_STREAM_READONLY ? "rb" : "w+b"); stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; self->innerstream = php_stream_memory_create_rel(mode); @@ -607,9 +605,10 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con char *comma, *semi, *sep, *key; size_t mlen, dlen, plen, vlen; off_t newoffs; - zval *meta = NULL; + zval meta; int base64 = 0, ilen; + ZVAL_NULL(&meta); if (memcmp(path, "data:", 5)) { return NULL; } @@ -639,14 +638,13 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return NULL; } - MAKE_STD_ZVAL(meta); - array_init(meta); + array_init(&meta); if (!semi) { /* there is only a mime type */ - add_assoc_stringl(meta, "mediatype", (char *) path, mlen, 1); + add_assoc_stringl(&meta, "mediatype", (char *) path, mlen, 1); mlen = 0; } else if (sep && sep < semi) { /* there is a mime type */ plen = semi - path; - add_assoc_stringl(meta, "mediatype", (char *) path, plen, 1); + add_assoc_stringl(&meta, "mediatype", (char *) path, plen, 1); mlen -= plen; path += plen; } else if (semi != path || mlen != sizeof(";base64")-1 || memcmp(path, ";base64", sizeof(";base64")-1)) { /* must be error since parameters are only allowed after mediatype */ @@ -676,7 +674,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con plen = sep - path; vlen = (semi ? semi - sep : mlen - plen) - 1 /* '=' */; key = estrndup(path, plen); - add_assoc_stringl_ex(meta, key, plen + 1, sep + 1, vlen, 1); + add_assoc_stringl_ex(&meta, key, plen + 1, sep + 1, vlen, 1); efree(key); plen += vlen + 1; mlen -= plen; @@ -688,10 +686,9 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con return NULL; } } else { - MAKE_STD_ZVAL(meta); - array_init(meta); + array_init(&meta); } - add_assoc_bool(meta, "base64", base64); + add_assoc_bool(&meta, "base64", base64); /* skip ',' */ comma++; @@ -724,7 +721,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con ts = (php_stream_temp_data*)stream->abstract; assert(ts != NULL); ts->mode = mode && mode[0] == 'r' && mode[1] != '+' ? TEMP_STREAM_READONLY : 0; - ts->meta = meta; + ZVAL_COPY_VALUE(&ts->meta, &meta); } efree(comma); diff --git a/main/streams/php_stream_context.h b/main/streams/php_stream_context.h index 5c6925a856..2c0a33aab7 100644 --- a/main/streams/php_stream_context.h +++ b/main/streams/php_stream_context.h @@ -38,7 +38,7 @@ typedef void (*php_stream_notification_func)(php_stream_context *context, FG(default_context) ? FG(default_context) : \ (FG(default_context) = php_stream_context_alloc(TSRMLS_C)) ) -#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->rsrc_id); zend_list_addref((context)->rsrc_id); } +#define php_stream_context_to_zval(context, zval) { ZVAL_RESOURCE(zval, (context)->res); zend_list_addref((context)->res); } typedef struct _php_stream_notifier php_stream_notifier; @@ -52,15 +52,15 @@ struct _php_stream_notifier { struct _php_stream_context { php_stream_notifier *notifier; - zval *options; /* hash keyed by wrapper family or specific wrapper */ - int rsrc_id; /* used for auto-cleanup */ + zval options; /* hash keyed by wrapper family or specific wrapper */ + zend_resource *res; /* used for auto-cleanup */ }; BEGIN_EXTERN_C() PHPAPI void php_stream_context_free(php_stream_context *context); PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D); -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue); +PHPAPI zval *php_stream_context_get_option(php_stream_context *context, + const char *wrappername, const char *optionname); PHPAPI int php_stream_context_set_option(php_stream_context *context, const char *wrappername, const char *optionname, zval *optionvalue); diff --git a/main/streams/php_stream_filter_api.h b/main/streams/php_stream_filter_api.h index 9d9894c1c5..fe58a7d709 100644 --- a/main/streams/php_stream_filter_api.h +++ b/main/streams/php_stream_filter_api.h @@ -119,7 +119,7 @@ struct _php_stream_filter { php_stream_bucket_brigade buffer; /* filters are auto_registered when they're applied */ - int rsrc_id; + zend_resource *res; }; /* stack filter onto a stream */ diff --git a/main/streams/streams.c b/main/streams/streams.c index 4c4764c1ea..de24aaf475 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -65,19 +65,20 @@ PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash_global(void) return &url_stream_wrappers_hash; } -static int _php_stream_release_context(zend_rsrc_list_entry *le, void *pContext TSRMLS_DC) +static int _php_stream_release_context(zval *zv, void *pContext TSRMLS_DC) { + zend_resource *le = Z_RES_P(zv); if (le->ptr == pContext) { - return --le->refcount == 0; + return --le->gc.refcount == 0; } return 0; } -static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static int forget_persistent_resource_id_numbers(zend_resource *rsrc TSRMLS_DC) { php_stream *stream; - if (Z_TYPE_P(rsrc) != le_pstream) { + if (rsrc->type != le_pstream) { return 0; } @@ -87,11 +88,11 @@ static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRM fprintf(stderr, "forget_persistent: %s:%p\n", stream->ops->label, stream); #endif - stream->rsrc_id = FAILURE; + stream->res = NULL; if (stream->context) { zend_hash_apply_with_argument(&EG(regular_list), - (apply_func_arg_t) _php_stream_release_context, + _php_stream_release_context, stream->context TSRMLS_CC); stream->context = NULL; } @@ -116,36 +117,32 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC) { - zend_rsrc_list_entry *le; + zend_resource *le; - if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) { - if (Z_TYPE_P(le) == le_pstream) { + if ((le = zend_hash_str_find_ptr(&EG(persistent_list), persistent_id, strlen(persistent_id))) != NULL) { + if (le->type == le_pstream) { if (stream) { HashPosition pos; - zend_rsrc_list_entry *regentry; - ulong index = -1; /* intentional */ + zend_resource *regentry; /* see if this persistent resource already has been loaded to the * regular list; allowing the same resource in several entries in the * regular list causes trouble (see bug #54623) */ zend_hash_internal_pointer_reset_ex(&EG(regular_list), &pos); - while (zend_hash_get_current_data_ex(&EG(regular_list), - (void **)®entry, &pos) == SUCCESS) { + while ((regentry = zend_hash_get_current_data_ptr_ex(&EG(regular_list), &pos)) != NULL) { if (regentry->ptr == le->ptr) { - zend_hash_get_current_key_ex(&EG(regular_list), NULL, NULL, - &index, 0, &pos); break; } zend_hash_move_forward_ex(&EG(regular_list), &pos); } *stream = (php_stream*)le->ptr; - if (index == -1) { /* not found in regular list */ - le->refcount++; - (*stream)->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream); + if (!regentry) { /* not found in regular list */ + le->gc.refcount++; + (*stream)->res = ZEND_REGISTER_RESOURCE(NULL, *stream, le_pstream); } else { - regentry->refcount++; - (*stream)->rsrc_id = index; + regentry->gc.refcount++; + (*stream)->res = regentry; } } return PHP_STREAM_PERSISTENT_SUCCESS; @@ -159,13 +156,11 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream * static zend_llist *php_get_wrapper_errors_list(php_stream_wrapper *wrapper TSRMLS_DC) { - zend_llist *list = NULL; if (!FG(wrapper_errors)) { return NULL; } else { - zend_hash_find(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, (void**)&list); - return list; + return (zend_llist*) zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, + sizeof wrapper); } } @@ -237,7 +232,7 @@ void php_stream_display_wrapper_errors(php_stream_wrapper *wrapper, const char * void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC) { if (wrapper && FG(wrapper_errors)) { - zend_hash_del(FG(wrapper_errors), (const char*)&wrapper, sizeof wrapper); + zend_hash_str_del(FG(wrapper_errors), (const char*)&wrapper, sizeof wrapper); } } @@ -265,15 +260,15 @@ PHPAPI void php_stream_wrapper_log_error(php_stream_wrapper *wrapper, int option zend_hash_init(FG(wrapper_errors), 8, NULL, (dtor_func_t)zend_llist_destroy, 0); } else { - zend_hash_find(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, (void**)&list); + list = zend_hash_str_find_ptr(FG(wrapper_errors), (const char*)&wrapper, + sizeof wrapper); } if (!list) { zend_llist new_list; zend_llist_init(&new_list, sizeof buffer, wrapper_error_dtor, 0); - zend_hash_update(FG(wrapper_errors), (const char*)&wrapper, - sizeof wrapper, &new_list, sizeof new_list, (void**)&list); + zend_hash_str_update_mem(FG(wrapper_errors), (const char*)&wrapper, + sizeof wrapper, &new_list, sizeof new_list); } /* append to linked list */ @@ -315,27 +310,23 @@ fprintf(stderr, "stream_alloc: %s:%p persistent=%s\n", ops->label, ret, persiste } if (persistent_id) { - zend_rsrc_list_entry le; + zval tmp; - Z_TYPE(le) = le_pstream; - le.ptr = ret; - le.refcount = 0; - - if (FAILURE == zend_hash_update(&EG(persistent_list), (char *)persistent_id, - strlen(persistent_id) + 1, - (void *)&le, sizeof(le), NULL)) { + ZVAL_NEW_PERSISTENT_RES(&tmp, -1, ret, le_pstream); + if (NULL == zend_hash_str_update(&EG(persistent_list), persistent_id, + strlen(persistent_id), &tmp)) { pefree(ret, 1); return NULL; } } - ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream); + ret->res = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : le_stream); strlcpy(ret->mode, mode, sizeof(ret->mode)); ret->wrapper = NULL; ret->wrapperthis = NULL; - ret->wrapperdata = NULL; + ZVAL_UNDEF(&ret->wrapperdata); ret->stdiocast = NULL; ret->orig_path = NULL; ret->context = NULL; @@ -374,8 +365,9 @@ static const char *_php_stream_pretty_free_options(int close_options, char *out) } #endif -static int _php_stream_free_persistent(zend_rsrc_list_entry *le, void *pStream TSRMLS_DC) +static int _php_stream_free_persistent(zval *zv, void *pStream TSRMLS_DC) { + zend_resource *le = Z_RES_P(zv); return le->ptr == pStream; } @@ -467,7 +459,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov * the resource list, otherwise the resource will point to invalid memory. * In any case, let's always completely delete it from the resource list, * not only when PHP_STREAM_FREE_RELEASE_STREAM is set */ - while (zend_list_delete(stream->rsrc_id) == SUCCESS) {} + while (zend_list_delete(stream->res) == SUCCESS) {} } if (close_options & PHP_STREAM_FREE_CALL_DTOR) { @@ -507,9 +499,9 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov stream->wrapper = NULL; } - if (stream->wrapperdata) { + if (Z_TYPE(stream->wrapperdata) != IS_UNDEF) { zval_ptr_dtor(&stream->wrapperdata); - stream->wrapperdata = NULL; + ZVAL_UNDEF(&stream->wrapperdata); } if (stream->readbuf) { @@ -559,7 +551,7 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov } if (context) { - zend_list_delete(context->rsrc_id); + zend_list_delete(context->res); } return ret; @@ -689,7 +681,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D stream->is_persistent); } - justread = stream->ops->read(stream, stream->readbuf + stream->writepos, + justread = stream->ops->read(stream, (char*)stream->readbuf + stream->writepos, stream->readbuflen - stream->writepos TSRMLS_CC); @@ -787,7 +779,7 @@ PHPAPI int _php_stream_putc(php_stream *stream, int c TSRMLS_DC) { unsigned char buf = c; - if (php_stream_write(stream, &buf, 1) > 0) { + if (php_stream_write(stream, (char*)&buf, 1) > 0) { return 1; } return EOF; @@ -842,7 +834,7 @@ PHPAPI const char *php_stream_locate_eol(php_stream *stream, const char *buf, si const char *readptr; if (!buf) { - readptr = stream->readbuf + stream->readpos; + readptr = (char*)stream->readbuf + stream->readpos; avail = stream->writepos - stream->readpos; } else { readptr = buf; @@ -914,7 +906,7 @@ PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, const char *eol; int done = 0; - readptr = stream->readbuf + stream->readpos; + readptr = (char*)stream->readbuf + stream->readpos; eol = php_stream_locate_eol(stream, NULL, 0 TSRMLS_CC); if (eol) { @@ -1604,14 +1596,14 @@ PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size /* {{{ wrapper init and registration */ -static void stream_resource_regular_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_resource_regular_dtor(zend_resource *rsrc TSRMLS_DC) { php_stream *stream = (php_stream*)rsrc->ptr; /* set the return value for pclose */ FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); } -static void stream_resource_persistent_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_resource_persistent_dtor(zend_resource *rsrc TSRMLS_DC) { php_stream *stream = (php_stream*)rsrc->ptr; FG(pclose_ret) = php_stream_free(stream, PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_RSRC_DTOR); @@ -1701,21 +1693,19 @@ PHPAPI int php_register_url_stream_wrapper(const char *protocol, php_stream_wrap return FAILURE; } - return zend_hash_add(&url_stream_wrappers_hash, protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); + return zend_hash_str_add_ptr(&url_stream_wrappers_hash, protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; } PHPAPI int php_unregister_url_stream_wrapper(const char *protocol TSRMLS_DC) { - return zend_hash_del(&url_stream_wrappers_hash, protocol, strlen(protocol) + 1); + return zend_hash_str_del(&url_stream_wrappers_hash, protocol, strlen(protocol)); } static void clone_wrapper_hash(TSRMLS_D) { - php_stream_wrapper *tmp; - ALLOC_HASHTABLE(FG(stream_wrappers)); zend_hash_init(FG(stream_wrappers), zend_hash_num_elements(&url_stream_wrappers_hash), NULL, NULL, 1); - zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL, &tmp, sizeof(tmp)); + zend_hash_copy(FG(stream_wrappers), &url_stream_wrappers_hash, NULL); } /* API for registering VOLATILE wrappers */ @@ -1731,7 +1721,7 @@ PHPAPI int php_register_url_stream_wrapper_volatile(const char *protocol, php_st clone_wrapper_hash(TSRMLS_C); } - return zend_hash_add(FG(stream_wrappers), protocol, protocol_len + 1, &wrapper, sizeof(wrapper), NULL); + return zend_hash_str_add_ptr(FG(stream_wrappers), protocol, protocol_len, wrapper) ? SUCCESS : FAILURE; } PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRMLS_DC) @@ -1740,7 +1730,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRML clone_wrapper_hash(TSRMLS_C); } - return zend_hash_del(FG(stream_wrappers), protocol, strlen(protocol) + 1); + return zend_hash_str_del(FG(stream_wrappers), protocol, strlen(protocol)); } /* }}} */ @@ -1748,7 +1738,7 @@ PHPAPI int php_unregister_url_stream_wrapper_volatile(const char *protocol TSRML PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options TSRMLS_DC) { HashTable *wrapper_hash = (FG(stream_wrappers) ? FG(stream_wrappers) : &url_stream_wrappers_hash); - php_stream_wrapper **wrapperpp = NULL; + php_stream_wrapper *wrapper = NULL; const char *p, *protocol = NULL; int n = 0; @@ -1775,9 +1765,9 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const if (protocol) { char *tmp = estrndup(protocol, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { php_strtolower(tmp, n); - if (FAILURE == zend_hash_find(wrapper_hash, (char*)tmp, n + 1, (void**)&wrapperpp)) { + if (NULL == (wrapper = zend_hash_str_find_ptr(wrapper_hash, (char*)tmp, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) { @@ -1787,7 +1777,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find the wrapper \"%s\" - did you forget to enable it when you configured PHP?", wrapper_name); - wrapperpp = NULL; + wrapper = NULL; protocol = NULL; } } @@ -1837,14 +1827,14 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const if (FG(stream_wrappers)) { /* The file:// wrapper may have been disabled/overridden */ - if (wrapperpp) { + if (wrapper) { /* It was found so go ahead and provide it */ - return *wrapperpp; + return wrapper; } /* Check again, the original check might have not known the protocol name */ - if (zend_hash_find(wrapper_hash, "file", sizeof("file"), (void**)&wrapperpp) == SUCCESS) { - return *wrapperpp; + if ((wrapper = zend_hash_str_find_ptr(wrapper_hash, "file", sizeof("file")-1)) != NULL) { + return wrapper; } if (options & REPORT_ERRORS) { @@ -1856,7 +1846,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const return plain_files_wrapper; } - if (wrapperpp && (*wrapperpp)->is_url && + if (wrapper && wrapper->is_url && (options & STREAM_DISABLE_URL_PROTECTION) == 0 && (!PG(allow_url_fopen) || (((options & STREAM_OPEN_FOR_INCLUDE) || @@ -1874,7 +1864,7 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, const return NULL; } - return *wrapperpp; + return wrapper; } /* }}} */ @@ -2155,10 +2145,10 @@ PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream stream->context = context; if (context) { - zend_list_addref(context->rsrc_id); + context->res->gc.refcount++; } if (oldcontext) { - zend_list_delete(oldcontext->rsrc_id); + zend_list_delete(oldcontext->res); } return oldcontext; @@ -2173,9 +2163,9 @@ PHPAPI void php_stream_notification_notify(php_stream_context *context, int noti PHPAPI void php_stream_context_free(php_stream_context *context) { - if (context->options) { + if (Z_TYPE(context->options) != IS_UNDEF) { zval_ptr_dtor(&context->options); - context->options = NULL; + ZVAL_UNDEF(&context->options); } if (context->notifier) { php_stream_notification_free(context->notifier); @@ -2190,10 +2180,9 @@ PHPAPI php_stream_context *php_stream_context_alloc(TSRMLS_D) context = ecalloc(1, sizeof(php_stream_context)); context->notifier = NULL; - MAKE_STD_ZVAL(context->options); - array_init(context->options); + array_init(&context->options); - context->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C)); + context->res = ZEND_REGISTER_RESOURCE(NULL, context, php_le_stream_context(TSRMLS_C)); return context; } @@ -2210,38 +2199,34 @@ PHPAPI void php_stream_notification_free(php_stream_notifier *notifier) efree(notifier); } -PHPAPI int php_stream_context_get_option(php_stream_context *context, - const char *wrappername, const char *optionname, zval ***optionvalue) +PHPAPI zval *php_stream_context_get_option(php_stream_context *context, + const char *wrappername, const char *optionname) { - zval **wrapperhash; + zval *wrapperhash; - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - return FAILURE; + if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) { + return NULL; } - return zend_hash_find(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)optionvalue); + return zend_hash_str_find(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname)); } PHPAPI int php_stream_context_set_option(php_stream_context *context, const char *wrappername, const char *optionname, zval *optionvalue) { - zval **wrapperhash; - zval *category, *copied_val; + zval *wrapperhash; + zval category, copied_val; - ALLOC_INIT_ZVAL(copied_val); - *copied_val = *optionvalue; - zval_copy_ctor(copied_val); - INIT_PZVAL(copied_val); + ZVAL_DUP(&copied_val, optionvalue); - if (FAILURE == zend_hash_find(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&wrapperhash)) { - MAKE_STD_ZVAL(category); - array_init(category); - if (FAILURE == zend_hash_update(Z_ARRVAL_P(context->options), (char*)wrappername, strlen(wrappername)+1, (void**)&category, sizeof(zval *), NULL)) { + if (NULL == (wrapperhash = zend_hash_str_find(Z_ARRVAL(context->options), wrappername, strlen(wrappername)))) { + array_init(&category); + if (NULL == zend_hash_str_update(Z_ARRVAL(context->options), (char*)wrappername, strlen(wrappername), &category)) { return FAILURE; } wrapperhash = &category; } - return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, strlen(optionname)+1, (void**)&copied_val, sizeof(zval *), NULL); + return zend_hash_str_update(Z_ARRVAL_P(wrapperhash), optionname, strlen(optionname), &copied_val) ? SUCCESS : FAILURE; } /* }}} */ diff --git a/main/streams/transports.c b/main/streams/transports.c index f54e8e6cdf..6588cb947e 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -31,12 +31,12 @@ PHPAPI HashTable *php_stream_xport_get_hash(void) PHPAPI int php_stream_xport_register(const char *protocol, php_stream_transport_factory factory TSRMLS_DC) { - return zend_hash_update(&xport_hash, protocol, strlen(protocol) + 1, &factory, sizeof(factory), NULL); + return zend_hash_str_update_ptr(&xport_hash, protocol, strlen(protocol), factory) ? SUCCESS : FAILURE; } PHPAPI int php_stream_xport_unregister(const char *protocol TSRMLS_DC) { - return zend_hash_del(&xport_hash, protocol, strlen(protocol) + 1); + return zend_hash_str_del(&xport_hash, protocol, strlen(protocol)); } #define ERR_REPORT(out_err, fmt, arg) \ @@ -107,7 +107,7 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in if (protocol) { char *tmp = estrndup(protocol, n); - if (FAILURE == zend_hash_find(&xport_hash, (char*)tmp, n + 1, (void**)&factory)) { + if (NULL == (factory = zend_hash_str_find_ptr(&xport_hash, tmp, n))) { char wrapper_name[32]; if (n >= sizeof(wrapper_name)) @@ -157,16 +157,16 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in ERR_RETURN(error_string, error_text, "bind() failed: %s"); failed = 1; } else if (flags & STREAM_XPORT_LISTEN) { - zval **zbacklog = NULL; + zval *zbacklog = NULL; int backlog = 32; - if (stream->context && php_stream_context_get_option(stream->context, "socket", "backlog", &zbacklog) == SUCCESS) { - zval *ztmp = *zbacklog; + if (stream->context && (zbacklog = php_stream_context_get_option(stream->context, "socket", "backlog")) != NULL) { + zval *ztmp = zbacklog; - convert_to_long_ex(&ztmp); + convert_to_long_ex(ztmp); backlog = Z_LVAL_P(ztmp); - if (ztmp != *zbacklog) { - zval_ptr_dtor(&ztmp); + if (ztmp != zbacklog) { + zval_ptr_dtor(ztmp); } } diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 7d958729e5..6629a3fd86 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -70,7 +70,7 @@ static php_stream_wrapper_ops user_stream_wops = { }; -static void stream_wrapper_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) +static void stream_wrapper_dtor(zend_resource *rsrc TSRMLS_DC) { struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr; @@ -281,18 +281,15 @@ typedef struct _php_userstream_data php_userstream_data_t; }}} **/ -static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context TSRMLS_DC) +static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context, zval *object TSRMLS_DC) { - zval *object; /* create an instance of our class */ - ALLOC_ZVAL(object); object_init_ex(object, uwrap->ce); - Z_SET_REFCOUNT_P(object, 1); - Z_SET_ISREF_P(object); +//??? Z_SET_ISREF_P(object); if (context) { - add_property_resource(object, "context", context->rsrc_id); - zend_list_addref(context->rsrc_id); + add_property_resource(object, "context", context->res); + context->res->gc.refcount++; } else { add_property_null(object, "context"); } @@ -300,14 +297,14 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph if (uwrap->ce->constructor) { zend_fcall_info fci; zend_fcall_info_cache fcc; - zval *retval_ptr; + zval retval; fci.size = sizeof(fci); fci.function_table = &uwrap->ce->function_table; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; fci.object_ptr = object; - fci.retval_ptr_ptr = &retval_ptr; + fci.retval = &retval; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; @@ -319,14 +316,12 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph fcc.object_ptr = object; if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name, uwrap->ce->constructor->common.function_name); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute %s::%s()", uwrap->ce->name->val, uwrap->ce->constructor->common.function_name->val); zval_dtor(object); - FREE_ZVAL(object); + ZVAL_UNDEF(object); return NULL; } else { - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(&retval); } } return object; @@ -335,10 +330,11 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { + zval object; struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; - zval *zfilename, *zmode, *zopened, *zoptions, *zretval = NULL, *zfuncname; - zval **args[4]; + zval zretval, zfuncname; + zval args[4]; int call_result; php_stream *stream = NULL; zend_bool old_in_user_include; @@ -364,7 +360,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * us = emalloc(sizeof(*us)); us->wrapper = uwrap; - us->object = user_stream_create_object(uwrap, context TSRMLS_CC); + us->object = user_stream_create_object(uwrap, context, &object TSRMLS_CC); if(us->object == NULL) { FG(user_stream_current_filename) = NULL; PG(in_user_include) = old_in_user_include; @@ -373,46 +369,31 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * } /* call it's stream_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_STRING(zmode, mode, 1); - args[1] = &zmode; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; + ZVAL_STRING(&args[0], filename); + ZVAL_STRING(&args[1], mode); + ZVAL_LONG(&args[2], options); + ZVAL_NEW_REF(&args[3], &EG(uninitialized_zval)); - MAKE_STD_ZVAL(zopened); - Z_SET_REFCOUNT_P(zopened, 1); - Z_SET_ISREF_P(zopened); - ZVAL_NULL(zopened); - args[3] = &zopened; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_OPEN, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_OPEN); call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, + us->object, + &zfuncname, &zretval, 4, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { + if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_ops, us, 0, mode); /* if the opened path is set, copy it out */ - if (Z_TYPE_P(zopened) == IS_STRING && opened_path) { - *opened_path = estrndup(Z_STRVAL_P(zopened), Z_STRLEN_P(zopened)); + if (Z_TYPE(args[4]) == IS_REFERENCE && Z_TYPE_P(Z_REFVAL(args[4])) == IS_STRING && opened_path) { + *opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[4])), Z_STRLEN_P(Z_REFVAL(args[4]))); } /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); + ZVAL_COPY(&stream->wrapperdata, us->object); } else { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_OPEN "\" call failed", us->wrapper->classname); @@ -420,17 +401,15 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * /* destroy everything else */ if (stream == NULL) { - zval_ptr_dtor(&us->object); + zval_ptr_dtor(us->object); efree(us); } - if (zretval) - zval_ptr_dtor(&zretval); - + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zopened); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&args[4]); + zval_ptr_dtor(&args[3]); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); FG(user_stream_current_filename) = NULL; @@ -441,10 +420,11 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { + zval object; struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; php_userstream_data_t *us; - zval *zfilename, *zoptions, *zretval = NULL, *zfuncname; - zval **args[2]; + zval zretval, zfuncname; + zval args[2]; int call_result; php_stream *stream = NULL; @@ -458,7 +438,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char us = emalloc(sizeof(*us)); us->wrapper = uwrap; - us->object = user_stream_create_object(uwrap, context TSRMLS_CC); + us->object = user_stream_create_object(uwrap, context, &object TSRMLS_CC); if(us->object == NULL) { FG(user_stream_current_filename) = NULL; efree(us); @@ -466,31 +446,24 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char } /* call it's dir_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; + ZVAL_STRING(&args[0], filename); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_DIR_OPEN, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN); call_result = call_user_function_ex(NULL, - &us->object, - zfuncname, + us->object, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && zval_is_true(zretval)) { + if (call_result == SUCCESS && Z_TYPE(zretval) != IS_UNDEF && zval_is_true(&zretval)) { /* the stream is now open! */ stream = php_stream_alloc_rel(&php_stream_userspace_dir_ops, us, 0, mode); /* set wrapper data to be a reference to our object */ - stream->wrapperdata = us->object; - zval_add_ref(&stream->wrapperdata); + ZVAL_COPY(&stream->wrapperdata, us->object); } else { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed", us->wrapper->classname); @@ -498,15 +471,14 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char /* destroy everything else */ if (stream == NULL) { - zval_ptr_dtor(&us->object); + zval_ptr_dtor(us->object); efree(us); } - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zoptions); - zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); FG(user_stream_current_filename) = NULL; @@ -518,43 +490,41 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char Registers a custom URL protocol handler class */ PHP_FUNCTION(stream_wrapper_register) { - char *protocol, *classname; - int protocol_len, classname_len; + zend_string *protocol, *classname; struct php_user_stream_wrapper * uwrap; - int rsrc_id; + zend_resource *rsrc; long flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &protocol, &protocol_len, &classname, &classname_len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|l", &protocol, &classname, &flags) == FAILURE) { RETURN_FALSE; } uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap)); - uwrap->protoname = estrndup(protocol, protocol_len); - uwrap->classname = estrndup(classname, classname_len); + uwrap->protoname = estrndup(protocol->val, protocol->len); + uwrap->classname = estrndup(classname->val, classname->len); uwrap->wrapper.wops = &user_stream_wops; uwrap->wrapper.abstract = uwrap; uwrap->wrapper.is_url = ((flags & PHP_STREAM_IS_URL) != 0); - rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); + rsrc = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols); - if (zend_lookup_class(uwrap->classname, classname_len, (zend_class_entry***)&uwrap->ce TSRMLS_CC) == SUCCESS) { - uwrap->ce = *(zend_class_entry**)uwrap->ce; - if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { + if ((uwrap->ce = zend_lookup_class(classname TSRMLS_CC)) != NULL) { + if (php_register_url_stream_wrapper_volatile(protocol->val, &uwrap->wrapper TSRMLS_CC) == SUCCESS) { RETURN_TRUE; } else { /* We failed. But why? */ - if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol); + if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol->val); } else { /* Hash doesn't exist so it must have been an invalid protocol scheme */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname, protocol); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname->val, protocol->val); } } } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname->val); } - zend_list_delete(rsrc_id); + zend_list_delete(rsrc); RETURN_FALSE; } /* }}} */ @@ -584,34 +554,30 @@ PHP_FUNCTION(stream_wrapper_unregister) Restore the original protocol handler, overriding if necessary */ PHP_FUNCTION(stream_wrapper_restore) { - char *protocol; - int protocol_len; - php_stream_wrapper **wrapperpp = NULL, *wrapper; + zend_string *protocol; + php_stream_wrapper *wrapper; HashTable *global_wrapper_hash; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &protocol) == FAILURE) { RETURN_FALSE; } global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global(); if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol->val); RETURN_TRUE; } - if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol); + if ((wrapper = zend_hash_find_ptr(global_wrapper_hash, protocol)) == NULL) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol->val); RETURN_FALSE; } - /* next line might delete the pointer that wrapperpp points at, so deref it now */ - wrapper = *wrapperpp; - /* A failure here could be okay given that the protocol might have been merely unregistered */ - php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC); + php_unregister_url_stream_wrapper_volatile(protocol->val TSRMLS_CC); - if (php_register_url_stream_wrapper_volatile(protocol, wrapper TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol); + if (php_register_url_stream_wrapper_volatile(protocol->val, wrapper TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol->val); RETURN_FALSE; } @@ -622,33 +588,31 @@ PHP_FUNCTION(stream_wrapper_restore) static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[1]; - zval *zbufptr; + zval args[1]; size_t didwrite = 0; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_WRITE, sizeof(USERSTREAM_WRITE)-1); - MAKE_STD_ZVAL(zbufptr); - ZVAL_STRINGL(zbufptr, (char*)buf, count, 1);; - args[0] = &zbufptr; + ZVAL_STRINGL(&args[0], (char*)buf, count); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zbufptr); + zval_ptr_dtor(&args[0]); didwrite = 0; - if (call_result == SUCCESS && retval != NULL) { - convert_to_long(retval); - didwrite = Z_LVAL_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + convert_to_long(&retval); + didwrite = Z_LVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!", us->wrapper->classname); @@ -662,8 +626,7 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t didwrite = count; } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return didwrite; } @@ -671,60 +634,57 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; - zval **args[1]; + zval retval; + zval args[1]; int call_result; size_t didread = 0; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval *zcount; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1); - MAKE_STD_ZVAL(zcount); - ZVAL_LONG(zcount, count); - args[0] = &zcount; + ZVAL_LONG(&args[0], count); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL) { - convert_to_string(retval); - didread = Z_STRLEN_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + convert_to_string(&retval); + didread = Z_STRLEN(retval); if (didread > count) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read %ld bytes more data than requested (%ld read, %ld max) - excess data will be lost", us->wrapper->classname, (long)(didread - count), (long)didread, (long)count); didread = count; } if (didread > 0) - memcpy(buf, Z_STRVAL_P(retval), didread); + memcpy(buf, Z_STRVAL(retval), didread); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!", us->wrapper->classname); } - zval_ptr_dtor(&zcount); + zval_ptr_dtor(&args[0]); - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + ZVAL_UNDEF(&retval); /* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */ - ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) { stream->eof = 1; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -734,10 +694,7 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count stream->eof = 1; } - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); return didread; } @@ -745,23 +702,23 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_CLOSE, sizeof(USERSTREAM_CLOSE)-1); call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); - zval_ptr_dtor(&us->object); + zval_ptr_dtor(us->object); efree(us); @@ -771,27 +728,27 @@ static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_FLUSH, sizeof(USERSTREAM_FLUSH)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) call_result = 0; else call_result = -1; - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return call_result; } @@ -799,69 +756,62 @@ static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result, ret; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - zval **args[2]; - zval *zoffs, *zwhence; + zval args[2]; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1); - MAKE_STD_ZVAL(zoffs); - ZVAL_LONG(zoffs, offset); - args[0] = &zoffs; - - MAKE_STD_ZVAL(zwhence); - ZVAL_LONG(zwhence, whence); - args[1] = &zwhence; + ZVAL_LONG(&args[0], offset); + ZVAL_LONG(&args[1], whence); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 2, args, 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zoffs); - zval_ptr_dtor(&zwhence); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&args[1]); if (call_result == FAILURE) { /* stream_seek is not implemented, so disable seeks for this stream */ stream->flags |= PHP_STREAM_FLAG_NO_SEEK; /* there should be no retval to clean up */ - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return -1; - } else if (call_result == SUCCESS && retval != NULL && zval_is_true(retval)) { + } else if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF && zval_is_true(&retval)) { ret = 0; } else { ret = -1; } - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + ZVAL_UNDEF(&retval); if (ret) { return ret; } /* now determine where we are */ - ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_LONG) { - *newoffs = Z_LVAL_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) { + *newoffs = Z_LVAL(retval); ret = 0; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname); @@ -870,9 +820,7 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o ret = -1; } - if (retval) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(&retval); return ret; } @@ -880,13 +828,13 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o * relevant fields into the statbuf provided */ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) { - zval **elem; + zval *elem; #define STAT_PROP_ENTRY_EX(name, name2) \ - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(array), #name, sizeof(#name), (void**)&elem)) { \ + if (NULL != (elem = zend_hash_str_find(Z_ARRVAL_P(array), #name, sizeof(#name)-1))) { \ SEPARATE_ZVAL(elem); \ - convert_to_long(*elem); \ - ssb->sb.st_##name2 = Z_LVAL_PP(elem); \ + convert_to_long(elem); \ + ssb->sb.st_##name2 = Z_LVAL_P(elem); \ } #define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name) @@ -926,21 +874,22 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; int ret = -1; - ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_STAT, sizeof(USERSTREAM_STAT)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_ARRAY) { - if (SUCCESS == statbuf_from_array(retval, ssb TSRMLS_CC)) + if (call_result == SUCCESS && Z_TYPE(retval) == IS_ARRAY) { + if (SUCCESS == statbuf_from_array(&retval, ssb TSRMLS_CC)) ret = 0; } else { if (call_result == FAILURE) { @@ -949,8 +898,7 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR } } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return ret; } @@ -958,19 +906,19 @@ static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSR static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; int ret = PHP_STREAM_OPTION_RETURN_NOTIMPL; - zval *zvalue = NULL; - zval **args[3]; + zval args[3]; switch (option) { case PHP_STREAM_OPTION_CHECK_LIVENESS: - ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); - call_result = call_user_function_ex(NULL, &us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { - ret = zval_is_true(retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; +//??? ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_EOF, sizeof(USERSTREAM_EOF)-1); + call_result = call_user_function_ex(NULL, us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); + if (call_result == SUCCESS && Z_TYPE(retval) == IS_BOOL) { + ret = zval_is_true(&retval) ? PHP_STREAM_OPTION_RETURN_ERR : PHP_STREAM_OPTION_RETURN_OK; } else { ret = PHP_STREAM_OPTION_RETURN_ERR; php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -980,37 +928,35 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value break; case PHP_STREAM_OPTION_LOCKING: - MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, 0); + ZVAL_LONG(&args[0], 0); if (value & LOCK_NB) { - Z_LVAL_P(zvalue) |= PHP_LOCK_NB; + Z_LVAL_P(&args[0]) |= PHP_LOCK_NB; } switch(value & ~LOCK_NB) { case LOCK_SH: - Z_LVAL_P(zvalue) |= PHP_LOCK_SH; + Z_LVAL_P(&args[0]) |= PHP_LOCK_SH; break; case LOCK_EX: - Z_LVAL_P(zvalue) |= PHP_LOCK_EX; + Z_LVAL_P(&args[0]) |= PHP_LOCK_EX; break; case LOCK_UN: - Z_LVAL_P(zvalue) |= PHP_LOCK_UN; + Z_LVAL_P(&args[0]) |= PHP_LOCK_UN; break; } - args[0] = &zvalue; - /* TODO wouldblock */ - ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_LOCK, sizeof(USERSTREAM_LOCK)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) == IS_BOOL) { - ret = !Z_LVAL_P(retval); + if (call_result == SUCCESS && Z_TYPE(retval) == IS_BOOL) { + ret = !Z_LVAL(retval); } else if (call_result == FAILURE) { if (value == 0) { /* lock support test (TODO: more check) */ @@ -1025,7 +971,8 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value break; case PHP_STREAM_OPTION_TRUNCATE_API: - ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_TRUNCATE, sizeof(USERSTREAM_TRUNCATE)-1); switch (value) { case PHP_STREAM_TRUNCATE_SUPPORTED: @@ -1039,18 +986,16 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value case PHP_STREAM_TRUNCATE_SET_SIZE: { ptrdiff_t new_size = *(ptrdiff_t*) ptrparam; if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) { - MAKE_STD_ZVAL(zvalue); - ZVAL_LONG(zvalue, (long)new_size); - args[0] = &zvalue; + ZVAL_LONG(&args[0], (long)new_size); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL) { - if (Z_TYPE_P(retval) == IS_BOOL) { - ret = Z_LVAL_P(retval) ? PHP_STREAM_OPTION_RETURN_OK : - PHP_STREAM_OPTION_RETURN_ERR; + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + if (Z_TYPE(retval) == IS_BOOL) { + ret = Z_LVAL(retval) ? PHP_STREAM_OPTION_RETURN_OK : + PHP_STREAM_OPTION_RETURN_ERR; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TRUNCATE " did not return a boolean!", @@ -1073,46 +1018,39 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value case PHP_STREAM_OPTION_WRITE_BUFFER: case PHP_STREAM_OPTION_READ_TIMEOUT: case PHP_STREAM_OPTION_BLOCKING: { - zval *zoption = NULL; - zval *zptrparam = NULL; - - ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1, 0); - ALLOC_INIT_ZVAL(zoption); - ZVAL_LONG(zoption, option); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1); - ALLOC_INIT_ZVAL(zvalue); - ALLOC_INIT_ZVAL(zptrparam); - - args[0] = &zoption; - args[1] = &zvalue; - args[2] = &zptrparam; + ZVAL_LONG(&args[0], option); + ZVAL_NULL(&args[1]); + ZVAL_NULL(&args[2]); switch(option) { case PHP_STREAM_OPTION_READ_BUFFER: case PHP_STREAM_OPTION_WRITE_BUFFER: - ZVAL_LONG(zvalue, value); + ZVAL_LONG(&args[1], value); if (ptrparam) { - ZVAL_LONG(zptrparam, *(long *)ptrparam); + ZVAL_LONG(&args[2], *(long *)ptrparam); } else { - ZVAL_LONG(zptrparam, BUFSIZ); + ZVAL_LONG(&args[2], BUFSIZ); } break; case PHP_STREAM_OPTION_READ_TIMEOUT: { struct timeval tv = *(struct timeval*)ptrparam; - ZVAL_LONG(zvalue, tv.tv_sec); - ZVAL_LONG(zptrparam, tv.tv_usec); + ZVAL_LONG(&args[1], tv.tv_sec); + ZVAL_LONG(&args[2], tv.tv_usec); break; } case PHP_STREAM_OPTION_BLOCKING: - ZVAL_LONG(zvalue, value); + ZVAL_LONG(&args[1], value); break; default: break; } call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 3, args, 0, NULL TSRMLS_CC); @@ -1121,32 +1059,22 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", us->wrapper->classname); ret = PHP_STREAM_OPTION_RETURN_ERR; - } else if (retval && zend_is_true(retval TSRMLS_CC)) { + } else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval TSRMLS_CC)) { ret = PHP_STREAM_OPTION_RETURN_OK; } else { ret = PHP_STREAM_OPTION_RETURN_ERR; } - if (zoption) { - zval_ptr_dtor(&zoption); - } - if (zptrparam) { - zval_ptr_dtor(&zptrparam); - } + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); break; } } /* clean up */ - if (retval) { - zval_ptr_dtor(&retval); - } - - - if (zvalue) { - zval_ptr_dtor(&zvalue); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&args[0]); return ret; } @@ -1155,46 +1083,42 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval; - zval **args[1]; + zval zfuncname, zretval; + zval args[1]; int call_result; - zval *object; + zval *object, tmp_object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); if(object == NULL) { return ret; } /* call the unlink method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], url); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_UNLINK, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_UNLINK); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 1, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_BOOL) { + ret = Z_LVAL(zretval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname); } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); - zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1203,51 +1127,44 @@ static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zold_name, *znew_name, *zfuncname, *zretval; - zval **args[2]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval *object, tmp_object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); if(object == NULL) { return ret; } /* call the rename method */ - MAKE_STD_ZVAL(zold_name); - ZVAL_STRING(zold_name, url_from, 1); - args[0] = &zold_name; + ZVAL_STRING(&args[0], url_from); + ZVAL_STRING(&args[1], url_to); - MAKE_STD_ZVAL(znew_name); - ZVAL_STRING(znew_name, url_to, 1); - args[1] = &znew_name; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RENAME); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_BOOL) { + ret = Z_LVAL(zretval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname); } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zold_name); - zval_ptr_dtor(&znew_name); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1256,57 +1173,46 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zmode, *zoptions, *zfuncname, *zretval; - zval **args[3]; + zval zfuncname, zretval; + zval args[3]; int call_result; - zval *object; + zval *object, tmp_object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); if(object == NULL) { return ret; } /* call the mkdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zmode); - ZVAL_LONG(zmode, mode); - args[1] = &zmode; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], mode); + ZVAL_LONG(&args[2], options); - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[2] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_MKDIR, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_MKDIR); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 3, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_BOOL) { + ret = Z_LVAL(zretval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname); } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zmode); - zval_ptr_dtor(&zoptions); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1315,52 +1221,44 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zoptions, *zfuncname, *zretval; - zval **args[3]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval *object, tmp_object; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); if(object == NULL) { return ret; } /* call the rmdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RMDIR); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_BOOL) { + ret = Z_LVAL(zretval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname); } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zoptions); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; } @@ -1369,81 +1267,70 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i void *value, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zoption, *zvalue, *zfuncname, *zretval; - zval **args[3]; + zval zfuncname, zretval; + zval args[3]; int call_result; - zval *object; + zval *object, tmp_object; int ret = 0; - MAKE_STD_ZVAL(zvalue); switch(option) { case PHP_STREAM_META_TOUCH: - array_init(zvalue); + array_init(&args[2]); if(value) { struct utimbuf *newtime = (struct utimbuf *)value; - add_index_long(zvalue, 0, newtime->modtime); - add_index_long(zvalue, 1, newtime->actime); + add_index_long(&args[2], 0, newtime->modtime); + add_index_long(&args[2], 1, newtime->actime); } break; case PHP_STREAM_META_GROUP: case PHP_STREAM_META_OWNER: case PHP_STREAM_META_ACCESS: - ZVAL_LONG(zvalue, *(long *)value); + ZVAL_LONG(&args[2], *(long *)value); break; case PHP_STREAM_META_GROUP_NAME: case PHP_STREAM_META_OWNER_NAME: - ZVAL_STRING(zvalue, value, 1); + ZVAL_STRING(&args[2], value); break; default: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option); - zval_ptr_dtor(&zvalue); + zval_ptr_dtor(&args[2]); return ret; } /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { - zval_ptr_dtor(&zvalue); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); + if (object == NULL) { + zval_ptr_dtor(&args[2]); return ret; } /* call the mkdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zoption); - ZVAL_LONG(zoption, option); - args[1] = &zoption; - - args[2] = &zvalue; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], option); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_METADATA, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_METADATA); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 3, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_BOOL) { + ret = Z_LVAL(zretval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname); } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) { - zval_ptr_dtor(&zretval); - } + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zoption); - zval_ptr_dtor(&zvalue); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[2]); return ret; } @@ -1453,40 +1340,34 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) { struct php_user_stream_wrapper *uwrap = (struct php_user_stream_wrapper*)wrapper->abstract; - zval *zfilename, *zfuncname, *zretval, *zflags; - zval **args[2]; + zval zfuncname, zretval; + zval args[2]; int call_result; - zval *object; + zval *object, tmp_object; int ret = -1; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); + object = user_stream_create_object(uwrap, context, &tmp_object TSRMLS_CC); if(object == NULL) { return ret; } /* call it's stat_url method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; - - MAKE_STD_ZVAL(zflags); - ZVAL_LONG(zflags, flags); - args[1] = &zflags; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], flags); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_STATURL, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_STATURL); call_result = call_user_function_ex(NULL, - &object, - zfuncname, + object, + &zfuncname, &zretval, 2, args, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && zretval != NULL && Z_TYPE_P(zretval) == IS_ARRAY) { + if (call_result == SUCCESS && Z_TYPE(zretval) == IS_ARRAY) { /* We got the info we needed */ - if (SUCCESS == statbuf_from_array(zretval, ssb TSRMLS_CC)) + if (SUCCESS == statbuf_from_array(&zretval, ssb TSRMLS_CC)) ret = 0; } else { if (call_result == FAILURE) { @@ -1496,13 +1377,12 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i } /* clean up */ - zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + zval_ptr_dtor(object); + zval_ptr_dtor(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); - zval_ptr_dtor(&zflags); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); return ret; @@ -1511,7 +1391,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; int call_result; size_t didread = 0; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; @@ -1521,18 +1401,19 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou if (count != sizeof(php_stream_dirent)) return 0; - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_READ, sizeof(USERSTREAM_DIR_READ)-1); call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && retval != NULL && Z_TYPE_P(retval) != IS_BOOL) { - convert_to_string(retval); - PHP_STRLCPY(ent->d_name, Z_STRVAL_P(retval), sizeof(ent->d_name), Z_STRLEN_P(retval)); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_BOOL) { + convert_to_string(&retval); + PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval)); didread = sizeof(php_stream_dirent); } else if (call_result == FAILURE) { @@ -1540,8 +1421,7 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou us->wrapper->classname); } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return didread; } @@ -1549,23 +1429,21 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; assert(us != NULL); - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_CLOSE, sizeof(USERSTREAM_DIR_CLOSE)-1); call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); - - zval_ptr_dtor(&us->object); + zval_ptr_dtor(us->object); efree(us); @@ -1575,19 +1453,19 @@ static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) { zval func_name; - zval *retval = NULL; + zval retval; php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; - ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_DIR_REWIND, sizeof(USERSTREAM_DIR_REWIND)-1); call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return 0; @@ -1597,28 +1475,26 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T { php_userstream_data_t *us = (php_userstream_data_t *)stream->abstract; zval func_name; - zval *retval = NULL; - zval *zcastas = NULL; - zval **args[1]; + zval retval; + zval args[1]; php_stream * intstream = NULL; int call_result; int ret = FAILURE; - ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1, 0); +//??? ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1, 0); + ZVAL_STRINGL(&func_name, USERSTREAM_CAST, sizeof(USERSTREAM_CAST)-1); - ALLOC_INIT_ZVAL(zcastas); switch(castas) { case PHP_STREAM_AS_FD_FOR_SELECT: - ZVAL_LONG(zcastas, PHP_STREAM_AS_FD_FOR_SELECT); + ZVAL_LONG(&args[0], PHP_STREAM_AS_FD_FOR_SELECT); break; default: - ZVAL_LONG(zcastas, PHP_STREAM_AS_STDIO); + ZVAL_LONG(&args[0], PHP_STREAM_AS_STDIO); break; } - args[0] = &zcastas; call_result = call_user_function_ex(NULL, - &us->object, + us->object, &func_name, &retval, 1, args, 0, NULL TSRMLS_CC); @@ -1629,7 +1505,7 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T us->wrapper->classname); break; } - if (retval == NULL || !zend_is_true(retval TSRMLS_CC)) { + if (Z_TYPE(retval) != IS_UNDEF || !zend_is_true(&retval TSRMLS_CC)) { break; } php_stream_from_zval_no_verify(intstream, &retval); @@ -1647,12 +1523,8 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T ret = php_stream_cast(intstream, castas, retptr, 1); } while (0); - if (retval) { - zval_ptr_dtor(&retval); - } - if (zcastas) { - zval_ptr_dtor(&zcastas); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&args[0]); return ret; } diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 9cef91cbb4..91b00496c7 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -618,7 +618,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ int portno, bindport = 0; int err = 0; int ret; - zval **tmpzval = NULL; + zval *tmpzval = NULL; #ifdef AF_UNIX if (stream->ops == &php_stream_unix_socket_ops || stream->ops == &php_stream_unixdg_socket_ops) { @@ -653,15 +653,15 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ return -1; } - if (stream->context && php_stream_context_get_option(stream->context, "socket", "bindto", &tmpzval) == SUCCESS) { - if (Z_TYPE_PP(tmpzval) != IS_STRING) { + if (stream->context && (tmpzval = php_stream_context_get_option(stream->context, "socket", "bindto")) != NULL) { + if (Z_TYPE_P(tmpzval) != IS_STRING) { if (xparam->want_errortext) { spprintf(&xparam->outputs.error_text, 0, "local_addr context option is not a string."); } efree(host); return -1; } - bindto = parse_ip_address_ex(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); + bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); } /* Note: the test here for php_stream_udp_socket_ops is important, because we @@ -733,7 +733,7 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t if (xparam->outputs.client) { xparam->outputs.client->context = stream->context; if (stream->context) { - zend_list_addref(stream->context->rsrc_id); + stream->context->res->gc.refcount++; } } } |
