Skip to content

Commit 245c840

Browse files
committed
phar: Reduce code duplication in destructor
We can make a variant of the macro to control the throwing behaviour.
1 parent 106079a commit 245c840

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
@@ -4518,28 +4518,27 @@ PHP_METHOD(PharFileInfo, __construct)
45184518
}
45194519
/* }}} */
45204520

4521-
#define PHAR_ENTRY_OBJECT() \
4521+
#define PHAR_ENTRY_OBJECT_EX(throw) \
45224522
zval *zobj = ZEND_THIS; \
45234523
phar_entry_object *entry_obj = (phar_entry_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset); \
45244524
if (!entry_obj->entry) { \
4525-
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
4526-
"Cannot call method on an uninitialized PharFileInfo object"); \
4527-
RETURN_THROWS(); \
4525+
if (throw) { \
4526+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \
4527+
"Cannot call method on an uninitialized PharFileInfo object"); \
4528+
} \
4529+
return; \
45284530
}
45294531

4532+
#define PHAR_ENTRY_OBJECT() PHAR_ENTRY_OBJECT_EX(true)
4533+
45304534
/* {{{ clean up directory-based entry objects */
45314535
PHP_METHOD(PharFileInfo, __destruct)
45324536
{
4533-
zval *zobj = ZEND_THIS;
4534-
phar_entry_object *entry_obj = (phar_entry_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset);
4535-
45364537
if (zend_parse_parameters_none() == FAILURE) {
45374538
RETURN_THROWS();
45384539
}
45394540

4540-
if (!entry_obj->entry) {
4541-
return;
4542-
}
4541+
PHAR_ENTRY_OBJECT_EX(false);
45434542

45444543
if (entry_obj->entry->is_temp_dir) {
45454544
if (entry_obj->entry->filename) {

0 commit comments

Comments
 (0)