Skip to content

Commit 9d8a462

Browse files
committed
this commit introduces support for explicitly cast array members
1 parent 8e8c3d7 commit 9d8a462

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

examples/ClosureFuture.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private function __construct(Closure $closure, array $args = []) {
1818
public function run() {
1919
$this->synchronized(function() {
2020
$this->result =
21-
($this->closure)(...$this->args);
21+
(array) ($this->closure)(...$this->args);
2222
$this->notify();
2323
});
2424
}

src/store.c

+24-8
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,31 @@ int pthreads_store_write(zval *object, zval *key, zval *write) {
278278
zval vol, member;
279279
pthreads_object_t *threaded = PTHREADS_FETCH_FROM(Z_OBJ_P(object));
280280
zend_bool coerced = pthreads_store_coerce(key, &member);
281-
281+
282282
if (Z_TYPE_P(write) == IS_ARRAY) {
283-
/* coerce arrays into volatile objects */
284-
object_init_ex(
285-
&vol, pthreads_volatile_entry);
286-
pthreads_store_merge(&vol, write, 1);
287-
/* this will be addref'd when caching the object */
288-
Z_SET_REFCOUNT(vol, 0);
289-
write = &vol;
283+
#define CED (EG(current_execute_data))
284+
#define CEF (CED)->func
285+
#define CEO (CED)->opline
286+
#define LEO ((CEO)-1)
287+
#define CEC (CEF)->op_array.opcodes
288+
#define CEE ((LEO)->opcode == ZEND_CAST && (LEO)->extended_value == IS_ARRAY)
289+
if (!(CED && CEF->type == ZEND_USER_FUNCTION && CEO) ||
290+
!(CEO > CEC) ||
291+
!(CEE)) {
292+
/* coerce arrays into volatile objects unless explicitly cast as array */
293+
object_init_ex(
294+
&vol, pthreads_volatile_entry);
295+
pthreads_store_merge(&vol, write, 1);
296+
/* this will be addref'd when caching the object */
297+
Z_SET_REFCOUNT(vol, 0);
298+
write = &vol;
299+
}
300+
#undef CED
301+
#undef CEF
302+
#undef CEO
303+
#undef LEO
304+
#undef CEC
305+
#undef CEE
290306
}
291307

292308
if (Z_TYPE_P(write) == IS_OBJECT) {

0 commit comments

Comments
 (0)