Skip to content

Commit

Permalink
attempt to fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
steverhoades committed Sep 5, 2014
1 parent 8e847ea commit a990f13
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ matrix:
allow_failures:
- php: hhvm

before_script:
- sudo apt-get install gdb

install: ./travis-init.sh

script:
- phpunit --coverage-text
- phpunit --coverage-text
- cat script.gdb | sudo gdb --args /home/travis/.phpenv/versions/5.6.0RC4/bin/php /home/travis/.phpenv/versions/5.6.0RC4/bin/phpunit
3 changes: 3 additions & 0 deletions script.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set env MALLOC_CHECK_=3
run
backtrace full
29 changes: 25 additions & 4 deletions src/ExtEvLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ExtEvLoop implements LoopInterface
private $timers;
private $readEvents = array();
private $writeEvents = array();

private $running = false;

public function __construct()
Expand Down Expand Up @@ -58,7 +59,7 @@ public function removeReadStream($stream)
{
$key = (int) $stream;
if(isset($this->readEvents[$key])) {
$this->readEvents[$key]->stop();
$this->readEvents[$key]->stop();
unset($this->readEvents[$key]);
}
}
Expand All @@ -72,8 +73,8 @@ public function removeWriteStream($stream)
{
$key = (int) $stream;
if(isset($this->writeEvents[$key])) {
$this->writeEvents[(int)$stream]->stop();
unset($this->writeEvents[(int)$stream]);
$this->writeEvents[$key]->stop();
unset($this->writeEvents[$key]);
}
}

Expand Down Expand Up @@ -147,7 +148,11 @@ public function cancelTimer(TimerInterface $timer)
if (isset($this->timers[$timer])) {
/* stop EvTimer */
$this->timers[$timer]->stop();
$this->timers->detach($timer);

/* defer timer */
$this->nextTick(function() use ($timer) {
$this->timers->detach($timer);
});
}
}

Expand Down Expand Up @@ -225,4 +230,20 @@ public function stop()
{
$this->running = false;
}

public function __destruct()
{
// mannually stop all watchers
foreach($this->timers as $timer) {
$this->timers[$timer]->stop();
}

foreach($this->readEvents as $event) {
$event->stop();
}

foreach($this->writeEvents as $event) {
$event->stop();
}
}
}
19 changes: 0 additions & 19 deletions tests/AbstractLoopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,6 @@ function () {
$this->loop->run();
}

public function testPeriodTimerExecutes()
{
$count = 0;
$this->loop->addPeriodicTimer(
0.001,
function ($timer) use (&$count) {
echo 'tick';
$count++;
if($count === 3) {
$timer->cancel();
}
}
);

$this->expectOutputString('tickticktick');

$this->loop->run();
}

public function testFutureTick()
{
$called = false;
Expand Down
1 change: 1 addition & 0 deletions travis-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then
phpize
./configure
make
make test
make install
popd
echo "extension=ev.so" >> "$(php -r 'echo php_ini_loaded_file();')"
Expand Down

0 comments on commit a990f13

Please sign in to comment.