@@ -41,9 +41,10 @@ ZEND_DECLARE_MODULE_GLOBALS(tarantool)
4141 zend_object_store_get_object(ID TSRMLS_CC)
4242
4343#define TARANTOOL_CONNECT_ON_DEMAND (CON , ID ) \
44- if (!CON->stream) \
44+ if (!CON->stream) { \
4545 if (__tarantool_connect(CON, ID TSRMLS_CC) == FAILURE) \
4646 RETURN_FALSE; \
47+ } \
4748 if (CON->stream && php_stream_eof(CON->stream) != 0) \
4849 if (__tarantool_reconnect(CON, ID TSRMLS_CC) == FAILURE)\
4950 RETURN_FALSE;
@@ -183,6 +184,7 @@ int __tarantool_connect(tarantool_object *obj, zval *id TSRMLS_DC) {
183184 char errstr [256 ];
184185 snprintf (errstr , 256 , "%s" , err );
185186 THROW_EXC (errstr );
187+ efree (err );
186188 return FAILURE ;
187189 }
188190 if (obj -> login != NULL && obj -> passwd != NULL ) {
@@ -256,11 +258,11 @@ static int64_t tarantool_step_recv(
256258 * body = NULL ;
257259 if (tarantool_stream_read (obj , pack_len , 5 ) != 5 ) {
258260 THROW_EXC ("Can't read query from server" );
259- goto error ;
261+ goto error_con ;
260262 }
261263 if (php_mp_check (pack_len , 5 )) {
262264 THROW_EXC ("Failed verifying msgpack" );
263- goto error ;
265+ goto error_con ;
264266 }
265267 size_t body_size = php_mp_unpack_package_size (pack_len );
266268 smart_string_ensure (obj -> value , body_size );
@@ -283,7 +285,7 @@ static int64_t tarantool_step_recv(
283285 }
284286 if (php_mp_check (pos , body_size )) {
285287 THROW_EXC ("Failed verifying msgpack" );
286- goto error ;
288+ goto error_con ;
287289 }
288290 if (php_mp_unpack (body , & pos ) == FAILURE ) {
289291 * body = NULL ;
@@ -298,7 +300,7 @@ static int64_t tarantool_step_recv(
298300 THROW_EXC ("request sync is not equal response sync. "
299301 "closing connection" );
300302 tarantool_stream_close (obj );
301- goto error ;
303+ goto error_con ;
302304 }
303305 }
304306 val = NULL ;
@@ -320,8 +322,9 @@ static int64_t tarantool_step_recv(
320322 goto error ;
321323 }
322324 THROW_EXC ("Failed to retrieve answer code" );
323- error :
325+ error_con :
324326 obj -> stream = NULL ;
327+ error :
325328 if (* header ) zval_ptr_dtor (header );
326329 if (* body ) zval_ptr_dtor (body );
327330 SSTR_LEN (obj -> value ) = 0 ;
@@ -333,6 +336,7 @@ static int64_t tarantool_step_recv(
333336const zend_function_entry tarantool_class_methods [] = {
334337 PHP_ME (tarantool_class , __construct , NULL , ZEND_ACC_PUBLIC )
335338 PHP_ME (tarantool_class , connect , NULL , ZEND_ACC_PUBLIC )
339+ PHP_ME (tarantool_class , reconnect , NULL , ZEND_ACC_PUBLIC )
336340 PHP_ME (tarantool_class , close , NULL , ZEND_ACC_PUBLIC )
337341 PHP_ME (tarantool_class , flush_schema , NULL , ZEND_ACC_PUBLIC )
338342 PHP_ME (tarantool_class , authenticate , NULL , ZEND_ACC_PUBLIC )
@@ -382,41 +386,40 @@ zval *tarantool_update_verify_op(zval *op, long position TSRMLS_DC) {
382386 Z_STRLEN_PP (opstr ) != 1 ) {
383387 THROW_EXC ("Field OP must be provided and must be STRING with "
384388 "length=1 at position %d" , position );
385- return NULL ;
389+ goto cleanup ;
386390 }
387391 if (zend_hash_find (ht , "field" , 6 , (void * * )& oppos ) == FAILURE ||
388392 !oppos || Z_TYPE_PP (oppos ) != IS_LONG ) {
389393 THROW_EXC ("Field FIELD must be provided and must be LONG at "
390394 "position %d" , position );
391- return NULL ;
392-
395+ goto cleanup ;
393396 }
394397 zval * * oparg , * * splice_len , * * splice_val ;
395398 switch (Z_STRVAL_PP (opstr )[0 ]) {
396399 case ':' :
397400 if (n != 5 ) {
398401 THROW_EXC ("Five fields must be provided for splice"
399402 " at position %d" , position );
400- return NULL ;
403+ goto cleanup ;
401404 }
402405 if (zend_hash_find (ht , "offset" , 7 ,
403406 (void * * )& oparg ) == FAILURE ||
404407 !oparg || Z_TYPE_PP (oparg ) != IS_LONG ) {
405408 THROW_EXC ("Field OFFSET must be provided and must be LONG for "
406409 "splice at position %d" , position );
407- return NULL ;
410+ goto cleanup ;
408411 }
409412 if (zend_hash_find (ht , "length" , 7 , (void * * )& splice_len ) == FAILURE ||
410413 !oparg || Z_TYPE_PP (splice_len ) != IS_LONG ) {
411414 THROW_EXC ("Field LENGTH must be provided and must be LONG for "
412415 "splice at position %d" , position );
413- return NULL ;
416+ goto cleanup ;
414417 }
415418 if (zend_hash_find (ht , "list" , 5 , (void * * )& splice_val ) == FAILURE ||
416419 !oparg || Z_TYPE_PP (splice_val ) != IS_STRING ) {
417420 THROW_EXC ("Field LIST must be provided and must be STRING for "
418421 "splice at position %d" , position );
419- return NULL ;
422+ goto cleanup ;
420423 }
421424 add_next_index_stringl (arr , Z_STRVAL_PP (opstr ), 1 , 1 );
422425 add_next_index_long (arr , Z_LVAL_PP (oppos ));
@@ -434,13 +437,13 @@ zval *tarantool_update_verify_op(zval *op, long position TSRMLS_DC) {
434437 if (n != 3 ) {
435438 THROW_EXC ("Three fields must be provided for '%s' at "
436439 "position %d" , Z_STRVAL_PP (opstr ), position );
437- return NULL ;
440+ goto cleanup ;
438441 }
439442 if (zend_hash_find (ht , "arg" , 4 , (void * * )& oparg ) == FAILURE ||
440443 !oparg || Z_TYPE_PP (oparg ) != IS_LONG ) {
441444 THROW_EXC ("Field ARG must be provided and must be LONG for "
442445 "'%s' at position %d" , Z_STRVAL_PP (opstr ), position );
443- return NULL ;
446+ goto cleanup ;
444447 }
445448 add_next_index_stringl (arr , Z_STRVAL_PP (opstr ), 1 , 1 );
446449 add_next_index_long (arr , Z_LVAL_PP (oppos ));
@@ -451,13 +454,13 @@ zval *tarantool_update_verify_op(zval *op, long position TSRMLS_DC) {
451454 if (n != 3 ) {
452455 THROW_EXC ("Three fields must be provided for '%s' at "
453456 "position %d" , Z_STRVAL_PP (opstr ), position );
454- return NULL ;
457+ goto cleanup ;
455458 }
456459 if (zend_hash_find (ht , "arg" , 4 , (void * * )& oparg ) == FAILURE ||
457460 !oparg || !PHP_MP_SERIALIZABLE_PP (oparg )) {
458461 THROW_EXC ("Field ARG must be provided and must be SERIALIZABLE for "
459462 "'%s' at position %d" , Z_STRVAL_PP (opstr ), position );
460- return NULL ;
463+ goto cleanup ;
461464 }
462465 add_next_index_stringl (arr , Z_STRVAL_PP (opstr ), 1 , 1 );
463466 add_next_index_long (arr , Z_LVAL_PP (oppos ));
@@ -467,10 +470,12 @@ zval *tarantool_update_verify_op(zval *op, long position TSRMLS_DC) {
467470 default :
468471 THROW_EXC ("Unknown operation '%s' at position %d" ,
469472 Z_STRVAL_PP (opstr ), position );
470- return NULL ;
471-
473+ goto cleanup ;
472474 }
473475 return arr ;
476+ cleanup :
477+ zval_ptr_dtor (& arr );
478+ return NULL ;
474479}
475480
476481zval * tarantool_update_verify_args (zval * args TSRMLS_DC ) {
@@ -497,11 +502,14 @@ zval *tarantool_update_verify_args(zval *args TSRMLS_DC) {
497502 goto cleanup ;
498503 if (add_next_index_zval (arr , op_arr ) == FAILURE ) {
499504 THROW_EXC ("Internal Array Error" );
505+ if (op_arr )
506+ zval_ptr_dtor (& op_arr );
500507 goto cleanup ;
501508 }
502509 }
503510 return arr ;
504511cleanup :
512+ zval_ptr_dtor (& arr );
505513 return NULL ;
506514}
507515
@@ -732,6 +740,14 @@ PHP_METHOD(tarantool_class, connect) {
732740 RETURN_TRUE ;
733741}
734742
743+ PHP_METHOD (tarantool_class , reconnect ) {
744+ TARANTOOL_PARSE_PARAMS (id , "" , id );
745+ TARANTOOL_FETCH_OBJECT (obj , id );
746+ if (__tarantool_reconnect (obj , id TSRMLS_CC ) == FAILURE )
747+ RETURN_FALSE ;
748+ RETURN_TRUE ;
749+ }
750+
735751int __tarantool_authenticate (tarantool_object * obj ) {
736752 TSRMLS_FETCH ();
737753
0 commit comments