X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fmodule.c;h=b06e0bd32a8d255b2cb50bc0c01c7e5b3efa0e5f;hb=514614a6765283ca9c74a48b0f6c6fd24d6fd8e2;hp=b5c8d2ba450205fdc6c2e05eef9041773ef769bf;hpb=f18f62c084371e0da16305db4de27bfa124934c1;p=m6w6%2Fext-psi diff --git a/src/module.c b/src/module.c index b5c8d2b..b06e0bd 100644 --- a/src/module.c +++ b/src/module.c @@ -6,6 +6,9 @@ #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" +#include "zend_exceptions.h" +#include "zend_constants.h" +#include "zend_operators.h" #include "php_psi.h" #include "parser.h" @@ -28,6 +31,9 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("psi.directory", "psi.d", PHP_INI_SYSTEM, OnUpdateString, directory, zend_psi_globals, psi_globals) PHP_INI_END(); +static zend_object_handlers psi_object_handlers; +static zend_class_entry *psi_class_entry; + void psi_error(int type, const char *msg, ...) { char buf[0x1000]; @@ -42,99 +48,46 @@ void psi_error(int type, const char *msg, ...) size_t psi_t_alignment(token_t t) { - size_t align; -#define PSI_TAS_D(T) struct PSI_TAS_ ##T { \ - char c; \ - T x; \ -} -#define PSI_TAS_P(T) struct PSI_TAS_ ## T ## _pointer { \ - char c; \ - T *x; \ -} -#define PSI_TAS_C(T) align = offsetof(struct PSI_TAS_ ##T, x) -#define PSI_TAS_CASE(T) { \ - PSI_TAS_D(T); \ - PSI_TAS_C(T); \ -} +#define PSI_ALIGNOF(T) case PSI_T_## T: return ALIGNOF_## T ##_T; switch (t) { - case PSI_T_INT8: - PSI_TAS_CASE(int8_t); - break; - case PSI_T_UINT8: - PSI_TAS_CASE(uint8_t); - break; - case PSI_T_INT16: - PSI_TAS_CASE(int16_t); - break; - case PSI_T_UINT16: - PSI_TAS_CASE(uint16_t); - break; - case PSI_T_INT32: - PSI_TAS_CASE(int32_t); - break; - case PSI_T_UINT32: - PSI_TAS_CASE(uint32_t); - break; - case PSI_T_INT64: - PSI_TAS_CASE(int64_t); - break; - case PSI_T_UINT64: - PSI_TAS_CASE(uint64_t); - break; + PSI_ALIGNOF(INT8); + PSI_ALIGNOF(UINT8); + PSI_ALIGNOF(INT16); + PSI_ALIGNOF(UINT16); + PSI_ALIGNOF(INT32); + PSI_ALIGNOF(UINT32); + PSI_ALIGNOF(INT64); + PSI_ALIGNOF(UINT64); case PSI_T_FLOAT: - PSI_TAS_CASE(float); - break; + return ALIGNOF_FLOAT; case PSI_T_DOUBLE: - PSI_TAS_CASE(double); - break; + return ALIGNOF_DOUBLE; case PSI_T_POINTER: - { - PSI_TAS_P(char); - PSI_TAS_C(char_pointer); - } - break; + return ALIGNOF_VOID_P; EMPTY_SWITCH_DEFAULT_CASE(); } - - return align; } size_t psi_t_size(token_t t) { - size_t size; - +#define PSI_SIZEOF(T) case PSI_T_## T : return SIZEOF_## T ##_T; switch (t) { - case PSI_T_INT8: - case PSI_T_UINT8: - size = 1; - break; - case PSI_T_INT16: - case PSI_T_UINT16: - size = 2; - break; - case PSI_T_INT: - size = sizeof(int); - break; - case PSI_T_INT32: - case PSI_T_UINT32: - size = 4; - break; - case PSI_T_INT64: - case PSI_T_UINT64: - size = 8; - break; + PSI_SIZEOF(INT8); + PSI_SIZEOF(UINT8); + PSI_SIZEOF(INT16); + PSI_SIZEOF(UINT16); + PSI_SIZEOF(INT32); + PSI_SIZEOF(UINT32); + PSI_SIZEOF(INT64); + PSI_SIZEOF(UINT64); case PSI_T_FLOAT: - size = sizeof(float); - break; + return SIZEOF_FLOAT; case PSI_T_DOUBLE: - size = sizeof(double); - break; + return SIZEOF_DOUBLE; case PSI_T_POINTER: - size = sizeof(char *); - break; + return SIZEOF_VOID_P; EMPTY_SWITCH_DEFAULT_CASE(); } - return size; } size_t psi_t_align(token_t t, size_t s) @@ -204,6 +157,11 @@ size_t psi_num_min_args(impl *impl) return n; } +void psi_to_void(zval *return_value, set_value *set, impl_val *ret_val) +{ + RETVAL_NULL(); +} + void psi_to_bool(zval *return_value, set_value *set, impl_val *ret_val) { psi_to_int(return_value, set, ret_val); @@ -282,9 +240,31 @@ void psi_to_double(zval *return_value, set_value *set, impl_val *ret_val) case PSI_T_DOUBLE: RETVAL_DOUBLE(v->dval); break; - default: - RETVAL_DOUBLE((double) v->lval); + case PSI_T_INT8: + RETVAL_DOUBLE((double) v->i8); + break; + case PSI_T_UINT8: + RETVAL_DOUBLE((double) v->u8); + break; + case PSI_T_INT16: + RETVAL_DOUBLE((double) v->i16); + break; + case PSI_T_UINT16: + RETVAL_DOUBLE((double) v->u16); break; + case PSI_T_INT32: + RETVAL_DOUBLE((double) v->i32); + break; + case PSI_T_UINT32: + RETVAL_DOUBLE((double) v->u32); + break; + case PSI_T_INT64: + RETVAL_DOUBLE((double) v->i64); + break; + case PSI_T_UINT64: + RETVAL_DOUBLE((double) v->u64); + break; + EMPTY_SWITCH_DEFAULT_CASE(); } } @@ -294,6 +274,7 @@ void psi_to_string(zval *return_value, set_value *set, impl_val *ret_val) token_t t = real_decl_type(var->arg->type)->type; switch (t) { + case PSI_T_VOID: case PSI_T_INT8: case PSI_T_UINT8: if (!var->arg->var->pointer_level) { @@ -314,7 +295,7 @@ void psi_to_string(zval *return_value, set_value *set, impl_val *ret_val) RETVAL_DOUBLE(deref_impl_val(ret_val, var)->dval); break; default: - RETVAL_LONG(deref_impl_val(ret_val, var)->lval); + psi_to_int(return_value, set, ret_val); break; } convert_to_string(return_value); @@ -378,16 +359,6 @@ void *psi_array_to_struct(decl_struct *s, HashTable *arr) return mem; } -static inline impl_val *struct_member_ref(decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) { - void *ptr = (char *) struct_ptr->ptr + set_arg->layout->pos; - impl_val *val = enref_impl_val(ptr, set_arg->var); - - if (val != ptr) { - *to_free = val; - } - - return val; -} void psi_to_array(zval *return_value, set_value *set, impl_val *r_val) { size_t i; @@ -450,12 +421,12 @@ void psi_to_array(zval *return_value, set_value *set, impl_val *r_val) } else if (set->vars->count > 1) { /* to_array(arr_var, cnt_var[, cnt_var...], to_int(*arr_var)) * check for length in second var - */ + * / size_t count = 0; zval ele; if (set->outer.set) { - /* struct */ + /* struct *//* for (i = 1; i < set->vars->count; ++i) { impl_val *tmp = NULL, *cnt_val; decl_var *cnt_var = set->vars->vars[i]; @@ -475,21 +446,56 @@ void psi_to_array(zval *return_value, set_value *set, impl_val *r_val) size_t size = psi_t_size(var->arg->var->pointer_level ? PSI_T_POINTER : t); impl_val *ptr = iterate(ret_val, size, i, &tmp); + set->inner[0]->func->handler(&ele, set->inner[0], ptr); + add_next_index_zval(return_value, &ele); + } + */ + } else if (set->num) { + /* to_array(arr_var, num_expr, to_int(*arr_var)) + */ + zval ele; + zend_long i, n = psi_long_num_exp(set->num, set->outer.val); + + for (i = 0; i < n; ++i) { + size_t size = psi_t_size(var->arg->var->pointer_level ? PSI_T_POINTER : t); + impl_val *ptr = iterate(ret_val, size, i, &tmp); + set->inner[0]->func->handler(&ele, set->inner[0], ptr); add_next_index_zval(return_value, &ele); } } else { ZEND_ASSERT(0); } +} + +void psi_to_object(zval *return_value, set_value *set, impl_val *r_val) +{ + decl_var *var = set->vars->vars[0]; + impl_val *ret_val = deref_impl_val(r_val, var); + psi_object *obj; + if (ret_val->ptr) { + object_init_ex(return_value, psi_class_entry); + obj = PSI_OBJ(return_value, NULL); + obj->data = ret_val->ptr; + } else { + RETVAL_NULL(); + } } static inline ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, impl *impl) { impl_arg *iarg; + zend_error_handling zeh; + + zend_replace_error_handling(EH_THROW, zend_exception_get_default(), &zeh); if (!impl->func->args->count) { - return zend_parse_parameters_none(); + ZEND_RESULT_CODE rv; + + rv = zend_parse_parameters_none(); + zend_restore_error_handling(&zeh); + return rv; } ZEND_PARSE_PARAMETERS_START(psi_num_min_args(impl), impl->func->args->count) @@ -528,7 +534,9 @@ static inline ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, i } } else if (PSI_T_ARRAY == iarg->type->type) { /* handled as _zv in let or set */ - Z_PARAM_PROLOGUE(0); + Z_PARAM_ARRAY_EX(iarg->_zv, 1, 0); + } else if (PSI_T_OBJECT == iarg->type->type) { + Z_PARAM_OBJECT_EX(iarg->_zv, 1, 0); } else { error_code = ZPP_ERROR_FAILURE; break; @@ -537,24 +545,21 @@ static inline ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, i if (_i < _max_num_args) { goto nextarg; } - ZEND_PARSE_PARAMETERS_END_EX(return FAILURE); + ZEND_PARSE_PARAMETERS_END_EX( + zend_restore_error_handling(&zeh); + return FAILURE + ); + zend_restore_error_handling(&zeh); return SUCCESS; } static inline void *psi_do_calloc(let_calloc *alloc) { - decl_type *type = real_decl_type(alloc->type); - size_t size; - - if (type->type == PSI_T_STRUCT) { - /* psi_do_clean expects at least one NULL pointer after the struct */ - size = type->strct->size + sizeof(void *); - } else { - size = psi_t_size(type->type); - } - - return ecalloc(alloc->n, size); + zend_long n = psi_long_num_exp(alloc->nmemb, NULL), s = psi_long_num_exp(alloc->size, NULL); + void *mem = safe_emalloc(n, s, sizeof(void *)); + memset(mem, 0, n * s + sizeof(void *)); + return mem; } static inline void *psi_do_let(decl_arg *darg) @@ -596,6 +601,7 @@ static inline void *psi_do_let(decl_arg *darg) arg_val->lval = zval_get_long(iarg->_zv); } break; + case PSI_T_PATHVAL: case PSI_T_STRVAL: if (iarg->type->type == PSI_T_STRING) { arg_val->ptr = estrdup(iarg->val.zend.str->val); @@ -607,6 +613,12 @@ static inline void *psi_do_let(decl_arg *darg) darg->let->mem = arg_val->ptr; zend_string_release(zs); } + if (PSI_T_PATHVAL == darg->let->val->func->type) { + if (SUCCESS != php_check_open_basedir(arg_val->ptr)) { + efree(arg_val->ptr); + return NULL; + } + } break; case PSI_T_STRLEN: if (iarg->type->type == PSI_T_STRING) { @@ -630,6 +642,18 @@ static inline void *psi_do_let(decl_arg *darg) } } break; + case PSI_T_OBJVAL: + if (iarg->type->type == PSI_T_OBJECT) { + psi_object *obj; + + if (!instanceof_function(Z_OBJCE_P(iarg->_zv), psi_class_entry)) { + return NULL; + } + + obj = PSI_OBJ(iarg->_zv, NULL); + arg_val->ptr = obj->data; + } + break; EMPTY_SWITCH_DEFAULT_CASE(); } } @@ -709,6 +733,232 @@ static inline void psi_do_clean(impl *impl) } } +static inline int psi_calc_num_exp_value(num_exp *exp, impl_val *ref, impl_val *res) { + impl_val *tmp = NULL; + + switch (exp->t) { + case PSI_T_NUMBER: + switch (is_numeric_string(exp->u.numb, strlen(exp->u.numb), (zend_long *) res, (double *) res, 0)) { + case IS_LONG: + return PSI_T_INT64; + case IS_DOUBLE: + return PSI_T_DOUBLE; + } + break; + + case PSI_T_NSNAME: + switch (exp->u.cnst->type->type) { + case PSI_T_INT: + res->i64 = zend_get_constant_str(exp->u.cnst->name, strlen(exp->u.cnst->name))->value.lval; + return PSI_T_INT64; + case PSI_T_FLOAT: + res->dval = zend_get_constant_str(exp->u.cnst->name, strlen(exp->u.cnst->name))->value.dval; + return PSI_T_DOUBLE; + default: + return 0; + } + break; + + case PSI_T_NAME: + if (exp->u.dvar->arg->let) { + ref = exp->u.dvar->arg->let->ptr; + } else { + ref = struct_member_ref(exp->u.dvar->arg, ref, &tmp); + } + switch (real_decl_type(exp->u.dvar->arg->type)->type) { + case PSI_T_INT8: + case PSI_T_UINT8: + case PSI_T_INT16: + case PSI_T_UINT16: + case PSI_T_INT32: + case PSI_T_UINT32: + case PSI_T_INT64: + case PSI_T_UINT64: + memcpy(res, deref_impl_val(ref, exp->u.dvar), sizeof(*res)); + if (tmp) { + free(tmp); + } + return real_decl_type(exp->u.dvar->arg->type)->type; + + case PSI_T_FLOAT: + case PSI_T_DOUBLE: + memcpy(res, deref_impl_val(ref, exp->u.dvar), sizeof(*res)); + if (tmp) { + free(tmp); + } + return real_decl_type(exp->u.dvar->arg->type)->type; + + EMPTY_SWITCH_DEFAULT_CASE(); + } + break; + + EMPTY_SWITCH_DEFAULT_CASE(); + } + return 0; +} + +int psi_calc_num_exp(num_exp *exp, impl_val *ref, impl_val *res) { + impl_val num = {0}; + int num_type = psi_calc_num_exp_value(exp, ref, &num); + + if (exp->operand) { + impl_val tmp = {0}; + int tmp_type = psi_calc_num_exp(exp->operand, ref, &tmp); + + return exp->calculator(num_type, &num, tmp_type, &tmp, res); + } + + memcpy(res, &num, sizeof(*res)); + return num_type; +} + +#define PRIfval "f" +#define PRIdval "lf" + +#define PSI_CALC_OP(var) do { \ + const char *fmt = "calc: %" PRI##var ", %" PRI##var ": %" PRI##var "\n"; \ + res->var = PSI_CALC(v1->var, v2->var); \ + /*fprintf(stderr, fmt, v1->var, v2->var, res->var);*/ \ +} while (0) +#define PSI_CALC_OP2(vres, var1, var2) do { \ + const char *fmt = "calc: %" PRI##var1 ", %" PRI##var2 ": %" PRI##vres "\n"; \ + res->vres = PSI_CALC(v1->var1, v2->var2); \ + /*fprintf(stderr, fmt, v1->var1, v2->var2, res->vres);*/ \ +} while(0) +#define PSI_CALC_FN(op) int psi_calc_##op(int t1, impl_val *v1, int t2, impl_val *v2, impl_val *res) \ +{ \ + if (t1 == t2) { \ + switch (t1) { \ + case PSI_T_FLOAT: PSI_CALC_OP(fval); break; \ + case PSI_T_DOUBLE: PSI_CALC_OP(dval); break; \ + case PSI_T_INT8: PSI_CALC_OP(i8); break; \ + case PSI_T_UINT8: PSI_CALC_OP(u8); break; \ + case PSI_T_INT16: PSI_CALC_OP(i16); break; \ + case PSI_T_UINT16: PSI_CALC_OP(u16); break; \ + case PSI_T_INT32: PSI_CALC_OP(i32); break; \ + case PSI_T_UINT32: PSI_CALC_OP(u32); break; \ + case PSI_T_INT64: PSI_CALC_OP(i64); break; \ + case PSI_T_UINT64: PSI_CALC_OP(u64); break; \ + EMPTY_SWITCH_DEFAULT_CASE(); \ + } \ + return t1; \ + } else if (t1 == PSI_T_DOUBLE) { \ + switch (t2) { \ + case PSI_T_FLOAT: PSI_CALC_OP2(dval, dval, fval); break; \ + case PSI_T_INT8: PSI_CALC_OP2(dval, dval, i8); break; \ + case PSI_T_UINT8: PSI_CALC_OP2(dval, dval, u8); break; \ + case PSI_T_INT16: PSI_CALC_OP2(dval, dval, i16); break; \ + case PSI_T_UINT16: PSI_CALC_OP2(dval, dval, u16); break; \ + case PSI_T_INT32: PSI_CALC_OP2(dval, dval, i32); break; \ + case PSI_T_UINT32: PSI_CALC_OP2(dval, dval, u32); break; \ + case PSI_T_INT64: PSI_CALC_OP2(dval, dval, i64); break; \ + case PSI_T_UINT64: PSI_CALC_OP2(dval, dval, u64); break; \ + EMPTY_SWITCH_DEFAULT_CASE(); \ + } \ + return t1; \ + } else if (t2 == PSI_T_DOUBLE) { \ + switch (t1) { \ + case PSI_T_FLOAT: PSI_CALC_OP2(dval, fval, dval); break; \ + case PSI_T_INT8: PSI_CALC_OP2(dval, i8, dval); break; \ + case PSI_T_UINT8: PSI_CALC_OP2(dval, u8, dval); break; \ + case PSI_T_INT16: PSI_CALC_OP2(dval, i16, dval); break; \ + case PSI_T_UINT16: PSI_CALC_OP2(dval, u16, dval); break; \ + case PSI_T_INT32: PSI_CALC_OP2(dval, i32, dval); break; \ + case PSI_T_UINT32: PSI_CALC_OP2(dval, u32, dval); break; \ + case PSI_T_INT64: PSI_CALC_OP2(dval, i64, dval); break; \ + case PSI_T_UINT64: PSI_CALC_OP2(dval, u64, dval); break; \ + EMPTY_SWITCH_DEFAULT_CASE(); \ + } \ + return t2; \ + } else if (t1 == PSI_T_FLOAT) { \ + switch (t2) { \ + case PSI_T_DOUBLE: PSI_CALC_OP2(dval, fval, dval); return t2; \ + case PSI_T_INT8: PSI_CALC_OP2(fval, fval, i8); break; \ + case PSI_T_UINT8: PSI_CALC_OP2(fval, fval, u8); break; \ + case PSI_T_INT16: PSI_CALC_OP2(fval, fval, i16); break; \ + case PSI_T_UINT16: PSI_CALC_OP2(fval, fval, u16); break; \ + case PSI_T_INT32: PSI_CALC_OP2(fval, fval, i32); break; \ + case PSI_T_UINT32: PSI_CALC_OP2(fval, fval, u32); break; \ + case PSI_T_INT64: PSI_CALC_OP2(fval, fval, i64); break; \ + case PSI_T_UINT64: PSI_CALC_OP2(fval, fval, u64); break; \ + EMPTY_SWITCH_DEFAULT_CASE(); \ + } \ + return t1; \ + } else if (t2 == PSI_T_FLOAT) { \ + switch (t1) { \ + case PSI_T_DOUBLE: PSI_CALC_OP2(dval, dval, fval); return t1; \ + case PSI_T_INT8: PSI_CALC_OP2(fval, i8, fval); break; \ + case PSI_T_UINT8: PSI_CALC_OP2(fval, u8, fval); break; \ + case PSI_T_INT16: PSI_CALC_OP2(fval, i16, fval); break; \ + case PSI_T_UINT16: PSI_CALC_OP2(fval, u16, fval); break; \ + case PSI_T_INT32: PSI_CALC_OP2(fval, i32, fval); break; \ + case PSI_T_UINT32: PSI_CALC_OP2(fval, u32, fval); break; \ + case PSI_T_INT64: PSI_CALC_OP2(fval, i64, fval); break; \ + case PSI_T_UINT64: PSI_CALC_OP2(fval, u64, fval); break; \ + EMPTY_SWITCH_DEFAULT_CASE(); \ + } \ + return t2; \ + } else { \ + int64_t sval1 = v1->i64, sval2 = v2->i64; \ + uint64_t uval1 = v1->u64, uval2 = v2->u64; \ + switch (t1) { \ + case PSI_T_INT8: sval1 >>= 8; \ + case PSI_T_INT16: sval1 >>= 8; \ + case PSI_T_INT32: sval1 >>= 8; \ + case PSI_T_INT64: \ + switch (t2) { \ + case PSI_T_INT8: sval2 >>= 8; \ + case PSI_T_INT16: sval2 >>= 8; \ + case PSI_T_INT32: sval2 >>= 8; \ + case PSI_T_INT64: \ + res->i64 = PSI_CALC(sval1 , sval2); \ + return PSI_T_INT64; \ + case PSI_T_UINT8: uval2 >>= 8; \ + case PSI_T_UINT16: uval2 >>= 8; \ + case PSI_T_UINT32: uval2 >>= 8; \ + case PSI_T_UINT64: \ + res->i64 = PSI_CALC(sval1, uval2); \ + return PSI_T_INT64; \ + } \ + break; \ + case PSI_T_UINT8: uval1 >>= 8; \ + case PSI_T_UINT16: uval1 >>= 8; \ + case PSI_T_UINT32: uval1 >>= 8; \ + case PSI_T_UINT64: \ + switch (t2) { \ + case PSI_T_INT8: sval2 >>= 8; \ + case PSI_T_INT16: sval2 >>= 8; \ + case PSI_T_INT32: sval2 >>= 8; \ + case PSI_T_INT64: \ + res->i64 = PSI_CALC(uval1, sval2); \ + return PSI_T_INT64; \ + case PSI_T_UINT8: uval2 >>= 8; \ + case PSI_T_UINT16: uval2 >>= 8; \ + case PSI_T_UINT32: uval2 >>= 8; \ + case PSI_T_UINT64: \ + res->u64 = PSI_CALC(uval1, uval2); \ + return PSI_T_UINT64; \ + } \ + break; \ + } \ + } \ + ZEND_ASSERT(0); \ + return 0; \ +} + +#undef PSI_CALC +#define PSI_CALC(var1, var2) (var1) + (var2) +PSI_CALC_FN(add) +#undef PSI_CALC +#define PSI_CALC(var1, var2) (var1) * (var2) +PSI_CALC_FN(mul) +#undef PSI_CALC +#define PSI_CALC(var1, var2) (var1) - (var2) +PSI_CALC_FN(sub) +#undef PSI_CALC +#define PSI_CALC(var1, var2) (var1) / (var2) +PSI_CALC_FN(div) + void psi_call(zend_execute_data *execute_data, zval *return_value, impl *impl) { impl_val ret_val; @@ -722,7 +972,9 @@ void psi_call(zend_execute_data *execute_data, zval *return_value, impl *impl) for (i = 0; i < impl->decl->args->count; ++i) { decl_arg *darg = impl->decl->args->args[i]; - impl->decl->call.args[i] = psi_do_let(darg); + if (!(impl->decl->call.args[i] = psi_do_let(darg))) { + goto cleanup; + } } } @@ -744,16 +996,52 @@ void psi_call(zend_execute_data *execute_data, zval *return_value, impl *impl) psi_do_free(fre); } + psi_do_clean(impl); + return; +cleanup: + memset(&ret_val, 0, sizeof(ret_val)); + psi_do_return(return_value, impl->stmts->ret.list[0], &ret_val); psi_do_clean(impl); } +static void psi_object_free(zend_object *o) +{ + psi_object *obj = PSI_OBJ(NULL, o); + + if (obj->data) { + // free(obj->data); + obj->data = NULL; + } + zend_object_std_dtor(o); +} + +static zend_object *psi_object_init(zend_class_entry *ce) +{ + psi_object *o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce)); + + zend_object_std_init(&o->std, ce); + object_properties_init(&o->std, ce); + o->std.handlers = &psi_object_handlers; + return &o->std; +} + PHP_MINIT_FUNCTION(psi) { PSI_ContextOps *ops = NULL; + zend_class_entry ce = {0}; REGISTER_INI_ENTRIES(); + INIT_NS_CLASS_ENTRY(ce, "psi", "object", NULL); + psi_class_entry = zend_register_internal_class_ex(&ce, NULL); + psi_class_entry->create_object = psi_object_init; + + memcpy(&psi_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + psi_object_handlers.offset = XtOffsetOf(psi_object, std); + psi_object_handlers.free_obj = psi_object_free; + psi_object_handlers.clone_obj = NULL; + #ifdef HAVE_LIBJIT if (!strcasecmp(PSI_G(engine), "jit")) { ops = PSI_Libjit(); @@ -771,7 +1059,7 @@ PHP_MINIT_FUNCTION(psi) PSI_ContextInit(&PSI_G(context), ops, psi_error); PSI_ContextBuild(&PSI_G(context), PSI_G(directory)); - if (getenv("PSI_DUMP")) { + if (psi_check_env("PSI_DUMP")) { PSI_ContextDump(&PSI_G(context), STDOUT_FILENO); }