/* {{{ */ static inline zend_string* php_memoize_scope(const zval *This, const zend_function *function) { if (!function->common.scope) { return NULL; } if (Z_TYPE_P(This) != IS_OBJECT) { return zend_string_copy(function->common.scope->name); } else { smart_str smart = {0}; php_serialize_data_t data; if (Z_OBJCE_P(This)->serialize == zend_class_serialize_deny) { return PHP_MEMOIZE_SCOPE_FAILURE; } PHP_VAR_SERIALIZE_INIT(data); php_var_serialize(&smart, (zval*) This, &data); PHP_VAR_SERIALIZE_DESTROY(data); if (EG(exception)) { smart_str_free(&smart); zend_clear_exception(); return PHP_MEMOIZE_SCOPE_FAILURE; } return smart.s; } return NULL; } /* }}} */
int shmcache_php_pack(zval *pzval, smart_str *buf) { php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(buf, GET_ZVAL_PTR(pzval), &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); return 0; }
CPINLINE void cp_serialize(smart_str *ser_data, zval *array) { // struct timeval start, end; // gettimeofday(&start, NULL); php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(ser_data, &array, &var_hash TSRMLS_CC); PHP_VAR_SERIALIZE_DESTROY(var_hash); // gettimeofday(&end, NULL); // int timeuse = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec; // printf("ser time: %d us\n", timeuse); }
void cp_serialize(smart_str *ser_data, zval *array) { php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); #if PHP_MAJOR_VERSION < 7 php_var_serialize(ser_data, &array, &var_hash TSRMLS_CC); #else php_var_serialize(ser_data, array, &var_hash TSRMLS_CC); #endif PHP_VAR_SERIALIZE_DESTROY(var_hash); // gettimeofday(&end, NULL); // int timeuse = 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec; // printf("ser time: %d us\n", timeuse); }
/* {{{ php serializer */ PHP_APCU_API int APC_SERIALIZER_NAME(php) (APC_SERIALIZER_ARGS) { smart_str strbuf = {0}; php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(&strbuf, (zval*) value, &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); if(strbuf.s->val) { *buf = (unsigned char *)estrndup(ZSTR_VAL(strbuf.s), ZSTR_LEN(strbuf.s)); *buf_len = ZSTR_LEN(strbuf.s); smart_str_free(&strbuf); return 1; } return 0; } /* }}} */
/** * @brief string|null Phalcon\Registry::serialize() */ PHP_METHOD(Phalcon_Registry, serialize){ zval *data; data = phalcon_read_property(getThis(), SL("_data"), PH_NOISY); smart_str buf = { 0 }; php_serialize_data_t var_hash; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(&buf, data, &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); if (buf.s) { RETURN_NEW_STR(buf.s); } RETURN_NULL(); }
int php_ds_pair_serialize(zval *object, unsigned char **buffer, size_t *length, zend_serialize_data *data) { smart_str buf = {0}; ds_pair_t *pair = Z_DS_PAIR_P(object); php_serialize_data_t serialize_data = (php_serialize_data_t) data; PHP_VAR_SERIALIZE_INIT(serialize_data); php_var_serialize(&buf, &pair->key, &serialize_data); php_var_serialize(&buf, &pair->value, &serialize_data); smart_str_0(&buf); SERIALIZE_SET_ZSTR(buf.s); zend_string_release(buf.s); PHP_VAR_SERIALIZE_DESTROY(serialize_data); return SUCCESS; }
/** * Serializes php variables without using the PHP userland */ void phalcon_serialize(zval *return_value, zval *var) { php_serialize_data_t var_hash; smart_str buf = {0}; PHP_VAR_SERIALIZE_INIT(var_hash); php_var_serialize(&buf, var, &var_hash); PHP_VAR_SERIALIZE_DESTROY(var_hash); if (EG(exception)) { smart_str_free(&buf); RETURN_FALSE; } if (buf.s) { RETURN_STR(buf.s); } else { RETURN_NULL(); } }
/* {{{ proto string SplDoublyLinkedList::serialize() Serializes storage */ SPL_METHOD(SplDoublyLinkedList, serialize) { spl_dllist_object *intern = Z_SPLDLLIST_P(getThis()); smart_str buf = {0}; spl_ptr_llist_element *current = intern->llist->head, *next; zval flags; php_serialize_data_t var_hash; if (zend_parse_parameters_none() == FAILURE) { return; } PHP_VAR_SERIALIZE_INIT(var_hash); /* flags */ ZVAL_LONG(&flags, intern->flags); php_var_serialize(&buf, &flags, &var_hash); zval_ptr_dtor(&flags); /* elements */ while (current) { smart_str_appendc(&buf, ':'); next = current->next; php_var_serialize(&buf, ¤t->data, &var_hash); current = next; } smart_str_0(&buf); /* done */ PHP_VAR_SERIALIZE_DESTROY(var_hash); if (buf.s) { RETURN_STR(buf.s); } else { RETURN_NULL(); } } /* }}} */
/* {{{ */ static inline zend_string* php_memoize_args(uint32_t argc, const zval *argv) { php_serialize_data_t data; zval serial; uint32_t it; smart_str smart = {0}; ZVAL_UNDEF(&serial); switch (argc) { case 0: return zend_string_copy(CG(empty_string)); case 1: { switch (Z_TYPE_P(argv)) { case IS_STRING: return zend_string_copy(Z_STR_P(argv)); case IS_LONG: case IS_DOUBLE: return zval_get_string((zval*) argv); case IS_TRUE: return zend_string_copy(PHP_MEMOIZE_STRING_TRUE); case IS_FALSE: return zend_string_copy(PHP_MEMOIZE_STRING_FALSE); case IS_NULL: return zend_string_copy(PHP_MEMOIZE_STRING_NULL); } ZVAL_COPY(&serial, argv); } /* intentionally fall through */ default: { if (Z_TYPE(serial) == IS_UNDEF) { array_init(&serial); for (it = 0; it < argc; it++) { if (add_index_zval(&serial, it, (zval*) argv + it) == SUCCESS) { Z_TRY_ADDREF_P((zval*) argv + it); } } } PHP_VAR_SERIALIZE_INIT(data); php_var_serialize(&smart, &serial, &data); PHP_VAR_SERIALIZE_DESTROY(data); if (EG(exception)) { zval_ptr_dtor(&serial); zend_clear_exception(); return NULL; } } } zval_ptr_dtor(&serial); return smart.s; } /* }}} */