Skip to content

Commit 820811b

Browse files
stdClass is CArray now.
1 parent 7b2ac51 commit 820811b

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

phpsci.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,39 @@
3030
#include "php.h"
3131

3232

33-
3433
/**
35-
*
36-
*
37-
* Henrique Borba <henrique.borba.dev>
34+
* @author Henrique Borba <henrique.borba.dev>
3835
* @param obj
3936
* @param uuid
4037
*/
4138
void set_obj_uuid(zval * obj, long uuid) {
4239
zend_update_property_long(phpsci_sc_entry, obj, "uuid", sizeof("uuid") - 1, uuid);
4340
}
4441

42+
/**
43+
* @author Henrique Borba <henrique.borba.dev>
44+
* @param rtn
45+
* @param x_rows_width
46+
* @param y_cols
47+
*/
48+
void generate_carray_object(zval * rtn, long uuid, long x_rows_width, long y_cols) {
49+
}
50+
4551
/**
4652
* PHPSci Constructor
4753
*/
4854
PHP_METHOD(CArray, __construct)
4955
{
50-
array_init(return_value);
56+
long uuid, x, y;
57+
ZEND_PARSE_PARAMETERS_START(3,3)
58+
Z_PARAM_LONG(uuid)
59+
Z_PARAM_LONG(x)
60+
Z_PARAM_LONG(y)
61+
ZEND_PARSE_PARAMETERS_END();
62+
zval * obj = getThis();
63+
set_obj_uuid(obj, uuid);
64+
zend_update_property_long(phpsci_sc_entry, obj, "x", sizeof("x") - 1, x);
65+
zend_update_property_long(phpsci_sc_entry, obj, "y", sizeof("y") - 1, y);
5166
}
5267

5368
/**
@@ -65,8 +80,10 @@ PHP_METHOD(CArray, identity)
6580
carray_init((int)m, (int)m, &ptr);
6681
CArray arr = ptr_to_carray(&ptr);
6782
identity(&arr, (int)m);
68-
object_init(return_value);
83+
object_init_ex(return_value, phpsci_sc_entry);
6984
set_obj_uuid(return_value, ptr.uuid);
85+
zend_update_property_long(phpsci_sc_entry, return_value, "x", sizeof("x") - 1, m);
86+
zend_update_property_long(phpsci_sc_entry, return_value, "y", sizeof("y") - 1, m);
7087
}
7188
PHP_METHOD(CArray, zeros)
7289
{
@@ -80,7 +97,7 @@ PHP_METHOD(CArray, zeros)
8097
carray_init((int)x, (int)y, &ptr);
8198
CArray arr = ptr_to_carray(&ptr);
8299
zeros(&arr, (int)x, (int)y);
83-
object_init(return_value);
100+
object_init_ex(return_value, phpsci_sc_entry);
84101
set_obj_uuid(return_value, ptr.uuid);
85102
}
86103
PHP_METHOD(CArray, fromArray)
@@ -94,7 +111,7 @@ PHP_METHOD(CArray, fromArray)
94111
MemoryPointer ptr;
95112
ptr.uuid = NULL;
96113
array_to_carray_ptr(&ptr, array, &a_rows, &a_cols);
97-
object_init(return_value);
114+
object_init_ex(return_value, phpsci_sc_entry);
98115
set_obj_uuid(return_value, ptr.uuid);
99116
zend_update_property_long(phpsci_sc_entry, return_value, "x", sizeof("x") - 1, a_rows);
100117
zend_update_property_long(phpsci_sc_entry, return_value, "y", sizeof("y") - 1, a_cols);
@@ -124,7 +141,7 @@ PHP_METHOD(CArray, transpose)
124141
MemoryPointer rtn;
125142
ptr.uuid = (int)uuid;
126143
transpose(&rtn, &ptr, (int)rows, (int)cols);
127-
object_init(return_value);
144+
object_init_ex(return_value, phpsci_sc_entry);
128145
set_obj_uuid(return_value, rtn.uuid);
129146
}
130147
PHP_METHOD(CArray, print_r) {
@@ -162,7 +179,7 @@ PHP_METHOD(CArray, linspace)
162179
ZEND_PARSE_PARAMETERS_END();
163180
MemoryPointer * ptr;
164181
linspace(ptr, (float)start, (float)stop, (float)num);
165-
object_init(return_value);
182+
object_init_ex(return_value, phpsci_sc_entry);
166183
set_obj_uuid(return_value, ptr->uuid);
167184
zend_update_property_long(phpsci_sc_entry, return_value, "x", sizeof("x") - 1, num);
168185
zend_update_property_long(phpsci_sc_entry, return_value, "y", sizeof("y") - 1, 0);
@@ -179,7 +196,7 @@ PHP_METHOD(CArray, logspace)
179196
ZEND_PARSE_PARAMETERS_END();
180197
MemoryPointer * ptr;
181198
logspace(ptr, (float)start, (float)stop, num, (float)base);
182-
object_init(return_value);
199+
object_init_ex(return_value, phpsci_sc_entry);
183200
set_obj_uuid(return_value, ptr->uuid);
184201
zend_update_property_long(phpsci_sc_entry, return_value, "x", sizeof("x") - 1, num);
185202
zend_update_property_long(phpsci_sc_entry, return_value, "y", sizeof("y") - 1, 0);
@@ -210,7 +227,7 @@ PHP_METHOD(CArray, matmul)
210227
a_ptr.uuid = (int)a_uuid;
211228
b_ptr.uuid = (int)b_uuid;
212229
matmul(&rtn_ptr, (int)a_rows, (int)a_cols, &a_ptr, (int)b_cols, &b_ptr);
213-
object_init(return_value);
230+
object_init_ex(return_value, phpsci_sc_entry);
214231
set_obj_uuid(return_value, rtn_ptr.uuid);
215232
}
216233
PHP_METHOD(CArray, arange)
@@ -224,7 +241,7 @@ PHP_METHOD(CArray, arange)
224241
ZEND_PARSE_PARAMETERS_END();
225242
MemoryPointer * ptr;
226243
arange(ptr, start, stop, step, &width);
227-
object_init(return_value);
244+
object_init_ex(return_value, phpsci_sc_entry);
228245
set_obj_uuid(return_value, ptr->uuid);
229246
zend_update_property_long(phpsci_sc_entry, return_value, "x", sizeof("x") - 1, width);
230247
zend_update_property_long(phpsci_sc_entry, return_value, "y", sizeof("y") - 1, 0);
@@ -235,7 +252,7 @@ PHP_METHOD(CArray, arange)
235252
*/
236253
static zend_function_entry phpsci_class_methods[] =
237254
{
238-
PHP_ME(CArray, __construct, NULL, ZEND_ACC_PUBLIC)
255+
// PHP_ME(CArray, __construct, NULL, ZEND_ACC_PUBLIC)
239256
// RANGES SECTION
240257
PHP_ME(CArray, arange, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
241258
PHP_ME(CArray, linspace, NULL, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)

phpsci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ extern zend_module_entry phpsci_module_entry;
4848
zend_throw_exception(phpsci_exception_sc_entry, message, (long)code TSRMLS_CC); \
4949
return;
5050

51+
void set_obj_uuid(zval * obj, long uuid);
52+
void generate_carray_object(zval * rtn, long uuid, long x_rows_width, long y_cols);
53+
5154
#endif //PHPSCI_EXT_PHPSCI_H

0 commit comments

Comments
 (0)