Repository navigation
Conversation
5df1993 to
c5a38d1
Compare
| zval_ptr_dtor(&errors_array); | ||
|
|
||
| zend_throw_exception_object(&ex); | ||
| zend_throw_exception_internal(ex); |
There was a problem hiding this comment.
Seeing this change, I wonder if the instanceof check should become an assertion in zend_throw_exception_internal.
There was a problem hiding this comment.
I'm guessing you mean in zend_throw_exception_object()? And it cannot as it is used by the ZEND_THROW opcode.
There was a problem hiding this comment.
No. I meant zend_throw_exception_internal(). Given that more users switched to zend_throw_exception_internal() directly, the instanceof check here in zend_throw_exception_object() could also become an assertion in zend_throw_exception_internal(), since the type system can only guarantee it's an object, but not that it's a throwable.
| zval_ptr_dtor(arg); | ||
| ZVAL_UNDEF(arg); | ||
| return FAILURE; | ||
| zend_object_store_ctor_failed(obj); |
There was a problem hiding this comment.
Is this change fixing a pre-existing bug?
There was a problem hiding this comment.
I don't think it does, as that branch is tested via the ext/zend_test/tests/zend_object_init_with_constructor.phpt and the destructor doesn't seem to be called already. So I'm slightly confused. But this whole logic will go away when I get back round to remove the annoying get_constructor object handler.
There was a problem hiding this comment.
I agree this looks like a sus behaviour change
There was a problem hiding this comment.
This should be testable with a non-final class that throws with a destructor. I don't think we have a class already that can show this difference
There was a problem hiding this comment.
Isn't that case already covered by the ThrowingUser class in ext/zend_test/tests/zend_object_init_with_constructor.phpt?
There was a problem hiding this comment.
No, you're looking for a class that throws in get_constructor without implicitly already calling zend_object_store_ctor_failed, and then subclass that with a destructor
c5a38d1 to
ada1544
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Didn't check all extensions, I trust you with those. Some additional smaller nits, overall LGTM.
ada1544 to
425e7ae
Compare
In preparation for a new object initializer API
By using the new zend_object_init_with_constructor() API.
Did not migrate object_init_ex() usage in create_driver_specific_pdo_object() as this needs some larger refactoring
425e7ae to
203213a
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Still couldn't be bothered to check all extensions. Changes LGTM now. Further comments are optional, either way no further review round necessary for them.
| #endif /* HAVE_DTRACE */ | ||
|
|
||
| if (exception != NULL) { | ||
| #ifdef ZEND_DEBUG |
There was a problem hiding this comment.
Explicit ZEND_DEBUG check should not be necessary for ZEND_ASSERT() to be elided including its calls (but perhaps check the assembly to verify).
There was a problem hiding this comment.
That's false. That requires the compiler to know the function is pure, which it doesn't at this point. The same ifdef pattern is used in the VM for a similar check.
There was a problem hiding this comment.
This should also be #if, not #ifdef, because the macro is always defined: it's just either 0 or 1
|
|
||
| /* Extract the $message property. */ | ||
| z = zend_read_property_ex(zend_ce_nodiscard, Z_OBJ_P(&obj), ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); | ||
| zval *z = zend_read_property_ex(zend_ce_nodiscard, obj, ZSTR_KNOWN(ZEND_STR_MESSAGE), false, NULL); |
There was a problem hiding this comment.
Could also declare that separately for consistency with Deprecated.
| add_property_resource(&object, "context", context->res); | ||
| zval tmp; | ||
| ZVAL_RES(&tmp, context->res); | ||
| zend_update_property(ce, object, ZEND_STRL("context"), &tmp); |
There was a problem hiding this comment.
This causes a refcount leak because add_property_resource dtors the input, so you need to remove the GC_ADDREF on line 262
There was a problem hiding this comment.
Also this new code has a behaviour change: it will behave differently wrt private/protected properties due to the fake scope.
| zval_ptr_dtor(arg); | ||
| ZVAL_UNDEF(arg); | ||
| return FAILURE; | ||
| zend_object_store_ctor_failed(obj); |
There was a problem hiding this comment.
I agree this looks like a sus behaviour change
| zval_ptr_dtor(arg); | ||
| ZVAL_UNDEF(arg); | ||
| return FAILURE; | ||
| zend_object_store_ctor_failed(obj); |
There was a problem hiding this comment.
This should be testable with a non-final class that throws with a destructor. I don't think we have a class already that can show this difference
| ftp->use_ssl = false; | ||
| #endif | ||
|
|
||
| object_init_ex(return_value, php_ftp_ce); |
There was a problem hiding this comment.
I disagree that the new code is better, the old code was more compact and return_value is open-coded plenty of times in the code base.
| object_init_ex(&zv, old_obj->ce); | ||
| GC_ADD_FLAGS(Z_OBJ(zv), IS_OBJ_DESTRUCTOR_CALLED); | ||
| return Z_OBJ(zv); | ||
| zend_object *obj = zend_object_init(old_obj->ce); |
There was a problem hiding this comment.
This on the other hand is a code change where the new coed looks better, same with the code above
Commits should be reviewed individually.
The motivation is that creating an object shouldn't require providing a zval backing storage, as often one only cares about the
zend_object*. The common case where we do have a backing storage is within userland functions wherereturn_valueis passed, this is IMHO suboptimal as it leaks an implementation detail that is usually hidden by the use of the RETURN/RETVAL macros, moreover it can make determining what the return value of userland function is confusing ifreturn_valueis initialized and a plainreturnstatement is used to return early.The commits follow the rough idea:
Obviously not all cases have been migrated, sometimes it makes more sense to use the existing
object_init_exAPI, or moving to the new API is desirable but various other refactorings need to be made at an extension level for it to make sense.Some future refactoring I am thinking of doing with the new APIs are: