/* {{{ Smart string functions */
typedef struct _string {
- char *string;
- int len;
+ zend_string *buf;
int alloced;
} string;
static void string_init(string *str)
{
- str->string = (char *) emalloc(1024);
- str->len = 1;
+ str->buf= STR_ALLOC(1024, 0);
str->alloced = 1024;
- *str->string = '\0';
+ str->buf->val[0] = '\0';
+ str->buf->len = 0;
}
static string *string_printf(string *str, const char *format, ...)
va_start(arg, format);
len = zend_vspprintf(&s_tmp, 0, format, arg);
if (len) {
- register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1);
+ register int nlen = (str->buf->len + 1 + len + (1024 - 1)) & ~(1024 - 1);
if (str->alloced < nlen) {
+ int old_len = str->buf->len;
str->alloced = nlen;
- str->string = erealloc(str->string, str->alloced);
+ str->buf = STR_REALLOC(str->buf, str->alloced, 0);
+ str->buf->len = old_len;
}
- memcpy(str->string + str->len - 1, s_tmp, len + 1);
- str->len += len;
+ memcpy(str->buf->val + str->buf->len, s_tmp, len + 1);
+ str->buf->len += len;
}
efree(s_tmp);
va_end(arg);
static string *string_write(string *str, char *buf, int len)
{
- register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1);
+ register int nlen = (str->buf->len + 1 + len + (1024 - 1)) & ~(1024 - 1);
if (str->alloced < nlen) {
+ int old_len = str->buf->len;
str->alloced = nlen;
- str->string = erealloc(str->string, str->alloced);
+ str->buf = STR_REALLOC(str->buf, str->alloced, 0);
+ str->buf->len = old_len;
}
- memcpy(str->string + str->len - 1, buf, len);
- str->len += len;
- str->string[str->len - 1] = '\0';
+ memcpy(str->buf->val + str->buf->len, buf, len);
+ str->buf->len += len;
+ str->buf->val[str->buf->len] = '\0';
return str;
}
static string *string_append(string *str, string *append)
{
- if (append->len > 1) {
- string_write(str, append->string, append->len - 1);
+ if (append->buf->len > 0) {
+ string_write(str, append->buf->val, append->buf->len);
}
return str;
}
static void string_free(string *str)
{
- efree(str->string);
- str->len = 0;
+ STR_RELEASE(str->buf);
str->alloced = 0;
- str->string = NULL;
+ str->buf = NULL;
}
/* }}} */
&& fptr->type == ZEND_INTERNAL_FUNCTION
&& (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0)
{
- efree((char*)fptr->internal_function.function_name);
+ STR_RELEASE(fptr->internal_function.function_name);
efree(fptr);
}
}
string_write(str, "\n", 1);
}
- if (obj) {
+ if (obj && Z_TYPE_P(obj) == IS_OBJECT) {
string_printf(str, "%sObject of class [ ", indent);
} else {
char *kind = "Class";
}
string_printf(str, "class ");
}
- string_printf(str, "%s", ce->name);
+ string_printf(str, "%s", ce->name->val);
if (ce->parent) {
- string_printf(str, " extends %s", ce->parent->name);
+ string_printf(str, " extends %s", ce->parent->name->val);
}
if (ce->num_interfaces) {
zend_uint i;
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
- string_printf(str, " extends %s", ce->interfaces[0]->name);
+ string_printf(str, " extends %s", ce->interfaces[0]->name->val);
} else {
- string_printf(str, " implements %s", ce->interfaces[0]->name);
+ string_printf(str, " implements %s", ce->interfaces[0]->name->val);
}
for (i = 1; i < ce->num_interfaces; ++i) {
- string_printf(str, ", %s", ce->interfaces[i]->name);
+ string_printf(str, ", %s", ce->interfaces[i]->name->val);
}
}
string_printf(str, " ] {\n");
/* The information where a class is declared is only available for user classes */
if (ce->type == ZEND_USER_CLASS) {
- string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename,
+ string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename->val,
ce->info.user.line_start, ce->info.user.line_end);
}
while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) {
if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) {
- _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC);
+ _property_string(str, prop, NULL, sub_indent.buf->val TSRMLS_CC);
}
zend_hash_move_forward_ex(&ce->properties_info, &pos);
&& ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
{
string_printf(str, "\n");
- _function_string(str, mptr, ce, sub_indent.string TSRMLS_CC);
+ _function_string(str, mptr, ce, sub_indent.buf->val TSRMLS_CC);
}
zend_hash_move_forward_ex(&ce->function_table, &pos);
}
while ((prop = zend_hash_get_current_data_ptr_ex(&ce->properties_info, &pos)) != NULL) {
if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) {
- _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC);
+ _property_string(str, prop, NULL, sub_indent.buf->val TSRMLS_CC);
}
zend_hash_move_forward_ex(&ce->properties_info, &pos);
}
string_printf(str, "%s }\n", indent);
}
- if (obj && Z_OBJ_HT_P(obj)->get_properties) {
+ if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) {
string dyn;
HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj TSRMLS_CC);
HashPosition pos;
if (prop_name->len && prop_name->val[0]) { /* skip all private and protected properties */
if (!zend_hash_exists(&ce->properties_info, prop_name)) {
count++;
- _property_string(&dyn, NULL, prop_name->val, sub_indent.string TSRMLS_CC);
+ _property_string(&dyn, NULL, prop_name->val, sub_indent.buf->val TSRMLS_CC);
}
}
efree(prop_name);
zend_function *closure;
/* see if this is a closure */
if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1)
- && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
+ && memcmp(mptr->common.function_name->val, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0
&& (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL)
{
mptr = closure;
closure = NULL;
}
string_printf(&dyn, "\n");
- _function_string(&dyn, mptr, ce, sub_indent.string TSRMLS_CC);
+ _function_string(&dyn, mptr, ce, sub_indent.buf->val TSRMLS_CC);
count++;
_free_function(closure TSRMLS_CC);
}
if (scope && fptr->common.scope) {
if (fptr->common.scope != scope) {
- string_printf(str, ", inherits %s", fptr->common.scope->name);
+ string_printf(str, ", inherits %s", fptr->common.scope->name->val);
} else if (fptr->common.scope->parent) {
lc_name_len = fptr->common.function_name->len;
lc_name = STR_ALLOC(lc_name_len, 0);
zend_str_tolower_copy(lc_name->val, fptr->common.function_name->val, lc_name_len);
if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) {
if (fptr->common.scope != overwrites->common.scope) {
- string_printf(str, ", overwrites %s", overwrites->common.scope->name);
+ string_printf(str, ", overwrites %s", overwrites->common.scope->name->val);
}
}
efree(lc_name);
}
}
if (fptr->common.prototype && fptr->common.prototype->common.scope) {
- string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name);
+ string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name->val);
}
if (fptr->common.fn_flags & ZEND_ACC_CTOR) {
string_printf(str, ", ctor");
if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
string_printf(str, "&");
}
- string_printf(str, "%s ] {\n", fptr->common.function_name);
+ string_printf(str, "%s ] {\n", fptr->common.function_name->val);
/* The information where a function is declared is only available for user classes */
if (fptr->type == ZEND_USER_FUNCTION) {
string_printf(str, "%s @@ %s %d - %d\n", indent,
- fptr->op_array.filename,
+ fptr->op_array.filename->val,
fptr->op_array.line_start,
fptr->op_array.line_end);
}
string_init(¶m_indent);
string_printf(¶m_indent, "%s ", indent);
if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) {
- _function_closure_string(str, fptr, param_indent.string TSRMLS_CC);
+ _function_closure_string(str, fptr, param_indent.buf->val TSRMLS_CC);
}
- _function_parameter_string(str, fptr, param_indent.string TSRMLS_CC);
+ _function_parameter_string(str, fptr, param_indent.buf->val TSRMLS_CC);
string_free(¶m_indent);
string_printf(str, "%s}\n", indent);
}
string str_ini;
string_init(&str_ini);
zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number);
- if (str_ini.len > 1) {
+ if (str_ini.buf->len > 0) {
string_printf(str, "\n - INI {\n");
string_append(str, &str_ini);
string_printf(str, "%s }\n", indent);
string_init(&sub_indent);
string_printf(&sub_indent, "%s ", indent);
string_init(&str_classes);
- zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.string, module, &num_classes);
+ zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.buf->val, module, &num_classes);
if (num_classes) {
string_printf(str, "\n - Classes [%d] {", num_classes);
string_append(str, &str_classes);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &argument_ptr, &return_output) == FAILURE) {
return;
}
+ ZVAL_COPY_VALUE(¶ms[0], argument_ptr);
+ ZVAL_NULL(¶ms[1]);
} else {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) {
return;
}
+ ZVAL_COPY_VALUE(¶ms[0], argument_ptr);
+ ZVAL_COPY_VALUE(¶ms[1], argument2_ptr);
}
//??? INIT_PZVAL(&output);
}
/* Call __construct() */
- ZVAL_COPY_VALUE(¶ms[0], argument_ptr);
- ZVAL_COPY_VALUE(¶ms[1], argument2_ptr);
fci.size = sizeof(fci);
fci.function_table = NULL;
ZVAL_COPY_VALUE(¶ms[0], &reflector);
ZVAL_COPY_VALUE(¶ms[1], output_ptr);
-//??? ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0);
- ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1);
+ ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1);
fci.function_table = &reflection_ptr->function_table;
fci.object_ptr = NULL;
fci.retval = &retval;
result = zend_call_function(&fci, NULL TSRMLS_CC);
+ zval_ptr_dtor(&fci.function_name);
+
if (result == FAILURE && EG(exception) == NULL) {
zval_ptr_dtor(&reflector);
zval_ptr_dtor(&retval);
GET_REFLECTION_OBJECT_PTR(fptr);
string_init(&str);
_function_string(&str, fptr, intern->ce, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
ZEND_METHOD(reflection_function, invoke)
{
zval retval;
-//???
zval *params = NULL;
int result, num_args = 0;
zend_fcall_info fci;
if (result == FAILURE) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of function %s() failed", fptr->common.function_name);
+ "Invocation of function %s() failed", fptr->common.function_name->val);
return;
}
if (result == FAILURE) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of function %s() failed", fptr->common.function_name);
+ "Invocation of function %s() failed", fptr->common.function_name->val);
return;
}
is_closure = 1;
} else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME))) == NULL) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s() does not exist", ce->name, ZEND_INVOKE_FUNC_NAME);
+ "Method %s::%s() does not exist", ce->name->val, ZEND_INVOKE_FUNC_NAME);
return;
}
}
GET_REFLECTION_OBJECT_PTR(param);
string_init(&str);
_parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "" TSRMLS_CC);
-///??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
GET_REFLECTION_OBJECT_PTR(mptr);
string_init(&str);
_function_string(&str, mptr, intern->ce, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
ZEND_METHOD(reflection_method, invoke)
{
zval retval;
-//???
zval *params = NULL;
zval object;
reflection_object *intern;
if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Trying to invoke abstract method %s::%s()",
- mptr->common.scope->name, mptr->common.function_name);
+ mptr->common.scope->name->val, mptr->common.function_name->val);
} else {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Trying to invoke %s method %s::%s() from scope %s",
mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
- mptr->common.scope->name, mptr->common.function_name,
- Z_OBJCE_P(getThis())->name);
+ mptr->common.scope->name->val, mptr->common.function_name->val,
+ Z_OBJCE_P(getThis())->name->val);
}
return;
}
if (result == FAILURE) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name);
+ "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val);
return;
}
if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Trying to invoke abstract method %s::%s()",
- mptr->common.scope->name, mptr->common.function_name);
+ mptr->common.scope->name->val, mptr->common.function_name->val);
} else {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Trying to invoke %s method %s::%s() from scope %s",
mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
- mptr->common.scope->name, mptr->common.function_name,
- Z_OBJCE_P(getThis())->name);
+ mptr->common.scope->name->val, mptr->common.function_name->val,
+ Z_OBJCE_P(getThis())->name->val);
}
return;
}
efree(params);
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
"Trying to invoke non static method %s::%s() without an object",
- mptr->common.scope->name, mptr->common.function_name);
+ mptr->common.scope->name->val, mptr->common.function_name->val);
return;
}
if (result == FAILURE) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name);
+ "Invocation of method %s::%s() failed", mptr->common.scope->name->val, mptr->common.function_name->val);
return;
}
if (!mptr->common.prototype) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Method %s::%s does not have a prototype", intern->ce->name, mptr->common.function_name);
+ "Method %s::%s does not have a prototype", intern->ce->name->val, mptr->common.function_name->val);
return;
}
GET_REFLECTION_OBJECT_PTR(ce);
string_init(&str);
_class_string(&str, ce, &intern->obj, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
}
if (!instanceof_function(ce, ce2 TSRMLS_CC)) {
- zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name, str_name, ce->name->val);
+ zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", ce2->name->val, str_name, ce->name->val);
return;
}
ce = ce2;
/* Run the constructor if there is one */
if (constructor) {
-//???
zval *params = NULL;
int num_args = 0;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name->val);
zval_dtor(return_value);
RETURN_NULL();
}
efree(params);
}
} else if (ZEND_NUM_ARGS()) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name);
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name->val);
}
}
/* }}} */
GET_REFLECTION_OBJECT_PTR(ce);
if (ce->create_object != NULL) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name);
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class that cannot be instantiated without invoking its constructor", ce->name->val);
}
object_init_ex(return_value, ce);
/* Run the constructor if there is one */
if (constructor) {
-//???
zval *params = NULL;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name);
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name->val);
zval_dtor(return_value);
RETURN_NULL();
}
if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) {
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Interface %s is a Class", interface_ce->name);
+ "Interface %s is a Class", interface_ce->name->val);
return;
}
RETURN_BOOL(instanceof_function(ce, interface_ce TSRMLS_CC));
}
}
if (dynam_prop == 0) {
- zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str);
+ zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name->val, name_str);
return;
}
}
GET_REFLECTION_OBJECT_PTR(ref);
string_init(&str);
_property_string(&str, &ref->prop, NULL, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) {
_default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC);
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name));
+ "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name));
zval_dtor(&name);
return;
}
if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) {
_default_get_entry(getThis(), "name", sizeof("name")-1, &name TSRMLS_CC);
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name));
+ "Cannot access non-public member %s::%s", intern->ce->name->val, Z_STRVAL(name));
zval_dtor(&name);
return;
}
GET_REFLECTION_OBJECT_PTR(module);
string_init(&str);
_extension_string(&str, module, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
if (number == constant->module_number) {
ZVAL_DUP(&const_val, &constant->value);
//??? INIT_PZVAL(const_val);
-//???
+
add_assoc_zval_ex(retval, constant->name->val, constant->name->len, &const_val);
}
return 0;
GET_REFLECTION_OBJECT_PTR(extension);
string_init(&str);
_zend_extension_string(&str, extension, "" TSRMLS_CC);
-//??? RETURN_STRINGL(str.string, str.len - 1, 0);
- RETURN_STRINGL(str.string, str.len - 1);
+ RETURN_STR(str.buf);
}
/* }}} */
|| (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class")))))
{
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
- "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name, Z_STRVAL_P(member));
+ "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name->val, Z_STRVAL_P(member));
}
else
{