Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81553 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66359 invoked from network); 2 Feb 2015 07:19:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 07:19:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=xinchen.h@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.215.51 as permitted sender) X-PHP-List-Original-Sender: xinchen.h@zend.com X-Host-Fingerprint: 209.85.215.51 mail-la0-f51.google.com Received: from [209.85.215.51] ([209.85.215.51:33710] helo=mail-la0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/81-58765-0F42FC45 for ; Mon, 02 Feb 2015 02:19:12 -0500 Received: by mail-la0-f51.google.com with SMTP id ge10so37891294lab.10 for ; Sun, 01 Feb 2015 23:19:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=ARJQZOV05YtD2HG3q7kx9jEScY5WsPnaP68q1lqSX3k=; b=dsuEVCKTfSxdwrCpQFVlyYd2aW+HoMhxyy+MuqV+Rj+OGDQA9kIXPQvHsZNdLgaFL+ 55R32tnI52uwERK4kSWHiRjkfVPhyrNsi9IuJtwK7hcRU7QFIQYQ0AmPb7RZ+NbcqOXQ QYsFbFVdmIa+aKxdhfuUmGC5YumCzpNv/cFlVIttSJu+q7Eo3Eb0MYla9KFN2MfoTj9a Pd0pnT3IB7ZaQM3jxnGDJbkvx6SewJgr1JbPongZY1mTYQgaLamJjeUrfZ7sr1AWWPfE VwB0UuNptQr1h2g2io9BblAT7PIt1Rot14l9xryZooYvfUPa0BlB2S0ejyx2oqwktmdS Xo8A== X-Gm-Message-State: ALoCoQmsKLJgtbsTWlY/yjErs6TB+ussf3Qo0ZWObYPjbnsGJX7fcTRXDmt3AvePh+BqXamxzTHiEE5y0Oq795/SiBLZvffQRdZZq+Y9fk7Q+0tE/FVFvlSL8WVNz9RP04cQ//dkE8f4rfr5Dpnij8+sntGwNxiD8A== X-Received: by 10.152.37.165 with SMTP id z5mr9343471laj.88.1422861548153; Sun, 01 Feb 2015 23:19:08 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPSA id h7sm4205992lbl.41.2015.02.01.23.19.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 01 Feb 2015 23:19:07 -0800 (PST) Received: by mail-la0-f44.google.com with SMTP id s18so37905299lam.3 for ; Sun, 01 Feb 2015 23:19:06 -0800 (PST) X-Received: by 10.112.198.1 with SMTP id iy1mr17892547lbc.13.1422861546419; Sun, 01 Feb 2015 23:19:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.114.28.193 with HTTP; Sun, 1 Feb 2015 23:18:46 -0800 (PST) In-Reply-To: References: <004e01d03eb4$a4dd8240$ee9886c0$@tekwire.net> Date: Mon, 2 Feb 2015 15:18:46 +0800 Message-ID: To: francois@tekwire.net Cc: PHP Internals , Dmitry Stogov Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [DICUSS]Cleanup resource handling APIs From: laruence@php.net (Xinchen Hui) Hey: On Mon, Feb 2, 2015 at 3:11 PM, Xinchen Hui wrote: > Hey: > > On Mon, Feb 2, 2015 at 2:51 PM, Fran=C3=A7ois Laupretre wrote: >>> De : Xinchen Hui [mailto:laruence@php.net] >>> 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 . >> >> Wrong. The IS_RESOURCE type has nothing to do with PHP 7. Only zend_reso= urce is new. And handle is not redundant. > of course it's a typo. I meant zend_resource >> >>> further more, the common usage when handling resource is like: >>> >>> if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &result, >>> &offset) =3D=3D 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.. >> >> There's no overhead here. Zend_parse_parameters checks that received arg= is IS_RESOURCE. Fetch then checks that received resource is one of the acc= epted resource types. Sorry to say that, but are you sure you understand th= e difference between zval types and resource types ? > ..... do you really read the FETCH_RESOURCE? > > 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, ...) > { > int actual_resource_type; > // void *resource; > va_list resource_types; > int i; > zend_resource *res; > const char *space; > const char *class_name; > > if (default_id=3D=3D-1) { /* use id */ > if (!passed_id) { > if (resource_type_name) { > class_name =3D get_active_class_name(&space); > zend_error(E_WARNING, "%s%s%s(): no %s resource > supplied", class_name, space, get_active_function_name(), > resource_type_name); > } > return NULL; > } else if (Z_TYPE_P(passed_id) !=3D IS_RESOURCE) { // < =3D=3D=3D= what are this? > if (resource_type_name) { > class_name =3D get_active_class_name(&space); > zend_error(E_WARNING, "%s%s%s(): supplied argument is > not a valid %s resource", class_name, space, > get_active_function_name(), resource_type_name); > } > return NULL; > } > > >> >>> 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 . >> >> What do you mean with 'rescue' type ? > expected resource_type >> >> Fetch is supposed to check for a variable number of possible resource ty= pes. It could probably be restricted to 2 possible types as, generally, it = is the maximum (one for non-persistent, one for persistent). But I am not s= ure the overhead of passing arg on the stack justifies a change. Remember t= hat id is searched in an array, which takes probably much more time that pu= shing/popping one or two arguments. >> >>> 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); >> >> If you drop ZEND_REGISTER_RESOURCE, how do you register new resources ? = Or do you mean you don't register them any more ? But registering them is m= andatory if we want them to be freed when request ends. >> >>> furthermore, I'd like to discuss remove the handle in zend_resource str= uct.. >>> >>> 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 =3D snprintf(buf, sizeof(buf), "Resource id #" >>>ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op)); >>> return zend_string_init(buf, len, 0); >>> } >> >> OK. You want to remove resource registration. But resources don't work t= his way (see http://devzone.zend.com/446/extension-writing-part-iii-resourc= es/). If you remove the handle, you remove the whole zend_list API. >> >> The zend_resource struct is not a structure you may fill with random dat= a. Using the handle to store long/double/string is not a legitimate usage. > ....I think you don't understand what I am talking about. sorry I think I'd better to explain a bit more. we used to use handle to lookup a resource in EG(regular_list).. and store the "int handle" into lval of zval. but now, we use zend_resource * , which can be directly accessed via Z_RES_P(zval). that's why I think the "handle" is a little redundant .. is that clear? thanks > > > thanks >> >> Regards >> >> Fran=C3=A7ois >> >> >> >> > > > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/ --=20 Xinchen Hui @Laruence http://www.laruence.com/