Skip to content

Commit

Permalink
Use new ZSTR_* macros
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Jul 2, 2015
1 parent ac29067 commit ce27a10
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ static ZEND_FUNCTION(msgpack_unserialize) /* {{{ */ {
}

if (object == NULL) {
php_msgpack_unserialize(return_value, str->val, str->len);
php_msgpack_unserialize(return_value, ZSTR_VAL(str), ZSTR_LEN(str));
} else {
zval zv;
php_msgpack_unserialize(&zv, str->val, str->len);
php_msgpack_unserialize(&zv, ZSTR_VAL(str), ZSTR_LEN(str));

if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) {
RETVAL_NULL();
Expand Down
22 changes: 11 additions & 11 deletions msgpack_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ static ZEND_METHOD(msgpack, unpack) /* {{{ */ {
MSGPACK_G(php_only) = base->php_only;

if (object == NULL) {
php_msgpack_unserialize(return_value, str->val, str->len);
php_msgpack_unserialize(return_value, ZSTR_VAL(str), ZSTR_LEN(str));
} else {
zval zv;
php_msgpack_unserialize(&zv, str->val, str->len);
php_msgpack_unserialize(&zv, ZSTR_VAL(str), ZSTR_LEN(str));

if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) {
RETVAL_NULL();
Expand Down Expand Up @@ -352,7 +352,7 @@ static ZEND_METHOD(msgpack_unpacker, feed) /* {{{ */ {
RETURN_FALSE;
}

smart_str_appendl(&unpacker->buffer, str->val, str->len);
smart_str_appendl(&unpacker->buffer, ZSTR_VAL(str), ZSTR_LEN(str));

RETURN_TRUE;
}
Expand All @@ -371,16 +371,16 @@ static ZEND_METHOD(msgpack_unpacker, execute) /* {{{ */ {
}

if (str) {
data = str->val;
len = str->len;
data = ZSTR_VAL(str);
len = ZSTR_LEN(str);
if (offset != NULL && (Z_TYPE_P(offset) == IS_LONG || Z_TYPE_P(offset) == IS_DOUBLE)) {
off = Z_LVAL_P(offset);
} else {
off = 0;
}
} else if (unpacker->buffer.s) {
data = unpacker->buffer.s->val;
len = unpacker->buffer.s->len;
data = ZSTR_VAL(unpacker->buffer.s);
len = ZSTR_LEN(unpacker->buffer.s);
off = unpacker->offset;
} else {
data = NULL;
Expand Down Expand Up @@ -463,9 +463,9 @@ static ZEND_METHOD(msgpack_unpacker, reset) /* {{{ */ {
smart_str buffer = {0};
php_msgpack_unpacker_t *unpacker = Z_MSGPACK_UNPACKER_P(getThis());

if (unpacker->buffer.s && unpacker->buffer.s->len > unpacker->offset) {
smart_str_appendl(&buffer, unpacker->buffer.s->val + unpacker->offset,
unpacker->buffer.s->len - unpacker->offset);
if (unpacker->buffer.s && ZSTR_LEN(unpacker->buffer.s) > unpacker->offset) {
smart_str_appendl(&buffer, ZSTR_VAL(unpacker->buffer.s) + unpacker->offset,
ZSTR_LEN(unpacker->buffer.s) - unpacker->offset);
}

smart_str_free(&unpacker->buffer);
Expand All @@ -476,7 +476,7 @@ static ZEND_METHOD(msgpack_unpacker, reset) /* {{{ */ {
unpacker->finished = 0;

if (buffer.s) {
smart_str_appendl(&unpacker->buffer, buffer.s->val, buffer.s->len);
smart_str_appendl(&unpacker->buffer, ZSTR_VAL(buffer.s), ZSTR_LEN(buffer.s));
}

smart_str_free(&buffer);
Expand Down
4 changes: 2 additions & 2 deletions msgpack_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static inline int msgpack_convert_string_to_properties(zval *object, zend_string
int return_code;

ZVAL_STR(&pub_name, key);
priv_name = zend_mangle_property_name(ce->name->val, ce->name->len, key->val, key->len, 1);
prot_name = zend_mangle_property_name("*", 1, key->val, key->len, 1);
priv_name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(key), ZSTR_LEN(key), 1);
prot_name = zend_mangle_property_name("*", 1, ZSTR_VAL(key), ZSTR_LEN(key), 1);

if (zend_hash_find(propers, priv_name) != NULL) {
zend_update_property_ex(ce, object, key, val);
Expand Down
16 changes: 8 additions & 8 deletions msgpack_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline void msgpack_serialize_class(smart_str *buf, zval *val, zval *retv
msgpack_serialize_string(buf, class_name, name_len);

ZEND_HASH_FOREACH_STR_KEY_VAL(ht, key_str, value) {
if (incomplete_class && strcmp(key_str->val, MAGIC_MEMBER) == 0) {
if (incomplete_class && strcmp(ZSTR_VAL(key_str), MAGIC_MEMBER) == 0) {
continue;
}

Expand All @@ -158,11 +158,11 @@ static inline void msgpack_serialize_class(smart_str *buf, zval *val, zval *retv
if (ce) {
zend_string *priv_name, *prot_name;
do {
priv_name = zend_mangle_property_name(ce->name->val, ce->name->len,
priv_name = zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name),
Z_STRVAL_P(value), Z_STRLEN_P(value),
ce->type & ZEND_INTERNAL_CLASS);
if ((data = zend_hash_find(Z_OBJPROP_P(val), priv_name)) != NULL) {
msgpack_serialize_string(buf, priv_name->val, priv_name->len);
msgpack_serialize_string(buf, ZSTR_VAL(priv_name), ZSTR_LEN(priv_name));
pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS);
msgpack_serialize_zval(buf, data, var_hash);
break;
Expand All @@ -175,7 +175,7 @@ static inline void msgpack_serialize_class(smart_str *buf, zval *val, zval *retv
ce->type & ZEND_INTERNAL_CLASS);

if ((data = zend_hash_find(Z_OBJPROP_P(val), prot_name)) != NULL) {
msgpack_serialize_string(buf, prot_name->val, prot_name->len);
msgpack_serialize_string(buf, ZSTR_VAL(prot_name), ZSTR_LEN(prot_name));
pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
msgpack_serialize_zval(buf, data, var_hash);
break;
Expand Down Expand Up @@ -265,11 +265,11 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
zval *value, *value_noref;

ZEND_HASH_FOREACH_KEY_VAL(ht, key_long, key_str, value) {
if (key_str && incomplete_class && strcmp(key_str->val, MAGIC_MEMBER) == 0) {
if (key_str && incomplete_class && strcmp(ZSTR_VAL(key_str), MAGIC_MEMBER) == 0) {
continue;
}
if (key_str && hash) {
msgpack_serialize_string(buf, key_str->val, key_str->len);
msgpack_serialize_string(buf, ZSTR_VAL(key_str), ZSTR_LEN(key_str));
} else if (hash) {
msgpack_pack_long(buf, key_long);
}
Expand Down Expand Up @@ -354,7 +354,7 @@ static inline void msgpack_serialize_object(smart_str *buf, zval *val, HashTable
msgpack_pack_nil(buf);
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT);

msgpack_serialize_string(buf, ce->name->val, ce->name->len);
msgpack_serialize_string(buf, ZSTR_VAL(ce->name), ZSTR_LEN(ce->name));
msgpack_pack_raw(buf, serialized_length);
msgpack_pack_raw_body(buf, serialized_data, serialized_length);
} else {
Expand Down Expand Up @@ -480,7 +480,7 @@ void msgpack_serialize_zval(smart_str *buf, zval *val, HashTable *var_hash) /* {
PHP_CLASS_ATTRIBUTES;
PHP_SET_CLASS_ATTRIBUTES(val_noref);

msgpack_serialize_object(buf, val, var_hash, class_name->val, class_name->len, incomplete_class);
msgpack_serialize_object(buf, val, var_hash, ZSTR_VAL(class_name), ZSTR_LEN(class_name), incomplete_class);

PHP_CLEANUP_CLASS_ATTRIBUTES();
}
Expand Down
7 changes: 3 additions & 4 deletions msgpack_unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string
zval_ptr_dtor(&user_func);
if (func_call_status != SUCCESS) {
MSGPACK_WARNING("[msgpack] (%s) defined (%s) but not found",
__FUNCTION__, class_name->val);
__FUNCTION__, ZSTR_VAL(class_name));

incomplete_class = 1;
ce = PHP_IC_ENTRY;
Expand All @@ -215,7 +215,7 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string
if ((ce = zend_lookup_class(class_name)) == NULL) {
MSGPACK_WARNING("[msgpack] (%s) Function %s() hasn't defined "
"the class it was called for",
__FUNCTION__, class_name->val);
__FUNCTION__, ZSTR_VAL(class_name));

incomplete_class = 1;
ce = PHP_IC_ENTRY;
Expand All @@ -234,7 +234,7 @@ static zend_class_entry* msgpack_unserialize_class(zval **container, zend_string

/* store incomplete class name */
if (incomplete_class) {
php_store_class_name(container_val, class_name->val, class_name->len);
php_store_class_name(container_val, ZSTR_VAL(class_name), ZSTR_LEN(class_name));
}

return ce;
Expand Down Expand Up @@ -421,7 +421,6 @@ int msgpack_unserialize_bin(msgpack_unserialize_data *unpack, const char* base,
}
/* }}} */


int msgpack_unserialize_array(msgpack_unserialize_data *unpack, unsigned int count, zval **obj) /* {{{ */ {
MSGPACK_UNSERIALIZE_ALLOC_VALUE(unpack);

Expand Down

0 comments on commit ce27a10

Please sign in to comment.