Skip to content

Internal class clean #1205

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 14 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -4128,15 +4128,6 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
}
/* }}} */

ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */
{
if (EX(return_value)) {
Z_OBJ_P(EX(return_value)) = NULL;
ZVAL_NULL(EX(return_value));
}
}
/* }}} */

ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */
{
if(ce->ce_flags & ZEND_ACC_TRAIT) {
Expand Down
6 changes: 0 additions & 6 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,6 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i
ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name);
ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f);

ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);

ZEND_API const char *zend_get_object_type(const zend_class_entry *ce);

#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
Expand Down Expand Up @@ -651,10 +649,6 @@ END_EXTERN_C()
} \
} while (0)

/* May be used in internal constructors to make them return NULL */
#define ZEND_CTOR_MAKE_NULL() \
zend_ctor_make_null(execute_data)

#define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; }

#define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))
Expand Down
7 changes: 0 additions & 7 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2950,10 +2950,6 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMPVAR|UNUSE
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (OP2_TYPE == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -4704,9 +4700,6 @@ ZEND_VM_HANDLER(68, ZEND_NEW, CONST|VAR, ANY)

if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
Expand Down
38 changes: 0 additions & 38 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -3100,9 +3100,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_CONST_HANDLER(ZEND_OP

if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
Expand Down Expand Up @@ -5082,10 +5079,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -6984,10 +6977,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -8466,10 +8455,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -10015,10 +10000,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -13795,9 +13776,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_VAR_HANDLER(ZEND_OPCO

if (EXPECTED(RETURN_VALUE_USED(opline))) {
ZVAL_COPY(EX_VAR(opline->result.var), &object_zval);
EX(call)->return_value = EX_VAR(opline->result.var);
} else {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
Expand Down Expand Up @@ -15880,10 +15858,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_CONST == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -17455,10 +17429,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_UNUSED == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -19072,10 +19042,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if (IS_CV == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down Expand Up @@ -20631,10 +20597,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V
EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION,
fbc, opline->extended_value, ce, object, EX(call));

if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) {
EX(call)->return_value = NULL;
}

CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
Expand Down
2 changes: 0 additions & 2 deletions ext/com_dotnet/com_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ PHP_FUNCTION(com_create_instance)
&typelib_name, &typelib_name_len)) {

php_com_throw_exception(E_INVALIDARG, "Could not create COM object - invalid arguments!");
ZEND_CTOR_MAKE_NULL();
return;
}

Expand Down Expand Up @@ -230,7 +229,6 @@ PHP_FUNCTION(com_create_instance)

php_com_throw_exception(res, msg);
efree(msg);
ZEND_CTOR_MAKE_NULL();
return;
}

Expand Down
3 changes: 0 additions & 3 deletions ext/com_dotnet/com_dotnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
if (err)
LocalFree(err);
php_com_throw_exception(hr, buf);
ZEND_CTOR_MAKE_NULL();
return;
}
stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
Expand Down Expand Up @@ -248,7 +247,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
&datatype_name, &datatype_name_len,
&obj->code_page)) {
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!");
ZEND_CTOR_MAKE_NULL();
return;
}

Expand Down Expand Up @@ -314,7 +312,6 @@ PHP_FUNCTION(com_dotnet_create_instance)
LocalFree(err);
}
php_com_throw_exception(hr, buf);
ZEND_CTOR_MAKE_NULL();
return;
}
}
Expand Down
10 changes: 2 additions & 8 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -2670,9 +2670,7 @@ PHP_METHOD(DateTime, __construct)

zend_replace_error_handling(EH_THROW, NULL, &error_handling);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
if (!php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1)) {
ZEND_CTOR_MAKE_NULL();
}
php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1);
}
zend_restore_error_handling(&error_handling);
}
Expand Down Expand Up @@ -3679,9 +3677,7 @@ PHP_METHOD(DateTimeZone, __construct)
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) {
tzobj = Z_PHPTIMEZONE_P(getThis());
if (FAILURE == timezone_initialize(tzobj, tz)) {
ZEND_CTOR_MAKE_NULL();
}
timezone_initialize(tzobj, tz);
}
zend_restore_error_handling(&error_handling);
}
Expand Down Expand Up @@ -4113,8 +4109,6 @@ PHP_METHOD(DateInterval, __construct)
diobj = Z_PHPINTERVAL_P(getThis());
diobj->diff = reltime;
diobj->initialized = 1;
} else {
ZEND_CTOR_MAKE_NULL();
}
}
zend_restore_error_handling(&error_handling);
Expand Down
49 changes: 35 additions & 14 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,6 @@ PHP_MINFO_FUNCTION(fileinfo)
}
/* }}} */

#define FILEINFO_DESTROY_OBJECT(object) \
do { \
if (object) { \
zend_object_store_ctor_failed(Z_OBJ_P(object)); \
Z_OBJ_P(object) = NULL; \
ZEND_CTOR_MAKE_NULL(); \
} \
} while (0)

/* {{{ proto resource finfo_open([int options [, string arg]])
Create a new fileinfo resource. */
PHP_FUNCTION(finfo_open)
Expand All @@ -301,9 +292,18 @@ PHP_FUNCTION(finfo_open)
php_fileinfo *finfo;
FILEINFO_DECLARE_INIT_OBJECT(object)
char resolved_path[MAXPATHLEN];
zend_error_handling zeh;

if (object) {
zend_replace_error_handling(EH_THROW, NULL, &zeh);
}
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}

Expand All @@ -322,11 +322,21 @@ PHP_FUNCTION(finfo_open)
} else if (file && *file) { /* user specified file, perform open_basedir checks */

if (php_check_open_basedir(file)) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) {
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}
file = resolved_path;
Expand All @@ -340,19 +350,30 @@ PHP_FUNCTION(finfo_open)
if (finfo->magic == NULL) {
efree(finfo);
php_error_docref(NULL, E_WARNING, "Invalid mode '%pd'.", options);
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}

if (magic_load(finfo->magic, file) == -1) {
php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
magic_close(finfo->magic);
efree(finfo);
FILEINFO_DESTROY_OBJECT(object);
if (object) {
zend_restore_error_handling(&zeh);
if (!EG(exception)) {
zend_throw_exception(NULL, "Constructor failed", 0);
}
}
RETURN_FALSE;
}

if (object) {
zend_restore_error_handling(&zeh);
FILEINFO_REGISTER_OBJECT(object, finfo);
} else {
RETURN_RES(zend_register_resource(finfo, le_fileinfo));
Expand Down
7 changes: 5 additions & 2 deletions ext/fileinfo/tests/bug61173.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ if (!class_exists('finfo'))
$finfo = new finfo(1, '', false);
var_dump($finfo);
--EXPECTF--
Warning: finfo::finfo() expects at most 2 parameters, 3 given in %s on line %d
NULL
Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects at most 2 parameters, 3 given' in %sbug61173.php:3
Stack trace:
#0 %sbug61173.php(3): finfo->finfo(1, '', false)
#1 {main}
thrown in %sbug61173.php on line 3
8 changes: 5 additions & 3 deletions ext/fileinfo/tests/finfo_open_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ resource(6) of type (file_info)
Warning: finfo_open() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 16
bool(false)

Warning: finfo::finfo() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 18
NULL
===DONE===
Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects parameter 1 to be integer, string given' in %sfinfo_open_error.php:18
Stack trace:
#0 %sfinfo_open_error.php(18): finfo->finfo('foobar')
#1 {main}
thrown in %sfinfo_open_error.php on line 18
11 changes: 7 additions & 4 deletions ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {
}

#include "../intl_convertcpp.h"
#include "../intl_common.h"

static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) {
return (RuleBasedBreakIterator*)bio->biter;
Expand Down Expand Up @@ -97,15 +98,17 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS)

U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct)
{
zval orig_this = *getThis();
zend_error_handling error_handling;

zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling);
return_value = getThis();
_php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU);

if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) {
zend_object_store_ctor_failed(Z_OBJ(orig_this));
ZEND_CTOR_MAKE_NULL();
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
}
}
zend_restore_error_handling(&error_handling);
}

U_CFUNC PHP_FUNCTION(rbbi_get_rules)
Expand Down
Loading