Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81550 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61480 invoked from network); 2 Feb 2015 06:51:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 06:51:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=francois@tekwire.net; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=francois@tekwire.net; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain tekwire.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@tekwire.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:46150] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/70-58765-96E1FC45 for ; Mon, 02 Feb 2015 01:51:23 -0500 Received: from moorea (unknown [82.240.16.115]) by smtp2-g21.free.fr (Postfix) with ESMTP id 3B7124B0204; Mon, 2 Feb 2015 07:48:10 +0100 (CET) Reply-To: To: "'Xinchen Hui'" , "'PHP Internals'" , "'Dmitry Stogov'" References: In-Reply-To: Date: Mon, 2 Feb 2015 07:51:16 +0100 Message-ID: <004e01d03eb4$a4dd8240$ee9886c0$@tekwire.net> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQHdbSTnoUvvQnF9fe5lyro9w/l3gJzChtzw Content-Language: fr X-Antivirus: avast! (VPS 150201-1, 01/02/2015), Outbound message X-Antivirus-Status: Clean Subject: RE: [PHP-DEV] [DICUSS]Cleanup resource handling APIs From: francois@tekwire.net (=?UTF-8?Q?Fran=C3=A7ois_Laupretre?=) > De : Xinchen Hui [mailto:laruence@php.net] > we used to use lval of zval as a handle to access resource type.. >=20 > 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_resource is new. And handle is not redundant. > further more, the common usage when handling resource is like: >=20 > 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); >=20 > 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 = accepted resource types. Sorry to say that, but are you sure you = understand the difference between zval types and resource types ? > 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, ...) >=20 > 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 ? Fetch is supposed to check for a variable number of possible resource = types. 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 sure the overhead of passing arg on the stack = justifies a change. Remember that id is searched in an array, which = takes probably much more time that pushing/popping one or two arguments. > so, I'd like propose a zend_resource handling API cleanup.. >=20 > 1. DROP ZEND_REGISTER_RESOURCE/FETCH_RESOURCE. >=20 > 2. add : >=20 > 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 mandatory if we want them to be freed when request ends. > 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 =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 = this way (see = http://devzone.zend.com/446/extension-writing-part-iii-resources/). 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 = data. Using the handle to store long/double/string is not a legitimate = usage. Regards Fran=C3=A7ois