-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Minor refactorings to zend_exceptions() #16684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,7 +529,7 @@ static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */ | |
} | ||
/* }}} */ | ||
|
||
static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* {{{ */ | ||
static void _build_trace_string(smart_str *str, const HashTable *ht, uint32_t num) /* {{{ */ | ||
{ | ||
zval *file, *tmp; | ||
|
||
|
@@ -539,16 +539,18 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* | |
|
||
file = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_FILE)); | ||
if (file) { | ||
if (Z_TYPE_P(file) != IS_STRING) { | ||
if (UNEXPECTED(Z_TYPE_P(file) != IS_STRING)) { | ||
/* This is a typed property and can only happen if modified via ArrayObject */ | ||
zend_error(E_WARNING, "File name is not a string"); | ||
smart_str_appends(str, "[unknown file]: "); | ||
} else{ | ||
zend_long line = 0; | ||
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_LINE)); | ||
if (tmp) { | ||
if (Z_TYPE_P(tmp) == IS_LONG) { | ||
if (EXPECTED(Z_TYPE_P(tmp) == IS_LONG)) { | ||
line = Z_LVAL_P(tmp); | ||
} else { | ||
/* This is a typed property and can only happen if modified via ArrayObject */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likely not true as well due to similar reasons as bug63762.phpt in Zend |
||
zend_error(E_WARNING, "Line is not an int"); | ||
} | ||
} | ||
|
@@ -566,7 +568,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* | |
smart_str_appendc(str, '('); | ||
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS)); | ||
if (tmp) { | ||
if (Z_TYPE_P(tmp) == IS_ARRAY) { | ||
if (EXPECTED(Z_TYPE_P(tmp) == IS_ARRAY)) { | ||
size_t last_len = ZSTR_LEN(str->s); | ||
zend_string *name; | ||
zval *arg; | ||
|
@@ -583,21 +585,22 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* | |
ZSTR_LEN(str->s) -= 2; /* remove last ', ' */ | ||
} | ||
} else { | ||
/* The trace property is typed and private */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check with bug63762.phpt in Zend |
||
zend_error(E_WARNING, "args element is not an array"); | ||
} | ||
} | ||
smart_str_appends(str, ")\n"); | ||
} | ||
/* }}} */ | ||
|
||
ZEND_API zend_string *zend_trace_to_string(HashTable *trace, bool include_main) { | ||
ZEND_API zend_string *zend_trace_to_string(const HashTable *trace, bool include_main) { | ||
zend_ulong index; | ||
zval *frame; | ||
uint32_t num = 0; | ||
smart_str str = {0}; | ||
|
||
ZEND_HASH_FOREACH_NUM_KEY_VAL(trace, index, frame) { | ||
if (Z_TYPE_P(frame) != IS_ARRAY) { | ||
if (UNEXPECTED(Z_TYPE_P(frame) != IS_ARRAY)) { | ||
zend_error(E_WARNING, "Expected array for frame " ZEND_ULONG_FMT, index); | ||
continue; | ||
} | ||
|
@@ -624,7 +627,7 @@ ZEND_METHOD(Exception, getTraceAsString) | |
zval *object = ZEND_THIS; | ||
zend_class_entry *base_ce = i_get_exception_base(Z_OBJ_P(object)); | ||
zval rv; | ||
zval *trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv); | ||
const zval *trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv); | ||
if (EG(exception)) { | ||
RETURN_THROWS(); | ||
} | ||
|
@@ -859,14 +862,13 @@ ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception | |
ZEND_API ZEND_COLD zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format, ...) /* {{{ */ | ||
{ | ||
va_list arg; | ||
char *message; | ||
zend_object *obj; | ||
|
||
va_start(arg, format); | ||
zend_vspprintf(&message, 0, format, arg); | ||
zend_string *msg_str = zend_vstrpprintf(0, format, arg); | ||
va_end(arg); | ||
obj = zend_throw_exception(exception_ce, message, code); | ||
efree(message); | ||
obj = zend_throw_exception_zstr(exception_ce, msg_str, code); | ||
zend_string_release(msg_str); | ||
return obj; | ||
} | ||
/* }}} */ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true, see bug63762.phpt in Zend