本文整理汇总了C++中zval_get_string函数的典型用法代码示例。如果您正苦于以下问题:C++ zval_get_string函数的具体用法?C++ zval_get_string怎么用?C++ zval_get_string使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zval_get_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zend_print_zval_r_to_buf
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
{
switch (Z_TYPE_P(expr)) {
case IS_ARRAY:
smart_str_appends(buf, "Array\n");
if (Z_REFCOUNTED_P(expr)) {
if (Z_IS_RECURSIVE_P(expr)) {
smart_str_appends(buf, " *RECURSION*");
return;
}
Z_PROTECT_RECURSION_P(expr);
}
print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
if (Z_REFCOUNTED_P(expr)) {
Z_UNPROTECT_RECURSION_P(expr);
}
break;
case IS_OBJECT:
{
HashTable *properties;
int is_temp;
zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
smart_str_appends(buf, ZSTR_VAL(class_name));
zend_string_release(class_name);
smart_str_appends(buf, " Object\n");
if (Z_IS_RECURSIVE_P(expr)) {
smart_str_appends(buf, " *RECURSION*");
return;
}
if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
break;
}
Z_PROTECT_RECURSION_P(expr);
print_hash(buf, properties, indent, 1);
Z_UNPROTECT_RECURSION_P(expr);
if (is_temp) {
zend_hash_destroy(properties);
FREE_HASHTABLE(properties);
}
break;
}
case IS_LONG:
smart_str_append_long(buf, Z_LVAL_P(expr));
break;
case IS_REFERENCE:
zend_print_zval_r_to_buf(buf, Z_REFVAL_P(expr), indent);
break;
default:
{
zend_string *str = zval_get_string(expr);
smart_str_append(buf, str);
zend_string_release(str);
}
break;
}
}
示例2: do_from_zval_err
/* error already emitted, but let's emit another more relevant */
do_from_zval_err(ctx, "could not resolve address '%s' to get an AF_INET6 "
"address", Z_STRVAL_P(zaddr_str));
}
zend_string_release(addr_str);
}
static void to_zval_read_sin6_addr(const char *data, zval *zv, res_context *ctx)
{
const struct in6_addr *addr = (const struct in6_addr *)data;
socklen_t size = INET6_ADDRSTRLEN;
zend_string *str = zend_string_alloc(size - 1, 0);
memset(str->val, '\0', size);
ZVAL_NEW_STR(zv, str);
if (inet_ntop(AF_INET6, addr, Z_STRVAL_P(zv), size) == NULL) {
do_to_zval_err(ctx, "could not convert IPv6 address to string "
"(errno %d)", errno);
return;
}
Z_STRLEN_P(zv) = strlen(Z_STRVAL_P(zv));
}
static const field_descriptor descriptors_sockaddr_in6[] = {
{"family", sizeof("family"), 0, offsetof(struct sockaddr_in6, sin6_family), from_zval_write_sa_family, to_zval_read_sa_family},
{"addr", sizeof("addr"), 0, offsetof(struct sockaddr_in6, sin6_addr), from_zval_write_sin6_addr, to_zval_read_sin6_addr},
{"port", sizeof("port"), 0, offsetof(struct sockaddr_in6, sin6_port), from_zval_write_net_uint16, to_zval_read_net_uint16},
{"flowinfo", sizeof("flowinfo"), 0, offsetof(struct sockaddr_in6, sin6_flowinfo), from_zval_write_uint32, to_zval_read_uint32},
{"scope_id", sizeof("scope_id"), 0, offsetof(struct sockaddr_in6, sin6_scope_id), from_zval_write_uint32, to_zval_read_uint32},
{0}
};
static void from_zval_write_sockaddr_in6(const zval *container, char *sockaddr6, ser_context *ctx)
{
from_zval_write_aggregation(container, sockaddr6, descriptors_sockaddr_in6, ctx);
}
static void to_zval_read_sockaddr_in6(const char *data, zval *zv, res_context *ctx)
{
to_zval_read_aggregation(data, zv, descriptors_sockaddr_in6, ctx);
}
#endif /* HAVE_IPV6 */
static void from_zval_write_sun_path(const zval *path, char *sockaddr_un_c, ser_context *ctx)
{
zend_string *path_str;
struct sockaddr_un *saddr = (struct sockaddr_un*)sockaddr_un_c;
path_str = zval_get_string((zval *) path);
/* code in this file relies on the path being nul terminated, even though
* this is not required, at least on linux for abstract paths. It also
* assumes that the path is not empty */
if (path_str->len == 0) {
do_from_zval_err(ctx, "%s", "the path is cannot be empty");
return;
}
if (path_str->len >= sizeof(saddr->sun_path)) {
do_from_zval_err(ctx, "the path is too long, the maximum permitted "
"length is %ld", sizeof(saddr->sun_path) - 1);
return;
}
memcpy(&saddr->sun_path, path_str->val, path_str->len);
saddr->sun_path[path_str->len] = '\0';
zend_string_release(path_str);
}
示例3: dom_node_node_value_write
int dom_node_node_value_write(dom_object *obj, zval *newval)
{
xmlNode *nodep = dom_object_get_node(obj);
if (nodep == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 0);
return FAILURE;
}
/* Access to Element node is implemented as a convience method */
switch (nodep->type) {
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
if (nodep->children) {
node_list_unlink(nodep->children);
php_libxml_node_free_list((xmlNodePtr) nodep->children);
nodep->children = NULL;
}
case XML_TEXT_NODE:
case XML_COMMENT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
{
zend_string *str = zval_get_string(newval);
xmlNodeSetContentLen(nodep, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str) + 1);
zend_string_release_ex(str, 0);
break;
}
default:
break;
}
return SUCCESS;
}
示例4: real_php_log_buffer
static int real_php_log_buffer(zval *msg_buffer, char *opt, int opt_len TSRMLS_DC)
{
php_stream *stream = NULL;
HashTable *ht;
#if PHP_VERSION_ID >= 70000
zend_ulong num_key;
zend_string *str_key;
zval *entry;
#else
zval **log;
#endif
stream = process_stream(opt,opt_len TSRMLS_CC);
if (stream == NULL)
{
return FAILURE;
}
#if PHP_VERSION_ID >= 70000
ht = HASH_OF(msg_buffer);
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, entry)
{
zend_string *s = zval_get_string(entry);
php_stream_write(stream, ZSTR_VAL(s), ZSTR_LEN(s));
zend_string_release(s);
}
示例5: dom_node_text_content_write
int dom_node_text_content_write(dom_object *obj, zval *newval)
{
xmlNode *nodep = dom_object_get_node(obj);
zend_string *str;
if (nodep == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 0);
return FAILURE;
}
if (nodep->type == XML_ELEMENT_NODE || nodep->type == XML_ATTRIBUTE_NODE) {
if (nodep->children) {
node_list_unlink(nodep->children);
php_libxml_node_free_list((xmlNodePtr) nodep->children);
nodep->children = NULL;
}
}
str = zval_get_string(newval);
/* we have to use xmlNodeAddContent() to get the same behavior as with xmlNewText() */
xmlNodeSetContent(nodep, (xmlChar *) "");
xmlNodeAddContent(nodep, (xmlChar *) ZSTR_VAL(str));
zend_string_release_ex(str, 0);
return SUCCESS;
}
示例6: ZEND_HASH_FOREACH_STR_KEY_VAL
ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) {
zend_string *str = zval_get_string(element);
if (str->len == 0) {
goto next_element;
}
if (string_key) {
if (string_key->len == 0) {
goto next_element;
}
l = string_key->len + str->len + 2;
memcpy(p, string_key->val, string_key->len);
strncat(p, "=", 1);
strncat(p, str->val, str->len);
#ifndef PHP_WIN32
*ep = p;
++ep;
#endif
p += l;
} else {
memcpy(p, str->val, str->len);
#ifndef PHP_WIN32
*ep = p;
++ep;
#endif
p += str->len + 1;
}
next_element:
STR_RELEASE(str);
} ZEND_HASH_FOREACH_END();
示例7: ZEND_METHOD
/* {{{ proto Closure Closure::bind(callable old, object to [, mixed scope])
Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
zval *newthis, *zclosure, *scope_arg = NULL;
zend_closure *closure, *new_closure;
zend_class_entry *ce, *called_scope;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
RETURN_NULL();
}
closure = (zend_closure *)Z_OBJ_P(zclosure);
if ((newthis != NULL) && (closure->func.common.fn_flags & ZEND_ACC_STATIC)) {
zend_error(E_WARNING, "Cannot bind an instance to a static closure");
}
if (scope_arg != NULL) { /* scope argument was given */
if (Z_TYPE_P(scope_arg) == IS_OBJECT) {
ce = Z_OBJCE_P(scope_arg);
} else if (Z_TYPE_P(scope_arg) == IS_NULL) {
ce = NULL;
} else {
zend_string *class_name = zval_get_string(scope_arg);
if (zend_string_equals_literal(class_name, "static")) {
ce = closure->func.common.scope;
} else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) {
zend_error(E_WARNING, "Class '%s' not found", ZSTR_VAL(class_name));
zend_string_release(class_name);
RETURN_NULL();
}
zend_string_release(class_name);
}
if(ce && ce != closure->func.common.scope && ce->type == ZEND_INTERNAL_CLASS) {
/* rebinding to internal class is not allowed */
zend_error(E_WARNING, "Cannot bind closure to scope of internal class %s", ZSTR_VAL(ce->name));
return;
}
} else { /* scope argument not given; do not change the scope by default */
ce = closure->func.common.scope;
}
if (newthis) {
called_scope = Z_OBJCE_P(newthis);
} else {
called_scope = ce;
}
zend_create_closure(return_value, &closure->func, ce, called_scope, newthis);
new_closure = (zend_closure *) Z_OBJ_P(return_value);
/* Runtime cache relies on bound scope to be immutable, hence we need a separate rt cache in case scope changed */
if (ZEND_USER_CODE(closure->func.type) && (closure->func.common.scope != new_closure->func.common.scope || (closure->func.op_array.fn_flags & ZEND_ACC_NO_RT_ARENA))) {
new_closure->func.op_array.run_time_cache = emalloc(new_closure->func.op_array.cache_size);
memset(new_closure->func.op_array.run_time_cache, 0, new_closure->func.op_array.cache_size);
new_closure->func.op_array.fn_flags |= ZEND_ACC_NO_RT_ARENA;
}
}
示例8: zend_print_zval_r_to_buf
static void zend_print_zval_r_to_buf(smart_str *buf, zval *expr, int indent) /* {{{ */
{
ZVAL_DEREF(expr);
switch (Z_TYPE_P(expr)) {
case IS_ARRAY:
smart_str_appends(buf, "Array\n");
if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr)) &&
++Z_ARRVAL_P(expr)->u.v.nApplyCount>1) {
smart_str_appends(buf, " *RECURSION*");
Z_ARRVAL_P(expr)->u.v.nApplyCount--;
return;
}
print_hash(buf, Z_ARRVAL_P(expr), indent, 0);
if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(expr))) {
Z_ARRVAL_P(expr)->u.v.nApplyCount--;
}
break;
case IS_OBJECT:
{
HashTable *properties;
int is_temp;
zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
smart_str_appends(buf, ZSTR_VAL(class_name));
zend_string_release(class_name);
smart_str_appends(buf, " Object\n");
if (Z_OBJ_APPLY_COUNT_P(expr) > 0) {
smart_str_appends(buf, " *RECURSION*");
return;
}
if ((properties = Z_OBJDEBUG_P(expr, is_temp)) == NULL) {
break;
}
Z_OBJ_INC_APPLY_COUNT_P(expr);
print_hash(buf, properties, indent, 1);
Z_OBJ_DEC_APPLY_COUNT_P(expr);
if (is_temp) {
zend_hash_destroy(properties);
FREE_HASHTABLE(properties);
}
break;
}
case IS_LONG:
smart_str_append_long(buf, Z_LVAL_P(expr));
break;
default:
{
zend_string *str = zval_get_string(expr);
smart_str_append(buf, str);
zend_string_release(str);
}
break;
}
}
示例9: zend_print_zval_ex
ZEND_API size_t zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent) /* {{{ */
{
zend_string *str = zval_get_string(expr);
size_t len = ZSTR_LEN(str);
if (len != 0) {
write_func(ZSTR_VAL(str), len);
}
zend_string_release(str);
return len;
}
示例10: _php_array_to_envp
/* {{{ _php_array_to_envp */
static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC)
{
zval *element;
php_process_env_t env;
zend_string *string_key;
#ifndef PHP_WIN32
char **ep;
#endif
char *p;
uint cnt, l, sizeenv=0;
HashTable *target_hash;
memset(&env, 0, sizeof(env));
if (!environment) {
return env;
}
cnt = zend_hash_num_elements(Z_ARRVAL_P(environment));
if (cnt < 1) {
#ifndef PHP_WIN32
env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent);
#endif
env.envp = (char *) pecalloc(4, 1, is_persistent);
return env;
}
target_hash = HASH_OF(environment);
if (!target_hash) {
return env;
}
/* first, we have to get the size of all the elements in the hash */
ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) {
zend_string *str = zval_get_string(element);
uint el_len = str->len;
STR_RELEASE(str);
if (el_len == 0) {
continue;
}
sizeenv += el_len + 1;
if (string_key) {
if (string_key->len == 0) {
continue;
}
sizeenv += string_key->len + 1;
}
} ZEND_HASH_FOREACH_END();
示例11: ZEND_METHOD
/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ] )
Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
zval *newthis, *zclosure, *scope_arg = NULL;
zend_closure *closure;
zend_class_entry *ce, *called_scope;
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
RETURN_NULL();
}
closure = (zend_closure *)Z_OBJ_P(zclosure);
if ((newthis != NULL) && (closure->func.common.fn_flags & ZEND_ACC_STATIC)) {
zend_error(E_WARNING, "Cannot bind an instance to a static closure");
}
if (scope_arg != NULL) { /* scope argument was given */
if (Z_TYPE_P(scope_arg) == IS_OBJECT) {
ce = Z_OBJCE_P(scope_arg);
} else if (Z_TYPE_P(scope_arg) == IS_NULL) {
ce = NULL;
} else {
zend_string *class_name = zval_get_string(scope_arg);
if (zend_string_equals_literal(class_name, "static")) {
ce = closure->func.common.scope;
} else if ((ce = zend_lookup_class_ex(class_name, NULL, 1)) == NULL) {
zend_error(E_WARNING, "Class '%s' not found", class_name->val);
zend_string_release(class_name);
RETURN_NULL();
}
zend_string_release(class_name);
}
if(ce && ce != closure->func.common.scope && ce->type == ZEND_INTERNAL_CLASS) {
/* rebinding to internal class is not allowed */
zend_error(E_WARNING, "Cannot bind closure to scope of internal class %s", ce->name->val);
return;
}
} else { /* scope argument not given; do not change the scope by default */
ce = closure->func.common.scope;
}
if (newthis) {
called_scope = Z_OBJCE_P(newthis);
} else {
called_scope = ce;
}
zend_create_closure(return_value, &closure->func, ce, called_scope, newthis);
}
示例12: _php_array_to_envp
/* {{{ _php_array_to_envp */
static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent)
{
zval *element;
php_process_env_t env;
zend_string *key, *str;
#ifndef PHP_WIN32
char **ep;
#endif
char *p;
size_t cnt, l, sizeenv = 0;
HashTable *env_hash;
memset(&env, 0, sizeof(env));
if (!environment) {
return env;
}
cnt = zend_hash_num_elements(Z_ARRVAL_P(environment));
if (cnt < 1) {
#ifndef PHP_WIN32
env.envarray = (char **) pecalloc(1, sizeof(char *), is_persistent);
#endif
env.envp = (char *) pecalloc(4, 1, is_persistent);
return env;
}
ALLOC_HASHTABLE(env_hash);
zend_hash_init(env_hash, cnt, NULL, NULL, 0);
/* first, we have to get the size of all the elements in the hash */
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(environment), key, element) {
str = zval_get_string(element);
if (ZSTR_LEN(str) == 0) {
zend_string_release(str);
continue;
}
sizeenv += ZSTR_LEN(str) + 1;
if (key && ZSTR_LEN(key)) {
sizeenv += ZSTR_LEN(key) + 1;
zend_hash_add_ptr(env_hash, key, str);
} else {
zend_hash_next_index_insert_ptr(env_hash, str);
}
} ZEND_HASH_FOREACH_END();
示例13: smart_str_appendz
void smart_str_appendz(smart_str *buffer, zval *value)
{
switch (Z_TYPE_P(value)) {
case IS_STRING:
smart_str_append(buffer, Z_STR_P(value));
return;
case IS_LONG:
smart_str_append_long(buffer, Z_LVAL_P(value));
return;
}
zend_string *str = zval_get_string(value);
smart_str_append(buffer, str);
zend_string_free(str);
}
示例14: PHP_FUNCTION
/* {{{ proto mixed hstore_encode(array hstore)
Decodes the hStore representation into a PHP value */
static PHP_FUNCTION(hstore_encode)
{
zval *array, *value;
zend_ulong num_idx;
zend_string *str_idx;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
return;
}
smart_str buf = {};
smart_str_alloc(&buf, 2048, 0);
zend_bool need_comma = 0;
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, value) {
if (need_comma) {
smart_str_appendl(&buf, ", ", 2);
} else {
need_comma = 1;
}
smart_str_appendc(&buf, '"');
if (str_idx) {
escape_string(&buf, str_idx);
} else {
smart_str_append_long(&buf, (long) num_idx);
}
smart_str_appendl(&buf, "\"=>", 3);
if (Z_TYPE_P(value) == IS_NULL) {
smart_str_appendl(&buf, "NULL", 4);
} else {
convert_to_string_ex(value);
smart_str_appendc(&buf, '"');
zend_string *str = zval_get_string(value);
escape_string(&buf, str);
zend_string_release(str);
smart_str_appendc(&buf, '"');
}
} ZEND_HASH_FOREACH_END();
smart_str_0(&buf); /* copy? */
ZVAL_NEW_STR(return_value, buf.s);
}
示例15: zlib_create_dictionary_string
static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict, size_t *dictlen) {
zval *option_buffer;
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) {
HashTable *dictionary;
ZVAL_DEREF(option_buffer);
if (Z_TYPE_P(option_buffer) != IS_ARRAY) {
php_error_docref(NULL, E_WARNING, "dictionary must be of type array, got %s", zend_get_type_by_const(Z_TYPE_P(option_buffer)));
return 0;
}
dictionary = Z_ARR_P(option_buffer);
if (zend_hash_num_elements(dictionary) > 0) {
char *dictptr;
zval *cur;
zend_string **strings = emalloc(sizeof(zend_string *) * zend_hash_num_elements(dictionary));
zend_string **end, **ptr = strings - 1;
ZEND_HASH_FOREACH_VAL(dictionary, cur) {
int i;
*++ptr = zval_get_string(cur);
if (!*ptr || (*ptr)->len == 0) {
if (*ptr) {
efree(*ptr);
}
while (--ptr >= strings) {
efree(ptr);
}
efree(strings);
php_error_docref(NULL, E_WARNING, "dictionary entries must be non-empty strings");
return 0;
}
for (i = 0; i < (*ptr)->len; i++) {
if ((*ptr)->val[i] == 0) {
do {
efree(ptr);
} while (--ptr >= strings);
efree(strings);
php_error_docref(NULL, E_WARNING, "dictionary entries must not contain a NULL-byte");
return 0;
}
}
*dictlen += (*ptr)->len + 1;
} ZEND_HASH_FOREACH_END();