NumPower / numpower

PHP extension for efficient scientific computing and array manipulation with GPU support
https://numpower.org
Other
190 stars 4 forks source link

Make __construct use ZVAL_TO_NDARRAY #9

Closed henrique-borba closed 1 year ago

henrique-borba commented 1 year ago

The __construct method must call ZVAL_TO_NDARRAY instead of Create_NDArray_FromZval directly.

ZEND_BEGIN_ARG_INFO(arginfo_construct, 1)
    ZEND_ARG_INFO(0, obj_zval)
ZEND_END_ARG_INFO();
PHP_METHOD(NDArray, __construct)
{
    zend_object *obj = Z_OBJ_P(ZEND_THIS);
    zval *obj_zval;
    ZEND_PARSE_PARAMETERS_START(1, 1)
        Z_PARAM_ZVAL(obj_zval)
    ZEND_PARSE_PARAMETERS_END();
    NDArray* array = Create_NDArray_FromZval(obj_zval);
    add_to_buffer(array, sizeof(NDArray));
    ZVAL_LONG(OBJ_PROP_NUM(obj, 0), NDArray_UUID(array));
}