update zend_make_printable_zval to take TSRM context

This commit is contained in:
krakjoe 2014-08-11 06:09:46 +01:00
parent 4513475a41
commit dc70139d85
12 changed files with 59 additions and 61 deletions

View File

@ -212,7 +212,7 @@ static void print_flat_hash(HashTable *ht TSRMLS_DC) /* {{{ */
} }
/* }}} */ /* }}} */
ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */ ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy TSRMLS_DC) /* {{{ */
{ {
if (Z_TYPE_P(expr) == IS_STRING) { if (Z_TYPE_P(expr) == IS_STRING) {
return 0; return 0;
@ -221,20 +221,16 @@ ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy) /* {{{ */
again: again:
switch (Z_TYPE_P(expr)) { switch (Z_TYPE_P(expr)) {
case IS_NULL: case IS_NULL:
case IS_FALSE: { case IS_FALSE:
TSRMLS_FETCH();
ZVAL_EMPTY_STRING(expr_copy); ZVAL_EMPTY_STRING(expr_copy);
break; break;
} case IS_TRUE:
case IS_TRUE: {
TSRMLS_FETCH();
if (CG(one_char_string)['1']) { if (CG(one_char_string)['1']) {
ZVAL_INT_STR(expr_copy, CG(one_char_string)['1']); ZVAL_INT_STR(expr_copy, CG(one_char_string)['1']);
} else { } else {
ZVAL_NEW_STR(expr_copy, STR_INIT("1", 1, 0)); ZVAL_NEW_STR(expr_copy, STR_INIT("1", 1, 0));
} }
break; break;
}
case IS_RESOURCE: { case IS_RESOURCE: {
char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG]; char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG];
int len; int len;
@ -249,35 +245,31 @@ again:
ZVAL_NEW_STR(expr_copy, STR_INIT("Array", sizeof("Array") - 1, 0)); ZVAL_NEW_STR(expr_copy, STR_INIT("Array", sizeof("Array") - 1, 0));
break; break;
case IS_OBJECT: case IS_OBJECT:
{ if (Z_OBJ_HANDLER_P(expr, cast_object)) {
TSRMLS_FETCH(); Z_ADDREF_P(expr);
if (Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
if (Z_OBJ_HANDLER_P(expr, cast_object)) {
Z_ADDREF_P(expr);
if (Z_OBJ_HANDLER_P(expr, cast_object)(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) {
zval_ptr_dtor(expr);
break;
}
zval_ptr_dtor(expr); zval_ptr_dtor(expr);
break;
} }
if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) { zval_ptr_dtor(expr);
zval rv;
zval *z = Z_OBJ_HANDLER_P(expr, get)(expr, &rv TSRMLS_CC);
Z_ADDREF_P(z);
if (Z_TYPE_P(z) != IS_OBJECT) {
if (zend_make_printable_zval(z, expr_copy)) {
zval_ptr_dtor(z);
} else {
ZVAL_ZVAL(expr_copy, z, 0, 1);
}
return 1;
}
zval_ptr_dtor(z);
}
zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name->val);
ZVAL_EMPTY_STRING(expr_copy);
} }
if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) {
zval rv;
zval *z = Z_OBJ_HANDLER_P(expr, get)(expr, &rv TSRMLS_CC);
Z_ADDREF_P(z);
if (Z_TYPE_P(z) != IS_OBJECT) {
if (zend_make_printable_zval(z, expr_copy TSRMLS_CC)) {
zval_ptr_dtor(z);
} else {
ZVAL_ZVAL(expr_copy, z, 0, 1);
}
return 1;
}
zval_ptr_dtor(z);
}
zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(expr)->name->val);
ZVAL_EMPTY_STRING(expr_copy);
break; break;
case IS_DOUBLE: case IS_DOUBLE:
ZVAL_DUP(expr_copy, expr); ZVAL_DUP(expr_copy, expr);

View File

@ -609,7 +609,7 @@ END_EXTERN_C()
BEGIN_EXTERN_C() BEGIN_EXTERN_C()
ZEND_API char *get_zend_version(void); ZEND_API char *get_zend_version(void);
ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy); ZEND_API int zend_make_printable_zval(zval *expr, zval *expr_copy TSRMLS_DC);
ZEND_API int zend_print_zval(zval *expr, int indent TSRMLS_DC); ZEND_API int zend_print_zval(zval *expr, int indent TSRMLS_DC);
ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC); ZEND_API int zend_print_zval_ex(zend_write_func_t write_func, zval *expr, int indent TSRMLS_DC);
ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC); ZEND_API void zend_print_zval_r(zval *expr, int indent TSRMLS_DC);

View File

@ -249,7 +249,7 @@ static int parse_arg_object_to_string(zval *arg, char **p, int *pl, int type TSR
if(Z_TYPE_P(z) != IS_OBJECT) { if(Z_TYPE_P(z) != IS_OBJECT) {
zval_dtor(arg); zval_dtor(arg);
ZVAL_NULL(arg); ZVAL_NULL(arg);
if (!zend_make_printable_zval(z, arg)) { if (!zend_make_printable_zval(z, arg TSRMLS_CC)) {
ZVAL_ZVAL(arg, z, 1, 1); ZVAL_ZVAL(arg, z, 1, 1);
} }
*pl = Z_STRLEN_P(arg); *pl = Z_STRLEN_P(arg);
@ -288,7 +288,7 @@ ZEND_API int parse_arg_object_to_str(zval *arg, zend_string **str, int type TSRM
if(Z_TYPE_P(z) != IS_OBJECT) { if(Z_TYPE_P(z) != IS_OBJECT) {
zval_dtor(arg); zval_dtor(arg);
ZVAL_NULL(arg); ZVAL_NULL(arg);
if (!zend_make_printable_zval(z, arg)) { if (!zend_make_printable_zval(z, arg TSRMLS_CC)) {
ZVAL_ZVAL(arg, z, 1, 1); ZVAL_ZVAL(arg, z, 1, 1);
} }
*str = Z_STR_P(arg); *str = Z_STR_P(arg);

View File

@ -1552,10 +1552,10 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_CONCAT); ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_CONCAT);
if (Z_TYPE_P(op1) != IS_STRING) { if (Z_TYPE_P(op1) != IS_STRING) {
use_copy1 = zend_make_printable_zval(op1, &op1_copy); use_copy1 = zend_make_printable_zval(op1, &op1_copy TSRMLS_CC);
} }
if (Z_TYPE_P(op2) != IS_STRING) { if (Z_TYPE_P(op2) != IS_STRING) {
use_copy2 = zend_make_printable_zval(op2, &op2_copy); use_copy2 = zend_make_printable_zval(op2, &op2_copy TSRMLS_CC);
} }
} }

View File

@ -2124,7 +2124,7 @@ ZEND_VM_HANDLER(56, ZEND_ADD_VAR, TMP|UNUSED, TMP|VAR|CV)
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;

View File

@ -10334,7 +10334,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_TMP_TMP_HANDLER(ZEND_OPCODE_HANDLER_
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;
@ -11174,7 +11174,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;
@ -12567,7 +12567,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_A
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;
@ -26721,7 +26721,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDL
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;
@ -28002,7 +28002,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_UNUSED_VAR_HANDLER(ZEND_OPCODE_HANDL
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;
@ -29794,7 +29794,7 @@ static int ZEND_FASTCALL ZEND_ADD_VAR_SPEC_UNUSED_CV_HANDLER(ZEND_OPCODE_HANDLE
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
ZVAL_DEREF(var); ZVAL_DEREF(var);
if (Z_TYPE_P(var) != IS_STRING) { if (Z_TYPE_P(var) != IS_STRING) {
use_copy = zend_make_printable_zval(var, &var_copy); use_copy = zend_make_printable_zval(var, &var_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
var = &var_copy; var = &var_copy;

View File

@ -392,7 +392,7 @@ zval* collator_convert_string_to_number_if_possible( zval* str, zval *rv )
* *
* @return zval* UTF16 string. * @return zval* UTF16 string.
*/ */
zval* collator_make_printable_zval( zval* arg, zval *rv ) zval* collator_make_printable_zval( zval* arg, zval *rv)
{ {
zval arg_copy; zval arg_copy;
int use_copy = 0; int use_copy = 0;
@ -400,7 +400,9 @@ zval* collator_make_printable_zval( zval* arg, zval *rv )
if( Z_TYPE_P(arg) != IS_STRING ) if( Z_TYPE_P(arg) != IS_STRING )
{ {
use_copy = zend_make_printable_zval(arg, &arg_copy); TSRMLS_FETCH();
use_copy = zend_make_printable_zval(arg, &arg_copy TSRMLS_CC);
if( use_copy ) if( use_copy )
{ {

View File

@ -273,7 +273,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
for (i = 0; i < op_array->last_literal; i++) { for (i = 0; i < op_array->last_literal; i++) {
zval zv = op_array->literals[i].constant; zval zv = op_array->literals[i].constant;
use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv); use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv TSRMLS_CC);
fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv)); fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv));
if (use_copy) { if (use_copy) {
zval_dtor(&zv); zval_dtor(&zv);
@ -454,7 +454,7 @@ static void optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_c
for (i = 0; i < op_array->last_literal; i++) { for (i = 0; i < op_array->last_literal; i++) {
zval zv = op_array->literals[i].constant; zval zv = op_array->literals[i].constant;
use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv); use_copy = zend_make_printable_zval(&op_array->literals[i].constant, &zv TSRMLS_CC);
fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv)); fprintf(stderr, "Literal %d, val (%d):%s\n", i, Z_STRLEN(zv), Z_STRVAL(zv));
if (use_copy) { if (use_copy) {
zval_dtor(&zv); zval_dtor(&zv);

View File

@ -1270,7 +1270,7 @@ SPL_METHOD(RecursiveTreeIterator, key)
} }
if (Z_TYPE(key) != IS_STRING) { if (Z_TYPE(key) != IS_STRING) {
if (zend_make_printable_zval(&key, &key_copy)) { if (zend_make_printable_zval(&key, &key_copy TSRMLS_CC)) {
key = key_copy; key = key_copy;
} }
} }
@ -2047,7 +2047,7 @@ SPL_METHOD(RegexIterator, accept)
} }
ZVAL_UNDEF(&subject_copy); ZVAL_UNDEF(&subject_copy);
use_copy = zend_make_printable_zval(subject_ptr, &subject_copy); use_copy = zend_make_printable_zval(subject_ptr, &subject_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
subject = Z_STRVAL(subject_copy); subject = Z_STRVAL(subject_copy);
subject_len = Z_STRLEN(subject_copy); subject_len = Z_STRLEN(subject_copy);
@ -2684,7 +2684,7 @@ static inline void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC)
} else { } else {
ZVAL_COPY_VALUE(&intern->u.caching.zstr, &intern->current.data); ZVAL_COPY_VALUE(&intern->u.caching.zstr, &intern->current.data);
} }
use_copy = zend_make_printable_zval(&intern->u.caching.zstr, &expr_copy); use_copy = zend_make_printable_zval(&intern->u.caching.zstr, &expr_copy TSRMLS_CC);
if (use_copy) { if (use_copy) {
ZVAL_COPY(&intern->u.caching.zstr, &expr_copy); ZVAL_COPY(&intern->u.caching.zstr, &expr_copy);
//??? INIT_PZVAL(intern->u.caching.zstr); //??? INIT_PZVAL(intern->u.caching.zstr);

View File

@ -442,7 +442,7 @@ static int _call_message_handler(zval *callback_name, CS_SERVERMSG *srvmsg TSRML
zval expr_copy; zval expr_copy;
int use_copy; int use_copy;
use_copy = zend_make_printable_zval(callback_name, &expr_copy); use_copy = zend_make_printable_zval(callback_name, &expr_copy TSRMLS_CC);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Cannot call the messagehandler %s", Z_STRVAL(expr_copy)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Sybase: Cannot call the messagehandler %s", Z_STRVAL(expr_copy));
zval_dtor(&expr_copy); zval_dtor(&expr_copy);
} }

View File

@ -781,9 +781,10 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
* It is reset to ' ' by non-numeric formats * It is reset to ' ' by non-numeric formats
*/ */
switch (*fmt) { switch (*fmt) {
case 'Z': case 'Z': {
zvp = (zval*) va_arg(ap, zval*); TSRMLS_FETCH();
free_zcopy = zend_make_printable_zval(zvp, &zcopy); zvp = (zval*) va_arg(ap, zval*);
free_zcopy = zend_make_printable_zval(zvp, &zcopy TSRMLS_CC);
if (free_zcopy) { if (free_zcopy) {
zvp = &zcopy; zvp = &zcopy;
} }
@ -791,8 +792,9 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
s = Z_STRVAL_P(zvp); s = Z_STRVAL_P(zvp);
if (adjust_precision && precision < s_len) { if (adjust_precision && precision < s_len) {
s_len = precision; s_len = precision;
} }
break; break;
}
case 'u': case 'u':
switch(modifier) { switch(modifier) {
default: default:

View File

@ -389,9 +389,10 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
* It is reset to ' ' by non-numeric formats * It is reset to ' ' by non-numeric formats
*/ */
switch (*fmt) { switch (*fmt) {
case 'Z': case 'Z': {
TSRMLS_FETCH();
zvp = (zval*) va_arg(ap, zval*); zvp = (zval*) va_arg(ap, zval*);
free_zcopy = zend_make_printable_zval(zvp, &zcopy); free_zcopy = zend_make_printable_zval(zvp, &zcopy TSRMLS_CC);
if (free_zcopy) { if (free_zcopy) {
zvp = &zcopy; zvp = &zcopy;
} }
@ -401,6 +402,7 @@ static void xbuf_format_converter(void *xbuf, zend_bool is_char, const char *fmt
s_len = precision; s_len = precision;
} }
break; break;
}
case 'u': case 'u':
switch(modifier) { switch(modifier) {
default: default: