% swig -php5 -make -withc "example.c" example.i
Edit makefile to:
* Change `php -r '{....}'` to $(shell php -r '....}')
* Change $(PROG) to $(MODULE)
* Add -DZTS, -pthread, etc.
(See the other php bug)
Copy example.so to the PHP5 module directory.
$ php -r 'dl("example.so"); echo gcd(27, 9) . "\n";'
9
/phpdev/php-5.2.0/Zend/zend_hash.c(679) : ht=0x88163e0 is already destroyed
Logged In: YES
user_id=14972
Originator: NO
Just a note that I'm unable to reproduce this with the Ubuntu edgy PHP5 package (PHP 5.1.6) which has ZTS disabled. So I guess this issue is related to ZTS in some way. Or perhaps it's specific to PHP5.2.
Logged In: YES
user_id=14972
Originator: NO
Teruhiko: Are you still able to reproduce this? In order to make any progress, we're going to need to know more about your system...
Logged In: YES
user_id=399386
Originator: YES
I tried this with swig-1.3.33 and php-5.2.5 on Linux, and I still see the error message.
The php manual reads that dl() is deprecated in SAPI except in CLI:
http://devzone.zend.com/manual/function.dl.html
Although I used this via CLI, dl() sounds like not well supported. As an experiment, I added:
extension=example.so
in php.ini and run the sample without the dl() function, i.e.:
php -r 'echo gcd(27,9) . "\n";'
Then the error message disappeared. So I think it is not a swig issue but a php issue, and I'm closing this bug.
Patch to SWIG SVN HEAD
Logged In: YES
user_id=14972
Originator: NO
Actually, I think I have an inkling what might be going on here. I have a suspicion this problem is caused by a fix for problems running under a ZTS build on Windows. It seems there's a new way to handle globals in PHP >= 5.1, so I've implemented that and attached a patch against SWIG HEAD, which will probably apply to SWIG 1.3.33 cleanly.
Can you try that and see if it fixes this for you?
If so, I'll get the person who had the problem on Windows to try it to check that it doesn't cause their problem to reappear.
If not, I'm happy to reclose this bug. As you say, dl() isn't generally recommended these days.
File Added: swig-php-globals.patch
I've just been talking to one of the PHP devs at the GSoC mentor meeting, and the cause of this is an inherent lack of thread safety in the deprecated (and now removed) PHP dl() function. So I'm going to reclose this bug. The workaround is not to use dl() (and I'll update the SWIG/PHP docs to advise against using dl() too).