pmmp / ext-pmmpthread

Fork of https://github.com/krakjoe/pthreads with a revamped API and PHP 8.1+ support
Other
81 stars 17 forks source link

Int backed enum - segfault #128

Closed JaxkDev closed 1 year ago

JaxkDev commented 1 year ago

Environment

Summary

As discussed in discord, having default property $test set to STARTING causes a segfault, with no default it works.

Reproducing Code

<?php

enum ThreadStatus: int{
    case STARTING = 0;
}

class thread extends \pmmp\thread\Thread{

    private ThreadStatus $test = ThreadStatus::STARTING;

    public function run(): void{}
}

(new thread())->start(\pmmp\thread\Thread::INHERIT_NONE);

Expected Output

N/A

Actual Output

Assertion failed: (prepared->backed_enum_table), function prepare_class_constants, file prepare.c, line 74.
Process 2432 stopped
* thread #6, stop reason = hit program assert
    frame #4: 0x00000001004609d0 php`prepare_class_constants(source=0x0000600003d08760, candidate=0x0000000107565370, prepared=0x0000000107603018) at prepare.c:74:5
   71                                                   zend_zval_type_name(enum_value)
   72                                           );
   73                                   }
-> 74                                   ZEND_ASSERT(prepared->backed_enum_table);
   75                                   //zend_enum_add_case() won't expect this to be populated, so we have to remove it (we populated it in prepare_backed_enum_table())
   76                                   if (Z_TYPE(copied_enum_value) == IS_STRING) {
   77                                           zend_hash_del(prepared->backed_enum_table, Z_STR(copied_enum_value));
Target 0: (php) stopped.
dktapps commented 1 year ago

Appears this is directly related to #100

dktapps commented 1 year ago

Fixed by 3b3beca146a9135d4524b074e340c264752b6828 and following commits