Skip to content

Commit f97ee5c

Browse files
authored
phar: Reduce code duplication in destructor (#20140)
We can make a variant of the macro to control the throwing behaviour.
1 parent da906ee commit f97ee5c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

ext/phar/phar_object.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,28 +4513,27 @@ PHP_METHOD(PharFileInfo, __construct)
45134513
}
45144514
/* }}} */
45154515

4516-
#define PHAR_ENTRY_OBJECT() \
4516+
#define PHAR_ENTRY_OBJECT_EX(throw) \
45174517
zval *zobj = ZEND_THIS; \
45184518
phar_entry_object *entry_obj = (phar_entry_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset); \
45194519
if (!entry_obj->entry) { \
4520-
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
4521-
"Cannot call method on an uninitialized PharFileInfo object"); \
4522-
RETURN_THROWS(); \
4520+
if (throw) { \
4521+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
4522+
"Cannot call method on an uninitialized PharFileInfo object"); \
4523+
} \
4524+
return; \
45234525
}
45244526

4527+
#define PHAR_ENTRY_OBJECT() PHAR_ENTRY_OBJECT_EX(true)
4528+
45254529
/* {{{ clean up directory-based entry objects */
45264530
PHP_METHOD(PharFileInfo, __destruct)
45274531
{
4528-
zval *zobj = ZEND_THIS;
4529-
phar_entry_object *entry_obj = (phar_entry_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset);
4530-
45314532
if (zend_parse_parameters_none() == FAILURE) {
45324533
RETURN_THROWS();
45334534
}
45344535

4535-
if (!entry_obj->entry) {
4536-
return;
4537-
}
4536+
PHAR_ENTRY_OBJECT_EX(false);
45384537

45394538
if (entry_obj->entry->is_temp_dir) {
45404539
if (entry_obj->entry->filename) {

0 commit comments

Comments
 (0)