Re: [PHP-DEV] Complete traits redesign for 5.5

2012-12-20 Thread Pierre Joye
hi Dmitry!

On Thu, Dec 20, 2012 at 7:54 AM, Dmitry Stogov dmi...@zend.com wrote:

Thanks a lot to work on that :)

 I'm not sure about APC, I saw the problem in ZendOptimizerPlus with
 php-5.4.10.
 O+ crashes (or corrupts memory and crashes on following requests) on each
 trait usage.
 The problem that PHP tries to deallocate names of methods defined in
 traits, but O+ keeps them in SHM.
 I believe APC must have the same problem.

Do you have some phpt to share? I can run them in our tests labs and
report issues to the bugs tracker, and see if Anatolyi can help to fix
them as well.


Cheers,
--
Pierre

@pierrejoye

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Complete traits redesign for 5.5

2012-12-20 Thread Pierre Joye
btw, same to test your changes/branch, as we have seen some crashes
happening more easily on windows (same bug(s) on linux but with harder
to get them crash).

On Thu, Dec 20, 2012 at 9:02 AM, Pierre Joye pierre@gmail.com wrote:
 hi Dmitry!

 On Thu, Dec 20, 2012 at 7:54 AM, Dmitry Stogov dmi...@zend.com wrote:

 Thanks a lot to work on that :)

 I'm not sure about APC, I saw the problem in ZendOptimizerPlus with
 php-5.4.10.
 O+ crashes (or corrupts memory and crashes on following requests) on each
 trait usage.
 The problem that PHP tries to deallocate names of methods defined in
 traits, but O+ keeps them in SHM.
 I believe APC must have the same problem.

 Do you have some phpt to share? I can run them in our tests labs and
 report issues to the bugs tracker, and see if Anatolyi can help to fix
 them as well.


 Cheers,
 --
 Pierre

 @pierrejoye



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] zend_parse_parameters() improvements

2012-12-20 Thread Gustavo Lopes

Em 2012-12-19 22:07, Nikita Popov escreveu:

On Wed, Jul 18, 2012 at 11:05 PM, Gustavo Lopes
glo...@nebm.ist.utl.pt wrote:


Some deficiencies in zpp have been constrai
ning the implementation of common scenarios such as allow integer or 
NULL* or the more general allow different types for an argument**.


So I propose the changes in this branch:

https://github.com/cataphract/php-src/compare/zpp_improv [2]


Whats the state of this?



I'll try to find the energy to write the RFC in the coming days.

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Complete traits redesign for 5.5

2012-12-20 Thread Dmitry Stogov
Hi Pierre,

The following test may crash on the second request with opcode cache.

?php

trait THello {

  public function hello() { echo 'Hello'; }
}

class TraitsTest { use THello; }

$test = new TraitsTest();
$test-hello();

?

Valgrind shows the problem even if PHP doesn't crash.

==2623== Invalid free() / delete / delete[] / realloc()
==2623== at 0x4007F0F: free (vg_replace_malloc.c:446)
==2623== by 0x837CC7C: zend_clear_trait_method_name (zend_opcode.c:273)
==2623== by 0x8393B1B: zend_hash_apply (zend_hash.c:716)
==2623== by 0x837D4C7: destroy_zend_class (zend_opcode.c:312)
==2623== by 0x8392464: zend_hash_apply_deleter (zend_hash.c:650)
==2623== by 0x8393D38: zend_hash_reverse_apply (zend_hash.c:804)
==2623== by 0x8378C3B: shutdown_executor (zend_execute_API.c:305)
==2623== by 0x8386C09: zend_deactivate (zend.c:938)
==2623== by 0x8329815: php_request_shutdown (main.c:1790)
With opcode cache op_code-function_name is actually allocated in shared
memory .

Thanks. Dmitry.

On Thu, Dec 20, 2012 at 12:07 PM, Pierre Joye pierre@gmail.com wrote:

 btw, same to test your changes/branch, as we have seen some crashes
 happening more easily on windows (same bug(s) on linux but with harder
 to get them crash).

 On Thu, Dec 20, 2012 at 9:02 AM, Pierre Joye pierre@gmail.com wrote:
  hi Dmitry!
 
  On Thu, Dec 20, 2012 at 7:54 AM, Dmitry Stogov dmi...@zend.com wrote:
 
  Thanks a lot to work on that :)
 
  I'm not sure about APC, I saw the problem in ZendOptimizerPlus with
  php-5.4.10.
  O+ crashes (or corrupts memory and crashes on following requests) on
 each
  trait usage.
  The problem that PHP tries to deallocate names of methods defined in
  traits, but O+ keeps them in SHM.
  I believe APC must have the same problem.
 
  Do you have some phpt to share? I can run them in our tests labs and
  report issues to the bugs tracker, and see if Anatolyi can help to fix
  them as well.
 
 
  Cheers,
  --
  Pierre
 
  @pierrejoye



 --
 Pierre

 @pierrejoye | http://blog.thepimp.net | http://www.libgd.org



Re: [PHP-DEV] Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752

2012-12-20 Thread Jani Ollikainen

Hi,

If someone wants access to machine where you can reproduce this
send me email. It's not just one machine where I can reproduce
this, so can't blame hardware.

Reproduced this there in CentOS 6.3 default php, php-5.3.19, php-5.4.9
and php-trunk-201212200830.

What I noticed that with trunk I got different places in .l for
the crash so it seems to me that something is really wrong with
mmap functionality and it gets somehow broken files?

This is the most often place:
1917switch (*YYCURSOR++) {

But I've also got these:
2267switch (yych) {
1087if (yych != '') goto yy4;

I see two possibilities here, php uses mmap somehow that there's
a possibility of that happening or there's a data corruption
bug in mmap itself.

Lets tackle the latter and lets get http://ltp.sourceforge.net/:
$ ./mmap-corruption01 -h1 -m1 -s1
mmap-corruption will run for= 3661, seconds
mmap-corruption PASSED

Well, no corruption according to that test, so it leaves me
the first option.

This is the script runme.sh I used to reproduce crashes.
It usually only needs 1-4 iterations to get the crash:

#!/bin/sh

# Touch so first run aren't full of include() errors
touch test.tpl

# Remove old core
/bin/rm core.* 1/dev/null 2/dev/null

# Do crash
NOCRASH=1
while [ $NOCRASH -eq 1 ];do
sapi/cli/php -n test3.php 
PHPPID=$!
echo Running php with pid $PHPPID...
sleep 5
ps $PHPPID /dev/null  NOCRASH=1 || NOCRASH=0
if [ $NOCRASH -eq 1 ];then
echo Killing php...;
kill -9 $PHPPID;
fi;
done

# Crash done
ls -la core.*

# Debug
gdb sapi/cli/php core.*


Where test3.php is almost the same, but added -n, so no apc or other
extension is to blame:

?php
if ($argv[1]  0) {
  while ($argv[1]--) file_put_contents('test.tpl', ?php 
#.str_repeat('A', mt_rand(4000, 5000)). ?\n, LOCK_EX);

} else {
  $p2 = popen(sapi/cli/php -n test3.php 100, r);
  while (1) include 'test.tpl';
}
?

With this patch, which disables mmap I've not been able to reproduce it
after it has been running for 10 minutes:
--- php-trunk-201212200830/main/main.c  2012-12-05 11:59:32.0 +0200
+++ php-trunk-patched-201212200830/main/main.c  2012-12-20 
12:18:10.491302651 +0200

@@ -1324,7 +1324,7 @@
/* can we mmap immeadiately? */
memset(handle-handle.stream.mmap, 0, 
sizeof(handle-handle.stream.mmap));

len = php_zend_stream_fsizer(stream TSRMLS_CC);
-   if (len != 0
+   if (0  len != 0
 #if HAVE_MMAP || defined(PHP_WIN32)
 ((len - 1) % page_size) = page_size - ZEND_MMAP_AHEAD
 #endif

Without that patch the crash comes in under half minute.

And now I'm out of ideas of what I could do more to help
get this issue fixed with my knowledge and skills.


On 19.12.2012 22:52, Jani Ollikainen wrote:

On 19.12.2012 22:27, Stas Malyshev wrote:

https://bugs.php.net/bug.php?id=52752

Just tried to reproduce it on Centos 6.2 install (without APC), works
just fine for me. I suspect it's some APC issue, does it reproduce for
you without APC loaded?



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Changes in libcurl for CURLOPT_SSL_VERIFYHOST in 7.28.1

2012-12-20 Thread jpauli
On Wed, Dec 19, 2012 at 5:35 AM, Pierrick Charron pierr...@webstart.frwrote:

 Hi all,

 About 2 month ago, we had a discussion on this list about the fact
 that CURLOPT_SSL_VERIFYHOST was most of the time used with a Boolean
 value (true) instead of int values (0,1 or 2). This bad usage was
 leading to some security issues. The result of this discussion was to
 trigger a notice if someone tried to set the CURLOPT_SSL_VERIFYHOST to
 true (boolean), and was committed to = 5.4

 On November 20th, Daniel (the author of libcurl) released cURL 7.28.1
 which no longer support the 1 value for CURLOPT_SSL_VERIFYHOST. This
 change introduced some bugs as #63795 (you'll find the cause of the
 bug in the comments).

 To fix this bug, and to minimize as much as possible the impact of
 this change, I'm proposing to do the following changes in the libcurl
 extension for future releases :

 When using libcurl  7.28.1, if someone try to set
 CURLOPT_SSL_VERIFYHOST to 1 (or true), set the value to 1, but trigger
 a notice to inform that this value is deprecated.


I dont know if it is the good way to deal with that. Does the PHP user have
to be aware that
the underlying libcurl is gonna change ? The deprecated message may let
him think that in the next *PHP* version, the value will have disapeared,
but in fact,
its in the next *libcurl* version, regardless PHP version.



 When using libcurl = 7.28.1 if someone try to set
 CURLOPT_SSL_VERIFYHOST to 1 (or true), set CURLOPT_SSL_VERIFYHOST to
 2, trigger a notice to inform the user that this value is no longer
 supported as of libcurl 7.28.1 but keep returning true.


Ok



 Also, as stated by Remy in bug #63795, when PHP is built with
 curl-wrappers, the context option curl_verify_ssl_host sets
 CURLOPT_SSL_VERIFYHOST to 1. I would like to modify this code to set
 CURLOPT_SSL_VERIFYHOST to 2. Since curl-wrappers is still marked as
 experimental I don't think this will cause a lot of troubles.

 If you have any comment, please do, otherwise, I'll commit those
 changes on Friday to all branches (including 5.3).



Julien.P


Re: [PHP-DEV] Changes in libcurl for CURLOPT_SSL_VERIFYHOST in 7.28.1

2012-12-20 Thread Pierrick Charron
Hi Julien,

I think we need to trigger a notice to prevent users to write code
that may not work in future version even if it doesn't depend on our
changes but on libraries changes.

Maybe we could be more explicit and tell the user that the 1 value
will not be available as of libcurl 7.28.1 (I just hope that people
will not be confused on what is libcurl and what's the version of it).

Pierrick


On 20 December 2012 08:59, jpauli jpa...@php.net wrote:
 On Wed, Dec 19, 2012 at 5:35 AM, Pierrick Charron pierr...@webstart.fr
 wrote:

 Hi all,

 About 2 month ago, we had a discussion on this list about the fact
 that CURLOPT_SSL_VERIFYHOST was most of the time used with a Boolean
 value (true) instead of int values (0,1 or 2). This bad usage was
 leading to some security issues. The result of this discussion was to
 trigger a notice if someone tried to set the CURLOPT_SSL_VERIFYHOST to
 true (boolean), and was committed to = 5.4

 On November 20th, Daniel (the author of libcurl) released cURL 7.28.1
 which no longer support the 1 value for CURLOPT_SSL_VERIFYHOST. This
 change introduced some bugs as #63795 (you'll find the cause of the
 bug in the comments).

 To fix this bug, and to minimize as much as possible the impact of
 this change, I'm proposing to do the following changes in the libcurl
 extension for future releases :

 When using libcurl  7.28.1, if someone try to set
 CURLOPT_SSL_VERIFYHOST to 1 (or true), set the value to 1, but trigger
 a notice to inform that this value is deprecated.


 I dont know if it is the good way to deal with that. Does the PHP user have
 to be aware that
 the underlying libcurl is gonna change ? The deprecated message may let
 him think that in the next *PHP* version, the value will have disapeared,
 but in fact,
 its in the next *libcurl* version, regardless PHP version.



 When using libcurl = 7.28.1 if someone try to set
 CURLOPT_SSL_VERIFYHOST to 1 (or true), set CURLOPT_SSL_VERIFYHOST to
 2, trigger a notice to inform the user that this value is no longer
 supported as of libcurl 7.28.1 but keep returning true.


 Ok



 Also, as stated by Remy in bug #63795, when PHP is built with
 curl-wrappers, the context option curl_verify_ssl_host sets
 CURLOPT_SSL_VERIFYHOST to 1. I would like to modify this code to set
 CURLOPT_SSL_VERIFYHOST to 2. Since curl-wrappers is still marked as
 experimental I don't think this will cause a lot of troubles.

 If you have any comment, please do, otherwise, I'll commit those
 changes on Friday to all branches (including 5.3).



 Julien.P

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] DateTime improvement

2012-12-20 Thread Larry Garfield
I've seen DateTimeValue used elsewhere for userspace immutable date time 
objects.  Whether that indicates we SHOULD or SHOULD NOT use that for an 
in-C version, I don't know.  (I'm inclined to say should-but-namespace, 
but I don't know if we're doing that yet.)


Of course, I have no idea if anyone in userspace is using 
DateTimeImmutable...


--Larry Garfield

On 12/17/12 2:52 PM, Lars Strojny wrote:

Hi Derick,

I would go with DateTimeValue or DateTimeImmutable as well.

Am 17.12.2012 um 19:42 schrieb Benjamin Eberlei kont...@beberlei.de:


On Mon, Dec 17, 2012 at 5:48 PM, Derick Rethans der...@php.net wrote:
I went for DateTimePoint. Point as in Point in time. I am not too
happy with the name, but I think it works better than DateTimeImmutable
as that just sounds quircky. I'm still fixing up a few things and adding
some test cases. I think I need to make it work with DatePeriod too -
but I haven't looked at that yet.

some suggestions:

DateTimeValue
DateTimeImmutable
DateImmutable
DateFixed
DateStatic
(and as a bonus: DateTime2)





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Larry Garfield

On 12/19/12 10:30 PM, Christopher Jones wrote:



On 12/19/2012 03:18 PM, Larry Garfield wrote:

You could likely simplify the code even further using an infinite
iterator:

http://us1.php.net/infiniteiterator

$result = preg_replace_callback(
 '/word/',
 function($matches) use ($replacements_iterator) {
 return $replacements-next();
 },
 'word word word word word'
);

--Larry Garfield



What am I missing that causes the first call to
$replacements_iterator-current() to return NULL
unless the iterator is rewound before use?


Eh, nothing.  You're right, next() doesn't return an element, it just 
advances, so you still need the current() call.  Which seems kinda silly 
to me, but whatev.


--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Changes in libcurl for CURLOPT_SSL_VERIFYHOST in 7.28.1

2012-12-20 Thread jpauli
On Thu, Dec 20, 2012 at 4:57 PM, Pierrick Charron pierr...@webstart.frwrote:

 Hi Julien,

 I think we need to trigger a notice to prevent users to write code
 that may not work in future version even if it doesn't depend on our
 changes but on libraries changes.

 Maybe we could be more explicit and tell the user that the 1 value
 will not be available as of libcurl 7.28.1 (I just hope that people
 will not be confused on what is libcurl and what's the version of it).


Well, I'd say what have we done before about that ?
We have already met lib API changes (libcurl, libxml, other usefull libs
exposed to the user), let's see what we did :-)

Julien.P


Re: [PHP-DEV] Changes in libcurl for CURLOPT_SSL_VERIFYHOST in 7.28.1

2012-12-20 Thread Pierrick Charron
I don't remember of any change in other binding (not saying there were
not any) which like this one were removing a feature without giving an
alternative to do the same thing. If someone can point me to one, I'll
be glad to look at how we managed this.

Pierrick

On 20 December 2012 11:57, jpauli jpa...@php.net wrote:


 On Thu, Dec 20, 2012 at 4:57 PM, Pierrick Charron pierr...@webstart.fr
 wrote:

 Hi Julien,

 I think we need to trigger a notice to prevent users to write code
 that may not work in future version even if it doesn't depend on our
 changes but on libraries changes.

 Maybe we could be more explicit and tell the user that the 1 value
 will not be available as of libcurl 7.28.1 (I just hope that people
 will not be confused on what is libcurl and what's the version of it).


 Well, I'd say what have we done before about that ?
 We have already met lib API changes (libcurl, libxml, other usefull libs
 exposed to the user), let's see what we did :-)

 Julien.P

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Complete traits redesign for 5.5

2012-12-20 Thread Rasmus Lerdorf
On 12/20/2012 06:36 AM, Dmitry Stogov wrote:
 Hi Pierre,
 
 The following test may crash on the second request with opcode cache.
 
 ?php
 
 trait THello {
 
   public function hello() { echo 'Hello'; }
 }
 
 class TraitsTest { use THello; }
 
 $test = new TraitsTest();
 $test-hello();
 
 ?
 
 Valgrind shows the problem even if PHP doesn't crash.

I'm not seeing anything from Valgrind's memcheck on this under php -S
with current PHP 5.4 and APC. Testing on 64-bit Linux.

-Rasmus


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] PHP5.5.0alpha2 release

2012-12-20 Thread jpauli
Hi Internals,

We just tagged PHP 5.5.0alpha2 today. This
release contains bug fixes against alpha1, as well as
new features.

The packages can be found at:

http://downloads.php.net/dsp

Please, note that the ext/mysql deprecation has been merged into
this release.
For other changes, as usual, you may consider reading the NEWS file.

Please test PHP5.5.0alpha2 carefully, and report any bugs in the bug
system. Alpha 3
will be tagged on January 5th.

Finaly, we'd like to thank every contributor who made this alpha2 possible.

Regards
  David and Julien


Re: [PHP-DEV] Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752

2012-12-20 Thread Stas Malyshev
Hi!

 ?php
 if ($argv[1]  0) {
while ($argv[1]--) file_put_contents('test.tpl', ?php 
 #.str_repeat('A', mt_rand(4000, 5000)). ?\n, LOCK_EX);
 } else {
$p2 = popen(sapi/cli/php -n test3.php 100, r);
while (1) include 'test.tpl';
 }
 ?

Yes, I can now reproduce this on my machine too. Not sure what I did
wrong last time, but now I get bus error. I suspect there's some race
condition between mmap and rewriting the file that creates the problem.
The error seems to happen at offset exactly 0x1000 from the start of the
map, which leads me to thinking that maybe the problem is that the page
needs to be loaded, but since the file is not there, being overwritten,
it can not be loaded anymore.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] DateTime improvement

2012-12-20 Thread Lazare Inepologlou
 Of course, I have no idea if anyone in userspace is using
DateTimeImmutable...

Well, it seems unlikely, unless he is Yoda or French.

I mean, in English, it is common to put the adjective in front of the noun,
isn't it?

Lazare INEPOLOGLOU
Ingénieur Logiciel


2012/12/20 Larry Garfield la...@garfieldtech.com

 I've seen DateTimeValue used elsewhere for userspace immutable date time
 objects.  Whether that indicates we SHOULD or SHOULD NOT use that for an
 in-C version, I don't know.  (I'm inclined to say should-but-namespace, but
 I don't know if we're doing that yet.)

 Of course, I have no idea if anyone in userspace is using
 DateTimeImmutable...

 --Larry Garfield

 On 12/17/12 2:52 PM, Lars Strojny wrote:

 Hi Derick,

 I would go with DateTimeValue or DateTimeImmutable as well.

 Am 17.12.2012 um 19:42 schrieb Benjamin Eberlei kont...@beberlei.de:

  On Mon, Dec 17, 2012 at 5:48 PM, Derick Rethans der...@php.net wrote:
 I went for DateTimePoint. Point as in Point in time. I am not too
 happy with the name, but I think it works better than DateTimeImmutable
 as that just sounds quircky. I'm still fixing up a few things and adding
 some test cases. I think I need to make it work with DatePeriod too -
 but I haven't looked at that yet.

 some suggestions:

 DateTimeValue
 DateTimeImmutable
 DateImmutable
 DateFixed
 DateStatic
 (and as a bonus: DateTime2)




 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




Fwd: [PHP-DEV] PHP5.5.0alpha2 release

2012-12-20 Thread Hannes Magnusson
From: jpauli jpa...@php.net
Date: Thu, Dec 20, 2012 at 9:26 AM
Subject: [PHP-DEV] PHP5.5.0alpha2 release
To: PHP Internals internals@lists.php.net



I would appreciate that you would use your full real name now that you
are representing the project as a release manager.

-Hannes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] How about implementing more data structures (ie Map, Set)

2012-12-20 Thread Levi Morrison
As mentioned earlier, I've been working on a
library(https://github.com/morrisonlevi/Ardent) with an honest effort
to make the data-structures usable in several different programming
styles.  I've tried several designs, but requiring something to
implement a `Comparable` interface turned out to not be a very good
way to do things, for several reasons I don't feel like going into at
the moment.

-

I hope you'll take a look at the current
Map(https://github.com/morrisonlevi/Ardent/blob/master/src/Ardent/Map.php)
and Set(https://github.com/morrisonlevi/Ardent/blob/master/src/Ardent/Set.php)
interfaces in my library and see if there is anything you are missing.
 I'd really love it if you cloned the repository and tried using it in
your project. I'm always looking for  feedback.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] PHP5.5.0alpha2 release

2012-12-20 Thread Julien Pauli
On Thu, Dec 20, 2012 at 9:30 PM, Hannes Magnusson 
hannes.magnus...@gmail.com wrote:

 From: jpauli jpa...@php.net
 Date: Thu, Dec 20, 2012 at 9:26 AM
 Subject: [PHP-DEV] PHP5.5.0alpha2 release
 To: PHP Internals internals@lists.php.net



 I would appreciate that you would use your full real name now that you
 are representing the project as a release manager




Ok I will.

Julien


Re: [PHP-DEV] Complete traits redesign for 5.5

2012-12-20 Thread Dmitry Stogov
hi Rasmus,

I don't know all the APC internals, but it seems it just doesn't free
memory carefully.
It sets zend_class_entry-refcount to something above 1000 and as result
all the nested structures are not freed as expected by destroy_zend_class().

I'm not sure which side effects this may have, but one of them is avoiding
of the trait related problem :)

Of course, It produces many memory leaks but most of them (probably all)
must be handled by zend_alloc

$ PHP_FCGI_MAX_REQUESTS=2 USE_ZEND_ALLOC=0 valgrind sapi/cgi/php-cgi -b
/tmp/fcgi-php5
...
==30930==definitely lost: 676 bytes in 10 blocks
==30930==indirectly lost: 1,213 bytes in 24 blocks
...

~2K memory leaks on 2 HTTP requests (the same trait.php test)

It also must change the destruction order of static members and methods
static variables, but I'm too lazy to prove it.

Anyway, the traits problem really exists and I almost found a solution for
5.4 without BC break.
I'll post a patch tomorrow or on next week.

Thanks. Dmitry.

On Thu, Dec 20, 2012 at 9:04 PM, Rasmus Lerdorf ras...@lerdorf.com wrote:

 On 12/20/2012 06:36 AM, Dmitry Stogov wrote:
  Hi Pierre,
 
  The following test may crash on the second request with opcode cache.
 
  ?php
 
  trait THello {
 
public function hello() { echo 'Hello'; }
  }
 
  class TraitsTest { use THello; }
 
  $test = new TraitsTest();
  $test-hello();
 
  ?
 
  Valgrind shows the problem even if PHP doesn't crash.

 I'm not seeing anything from Valgrind's memcheck on this under php -S
 with current PHP 5.4 and APC. Testing on 64-bit Linux.

 -Rasmus




Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Christopher Jones



On 12/20/2012 08:31 AM, Larry Garfield wrote:

On 12/19/12 10:30 PM, Christopher Jones wrote:



On 12/19/2012 03:18 PM, Larry Garfield wrote:

You could likely simplify the code even further using an infinite
iterator:

http://us1.php.net/infiniteiterator

$result = preg_replace_callback(
 '/word/',
 function($matches) use ($replacements_iterator) {
 return $replacements-next();
 },
 'word word word word word'
);

--Larry Garfield



What am I missing that causes the first call to
$replacements_iterator-current() to return NULL
unless the iterator is rewound before use?


Eh, nothing.  You're right, next() doesn't return an element, it just advances, 
so you still need the current() call.  Which seems kinda silly to me, but 
whatev.


That is documented, so it's OK.  The curiosity (bug?) is the need to call 
rewind():

$replacements_iterator = new InfiniteIterator(new ArrayIterator($replacements));
$replacements_iterator-rewind();  // why is the rewind needed?

$result = preg_replace_callback(
'/word/',
function($matches) use ($replacements_iterator) {
$r = $replacements_iterator-current();
$replacements_iterator-next();
return $r;
},
'word word word word word word word word'
);

In other (simple) scripts using InfiniteIterator the rewind wasn't needed.


--
christopher.jo...@oracle.com  http://twitter.com/ghrd

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread David Muir

On 21/12/12 10:34, Christopher Jones wrote:



On 12/20/2012 08:31 AM, Larry Garfield wrote:

On 12/19/12 10:30 PM, Christopher Jones wrote:



On 12/19/2012 03:18 PM, Larry Garfield wrote:

You could likely simplify the code even further using an infinite
iterator:

http://us1.php.net/infiniteiterator

$result = preg_replace_callback(
 '/word/',
 function($matches) use ($replacements_iterator) {
 return $replacements-next();
 },
 'word word word word word'
);

--Larry Garfield



What am I missing that causes the first call to
$replacements_iterator-current() to return NULL
unless the iterator is rewound before use?


Eh, nothing.  You're right, next() doesn't return an element, it just 
advances, so you still need the current() call.  Which seems kinda 
silly to me, but whatev.


That is documented, so it's OK.  The curiosity (bug?) is the need to 
call rewind():


$replacements_iterator = new InfiniteIterator(new 
ArrayIterator($replacements));

$replacements_iterator-rewind();  // why is the rewind needed?

$result = preg_replace_callback(
'/word/',
function($matches) use ($replacements_iterator) {
$r = $replacements_iterator-current();
$replacements_iterator-next();
return $r;
},
'word word word word word word word word'
);

In other (simple) scripts using InfiniteIterator the rewind wasn't 
needed.






What happens if you do:
$replacements_iterator = new InfiniteIterator(new 
ArrayIterator($replacements));

var_dump($replacements_iterator-current());

If I remember correctly, when you pass a traversable into foreach, under 
the hood, it basically calls:


$iterator-rewind();
while($iterator-valid()){
$value = $iterator-current();
(foreach block)
$iterator-next();
}

So that might explain why it works in (simple) scripts.

It does seem like a bug that the rewind is required though. A newly 
created iterator should already be in a rewound state so the call 
shouldn't be needed.


Cheers,
David

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] DateTime improvement

2012-12-20 Thread Peter Cowburn
On 20 December 2012 20:06, Lazare Inepologlou linep...@gmail.com wrote:
 Of course, I have no idea if anyone in userspace is using
 DateTimeImmutable...

 Well, it seems unlikely, unless he is Yoda or French.

 I mean, in English, it is common to put the adjective in front of the noun,
 isn't it?

Class names aren't particularly subject, too strictly, to English
grammar rules.  Besides, the coding standards [1] dictate the class
name should be prefixed with the 'parent set' (e.g. extension name),
which in this case is not Immutable.

[1] https://github.com/php/php-src/blob/master/CODING_STANDARDS#L152


 Lazare INEPOLOGLOU
 Ingénieur Logiciel



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] PHP5.5.0alpha2 release

2012-12-20 Thread Adam Harvey
On 21 December 2012 01:26, jpauli jpa...@php.net wrote:
 We just tagged PHP 5.5.0alpha2 today. This
 release contains bug fixes against alpha1, as well as
 new features.

Are we going to have a news post for this on the Web site?
(Alternative question: would you like me to write one?)

Adam

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752

2012-12-20 Thread Patrick Schaaf
On Thursday 20 December 2012 10:40:32 Stas Malyshev wrote:
 Hi!
 
  ?php
  if ($argv[1]  0) {
  
 while ($argv[1]--) file_put_contents('test.tpl', ?php
  
  #.str_repeat('A', mt_rand(4000, 5000)). ?\n, LOCK_EX);
  } else {
  
 $p2 = popen(sapi/cli/php -n test3.php 100, r);
 while (1) include 'test.tpl';
  
  }
  ?
 
 Yes, I can now reproduce this on my machine too. Not sure what I did
 wrong last time, but now I get bus error. I suspect there's some race
 condition between mmap and rewriting the file that creates the problem.
 The error seems to happen at offset exactly 0x1000 from the start of the
 map, which leads me to thinking that maybe the problem is that the page
 needs to be loaded, but since the file is not there, being overwritten,
 it can not be loaded anymore.

Is include supposed to take a LOCK_EX somehow? I can neither see that in php-
src (5.4.9) nor APC-trunk, doing a cursory grepping.

 APC takes a LOCK_EX in exactly one place, apc_bin_dumpfile(), which does not 
look to me like it's related to include. The usage there is fishy anyway, 
not exactly sure, but I think the open that happens before taking LOCK_EX, 
will have truncated the file already, leading to the same type of problem as 
discussed above wrt concurrent readers.

The only chance to get the above piece of code to work reliably in theory, 
would be for the include to take a LOCK_EX before looking at anything 
related to the file structure, including the stat call that determines how 
much to mmap.

The prudent approach, which should avoid the problem altogether and not need 
any LOCK_EX, dictates to ALWAYS write a temporary file (new inode), then 
rename it when the write completely succeeds. Otherwise any reader, like 
include, runs the chance of seeing a partially written file, and even 
without include using mmap internally, syntax errors would happen from time to 
time.

So, my conclusion would be that it is the code snippet above, and not any part 
of PHP or the kernel, that is at fault.

best regards
  Patrick

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Extension for str_replace / preg_replace with arrays

2012-12-20 Thread Christopher Jones



On 12/20/2012 04:05 PM, David Muir wrote:


The curiosity (bug?) is the need to call rewind():

$replacements_iterator = new InfiniteIterator(new ArrayIterator($replacements));
$replacements_iterator-rewind();  // why is the rewind needed?

$result = preg_replace_callback(
'/word/',
function($matches) use ($replacements_iterator) {
$r = $replacements_iterator-current();
$replacements_iterator-next();
return $r;
},
'word word word word word word word word'
);

In other (simple) scripts using InfiniteIterator the rewind wasn't needed.





What happens if you do:
$replacements_iterator = new InfiniteIterator(new ArrayIterator($replacements));
var_dump($replacements_iterator-current());

If I remember correctly, when you pass a traversable into foreach, under the 
hood, it basically calls:

$iterator-rewind();
while($iterator-valid()){
 $value = $iterator-current();
 (foreach block)
 $iterator-next();
}

So that might explain why it works in (simple) scripts.

It does seem like a bug that the rewind is required though. A newly created 
iterator should already be in a rewound state so the call shouldn't be needed.

Cheers,
David


I logged a bug so this can be tracked and re-discovered: 
https://bugs.php.net/bug.php?id=63823

Chris
--
christopher.jo...@oracle.com  http://twitter.com/ghrd
Newly updated, free PHP  Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Crashes in lex_scan at Zend/zend_language_scanner.c / BUG #52752

2012-12-20 Thread Stas Malyshev
Hi!

 Is include supposed to take a LOCK_EX somehow? I can neither see that in php-
 src (5.4.9) nor APC-trunk, doing a cursory grepping.

I'm not sure how any lock would help, since locks are optional, meaning
you still can do the same thing without the locks.

 The prudent approach, which should avoid the problem altogether and not need 
 any LOCK_EX, dictates to ALWAYS write a temporary file (new inode), then 
 rename it when the write completely succeeds. Otherwise any reader, like 
 include, runs the chance of seeing a partially written file, and even 
 without include using mmap internally, syntax errors would happen from time 
 to 
 time.

This looks like a very good advice, regardless of bus errors.

 So, my conclusion would be that it is the code snippet above, and not any 
 part 
 of PHP or the kernel, that is at fault.

We could probably add an option to skip mmaps, but since as you pointed
out that doesn't really fix the issue completely, better idea indeed is
to fix the code.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php