This commit is contained in:
CismonX 2019-03-28 12:27:29 +08:00
parent 633e52f32f
commit d7c9ca7d13
5 changed files with 18 additions and 23 deletions

View File

@ -8,6 +8,15 @@
namespace php_arma
{
template <typename T>
zend_always_inline
void property_declare(zend_class_entry *ce, const char *name)
{
zval property;
zval_set_scalar(&property, static_cast<T>(0));
zend_declare_property(ce, name, strlen(name), &property, ZEND_ACC_PUBLIC);
}
template <typename T>
PHP_ARMA_FUNCTION(complex, __construct, T)
{
@ -22,10 +31,7 @@ namespace php_arma
auto has_imag = num_args == 2;
auto has_real = num_args > 0;
zval zero_val;
zval_set_scalar(&zero_val, static_cast<T>(0));
zend_object *current = Z_OBJ_P(getThis());
auto current = Z_OBJ_P(getThis());
if (EXPECTED(has_real)) {
if (!zval_check_scalar<T>(real)) {
@ -37,12 +43,7 @@ namespace php_arma
return;
}
object_set_property(current, 1, imag);
} else {
object_set_property(current, 1, &zero_val);
}
} else {
object_set_property(current, 0, &zero_val);
object_set_property(current, 1, &zero_val);
}
current->handlers = &handlers;
@ -78,8 +79,8 @@ namespace php_arma
void complex<T>::ce_init(const char *name, zend_class_entry *parent_ce)
{
ce = class_register(name, parent_ce, me);
property_declare(ce, "real");
property_declare(ce, "imag");
property_declare<T>(ce, "real");
property_declare<T>(ce, "imag");
object_handlers_init(&handlers);
handlers.write_property = write_property;
}

View File

@ -26,7 +26,7 @@ namespace php_arma
template <typename T, bool B1, bool B2>
PHP_ARMA_FUNCTION(mapval, val, T, B1, B2)
{
zend_object *current = Z_OBJ_P(getThis());
auto current = Z_OBJ_P(getThis());
zval_set_scalar(return_value, get_val(current));
}
@ -42,7 +42,7 @@ namespace php_arma
return;
}
zend_object *current = Z_OBJ_P(getThis());
auto current = Z_OBJ_P(getThis());
set_val(current, zval_get_scalar<T>(val));
}

View File

@ -45,12 +45,12 @@ namespace php_arma
static zend_object *create(native_t init_val)
{
if constexpr (IsSparse) {
return object_create<native_t>(ce, [&init_val](native_t *obj) {
return object_create<native_t>(ce, [&init_val](auto obj) {
memcpy(obj, &init_val, sizeof(native_t));
return &handlers;
});
} else {
return object_create<native_t>(ce, [init_val](native_t *obj) {
return object_create<native_t>(ce, [init_val](auto obj) {
*obj = init_val;
return &handlers;
});

View File

@ -105,12 +105,6 @@ namespace php_arma
return ce;
}
zend_always_inline
void property_declare(zend_class_entry *ce, const char *name)
{
zend_declare_property_null(ce, name, strlen(name), ZEND_ACC_PUBLIC);
}
zend_always_inline
void object_handlers_init(zend_object_handlers *handlers)
{

View File

@ -6,8 +6,8 @@ Test for constants.
<?php
require_once 'includes/assert.php';
$fill = [
Arma\Fill::NONE, Arma\Fill::ZEROS, Arma\Fill::ONES,
Arma\Fill::EYE, Arma\Fill::RANDU, Arma\Fill::RANDN
Arma\Fill::NONE, Arma\Fill::ZEROS, Arma\Fill::ONES,
Arma\Fill::EYE, Arma\Fill::RANDU, Arma\Fill::RANDN
];
$file_type = [
Arma\FileType::AUTO_DETECT, Arma\FileType::ARMA_BINARY,