Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Commit 99a4400

Browse files
CArray shape() method
1 parent 27edac9 commit 99a4400

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

phpsci.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,23 @@ PHP_METHOD(CArray, setShape)
347347
newcarray = CArray_Newshape(carray, new_shape, zend_hash_num_elements(Z_ARRVAL_P(new_shape_zval)), CARRAY_CORDER, &ptr);
348348
FREE_TUPLE(new_shape);
349349
}
350+
PHP_METHOD(CArray, shape)
351+
{
352+
MemoryPointer ptr;
353+
CArray * target;
354+
zval * obj = getThis();
355+
zval tmp_zval;
356+
int i;
357+
358+
ZVAL_TO_MEMORYPOINTER(obj, &ptr, NULL);
359+
target = CArray_FromMemoryPointer(&ptr);
360+
361+
array_init_size(return_value, CArray_NDIM(target));
362+
for (i = 0; i < CArray_NDIM(target); i++) {
363+
ZVAL_LONG(&tmp_zval, CArray_DIMS(target)[i]);
364+
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp_zval);
365+
}
366+
}
350367
PHP_METHOD(CArray, reshape)
351368
{
352369
MemoryPointer ptr;
@@ -2535,6 +2552,10 @@ PHP_METHOD(CArray, map)
25352552
}
25362553
efree(params);
25372554
}
2555+
PHP_METHOD(CArray, __invoke)
2556+
{
2557+
throw_notimplemented_exception();
2558+
}
25382559

25392560
/**
25402561
* CLASS METHODS
@@ -2546,6 +2567,7 @@ static zend_function_entry carray_class_methods[] =
25462567
PHP_ME(CArray, dump, NULL, ZEND_ACC_PUBLIC)
25472568
PHP_ME(CArray, print, NULL, ZEND_ACC_PUBLIC)
25482569
PHP_ME(CArray, __set, arginfo_array_set, ZEND_ACC_PUBLIC)
2570+
PHP_ME(CArray, __invoke, NULL, ZEND_ACC_PUBLIC)
25492571
PHP_ME(CArray, __toString, NULL, ZEND_ACC_PUBLIC)
25502572
PHP_ME(CArray, toArray, NULL, ZEND_ACC_PUBLIC)
25512573
PHP_ME(CArray, map, NULL, ZEND_ACC_PUBLIC)
@@ -2599,6 +2621,7 @@ static zend_function_entry carray_class_methods[] =
25992621
PHP_ME(CArray, transpose, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
26002622
PHP_ME(CArray, reshape, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
26012623
PHP_ME(CArray, setShape, NULL, ZEND_ACC_PUBLIC)
2624+
PHP_ME(CArray, shape, NULL, ZEND_ACC_PUBLIC)
26022625

26032626
//ROUNDING
26042627
PHP_ME(CArray, ceil, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
@@ -2764,7 +2787,8 @@ static int carray_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zv
27642787
}
27652788
}
27662789

2767-
static int carray_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ */
2790+
static
2791+
int carray_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ */
27682792
{
27692793
CArray *a, *b;
27702794
MemoryPointer ptr1, ptr2;
@@ -2780,7 +2804,7 @@ static int carray_compare(zval *object1, zval *object2 TSRMLS_DC) /* {{{ */
27802804
return FAILURE;
27812805
}
27822806

2783-
int
2807+
static int
27842808
carray_count(zval *object, long *count TSRMLS_DC) {
27852809
MemoryPointer ptr;
27862810
CArray * target;
@@ -2794,7 +2818,8 @@ carray_count(zval *object, long *count TSRMLS_DC) {
27942818
return SUCCESS;
27952819
}
27962820

2797-
static int carray_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
2821+
static
2822+
int carray_do_operation(zend_uchar opcode, zval *result, zval *op1, zval *op2) /* {{{ */
27982823
{
27992824
zval op1_copy;
28002825
int retval;
@@ -2835,6 +2860,7 @@ static PHP_MINIT_FUNCTION(carray)
28352860
carray_object_handlers.cast_object = carray_cast;
28362861
carray_object_handlers.count_elements = carray_count;
28372862

2863+
28382864
zend_class_implements(carray_sc_entry, 1, zend_ce_arrayaccess);
28392865

28402866
init_exception_objects();

0 commit comments

Comments
 (0)