Re: [PHP-DEV] PHP 7 : Cannot use stream wrappers during MINIT

2015-11-20 Thread François Laupretre



Le 09/11/2015 16:41, Dan Ackroyd a écrit :

On 6 November 2015 at 00:08, François Laupretre  wrote:

Hi,

An uninitialized HashTable generally is
filled with 0s. Today, using an uninitialized HashTable goes undetected,
even in debug mode (because HT_OK == 0), and is very hard to track.

Uninitialized variables should be pretty easy to check by setting
`export USE_ZEND_ALLOC=0` to make allocs go straight through to malloc
and then running the program through valgrind. That should report all
uninitialized data. Additionally using the --malloc-fill=255 (or
appropriate value) should make the code blow up pretty quickly.

I'd be interested to know if that's doesn't report the issues for you
- as that's the backup to check that I haven't forgotten to initialize
anything, and if that's not reliableI might need to check some
stuff.

cheers
Dan


Your method works for dynamically allocated data but, in my case, the 
uninitialized HashTable is EG(regular_list), which is not dynamically 
allocated in non-ZTS mode. For data coming from the data or bss sections 
of the executable, I think that valgrind cannot detect anything (not 
sure for bss, not tested).


The problem with uninitialized hash struct is that, for various reasons, 
the issue may remain unnoticed during a long time before the final crash 
and, because of this delay, it is quite hard to go back to the primary 
cause. That's why I propose to add an assert. This is not perfect but, 
in many cases, this will avoid the program to return happily from a 
failed operation on an uninitialized hash.


Regards

François

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



Re: [PHP-DEV] PHP 7 : Cannot use stream wrappers during MINIT

2015-11-09 Thread Dan Ackroyd
On 6 November 2015 at 00:08, François Laupretre  wrote:
> Hi,
>
> An uninitialized HashTable generally is
> filled with 0s. Today, using an uninitialized HashTable goes undetected,
> even in debug mode (because HT_OK == 0), and is very hard to track.

Uninitialized variables should be pretty easy to check by setting
`export USE_ZEND_ALLOC=0` to make allocs go straight through to malloc
and then running the program through valgrind. That should report all
uninitialized data. Additionally using the --malloc-fill=255 (or
appropriate value) should make the code blow up pretty quickly.

I'd be interested to know if that's doesn't report the issues for you
- as that's the backup to check that I haven't forgotten to initialize
anything, and if that's not reliableI might need to check some
stuff.

cheers
Dan

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



[PHP-DEV] PHP 7 : Cannot use stream wrappers during MINIT

2015-11-05 Thread François Laupretre

Hi,

First, I don't know if this must be considered as a bug, because a lot 
of features are not available during MINIT but it seems quite 
inconsistent. I precise I'm using the 7.x master branch (I don't know if 
it works on 5.x or not).


I am writing an extension where I need to read a file tree during the 
MINIT phase. So, I am using php_stream_scandir() to read some 
directories. At this time, php_init_stream_wrappers() has run, so I 
consider stream wrappers are available.


Unfortunately, this is not true because stream wrappers register 
resources in EG(regular_list), which is not initialized before 
init_compiler() has run. If I call zend_hash_init(&(EG(regular_list))) 
before calling php_stream_scandir(), it seems to works. But it is not 
the solution because the hashtable is never destroyed and there are 
probably other side effects. The same potentially applies to 
EG(persistent_list).


So, does it mean that stream wrappers cannot be used during MINIT, or do 
you know a workaround ? I can revert to the C stdio library but, for 
portability reasons, I'd prefer using the plain wrapper. Every 
suggestion is welcome.


Another suggestion to help detecting such issues : can we consider, in 
_zend_is_inconsistent(), that a HashTable whose nTableSize is null is 
inconsistent and raises an alert. An uninitialized HashTable generally 
is filled with 0s. Today, using an uninitialized HashTable goes 
undetected, even in debug mode (because HT_OK == 0), and is very hard to 
track.


Regards

François

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