def array_init(arg): zv = zval_utils.make_empty_zval() from happy_variables import zval_ptr_dtor zv.happy_ht = happy_hash.zend_hash_init(None, 0, None, zval_ptr_dtor, False) zval_utils.Z_SET_TYPE(zv, IS_ARRAY) arg.assign(zv) return 0
def hash_get(ptr, ikey, skey, key_is_str): ht = _cast_ptr_to_ht(ptr) zval = zval_utils.make_empty_zval() retval_ptr = zval_utils.zppp_stack(global_state.null_zval_ptr_ptr) if key_is_str: ms = objects.MutableString.from_string_data(skey) res = happy_hash.zend_hash_find(ht, ms, 1, retval_ptr) else: res = happy_hash.zend_hash_index_find(ht, ikey, retval_ptr) if res == happy_hash.FAILURE: return zval_null return _return_retval(retval_ptr)
def zend_print_zval_ex(write_func, expr, indent): expr_copy = zval_utils.make_empty_zval() expr_copy_ptr = zval_utils.zp_stack(expr_copy) use_copy = zend_make_printable_zval(expr, expr_copy_ptr) if use_copy: expr = expr_copy_ptr if not zval_utils.Z_STRLEN_P(expr): if use_copy: zval_utils.zval_dtor(expr) return 0 write_func(zval_utils.Z_STRVAL_P(expr), zval_utils.Z_STRLEN_P(expr)) if use_copy: zval_utils.zval_dtor(expr) return zval_utils.Z_STRLEN_P(expr)
def hash_add(ptr, ikey, skey, key_is_str, ptr2): ht = _cast_ptr_to_ht(ptr) zval = _cast_ptr_to_zval(ptr2) if not zval: zval = zval_utils.make_empty_zval() zval_ptr = zval_utils.zp_stack(zval) zval_ptr_ptr = zval_utils.zpp_stack(zval_ptr) retval_ptr = zval_utils.zppp_stack(global_state.null_zval_ptr_ptr) # TODO: ADDREF on zval??? if key_is_str: ms = objects.MutableString.from_string_data(skey) res = happy_hash.zend_hash_add(ht, ms, 1, zval_ptr_ptr, 0, retval_ptr) else: res = happy_hash.zend_hash_index_update(ht, ikey, zval_ptr_ptr, 0, retval_ptr) if res == happy_hash.FAILURE: return zval_null return _return_retval(retval_ptr)
raise Exception('null pointer assignment') self.__cp = cp def deref(self): if self.null: raise Exception('null pointer dereference') return self.__cp def __nonzero__(self): raise Exception('use is_null() for casting to bool') def copy(self): return zend_constant_ptr_ptr(self.__cp, self.null) const_null_ptr = zend_constant_ptr(zend_constant(None, zval_ptr(zval_utils.make_empty_zval(), True), CONST_CS, PHP_USER_CONSTANT), True) const_null_ptr_ptr = zend_constant_ptr_ptr(const_null_ptr, True) const_null_ptr = zend_constant_ptr(zend_constant(None, zval_ptr(zval_utils.make_empty_zval(), True), CONST_CS, PHP_USER_CONSTANT), True) const_null_ptr_ptr = zend_constant_ptr_ptr(const_null_ptr, True) def zend_get_constant(name, name_len, result): # TODO: make it correct assert isinstance(name, MutableString) assert isinstance(result, zval_ptr) import global_state c_ptr = zend_constant_ptr_ptr(const_null_ptr, False) retval = True
def new_zval(): new_zval = zval_utils.make_empty_zval() return _cast_to_zval_ptr(new_zval)