diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 34ab803321aae..0c477a8d5a625 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2145,122 +2145,6 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) / } /* }}} */ -ZEND_API void add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long n) /* {{{ */ -{ - zval tmp; - - ZVAL_LONG(&tmp, n); - add_property_zval_ex(arg, key, key_len, &tmp); -} -/* }}} */ - -ZEND_API void add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b) /* {{{ */ -{ - zval tmp; - - ZVAL_BOOL(&tmp, b); - add_property_zval_ex(arg, key, key_len, &tmp); -} -/* }}} */ - -ZEND_API void add_property_null_ex(zval *arg, const char *key, size_t key_len) /* {{{ */ -{ - zval tmp; - - ZVAL_NULL(&tmp); - add_property_zval_ex(arg, key, key_len, &tmp); -} -/* }}} */ - -ZEND_API void add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r) /* {{{ */ -{ - zval tmp; - - ZVAL_RES(&tmp, r); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_double_ex(zval *arg, const char *key, size_t key_len, double d) /* {{{ */ -{ - zval tmp; - - ZVAL_DOUBLE(&tmp, d); - add_property_zval_ex(arg, key, key_len, &tmp); -} -/* }}} */ - -ZEND_API void add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str) /* {{{ */ -{ - zval tmp; - - ZVAL_STR(&tmp, str); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str) /* {{{ */ -{ - zval tmp; - - ZVAL_STRING(&tmp, str); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length) /* {{{ */ -{ - zval tmp; - - ZVAL_STRINGL(&tmp, str, length); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr) /* {{{ */ -{ - zval tmp; - - ZVAL_ARR(&tmp, arr); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj) /* {{{ */ -{ - zval tmp; - - ZVAL_OBJ(&tmp, obj); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref) /* {{{ */ -{ - zval tmp; - - ZVAL_REF(&tmp, ref); - add_property_zval_ex(arg, key, key_len, &tmp); - zval_ptr_dtor(&tmp); /* write_property will add 1 to refcount */ -} -/* }}} */ - -ZEND_API void add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value) /* {{{ */ -{ - zend_string *str; - - str = zend_string_init(key, key_len, 0); - Z_OBJ_HANDLER_P(arg, write_property)(Z_OBJ_P(arg), str, value, NULL); - zend_string_release_ex(str, 0); -} -/* }}} */ - ZEND_API zend_result zend_startup_module_ex(zend_module_entry *module) /* {{{ */ { size_t name_len; @@ -4697,6 +4581,30 @@ ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const cha } /* }}} */ +ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */ +{ + zend_string *property; + zend_class_entry *old_scope = EG(fake_scope); + + EG(fake_scope) = scope; + + property = zend_string_init(name, name_length, 0); + object->handlers->unset_property(object, property, 0); + zend_string_release_ex(property, 0); + + EG(fake_scope) = old_scope; +} +/* }}} */ + +ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name) +{ + zend_class_entry *old_scope = EG(fake_scope); + + EG(fake_scope) = scope; + object->handlers->unset_property(object, name, 0); + EG(fake_scope) = old_scope; +} + ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value) /* {{{ */ { zend_class_entry *old_scope = EG(fake_scope); @@ -4733,29 +4641,30 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *ob } /* }}} */ -ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */ +ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name) { - zend_string *property; - zend_class_entry *old_scope = EG(fake_scope); + zval tmp; - EG(fake_scope) = scope; + ZVAL_NULL(&tmp); + zend_update_property_ex(scope, object, name, &tmp); +} - property = zend_string_init(name, name_length, 0); - object->handlers->unset_property(object, property, 0); - zend_string_release_ex(property, 0); +ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value) /* {{{ */ +{ + zval tmp; - EG(fake_scope) = old_scope; + ZVAL_BOOL(&tmp, value); + zend_update_property(scope, object, name, name_length, &tmp); } /* }}} */ -ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */ +ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value) { zval tmp; ZVAL_BOOL(&tmp, value); - zend_update_property(scope, object, name, name_length, &tmp); + zend_update_property_ex(scope, object, name, &tmp); } -/* }}} */ ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */ { @@ -4766,6 +4675,14 @@ ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *ob } /* }}} */ +ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value) +{ + zval tmp; + + ZVAL_LONG(&tmp, value); + zend_update_property_ex(scope, object, name, &tmp); +} + ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value) /* {{{ */ { zval tmp; @@ -4775,6 +4692,14 @@ ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object * } /* }}} */ +ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value) +{ + zval tmp; + + ZVAL_DOUBLE(&tmp, value); + zend_update_property_ex(scope, object, name, &tmp); +} + ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value) /* {{{ */ { zval tmp; @@ -4784,6 +4709,14 @@ ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *obj } /* }}} */ +ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value) +{ + zval tmp; + + ZVAL_STR(&tmp, value); + zend_update_property_ex(scope, object, name, &tmp); +} + ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value) /* {{{ */ { zval tmp; @@ -4794,6 +4727,15 @@ ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object * } /* }}} */ +ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value) +{ + zval tmp; + + ZVAL_STRING(&tmp, value); + Z_SET_REFCOUNT(tmp, 0); + zend_update_property_ex(scope, object, name, &tmp); +} + ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */ { zval tmp; @@ -4804,6 +4746,15 @@ ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object } /* }}} */ +ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len) +{ + zval tmp; + + ZVAL_STRINGL(&tmp, value, value_len); + Z_SET_REFCOUNT(tmp, 0); + zend_update_property_ex(scope, object, name, &tmp); +} + ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value) /* {{{ */ { zval *property, tmp; @@ -4858,7 +4809,15 @@ ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, c } /* }}} */ -ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */ +ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name) +{ + zval tmp; + + ZVAL_NULL(&tmp); + return zend_update_static_property_ex(scope, name, &tmp); +} + +ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value) /* {{{ */ { zval tmp; @@ -4867,6 +4826,14 @@ ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, c } /* }}} */ +ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value) +{ + zval tmp; + + ZVAL_BOOL(&tmp, value); + return zend_update_static_property_ex(scope, name, &tmp); +} + ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */ { zval tmp; @@ -4876,6 +4843,14 @@ ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, c } /* }}} */ +ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value) +{ + zval tmp; + + ZVAL_LONG(&tmp, value); + return zend_update_static_property_ex(scope, name, &tmp); +} + ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value) /* {{{ */ { zval tmp; @@ -4885,6 +4860,30 @@ ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, } /* }}} */ +ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value) +{ + zval tmp; + + ZVAL_DOUBLE(&tmp, value); + return zend_update_static_property_ex(scope, name, &tmp); +} + +ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value) +{ + zval tmp; + + ZVAL_STR(&tmp, value); + return zend_update_static_property(scope, name, name_length, &tmp); +} + +ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value) +{ + zval tmp; + + ZVAL_STR(&tmp, value); + return zend_update_static_property_ex(scope, name, &tmp); +} + ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value) /* {{{ */ { zval tmp; @@ -4895,6 +4894,15 @@ ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, } /* }}} */ +ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value) +{ + zval tmp; + + ZVAL_STRING(&tmp, value); + Z_SET_REFCOUNT(tmp, 0); + return zend_update_static_property_ex(scope, name, &tmp); +} + ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */ { zval tmp; @@ -4905,6 +4913,15 @@ ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope } /* }}} */ +ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len) +{ + zval tmp; + + ZVAL_STRINGL(&tmp, value, value_len); + Z_SET_REFCOUNT(tmp, 0); + return zend_update_static_property_ex(scope, name, &tmp); +} + ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv) /* {{{ */ { zval *value; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index acdc5b06b3d52..38982bceb36d4 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -490,22 +490,100 @@ static zend_always_inline HashTable *zend_class_backed_enum_table(zend_class_ent ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value); ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value); ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length); -ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value); +ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name); +ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value); +ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value); ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value); +ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value); ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value); +ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value); ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value); +ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value); ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value); +ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value); ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length); +ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len); ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length); +ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name); + +/* Legacy API */ +static zend_always_inline void add_property_zval(zval *z_object, const char *name, zval *value) { + zend_update_property(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); +} +static zend_always_inline void add_property_zval_ex(zval *z_object, const char *name, size_t name_length, zval *value) { + zend_update_property(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); +} +static zend_always_inline void add_property_null(zval *z_object, const char *name) { + zend_update_property_null(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name)); +} +static zend_always_inline void add_property_null_ex(zval *z_object, const char *name, size_t name_length) { + zend_update_property_null(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length); +} +static zend_always_inline void add_property_bool(zval *z_object, const char *name, bool value) { + zend_update_property_bool(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); +} +static zend_always_inline void add_property_bool_ex(zval *z_object, const char *name, size_t name_length, bool value) { + zend_update_property_bool(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); +} +static zend_always_inline void add_property_long(zval *z_object, const char *name, zend_long value) { + zend_update_property_long(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); +} +static zend_always_inline void add_property_long_ex(zval *z_object, const char *name, size_t name_length, zend_long value) { + zend_update_property_long(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); +} +static zend_always_inline void add_property_double(zval *z_object, const char *name, double value) { + zend_update_property_double(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); +} +static zend_always_inline void add_property_double_ex(zval *z_object, const char *name, size_t name_length, double value) { + zend_update_property_double(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); +} +static zend_always_inline void add_property_str(zval *z_object, const char *name, zend_string *value) { + zend_update_property_str(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); + /* This legacy API assumed that the passed zend_string* would be freed */ + zend_string_release(value); +} +static zend_always_inline void add_property_str_ex(zval *z_object, const char *name, size_t name_length, zend_string *value) { + zend_update_property_str(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); + /* This legacy API assumed that the passed zend_string* would be freed */ + zend_string_release(value); +} +static zend_always_inline void add_property_string(zval *z_object, const char *name, const char *value) { + zend_update_property_string(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value); +} +static zend_always_inline void add_property_string_ex(zval *z_object, const char *name, size_t name_length, const char *value) { + zend_update_property_string(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value); +} +static zend_always_inline void add_property_stringl(zval *z_object, const char *name, const char *value, size_t value_len) { + zend_update_property_stringl(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), value, value_len); +} +static zend_always_inline void add_property_stringl_ex(zval *z_object, const char *name, size_t name_length, const char *value, size_t value_len) { + zend_update_property_stringl(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, name_length, value, value_len); +} +/* Resource variant only has non ex version as it is rarely used */ +static zend_always_inline void add_property_resource(zval *z_object, const char *name, zend_resource *resource) { + zval tmp; + + ZVAL_RES(&tmp, resource); + zend_update_property(Z_OBJCE_P(z_object), Z_OBJ_P(z_object), name, strlen(name), &tmp); + zval_ptr_dtor(&tmp); /* Updating property will increase refcount by 1 */ +} ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value); ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value); ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length); -ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value); +ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name); +ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value); +ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value); ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value); +ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value); ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value); +ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value); +ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value); +ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value); ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value); +ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value); ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length); +ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len); ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv); ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv); @@ -625,56 +703,6 @@ static zend_always_inline zend_result add_next_index_zval(zval *arg, zval *value ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value); -ZEND_API void add_property_long_ex(zval *arg, const char *key, size_t key_len, zend_long l); -ZEND_API void add_property_null_ex(zval *arg, const char *key, size_t key_len); -ZEND_API void add_property_bool_ex(zval *arg, const char *key, size_t key_len, zend_long b); -ZEND_API void add_property_resource_ex(zval *arg, const char *key, size_t key_len, zend_resource *r); -ZEND_API void add_property_double_ex(zval *arg, const char *key, size_t key_len, double d); -ZEND_API void add_property_str_ex(zval *arg, const char *key, size_t key_len, zend_string *str); -ZEND_API void add_property_string_ex(zval *arg, const char *key, size_t key_len, const char *str); -ZEND_API void add_property_stringl_ex(zval *arg, const char *key, size_t key_len, const char *str, size_t length); -ZEND_API void add_property_array_ex(zval *arg, const char *key, size_t key_len, zend_array *arr); -ZEND_API void add_property_object_ex(zval *arg, const char *key, size_t key_len, zend_object *obj); -ZEND_API void add_property_reference_ex(zval *arg, const char *key, size_t key_len, zend_reference *ref); -ZEND_API void add_property_zval_ex(zval *arg, const char *key, size_t key_len, zval *value); - -static zend_always_inline void add_property_long(zval *arg, const char *key, zend_long n) { - add_property_long_ex(arg, key, strlen(key), n); -} -static zend_always_inline void add_property_null(zval *arg, const char *key) { - add_property_null_ex(arg, key, strlen(key)); -} -static zend_always_inline void add_property_bool(zval *arg, const char *key, bool b) { - add_property_bool_ex(arg, key, strlen(key), b); -} -static zend_always_inline void add_property_resource(zval *arg, const char *key, zend_resource *r) { - add_property_resource_ex(arg, key, strlen(key), r); -} -static zend_always_inline void add_property_double(zval *arg, const char *key, double d) { - add_property_double_ex(arg, key, strlen(key), d); -} -static zend_always_inline void add_property_str(zval *arg, const char *key, zend_string *str) { - add_property_str_ex(arg, key, strlen(key), str); -} -static zend_always_inline void add_property_string(zval *arg, const char *key, const char *str) { - add_property_string_ex(arg, key, strlen(key), str); -} -static zend_always_inline void add_property_stringl(zval *arg, const char *key, const char *str, size_t length) { - add_property_stringl_ex(arg, key, strlen(key), str, length); -} -static zend_always_inline void add_property_array(zval *arg, const char *key, zend_array *arr) { - add_property_array_ex(arg, key, strlen(key), arr); -} -static zend_always_inline void add_property_object(zval *arg, const char *key, zend_object *obj) { - add_property_object_ex(arg, key, strlen(key), obj); -} -static zend_always_inline void add_property_reference(zval *arg, const char *key, zend_reference *ref) { - add_property_reference_ex(arg, key, strlen(key), ref); -} -static zend_always_inline void add_property_zval(zval *arg, const char *key, zval *value) { - add_property_zval_ex(arg, key, strlen(key), value); -} - ZEND_API zend_result _call_user_function_impl(zval *object, zval *function_name, zval *retval_ptr, uint32_t param_count, zval params[], HashTable *named_params); #define call_user_function(function_table, object, function_name, retval_ptr, param_count, params) \ diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 68b55e1d78d35..51b70fdc7ab4c 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -523,12 +523,12 @@ PHP_FUNCTION(mysqli_execute_query) if (FAIL == mysql_stmt_prepare(stmt->stmt, query, query_len)) { MYSQLI_REPORT_STMT_ERROR(stmt->stmt); - + close_stmt_and_copy_errors(stmt, mysql); RETURN_FALSE; } - /* The bit below, which is copied from mysqli_prepare, is needed for bad index exceptions */ + /* The bit below, which is copied from mysqli_prepare, is needed for bad index exceptions */ /* don't initialize stmt->query with NULL, we ecalloc()-ed the memory */ /* Get performance boost if reporting is switched off */ if (query_len && (MyG(report_mode) & MYSQLI_REPORT_INDEX)) { @@ -647,28 +647,118 @@ PHP_FUNCTION(mysqli_stmt_fetch) /* }}} */ /* {{{ php_add_field_properties */ -static void php_add_field_properties(zval *value, const MYSQL_FIELD *field) -{ - add_property_str(value, "name", zend_string_copy(field->sname)); - - add_property_stringl(value, "orgname", (field->org_name ? field->org_name : ""), field->org_name_length); - add_property_stringl(value, "table", (field->table ? field->table : ""), field->table_length); - add_property_stringl(value, "orgtable", (field->org_table ? field->org_table : ""), field->org_table_length); - add_property_stringl(value, "def", (field->def ? field->def : ""), field->def_length); - add_property_stringl(value, "db", (field->db ? field->db : ""), field->db_length); +static void php_add_field_properties(zval *z_object, const MYSQL_FIELD *field) +{ + zend_update_property_str_ex( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + ZSTR_KNOWN(ZEND_STR_NAME), field->sname + ); + if (field->org_name) { + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "orgname", strlen("orgname"), + field->org_name, field->org_name_length + ); + } else { + zend_update_property_str( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "orgname", strlen("orgname"), + zend_empty_string + ); + } + if (field->table) { + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "table", strlen("table"), + field->table, field->table_length + ); + } else { + zend_update_property_str( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "table", strlen("table"), + zend_empty_string + ); + } + if (field->org_table) { + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "orgtable", strlen("orgtable"), + field->org_table, field->org_table_length + ); + } else { + zend_update_property_str( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "orgtable", strlen("orgtable"), + zend_empty_string + ); + } + if (field->def) { + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "def", strlen("def"), + field->def, field->def_length + ); + } else { + zend_update_property_str( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "def", strlen("def"), + zend_empty_string + ); + } + if (field->db) { + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "db", strlen("db"), + field->db, field->db_length + ); + } else { + zend_update_property_str( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "db", strlen("db"), + zend_empty_string + ); + } /* FIXME: manually set the catalog to "def" due to bug in * libmysqlclient which does not initialize field->catalog * and in addition, the catalog is always be "def" */ - add_property_string(value, "catalog", "def"); - - add_property_long(value, "max_length", 0); - add_property_long(value, "length", field->length); - add_property_long(value, "charsetnr", field->charsetnr); - add_property_long(value, "flags", field->flags); - add_property_long(value, "type", field->type); - add_property_long(value, "decimals", field->decimals); + zend_update_property_stringl( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "catalog", strlen("catalog"), + "def", strlen("def") + ); + + zend_update_property_long( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "max_length", strlen("max_length"), + 0 + ); + zend_update_property_long( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "length", strlen("length"), + field->length + ); + zend_update_property_long( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "charsetnr", strlen("charsetnr"), + field->charsetnr + ); + zend_update_property_long( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "flags", strlen("flags"), + field->flags + ); + zend_update_property_long_ex( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + ZSTR_KNOWN(ZEND_STR_TYPE), + field->type + ); + zend_update_property_long( + Z_OBJCE_P(z_object), Z_OBJ_P(z_object), + "decimals", strlen("decimals"), + field->decimals + ); } /* }}} */ diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 406d928699784..49f76a1d1a121 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -988,14 +988,78 @@ PHP_FUNCTION(mysqli_get_charset) state = 1; /* all charsets are compiled in */ object_init(return_value); - add_property_string(return_value, "charset", (name) ? (char *)name : ""); - add_property_string(return_value, "collation",(collation) ? (char *)collation : ""); - add_property_string(return_value, "dir", (dir) ? (char *)dir : ""); - add_property_long(return_value, "min_length", minlength); - add_property_long(return_value, "max_length", maxlength); - add_property_long(return_value, "number", number); - add_property_long(return_value, "state", state); - add_property_string(return_value, "comment", (comment) ? (char *)comment : ""); + if (name) { + zend_update_property_string( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "charset", strlen("charset"), + (char *)name + ); + } else { + zend_update_property_str( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "charset", strlen("charset"), + zend_empty_string + ); + } + if (collation) { + zend_update_property_string( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "collation", strlen("collation"), + (char *)collation + ); + } else { + zend_update_property_str( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "collation", strlen("collation"), + zend_empty_string + ); + } + if (dir) { + zend_update_property_string( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "dir", strlen("dir"), + (char *)dir + ); + } else { + zend_update_property_str( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "dir", strlen("dir"), + zend_empty_string + ); + } + zend_update_property_long( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "min_length", strlen("min_length"), + minlength + ); + zend_update_property_long( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "max_length", strlen("max_length"), + maxlength + ); + zend_update_property_long( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "number", strlen("number"), + number + ); + zend_update_property_long( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "state", strlen("state"), + state + ); + if (comment) { + zend_update_property_string( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "comment", strlen("comment"), + (char *)comment + ); + } else { + zend_update_property_str( + Z_OBJCE_P(return_value), Z_OBJ_P(return_value), + "comment", strlen("comment"), + zend_empty_string + ); + } } /* }}} */