On Mon, Feb 2, 2015 at 1:34 PM, Xinchen Hui <[email protected]> wrote:
> Hey:
>
> we used to use lval of zval as a handle to access resource type..
>
> but now, we introduced a new type IS_RESOURCE, which make the
> handle(id) sort of redundant .
>
> further more, the common usage when handling resource is like:
>
> if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &result,
> &offset) == FAILURE) {
> return;
> }
> ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL
> result", le_result);
>
> as you can see, we use "r" to receive a IS_RESOURCE type, that
> means, check the type in ZEND_FETCH_RESOURCE is overhead..
>
> and:
>
> ZEND_API void *zend_fetch_resource(zval *passed_id, int default_id,
> const char *resource_type_name, int *found_resource_type, int
> num_resource_types, ...)
>
> we use va_args to passing resource type, that means, the rescue
> type arguments can not be passed by register but by stack.. which is a
> little low effiicient .
>
> so, I'd like propose a zend_resource handling API cleanup..
>
> 1. DROP ZEND_REGISTER_RESOURCE/FETCH_RESOURCE.
>
> 2. add :
>
> ZEND_API void *zend_fetch_resource(zend_resource *res, const
> char *resource_type_name, int resource_type);
> ZEND_API void *zend_fetch_resource2(zend_resource *res, const char
> *resource_type_name, int *found_type, int resource_type, int
> resource_type2);
> ZEND_API void *zend_fetch_resource_ex(zval *res, const char
> *resource_type_name, int resource_type);
> ZEND_API void *zend_fetch_resource2_ex(zval *res, const char
> *resource_type_name, int *found_type, int resource_type, int
> resource_type2);
>
> a underworking patch could be found at:
> https://github.com/php/php-src/pull/1042
>
> any ideas & objections?
furthermore, I'd like to discuss remove the handle in zend_resource struct..
it may breaks some usage (use resource as long/double/string)
case IS_RESOURCE: {
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
int len;
len = snprintf(buf, sizeof(buf), "Resource id #"
ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op));
return zend_string_init(buf, len, 0);
}
thanks
>
> thanks
>
> --
> Xinchen Hui
> @Laruence
> http://www.laruence.com/
--
Xinchen Hui
@Laruence
http://www.laruence.com/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php