Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81559 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76137 invoked from network); 2 Feb 2015 08:02:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 08:02:33 -0000 Authentication-Results: pb1.pair.com header.from=zxcvdavid@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zxcvdavid@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.48 as permitted sender) X-PHP-List-Original-Sender: zxcvdavid@gmail.com X-Host-Fingerprint: 209.85.220.48 mail-pa0-f48.google.com Received: from [209.85.220.48] ([209.85.220.48:47880] helo=mail-pa0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/91-02376-41F2FC45 for ; Mon, 02 Feb 2015 03:02:29 -0500 Received: by mail-pa0-f48.google.com with SMTP id ey11so79388365pad.7 for ; Mon, 02 Feb 2015 00:02:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version:content-type; bh=Em7j19fJCzwUqrVZBdBjTff4r2USplMMfY6n2tc8ASY=; b=Thrdx8sdO7kiQCFQQRLllWUyVcaOU8whrU4QI3J9tGJavaGcmZvGqgFtmeGJeqON6o v9vuVVEy/xJfUcWResZUutCzR9WcqZxyNeUcS2xUCoZO6aHNOaJ1X7LEh13qKT+Q6Mdy 5a8OAbRcKe3BsV6GnHTngd/R90+CepZ8XqxRLl7gz9ZR7hSFbR2k9UaG6jlqmCV5FH4u juWZHoF01j8KIAYJWfQxDGajd9VAye4ZDS8eJG1+93bqM1BCdyr577bZBw/GgwgIf4IE 04bYEUieCmErGI4gw40kCK36YYGYyxCGva8QTPqh80nSFvLK7p42jk8rkOCPRD51TaD/ bhOQ== X-Received: by 10.70.34.208 with SMTP id b16mr26776892pdj.141.1422864143691; Mon, 02 Feb 2015 00:02:23 -0800 (PST) Received: from [10.0.23.191] ([207.226.142.175]) by mx.google.com with ESMTPSA id ph7sm17941911pbb.6.2015.02.02.00.02.21 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Feb 2015 00:02:22 -0800 (PST) Date: Mon, 2 Feb 2015 16:02:29 +0800 To: francois@tekwire.net Cc: Xinchen Hui , PHP Internals , Dmitry Stogov Message-ID: In-Reply-To: <004e01d03eb4$a4dd8240$ee9886c0$@tekwire.net> References: <004e01d03eb4$a4dd8240$ee9886c0$@tekwire.net> X-Mailer: sparrow 1.6.4 (build 1178) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="54cf2f15_15014acb_c4" Subject: =?utf-8?Q?=E5=9B=9E=E5=A4=8D=EF=BC=9A_?=[PHP-DEV] [DICUSS]Cleanup resource handling APIs From: zxcvdavid@gmail.com (Wei Dai) --54cf2f15_15014acb_c4 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline > > De : Xinchen Hui =5Bmailto:laruence=40php.net=5D > > we used to use lval of zval as a handle to access resource type.. > > =20 > > but now, we introduced a new type IS=5FRESOURCE, which make the > > handle(id) sort of redundant . > > =20 > =20 > =20 > Wrong. The IS=5FRESOURCE type has nothing to do with PHP 7. Only zend=5F= resource is new. And handle is not redundant. > =20 > > further more, the common usage when handling resource is like: > > =20 > > if (zend=5Fparse=5Fparameters(ZEND=5FNUM=5FARGS(), =22rl=22, &result,= > > &offset) =3D=3D =46AILURE) =7B > > return; > > =7D > > ZEND=5F=46ETCH=5FRESOURCE(mysql=5Fresult, MYSQL=5FRES *, result, -1, = =22MySQL > > result=22, le=5Fresult); > > =20 > > as you can see, we use =22r=22 to receive a IS=5FRESOURCE type, that > > means, check the type in ZEND=5F=46ETCH=5FRESOURCE is overhead.. > > =20 > =20 > =20 > There's no overhead here. Zend=5Fparse=5Fparameters checks that receive= d arg is IS=5FRESOURCE. =46etch 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 =3F Are you kidding=3F he is one of the main authors of PHP7.. =20 > =20 > > ZEND=5FAPI void *zend=5Ffetch=5Fresource(zval *passed=5Fid, int defau= lt=5Fid, > > const char *resource=5Ftype=5Fname, int *found=5Fresource=5Ftype, int= > > num=5Fresource=5Ftypes, ...) > > =20 > > we use va=5Fargs 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 . > > =20 > =20 > =20 > What do you mean with 'rescue' type =3F > =20 > =46etch 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 a= m not sure the overhead of passing arg on the stack justifies a change. R= emember that id is searched in an array, which takes probably much more t= ime that pushing/popping one or two arguments. > =20 > > so, I'd like propose a zend=5Fresource handling API cleanup.. > > =20 > > 1. DROP ZEND=5FREGISTER=5FRESOURCE/=46ETCH=5FRESOURCE. > > =20 > > 2. add : > > =20 > > ZEND=5FAPI void *zend=5Ffetch=5Fresource(zend=5Fresource *res, const > > char *resource=5Ftype=5Fname, int resource=5Ftype); > > ZEND=5FAPI void *zend=5Ffetch=5Fresource2(zend=5Fresource *res, const= char > > *resource=5Ftype=5Fname, int *found=5Ftype, int resource=5Ftype, int > > resource=5Ftype2); > > ZEND=5FAPI void *zend=5Ffetch=5Fresource=5Fex(zval *res, const char > > *resource=5Ftype=5Fname, int resource=5Ftype); > > ZEND=5FAPI void *zend=5Ffetch=5Fresource2=5Fex(zval *res, const char > > *resource=5Ftype=5Fname, int *found=5Ftype, int resource=5Ftype, int > > resource=5Ftype2); > > =20 > =20 > =20 > If you drop ZEND=5FREGISTER=5FRESOURCE, how do you register new resourc= es =3F Or do you mean you don't register them any more =3F But registerin= g them is mandatory if we want them to be freed when request ends. > =20 > > furthermore, I'd like to discuss remove the handle in zend=5Fresource= struct.. > > =20 > > it may breaks some usage (use resource as long/double/string) > > =20 > > case IS=5FRESOURCE: =7B > > char buf=5Bsizeof(=22Resource id =23=22) + MAX=5FLENGTH=5FO=46=5FLONG= =5D; > > int len; > > =20 > > len =3D snprintf(buf, sizeof(buf), =22Resource id =23=22 > > ZEND=5FLONG=5F=46MT, (zend=5Flong)Z=5FRES=5FHANDLE=5FP(op)); > > return zend=5Fstring=5Finit(buf, len, 0); > > =7D > > =20 > =20 > =20 > OK. You want to remove resource registration. But resources don't work = this way (see http://devzone.zend.com/446/extension-writing-part-iii-reso= urces/). If you remove the handle, you remove the whole zend=5Flist API. > =20 > The zend=5Fresource struct is not a structure you may fill with random = data. Using the handle to store long/double/string is not a legitimate us= age. > =20 > Regards > =20 > =46ran=C3=A7ois > =20 > =20 > =20 > =20 > =20 > -- =20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > =20 > =20 Best, =20 Wei Dai --54cf2f15_15014acb_c4--