@@ -24,75 +24,73 @@ zend_class_entry *cassandra_future_rows_ce = NULL;
24
24
ZEND_EXTERN_MODULE_GLOBALS (cassandra )
25
25
26
26
static void
27
- php_cassandra_future_clear ( cassandra_future_rows * self )
27
+ free_result ( void * result )
28
28
{
29
- if (self -> statement ) {
30
- php_cassandra_del_ref (& self -> statement );
31
- self -> statement = NULL ;
32
- }
29
+ cass_result_free ((CassResult * ) result );
30
+ }
33
31
34
- PHP5TO7_ZVAL_MAYBE_DESTROY (self -> session );
35
- if (self -> future ) {
36
- cass_future_free (self -> future );
37
- self -> future = NULL ;
32
+ int
33
+ php_cassandra_future_rows_get_result (cassandra_future_rows * future_rows , zval * timeout TSRMLS_DC )
34
+ {
35
+ if (!future_rows -> result ) {
36
+ const CassResult * result = NULL ;
37
+
38
+ if (php_cassandra_future_wait_timed (future_rows -> future , timeout TSRMLS_CC ) == FAILURE ) {
39
+ return FAILURE ;
40
+ }
41
+
42
+ if (php_cassandra_future_is_error (future_rows -> future TSRMLS_CC ) == FAILURE ) {
43
+ return FAILURE ;
44
+ }
45
+
46
+ result = cass_future_get_result (future_rows -> future );
47
+ if (!result ) {
48
+ zend_throw_exception_ex (cassandra_runtime_exception_ce , 0 TSRMLS_CC ,
49
+ "Future doesn't contain a result." );
50
+ return FAILURE ;
51
+ }
52
+
53
+ future_rows -> result = php_cassandra_new_ref ((void * )result , free_result );
38
54
}
55
+
56
+ return SUCCESS ;
39
57
}
40
58
41
59
PHP_METHOD (FutureRows , get )
42
60
{
43
61
zval * timeout = NULL ;
44
62
cassandra_rows * rows = NULL ;
45
- const CassResult * result = NULL ;
46
63
47
64
cassandra_future_rows * self = PHP_CASSANDRA_GET_FUTURE_ROWS (getThis ());
48
65
49
- if (!PHP5TO7_ZVAL_IS_UNDEF (self -> rows )) {
50
- RETURN_ZVAL (PHP5TO7_ZVAL_MAYBE_P (self -> rows ), 1 , 0 );
51
- }
52
-
53
66
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "|z" , & timeout ) == FAILURE ) {
54
67
return ;
55
68
}
56
69
57
- if (php_cassandra_future_wait_timed (self -> future , timeout TSRMLS_CC ) == FAILURE ) {
70
+ if (php_cassandra_future_rows_get_result (self , timeout TSRMLS_CC ) == FAILURE ) {
58
71
return ;
59
72
}
60
73
61
- if (php_cassandra_future_is_error (self -> future TSRMLS_CC ) == FAILURE ) {
62
- return ;
74
+ if (PHP5TO7_ZVAL_IS_UNDEF (self -> rows )) {
75
+ if (php_cassandra_get_result ((const CassResult * ) self -> result -> data ,
76
+ & self -> rows TSRMLS_CC ) == FAILURE ) {
77
+ PHP5TO7_ZVAL_MAYBE_DESTROY (self -> rows );
78
+ return ;
79
+ }
63
80
}
64
81
65
- result = cass_future_get_result (self -> future );
66
-
67
- if (!result ) {
68
- zend_throw_exception_ex (cassandra_runtime_exception_ce , 0 TSRMLS_CC ,
69
- "Future doesn't contain a result." );
70
- return ;
71
- }
82
+ object_init_ex (return_value , cassandra_rows_ce );
83
+ rows = PHP_CASSANDRA_GET_ROWS (return_value );
72
84
73
- PHP5TO7_ZVAL_MAYBE_MAKE (self -> rows );
74
- object_init_ex (PHP5TO7_ZVAL_MAYBE_P (self -> rows ), cassandra_rows_ce );
75
- rows = PHP_CASSANDRA_GET_ROWS (PHP5TO7_ZVAL_MAYBE_P (self -> rows ));
85
+ PHP5TO7_ZVAL_COPY (PHP5TO7_ZVAL_MAYBE_P (rows -> rows ),
86
+ PHP5TO7_ZVAL_MAYBE_P (self -> rows ));
76
87
77
- if (php_cassandra_get_result (result , & rows -> rows TSRMLS_CC ) == FAILURE ) {
78
- cass_result_free (result );
79
- zval_ptr_dtor (& self -> rows );
80
- PHP5TO7_ZVAL_UNDEF (self -> rows );
81
- return ;
82
- }
83
-
84
- if (cass_result_has_more_pages (result )) {
88
+ if (cass_result_has_more_pages ((const CassResult * )self -> result -> data )) {
85
89
PHP5TO7_ZVAL_COPY (PHP5TO7_ZVAL_MAYBE_P (rows -> session ),
86
90
PHP5TO7_ZVAL_MAYBE_P (self -> session ));
87
91
rows -> statement = php_cassandra_add_ref (self -> statement );
88
- rows -> result = result ;
89
- } else {
90
- cass_result_free (result );
92
+ rows -> result = php_cassandra_add_ref (self -> result );
91
93
}
92
-
93
- php_cassandra_future_clear (self );
94
-
95
- RETURN_ZVAL (PHP5TO7_ZVAL_MAYBE_P (self -> rows ), 1 , 0 );
96
94
}
97
95
98
96
ZEND_BEGIN_ARG_INFO_EX (arginfo_timeout , 0 , ZEND_RETURN_VALUE , 0 )
@@ -129,8 +127,12 @@ php_cassandra_future_rows_free(php5to7_zend_object_free *object TSRMLS_DC)
129
127
cassandra_future_rows * self = PHP5TO7_ZEND_OBJECT_GET (future_rows , object );
130
128
131
129
PHP5TO7_ZVAL_MAYBE_DESTROY (self -> rows );
130
+ PHP5TO7_ZVAL_MAYBE_DESTROY (self -> session );
131
+
132
+ php_cassandra_del_ref (& self -> statement );
133
+ php_cassandra_del_ref (& self -> result );
132
134
133
- php_cassandra_future_clear (self );
135
+ cass_future_free (self -> future );
134
136
135
137
zend_object_std_dtor (& self -> zval TSRMLS_CC );
136
138
PHP5TO7_MAYBE_EFREE (self );
@@ -144,6 +146,7 @@ php_cassandra_future_rows_new(zend_class_entry *ce TSRMLS_DC)
144
146
145
147
self -> future = NULL ;
146
148
self -> statement = NULL ;
149
+ self -> result = NULL ;
147
150
PHP5TO7_ZVAL_UNDEF (self -> rows );
148
151
PHP5TO7_ZVAL_UNDEF (self -> session );
149
152
0 commit comments