diff options
Diffstat (limited to 'main/streams/userspace.c')
| -rw-r--r-- | main/streams/userspace.c | 936 |
1 files changed, 406 insertions, 530 deletions
diff --git a/main/streams/userspace.c b/main/streams/userspace.c index 38a5dd3107..b73db20d40 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2015 The PHP Group | +----------------------------------------------------------------------+ @@ -45,15 +45,15 @@ struct php_user_stream_wrapper { php_stream_wrapper wrapper; }; -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); -static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC); -static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC); -static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC); +static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); +static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context); +static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context); +static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context); +static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, int options, php_stream_context *context); +static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context); +static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context); 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); + int options, zend_string **opened_path, php_stream_context *context STREAMS_DC); static php_stream_wrapper_ops user_stream_wops = { user_wrapper_opener, @@ -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) { struct php_user_stream_wrapper * uwrap = (struct php_user_stream_wrapper*)rsrc->ptr; @@ -120,7 +120,7 @@ PHP_MINIT_FUNCTION(user_streams) struct _php_userstream_data { struct php_user_stream_wrapper * wrapper; - zval * object; + zval object; }; typedef struct _php_userstream_data php_userstream_data_t; @@ -281,18 +281,14 @@ 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 void user_stream_create_object(struct php_user_stream_wrapper *uwrap, php_stream_context *context, zval *object) { - 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); if (context) { - add_property_resource(object, "context", context->rsrc_id); - zend_list_addref(context->rsrc_id); + add_property_resource(object, "context", context->res); + GC_REFCOUNT(context->res)++; } else { add_property_null(object, "context"); } @@ -300,14 +296,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.object = Z_OBJ_P(object); + fci.retval = &retval; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; @@ -316,36 +312,32 @@ static zval *user_stream_create_object(struct php_user_stream_wrapper *uwrap, ph fcc.function_handler = uwrap->ce->constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(object); - fcc.object_ptr = object; + fcc.object = Z_OBJ_P(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); + if (zend_call_function(&fci, &fcc) == FAILURE) { + php_error_docref(NULL, E_WARNING, "Could not execute %s::%s()", ZSTR_VAL(uwrap->ce->name), ZSTR_VAL(uwrap->ce->constructor->common.function_name)); zval_dtor(object); - FREE_ZVAL(object); - return NULL; + ZVAL_UNDEF(object); } else { - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(&retval); } } - return object; } 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) + int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) { 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; /* Try to catch bad usage without preventing flexibility */ if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented"); + php_stream_wrapper_log_error(wrapper, options, "infinite recursion prevented"); return NULL; } FG(user_stream_current_filename) = filename; @@ -364,8 +356,8 @@ 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); - if(us->object == NULL) { + user_stream_create_object(uwrap, context, &us->object); + if (Z_TYPE(us->object) == IS_UNDEF) { FG(user_stream_current_filename) = NULL; PG(in_user_include) = old_in_user_include; efree(us); @@ -373,64 +365,48 @@ 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, + Z_ISUNDEF(us->object)? NULL : &us->object, + &zfuncname, &zretval, 4, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - 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_ISREF(args[3]) && Z_TYPE_P(Z_REFVAL(args[3])) == IS_STRING && opened_path) { + *opened_path = zend_string_copy(Z_STR_P(Z_REFVAL(args[3]))); } /* 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", + php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_OPEN "\" call failed", us->wrapper->classname); } /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&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[3]); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); FG(user_stream_current_filename) = NULL; @@ -439,18 +415,18 @@ 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) + int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) { 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; /* Try to catch bad usage without preventing flexibility */ if (FG(user_stream_current_filename) != NULL && strcmp(filename, FG(user_stream_current_filename)) == 0) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "infinite recursion prevented"); + php_stream_wrapper_log_error(wrapper, options, "infinite recursion prevented"); return NULL; } FG(user_stream_current_filename) = filename; @@ -458,55 +434,48 @@ 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); - if(us->object == NULL) { + user_stream_create_object(uwrap, context, &us->object); + if (Z_TYPE(us->object) == IS_UNDEF) { FG(user_stream_current_filename) = NULL; efree(us); return NULL; } /* call it's dir_open method - set up params first */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, filename, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], filename); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; - - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, + &zfuncname, &zretval, 2, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - 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", + php_stream_wrapper_log_error(wrapper, options, "\"%s::" USERSTREAM_DIR_OPEN "\" call failed", us->wrapper->classname); } /* destroy everything else */ if (stream == NULL) { zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&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 +487,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; - long flags = 0; + zend_resource *rsrc; + zend_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(), "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(ZSTR_VAL(protocol), ZSTR_LEN(protocol)); + uwrap->classname = estrndup(ZSTR_VAL(classname), ZSTR_LEN(classname)); 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(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)) != NULL) { + if (php_register_url_stream_wrapper_volatile(ZSTR_VAL(protocol), &uwrap->wrapper) == 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, E_WARNING, "Protocol %s:// is already defined.", ZSTR_VAL(protocol)); } 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, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", ZSTR_VAL(classname), ZSTR_VAL(protocol)); } } } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname); + php_error_docref(NULL, E_WARNING, "class '%s' is undefined", ZSTR_VAL(classname)); } - zend_list_delete(rsrc_id); + zend_list_delete(rsrc); RETURN_FALSE; } /* }}} */ @@ -564,15 +531,15 @@ PHP_FUNCTION(stream_wrapper_register) PHP_FUNCTION(stream_wrapper_unregister) { char *protocol; - int protocol_len; + size_t protocol_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &protocol, &protocol_len) == FAILURE) { RETURN_FALSE; } - if (php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC) == FAILURE) { + if (php_unregister_url_stream_wrapper_volatile(protocol) == FAILURE) { /* We failed */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to unregister protocol %s://", protocol); + php_error_docref(NULL, E_WARNING, "Unable to unregister protocol %s://", protocol); RETURN_FALSE; } @@ -584,34 +551,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(), "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, E_NOTICE, "%s:// was never changed, nothing to restore", ZSTR_VAL(protocol)); 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, E_WARNING, "%s:// never existed, nothing to restore", ZSTR_VAL(protocol)); 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(ZSTR_VAL(protocol)); - 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(ZSTR_VAL(protocol), wrapper) == FAILURE) { + php_error_docref(NULL, E_WARNING, "Unable to restore original %s:// wrapper", ZSTR_VAL(protocol)); RETURN_FALSE; } @@ -619,31 +582,29 @@ PHP_FUNCTION(stream_wrapper_restore) } /* }}} */ -static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) +static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t count) { 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); - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 1, args, - 0, NULL TSRMLS_CC); - zval_ptr_dtor(&zbufptr); + 0, NULL); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&func_name); didwrite = 0; @@ -651,252 +612,237 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t return 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!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!", us->wrapper->classname); } /* don't allow strange buffer overruns due to bogus return */ if (didwrite > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote %ld bytes more data than requested (%ld written, %ld max)", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_WRITE " wrote " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " written, " ZEND_LONG_FMT " max)", us->wrapper->classname, - (long)(didwrite - count), (long)didwrite, (long)count); + (zend_long)(didwrite - count), (zend_long)didwrite, (zend_long)count); didwrite = count; } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); return didwrite; } -static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) +static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count) { 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); - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 1, args, - 0, NULL TSRMLS_CC); + 0, NULL); - zval_ptr_dtor(&zcount); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&func_name); if (EG(exception)) { - return 0; + return -1; } - 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); + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_LONG_FMT " bytes more data than requested (" ZEND_LONG_FMT " read, " ZEND_LONG_FMT " max) - excess data will be lost", + us->wrapper->classname, (zend_long)(didread - count), (zend_long)didread, (zend_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!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_READ " is not implemented!", us->wrapper->classname); } - 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); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - 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, + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_EOF " is not implemented! Assuming EOF", us->wrapper->classname); stream->eof = 1; } - if (retval) { - zval_ptr_dtor(&retval); - retval = NULL; - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return didread; } -static int php_userstreamop_close(php_stream *stream, int close_handle TSRMLS_DC) +static int php_userstreamop_close(php_stream *stream, int close_handle) { 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); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); return 0; } -static int php_userstreamop_flush(php_stream *stream TSRMLS_DC) +static int php_userstreamop_flush(php_stream *stream) { 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); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - 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); + zval_ptr_dtor(&func_name); return call_result; } -static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_userstreamop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs) { 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); - - MAKE_STD_ZVAL(zoffs); - ZVAL_LONG(zoffs, offset); - args[0] = &zoffs; + ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1); - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 2, args, - 0, NULL TSRMLS_CC); + 0, NULL); - zval_ptr_dtor(&zoffs); - zval_ptr_dtor(&zwhence); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&func_name); 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); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - 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); + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname); ret = -1; } else { ret = -1; } - if (retval) { - zval_ptr_dtor(&retval); - } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return ret; } /* parse the return value from one of the stat functions and store the * relevant fields into the statbuf provided */ -static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) +static int statbuf_from_array(zval *array, php_stream_statbuf *ssb) { - 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) @@ -933,114 +879,116 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) return SUCCESS; } -static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC) +static int php_userstreamop_stat(php_stream *stream, php_stream_statbuf *ssb) { 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); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - 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)) ret = 0; } else { if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STAT " is not implemented!", us->wrapper->classname); } } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return ret; } -static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam TSRMLS_DC) { +static int php_userstreamop_set_option(php_stream *stream, int option, int value, void *ptrparam) { 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); + call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, 0, NULL); + if (call_result == SUCCESS && (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE)) { + 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, + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_EOF " is not implemented! Assuming EOF", us->wrapper->classname); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); 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); call_result = call_user_function_ex(NULL, - &us->object, - &func_name, - &retval, - 1, args, 0, NULL TSRMLS_CC); + Z_ISUNDEF(us->object)? NULL : &us->object, + &func_name, + &retval, + 1, args, 0, NULL); - 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_FALSE || Z_TYPE(retval) == IS_TRUE)) { + ret = (Z_TYPE(retval) == IS_FALSE); } else if (call_result == FAILURE) { if (value == 0) { /* lock support test (TODO: more check) */ ret = PHP_STREAM_OPTION_RETURN_OK; } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_LOCK " is not implemented!", us->wrapper->classname); ret = PHP_STREAM_OPTION_RETURN_ERR; } } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); + zval_ptr_dtor(&args[0]); 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); switch (value) { case PHP_STREAM_TRUNCATE_SUPPORTED: - if (zend_is_callable_ex(&func_name, us->object, IS_CALLABLE_CHECK_SILENT, - NULL, NULL, NULL, NULL TSRMLS_CC)) + if (zend_is_callable_ex(&func_name, + Z_ISUNDEF(us->object)? NULL : Z_OBJ(us->object), + IS_CALLABLE_CHECK_SILENT, NULL, NULL, NULL)) ret = PHP_STREAM_OPTION_RETURN_OK; else ret = PHP_STREAM_OPTION_RETURN_ERR; @@ -1049,479 +997,413 @@ 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], (zend_long)new_size); call_result = call_user_function_ex(NULL, - &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; + Z_ISUNDEF(us->object)? NULL : &us->object, + &func_name, + &retval, + 1, args, 0, NULL); + if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + if (Z_TYPE(retval) == IS_FALSE || Z_TYPE(retval) == IS_TRUE) { + ret = (Z_TYPE(retval) == IS_TRUE) ? PHP_STREAM_OPTION_RETURN_OK : + PHP_STREAM_OPTION_RETURN_ERR; } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TRUNCATE " did not return a boolean!", us->wrapper->classname); } } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_TRUNCATE " is not implemented!", us->wrapper->classname); } + zval_ptr_dtor(&retval); + zval_ptr_dtor(&args[0]); } else { /* bad new size */ ret = PHP_STREAM_OPTION_RETURN_ERR; } break; } } + zval_ptr_dtor(&func_name); break; case PHP_STREAM_OPTION_READ_BUFFER: 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); - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 3, args, 0, NULL TSRMLS_CC); + 3, args, 0, NULL); if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_SET_OPTION " is not implemented!", + php_error_docref(NULL, 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)) { + } else if (Z_TYPE(retval) != IS_UNDEF && zend_is_true(&retval)) { 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(&retval); + zval_ptr_dtor(&args[2]); + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); + zval_ptr_dtor(&func_name); break; } } - /* clean up */ - if (retval) { - zval_ptr_dtor(&retval); - } - - - if (zvalue) { - zval_ptr_dtor(&zvalue); - } - return ret; } -static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) +static int user_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context) { 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; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { 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, + &zfuncname, &zretval, 1, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_UNLINK " is not implemented!", uwrap->classname); + php_error_docref(NULL, 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(&zretval); zval_ptr_dtor(&zfuncname); - zval_ptr_dtor(&zfilename); + + zval_ptr_dtor(&args[0]); return ret; } static int user_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, - int options, php_stream_context *context TSRMLS_DC) + int options, php_stream_context *context) { 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; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the rename method */ - MAKE_STD_ZVAL(zold_name); - ZVAL_STRING(zold_name, url_from, 1); - args[0] = &zold_name; - - MAKE_STD_ZVAL(znew_name); - ZVAL_STRING(znew_name, url_to, 1); - args[1] = &znew_name; + ZVAL_STRING(&args[0], url_from); + ZVAL_STRING(&args[1], url_to); - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RENAME, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RENAME); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 2, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RENAME " is not implemented!", uwrap->classname); + php_error_docref(NULL, 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(&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; } static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int mode, - int options, php_stream_context *context TSRMLS_DC) + int options, php_stream_context *context) { 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; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { 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, + &zfuncname, &zretval, 3, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_MKDIR " is not implemented!", uwrap->classname); + php_error_docref(NULL, 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(&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; } static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, - int options, php_stream_context *context TSRMLS_DC) + int options, php_stream_context *context) { 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; int ret = 0; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { return ret; } /* call the rmdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], options); - MAKE_STD_ZVAL(zoptions); - ZVAL_LONG(zoptions, options); - args[1] = &zoptions; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_RMDIR, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_RMDIR); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 2, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = (Z_TYPE(zretval) == IS_TRUE); } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_RMDIR " is not implemented!", uwrap->classname); + php_error_docref(NULL, 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(&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; } static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, int option, - void *value, php_stream_context *context TSRMLS_DC) + void *value, php_stream_context *context) { 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; 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); + php_error_docref(NULL, E_WARNING, "Unknown option %d for " USERSTREAM_METADATA, option); + 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); + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { + zval_ptr_dtor(&args[2]); return ret; } /* call the mkdir method */ - MAKE_STD_ZVAL(zfilename); - ZVAL_STRING(zfilename, url, 1); - args[0] = &zfilename; + ZVAL_STRING(&args[0], url); + ZVAL_LONG(&args[1], option); - MAKE_STD_ZVAL(zoption); - ZVAL_LONG(zoption, option); - args[1] = &zoption; - - args[2] = &zvalue; - - MAKE_STD_ZVAL(zfuncname); - ZVAL_STRING(zfuncname, USERSTREAM_METADATA, 1); + ZVAL_STRING(&zfuncname, USERSTREAM_METADATA); call_result = call_user_function_ex(NULL, &object, - zfuncname, + &zfuncname, &zretval, 3, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - if (call_result == SUCCESS && zretval && Z_TYPE_P(zretval) == IS_BOOL) { - ret = Z_LVAL_P(zretval); + if (call_result == SUCCESS && (Z_TYPE(zretval) == IS_FALSE || Z_TYPE(zretval) == IS_TRUE)) { + ret = Z_TYPE(zretval) == IS_TRUE; } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_METADATA " is not implemented!", uwrap->classname); + php_error_docref(NULL, 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(&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; } static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, int flags, - php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC) + php_stream_statbuf *ssb, php_stream_context *context) { 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; int ret = -1; /* create an instance of our class */ - object = user_stream_create_object(uwrap, context TSRMLS_CC); - if(object == NULL) { + user_stream_create_object(uwrap, context, &object); + if (Z_TYPE(object) == IS_UNDEF) { 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, + &zfuncname, &zretval, 2, args, - 0, NULL TSRMLS_CC); + 0, NULL ); - 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)) ret = 0; } else { if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_STATURL " is not implemented!", uwrap->classname); } } /* clean up */ zval_ptr_dtor(&object); - if (zretval) - zval_ptr_dtor(&zretval); + 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; } -static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count TSRMLS_DC) +static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t count) { 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; @@ -1531,125 +1413,122 @@ 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); call_result = call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, 0, NULL, - 0, NULL TSRMLS_CC); + 0, NULL); - 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_FALSE && Z_TYPE(retval) != IS_TRUE) { + 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) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_DIR_READ " is not implemented!", us->wrapper->classname); } - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return didread; } -static int php_userstreamop_closedir(php_stream *stream, int close_handle TSRMLS_DC) +static int php_userstreamop_closedir(php_stream *stream, int close_handle) { 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); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); + 0, NULL, 0, NULL); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); zval_ptr_dtor(&us->object); + ZVAL_UNDEF(&us->object); efree(us); return 0; } -static int php_userstreamop_rewinddir(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_userstreamop_rewinddir(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs) { 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); call_user_function_ex(NULL, - &us->object, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 0, NULL, 0, NULL TSRMLS_CC); + 0, NULL, 0, NULL); - if (retval) - zval_ptr_dtor(&retval); + zval_ptr_dtor(&retval); + zval_ptr_dtor(&func_name); return 0; } -static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr TSRMLS_DC) +static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr) { 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); - 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, + Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, &retval, - 1, args, 0, NULL TSRMLS_CC); + 1, args, 0, NULL); do { if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " is not implemented!", us->wrapper->classname); break; } - if (retval == NULL || !zend_is_true(retval)) { + if (Z_ISUNDEF(retval) || !zend_is_true(&retval)) { break; } php_stream_from_zval_no_verify(intstream, &retval); if (!intstream) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must return a stream resource", us->wrapper->classname); break; } if (intstream == stream) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself", + php_error_docref(NULL, E_WARNING, "%s::" USERSTREAM_CAST " must not return itself", us->wrapper->classname); intstream = NULL; break; @@ -1657,12 +1536,9 @@ 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(&func_name); + zval_ptr_dtor(&args[0]); return ret; } |
