diff --git a/phper-sys/c/php_classes.c b/phper-sys/c/php_classes.c new file mode 100644 index 0000000..d9882b3 --- /dev/null +++ b/phper-sys/c/php_classes.c @@ -0,0 +1,30 @@ +#include + +zend_class_entry phper_init_class_entry_ex(const char *class_name, + size_t class_name_len) { + zend_class_entry class_ce = {0}; + class_ce.name = zend_string_init_interned(class_name, class_name_len, true); + class_ce.default_object_handlers = &std_object_handlers; + return class_ce; +} + +zend_class_entry * +phper_register_class_entry_ex(zend_class_entry *ce, zend_class_entry *parent, + const zend_function_entry *functions) { + ce->info.internal.builtin_functions = functions; + + if (parent == NULL) { + return zend_register_internal_class(ce); + } + + return zend_register_internal_class_ex(ce, parent); +} + +zend_class_entry phper_init_interface_entry_ex(const char *class_name, + size_t class_name_len) { + zend_class_entry class_ce = {0}; + class_ce.name = zend_string_init_interned(class_name, class_name_len, true); + class_ce.default_object_handlers = &std_object_handlers; + + return class_ce; +} diff --git a/phper-sys/c/php_functions.c b/phper-sys/c/php_functions.c new file mode 100644 index 0000000..c1bf735 --- /dev/null +++ b/phper-sys/c/php_functions.c @@ -0,0 +1,36 @@ +#include + +zend_string *phper_get_function_or_method_name(const zend_function *func) { + return get_function_or_method_name(func); +} + +zend_string *phper_get_function_name(const zend_function *func) { + return func->common.function_name; +} + +bool phper_call_user_function(zval *object, zval *function_name, + zval *retval_ptr, zval params[static 1], + uint32_t param_count, HashTable *named_params) { + + _call_user_function_impl(object, function_name, retval_ptr, param_count, + params, named_params) == SUCCESS; +} + +const zval *phper_zend_call_var_num(const zend_execute_data *execute_data, + int index) { + return ZEND_CALL_VAR_NUM(execute_data, index); +} + +const zval *phper_zend_call_arg(const zend_execute_data *execute_data, + int index) { + return ZEND_CALL_ARG(execute_data, index); +} + +uint32_t phper_zend_num_args(const zend_execute_data *execute_data) { + return ZEND_NUM_ARGS(); +} + +bool phper_zend_get_parameters_array_ex(uint32_t param_count, + zval *argument_array) { + return zend_get_parameters_array_ex(param_count, argument_array) == SUCCESS; +} diff --git a/phper-sys/c/php_interfaces.c b/phper-sys/c/php_interfaces.c new file mode 100644 index 0000000..8aa4d5e --- /dev/null +++ b/phper-sys/c/php_interfaces.c @@ -0,0 +1,13 @@ +#include + +zend_class_entry * +phper_register_interface_entry_ex(zend_class_entry *ce, + const zend_function_entry *functions) { + ce->info.internal.builtin_functions = functions; + return zend_register_internal_interface(ce); +} + +bool phper_instanceof_function(const zend_class_entry *instance_ce, + const zend_class_entry *ce) { + return instanceof_function(instance_ce, ce) != 0; +} \ No newline at end of file diff --git a/phper-sys/c/php_objects.c b/phper-sys/c/php_objects.c new file mode 100644 index 0000000..25fe262 --- /dev/null +++ b/phper-sys/c/php_objects.c @@ -0,0 +1,25 @@ +#include + +zval *phper_get_this(const zend_execute_data *execute_data) { + return getThis(); +} + +size_t phper_zend_object_properties_size(const zend_class_entry *ce) { + return zend_object_properties_size((zend_class_entry *)ce); +} + +void *phper_zend_object_alloc(size_t obj_size, const zend_class_entry *ce) { + return zend_object_alloc(obj_size, (zend_class_entry *)ce); +} + +bool phper_object_init_ex(zval *arg, const zend_class_entry *class_type) { + return object_init_ex(arg, (zend_class_entry *)class_type) == SUCCESS; +} + +void phper_zend_object_release(zend_object *obj) { + zend_object_release(obj); +} + +uint32_t phper_zend_object_gc_refcount(const zend_object *obj) { + return GC_REFCOUNT(obj); +} \ No newline at end of file diff --git a/phper-sys/c/php_wrapper.c b/phper-sys/c/php_wrapper.c index 37bb9b1..7e4264a 100644 --- a/phper-sys/c/php_wrapper.c +++ b/phper-sys/c/php_wrapper.c @@ -10,121 +10,6 @@ #include -// ================================================== -// object apis: -// ================================================== - -zval *phper_get_this(zend_execute_data *execute_data) { - return getThis(); -} - -size_t phper_zend_object_properties_size(zend_class_entry *ce) { - return zend_object_properties_size(ce); -} - -void *phper_zend_object_alloc(size_t obj_size, zend_class_entry *ce) { - return zend_object_alloc(obj_size, ce); -} - -zend_object *(**phper_get_create_object(zend_class_entry *ce))( - zend_class_entry *class_type) { - return &ce->create_object; -} - -bool phper_object_init_ex(zval *arg, zend_class_entry *class_type) { - return object_init_ex(arg, class_type) == SUCCESS; -} - -void phper_zend_object_release(zend_object *obj) { - zend_object_release(obj); -} - -uint32_t phper_zend_object_gc_refcount(const zend_object *obj) { - return GC_REFCOUNT(obj); -} - -// ================================================== -// class apis: -// ================================================== - -zend_class_entry phper_init_class_entry_ex(const char *class_name, - size_t class_name_len) { - zend_class_entry class_ce = {0}; - class_ce.name = zend_string_init_interned(class_name, class_name_len, true); - class_ce.default_object_handlers = &std_object_handlers; - return class_ce; -} - -zend_class_entry * -phper_register_class_entry_ex(zend_class_entry *ce, zend_class_entry *parent, - const zend_function_entry *functions) { - ce->info.internal.builtin_functions = functions; - - if (parent == NULL) { - return zend_register_internal_class(ce); - } - - return zend_register_internal_class_ex(ce, parent); -} - -zend_class_entry phper_init_interface_entry_ex(const char *class_name, - size_t class_name_len) { - zend_class_entry class_ce = {0}; - class_ce.name = zend_string_init_interned(class_name, class_name_len, true); - class_ce.default_object_handlers = &std_object_handlers; - - return class_ce; -} - -zend_class_entry * -phper_register_interface_entry_ex(zend_class_entry *ce, - const zend_function_entry *functions) { - ce->info.internal.builtin_functions = functions; - return zend_register_internal_interface(ce); -} - -bool phper_instanceof_function(const zend_class_entry *instance_ce, - const zend_class_entry *ce) { - return instanceof_function(instance_ce, ce) != 0; -} - -// ================================================== -// function apis: -// ================================================== - -zend_string *phper_get_function_or_method_name(const zend_function *func) { - return get_function_or_method_name(func); -} - -zend_string *phper_get_function_name(const zend_function *func) { - return func->common.function_name; -} - -bool phper_call_user_function(HashTable *function_table, zval *object, - zval *function_name, zval *retval_ptr, - uint32_t param_count, zval params[]) { - (void)function_table; // suppress "unused parameter" warnings. - return call_user_function(function_table, object, function_name, retval_ptr, - param_count, params) == SUCCESS; -} - -zval *phper_zend_call_var_num(zend_execute_data *execute_data, int index) { - return ZEND_CALL_VAR_NUM(execute_data, index); -} - -zval *phper_zend_call_arg(zend_execute_data *execute_data, int index) { - return ZEND_CALL_ARG(execute_data, index); -} - -uint32_t phper_zend_num_args(const zend_execute_data *execute_data) { - return ZEND_NUM_ARGS(); -} - -bool phper_zend_get_parameters_array_ex(uint32_t param_count, - zval *argument_array) { - return zend_get_parameters_array_ex(param_count, argument_array) != 0; -} - // ================================================== // module apis: // ================================================== diff --git a/phper-sys/include/phper.h b/phper-sys/include/phper.h index 7eb942f..5a8d6bb 100644 --- a/phper-sys/include/phper.h +++ b/phper-sys/include/phper.h @@ -192,12 +192,10 @@ bool phper_zend_str_exists(HashTable *ht, const char *str, size_t len); // object apis: // ================================================== -zval *phper_get_this(zend_execute_data *execute_data); -size_t phper_zend_object_properties_size(zend_class_entry *ce); -void *phper_zend_object_alloc(size_t obj_size, zend_class_entry *ce); -zend_object *(**phper_get_create_object(zend_class_entry *ce))( - zend_class_entry *class_type); -bool phper_object_init_ex(zval *arg, zend_class_entry *class_type); +zval *phper_get_this(const zend_execute_data *execute_data); +size_t phper_zend_object_properties_size(const zend_class_entry *ce); +void *phper_zend_object_alloc(size_t obj_size, const zend_class_entry *ce); +bool phper_object_init_ex(zval *arg, const zend_class_entry *class_type); void phper_zend_object_release(zend_object *obj); uint32_t phper_zend_object_gc_refcount(const zend_object *obj); @@ -223,11 +221,13 @@ phper_register_interface_entry_ex(zend_class_entry *ce, zend_string *phper_get_function_or_method_name(const zend_function *func); zend_string *phper_get_function_name(const zend_function *func); -bool phper_call_user_function(HashTable *function_table, zval *object, - zval *function_name, zval *retval_ptr, - uint32_t param_count, zval params[]); -zval *phper_zend_call_var_num(zend_execute_data *execute_data, int index); -zval *phper_zend_call_arg(zend_execute_data *execute_data, int index); +bool phper_call_user_function(zval *object, zval *function_name, + zval *retval_ptr, zval params[static 1], + uint32_t param_count, HashTable *named_params); +const zval *phper_zend_call_var_num(const zend_execute_data *execute_data, + int index); +const zval *phper_zend_call_arg(const zend_execute_data *execute_data, + int index); uint32_t phper_zend_num_args(const zend_execute_data *execute_data); bool phper_zend_get_parameters_array_ex(uint32_t param_count, zval *argument_array); @@ -259,6 +259,7 @@ zend_internal_arg_info phper_zend_begin_arg_info_ex(bool return_reference, uintptr_t required_num_args); zend_internal_arg_info phper_zend_arg_info(bool pass_by_ref, const char *name); + // ================================================== // Constants API: // ================================================== diff --git a/phper/src/classes/entity.rs b/phper/src/classes/entity.rs index be1bf1e..7e2d768 100644 --- a/phper/src/classes/entity.rs +++ b/phper/src/classes/entity.rs @@ -1,7 +1,7 @@ use std::{any::Any, marker::PhantomData, mem::zeroed, ptr::null_mut, rc::Rc}; use phper_sys::{ - phper_get_create_object, phper_init_class_entry_ex, phper_register_class_entry_ex, + phper_init_class_entry_ex, phper_register_class_entry_ex, zend_class_entry, zend_class_implements, zend_function_entry, }; @@ -322,7 +322,7 @@ impl crate::modules::Registerer for ClassEntity { zend_class_implements(class_ce, 1, interface_ce); } - *phper_get_create_object(class_ce) = Some(create_object); + (*class_ce).__bindgen_anon_2.create_object = Some(create_object); for property in &self.property_entities { property.declare(class_ce); diff --git a/phper/src/functions.rs b/phper/src/functions.rs index dbd1006..dd4e2e4 100644 --- a/phper/src/functions.rs +++ b/phper/src/functions.rs @@ -13,7 +13,6 @@ //! TODO Add lambda. use crate::{ - cg, classes::{entry::ClassEntry, RawVisibility, Visibility}, errors::{throw, ArgumentCountError, ExceptionGuard, ThrowObject, Throwable}, objects::{StateObj, ZObj, ZObject}, @@ -469,15 +468,15 @@ pub(crate) fn call_internal( call_raw_common(|ret| unsafe { phper_call_user_function( - cg!(function_table), object_val .as_mut() .map(|o| o.as_mut_ptr()) .unwrap_or(null_mut()), func_ptr, ret.as_mut_ptr(), - arguments.len() as u32, arguments.as_mut_ptr().cast(), + arguments.len() as u32, + null_mut(), ); }) } diff --git a/phper/src/values.rs b/phper/src/values.rs index 606a476..cb66f83 100644 --- a/phper/src/values.rs +++ b/phper/src/values.rs @@ -168,13 +168,7 @@ impl ExecuteData { } } - /// Gets mutable parameter by index. - pub fn get_mut_parameter(&mut self, index: usize) -> &mut ZVal { - unsafe { - let val = phper_zend_call_var_num(self.as_mut_ptr(), index.try_into().unwrap()); - ZVal::from_mut_ptr(val) - } - } + } /// Wrapper of [zval].