Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:39325 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95429 invoked from network); 25 Jul 2008 16:34:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jul 2008 16:34:54 -0000 Authentication-Results: pb1.pair.com header.from=php_lists@realplain.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php_lists@realplain.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain realplain.com from 209.235.152.150 cause and error) X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 209.235.152.150 mail960c35.nsolutionszone.com Linux 2.5 (sometimes 2.4) (4) Received: from [209.235.152.150] ([209.235.152.150:58732] helo=mail960c35.nsolutionszone.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D6/CA-22699-DA00A884 for ; Fri, 25 Jul 2008 12:34:54 -0400 X-POP-User: wilmascam.centurytel.net Received: from pc1 (d13-125.rt-bras.pell.centurytel.net [69.179.187.125]) by mail960c35.nsolutionszone.com (8.13.6.20060614/8.13.1) with SMTP id m6PGYl2S006600; Fri, 25 Jul 2008 16:34:49 GMT Message-ID: <022c01c8ee74$5b539340$0201a8c0@pc1> To: , "Dmitry Stogov" References: <00ea01c8a160$2edd8160$0201a8c0@pc1> <016c01c8eccd$e28cfac0$0201a8c0@pc1> <488835D0.1040005@zend.com> <00e501c8ed77$3498cf20$0201a8c0@pc1> <48889901.8000008@zend.com> Date: Fri, 25 Jul 2008 11:34:47 -0500 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0229_01C8EE4A.716B57F0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1914 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1914 Subject: Re: [PHP-DEV] [PATCH] No runtime fetching of built-in global constants From: php_lists@realplain.com ("Matt Wilmas") ------=_NextPart_000_0229_01C8EE4A.716B57F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi Dmitry, I saw that you commited this patch, with the addition of only replacing persistent constants (just mentioning for others on the list). The attached patches have a few tweaks: The main thing I noticed is that if "something" creates a persistent, case-INsensitive constant (any of those in "standard" PHP, besides TRUE/FALSE/NULL?), it could still wrongly be substituted. My change eliminates that possibility. Checking Z_TYPE(c->value) != IS_CONSTANT[_ARRAY] isn't needed with the persistent check now, is it? From orginal patch (zend_constants.c part), the memcmp(...) != 0 isn't needed as it will always be true. If it wasn't, the *first* hash lookup wouldn't have failed. :-) Like I said in the original message, it's old code from a long time ago, but was never removed... - Matt ----- Original Message ----- From: "Dmitry Stogov" Sent: Thursday, July 24, 2008 > I would propose the attached patch for this optimization. > > Opcode caches and encoders will have to disable this optimization with > ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION > > Any objections? > > Thanks. Dmitry. > ---------------------------------------------------------------------------- ---- > Index: Zend/zend_compile.c > =================================================================== > RCS file: /repository/ZendEngine2/zend_compile.c,v > retrieving revision 1.647.2.27.2.41.2.74 > diff -u -p -d -r1.647.2.27.2.41.2.74 zend_compile.c > --- Zend/zend_compile.c 24 Jul 2008 11:47:49 -0000 1.647.2.27.2.41.2.74 > +++ Zend/zend_compile.c 24 Jul 2008 14:40:12 -0000 > @@ -3804,6 +3804,12 @@ static zend_constant* zend_get_ct_const( > if (c->flags & CONST_CT_SUBST) { > return c; > } > + if (!CG(current_namespace) && > + !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) && > + Z_TYPE(c->value) != IS_CONSTANT && > + Z_TYPE(c->value) != IS_CONSTANT_ARRAY) { > + return c; > + } > return NULL; > } > /* }}} */ > @@ -5169,12 +5175,14 @@ void zend_do_use(znode *ns_name, znode * > void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC) /* {{{ */ > { > zend_op *opline; > + zend_constant *c; > > if(Z_TYPE(value->u.constant) == IS_CONSTANT_ARRAY) { > zend_error(E_COMPILE_ERROR, "Arrays are not allowed as constants"); > } > > - if (zend_get_ct_const(&name->u.constant TSRMLS_CC)) { > + c = zend_get_ct_const(&name->u.constant TSRMLS_CC); > + if (c && (c->flags & CONST_CT_SUBST)) { > zend_error(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", Z_STRVAL(name->u.constant)); > } > > Index: Zend/zend_compile.h > =================================================================== > RCS file: /repository/ZendEngine2/zend_compile.h,v > retrieving revision 1.316.2.8.2.12.2.27 > diff -u -p -d -r1.316.2.8.2.12.2.27 zend_compile.h > --- Zend/zend_compile.h 24 Jul 2008 11:47:49 -0000 1.316.2.8.2.12.2.27 > +++ Zend/zend_compile.h 24 Jul 2008 14:40:13 -0000 > @@ -762,6 +762,9 @@ END_EXTERN_C() > /* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */ > #define ZEND_COMPILE_DELAYED_BINDING (1<<4) > > +/* disable constant substitution at compile-time */ > +#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION (1<<5) > + > /* The default value for CG(compiler_options) */ > #define ZEND_COMPILE_DEFAULT ZEND_COMPILE_HANDLE_OP_ARRAY > > ------=_NextPart_000_0229_01C8EE4A.716B57F0 Content-Type: text/plain; name="constants.diff.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="constants.diff.txt" Index: Zend/zend_compile.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_compile.c,v=0A= retrieving revision 1.832=0A= diff -u -r1.832 zend_compile.c=0A= --- Zend/zend_compile.c 25 Jul 2008 04:54:56 -0000 1.832=0A= +++ Zend/zend_compile.c 25 Jul 2008 09:30:00 -0000=0A= @@ -3996,24 +3996,20 @@=0A= zstr lookup_name =3D zend_u_str_case_fold(Z_TYPE_P(const_name), = Z_UNIVAL_P(const_name), Z_UNILEN_P(const_name), 1, &lookup_name_len);=0A= =0A= if (zend_u_hash_find(EG(zend_constants), Z_TYPE_P(const_name), = lookup_name, lookup_name_len+1, (void **) &c)=3D=3DSUCCESS) {=0A= - if ((c->flags & CONST_CS) && memcmp(c->name.v, = Z_UNIVAL_P(const_name).v, = UG(unicode)?UBYTES(Z_USTRLEN_P(const_name)):Z_STRLEN_P(const_name))!=3D0)= {=0A= + if ((c->flags & CONST_CT_SUBST) && !(c->flags & CONST_CS)) {=0A= efree(lookup_name.v);=0A= - return NULL;=0A= + return c;=0A= }=0A= - } else {=0A= - efree(lookup_name.v);=0A= - return NULL;=0A= }=0A= efree(lookup_name.v);=0A= + return NULL;=0A= }=0A= if (c->flags & CONST_CT_SUBST) {=0A= return c;=0A= }=0A= if ((c->flags & CONST_PERSISTENT) &&=0A= !CG(current_namespace) &&=0A= - !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) &&=0A= - Z_TYPE(c->value) !=3D IS_CONSTANT &&=0A= - Z_TYPE(c->value) !=3D IS_CONSTANT_ARRAY) {=0A= + !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {=0A= return c;=0A= }=0A= return NULL;=0A= Index: Zend/zend_constants.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_constants.c,v=0A= retrieving revision 1.111=0A= diff -u -r1.111 zend_constants.c=0A= --- Zend/zend_constants.c 21 Jul 2008 09:36:21 -0000 1.111=0A= +++ Zend/zend_constants.c 25 Jul 2008 09:34:30 -0000=0A= @@ -278,7 +278,7 @@=0A= lookup_name =3D zend_u_str_case_fold(type, name, name_len, 1, = &lookup_name_len);=0A= =0A= if (zend_u_hash_find(EG(zend_constants), type, lookup_name, = lookup_name_len+1, (void **) &c)=3D=3DSUCCESS) {=0A= - if ((c->flags & CONST_CS) && memcmp(c->name.v, name.v, = UG(unicode)?UBYTES(name_len):name_len)!=3D0) {=0A= + if (c->flags & CONST_CS) {=0A= retval=3D0;=0A= }=0A= } else {=0A= ------=_NextPart_000_0229_01C8EE4A.716B57F0 Content-Type: text/plain; name="constants_5_3.diff.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="constants_5_3.diff.txt" Index: Zend/zend_compile.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_compile.c,v=0A= retrieving revision 1.647.2.27.2.41.2.77=0A= diff -u -r1.647.2.27.2.41.2.77 zend_compile.c=0A= --- Zend/zend_compile.c 25 Jul 2008 04:54:08 -0000 1.647.2.27.2.41.2.77=0A= +++ Zend/zend_compile.c 25 Jul 2008 09:30:00 -0000=0A= @@ -3791,24 +3791,20 @@=0A= char *lookup_name =3D zend_str_tolower_dup(Z_STRVAL_P(const_name), = Z_STRLEN_P(const_name));=0A= =0A= if (zend_hash_find(EG(zend_constants), lookup_name, = Z_STRLEN_P(const_name)+1, (void **) &c)=3D=3DSUCCESS) {=0A= - if ((c->flags & CONST_CS) && memcmp(c->name, Z_STRVAL_P(const_name), = Z_STRLEN_P(const_name))!=3D0) {=0A= + if ((c->flags & CONST_CT_SUBST) && !(c->flags & CONST_CS)) {=0A= efree(lookup_name);=0A= - return NULL;=0A= + return c;=0A= }=0A= - } else {=0A= - efree(lookup_name);=0A= - return NULL;=0A= }=0A= efree(lookup_name);=0A= + return NULL;=0A= }=0A= if (c->flags & CONST_CT_SUBST) {=0A= return c;=0A= }=0A= if ((c->flags & CONST_PERSISTENT) &&=0A= !CG(current_namespace) &&=0A= - !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION) &&=0A= - Z_TYPE(c->value) !=3D IS_CONSTANT &&=0A= - Z_TYPE(c->value) !=3D IS_CONSTANT_ARRAY) {=0A= + !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {=0A= return c;=0A= }=0A= return NULL;=0A= Index: Zend/zend_constants.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/ZendEngine2/zend_constants.c,v=0A= retrieving revision 1.71.2.5.2.7.2.10=0A= diff -u -r1.71.2.5.2.7.2.10 zend_constants.c=0A= --- Zend/zend_constants.c 21 Jul 2008 09:41:00 -0000 1.71.2.5.2.7.2.10=0A= +++ Zend/zend_constants.c 25 Jul 2008 09:34:30 -0000=0A= @@ -231,7 +231,7 @@=0A= lookup_name =3D zend_str_tolower_dup(name, name_len);=0A= =0A= if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void = **) &c)=3D=3DSUCCESS) {=0A= - if ((c->flags & CONST_CS) && memcmp(c->name, name, name_len) !=3D 0) = {=0A= + if (c->flags & CONST_CS) {=0A= retval=3D0;=0A= }=0A= } else {=0A= ------=_NextPart_000_0229_01C8EE4A.716B57F0--