-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix usage of resumable function with ArrayAccess methods (#1198)
- Loading branch information
1 parent
23ce77b
commit 95a09ea
Showing
4 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@ok | ||
<?php | ||
require_once 'kphp_tester_include.php'; | ||
|
||
function like_rpc_write() { | ||
echo "log\n"; | ||
sched_yield(); // resumable | ||
} | ||
|
||
class A implements \ArrayAccess { | ||
public function offsetSet($offset, $value) {} | ||
/** @return bool */ | ||
public function offsetExists($offset) {return true;} | ||
public function offsetUnset($offset) {} | ||
/** @return mixed */ | ||
public function offsetGet($offset) { | ||
return null; | ||
} | ||
|
||
public function to_be_forked() { | ||
echo "in to_be_forked\n"; | ||
like_rpc_write(); | ||
return null; | ||
} | ||
} | ||
|
||
function test() { | ||
$x = new A(); | ||
|
||
$fut = fork($x->to_be_forked()); | ||
wait($fut); | ||
} | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@kphp_should_fail | ||
/Function \[ArrayAccess::offsetGet\] is a method of ArrayAccess, it cannot call (resumable|interruptible) functions/ | ||
/Function transitively calls the (resumable|interruptible) function along the following chain:/ | ||
/ArrayAccess::offsetGet -> A::offsetGet -> like_rpc_write -> sched_yield/ | ||
|
||
<?php | ||
|
||
function like_rpc_write() { | ||
printf("log\n"); | ||
sched_yield(); // resumable | ||
} | ||
|
||
class A implements \ArrayAccess { | ||
public function offsetSet($offset, $value) {} | ||
/** @return bool */ | ||
public function offsetExists($offset) {return true;} | ||
public function offsetUnset($offset) {} | ||
/** @return mixed */ | ||
public function offsetGet($offset) { | ||
like_rpc_write(); | ||
return null; | ||
} | ||
} | ||
|
||
function test() { | ||
$x = new A(); | ||
} | ||
|
||
test(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@kphp_should_fail | ||
/Function \[ArrayAccess::offsetGet\] is a method of ArrayAccess, it cannot call (resumable|interruptible) functions/ | ||
/Function transitively calls the (resumable|interruptible) function along the following chain:/ | ||
/ArrayAccess::offsetGet -> A::offsetGet/ | ||
|
||
<?php | ||
|
||
class A implements \ArrayAccess { | ||
public function offsetSet($offset, $value) {} | ||
/** @return bool */ | ||
public function offsetExists($offset) {return true;} | ||
public function offsetUnset($offset) {} | ||
/** @return mixed */ | ||
public function offsetGet($offset) {return null;} | ||
} | ||
|
||
function test() { | ||
$x = new A(); | ||
$y = fork($x->offsetGet(42)); | ||
|
||
wait($y); | ||
} | ||
|
||
test(); |