Skip to content

Commit

Permalink
Some clean up for array_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam committed Jul 25, 2018
1 parent 3506f35 commit 3bc302b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
10 changes: 7 additions & 3 deletions source/shared/core_sqlsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2377,10 +2377,14 @@ namespace core {

inline void sqlsrv_array_init( _Inout_ sqlsrv_context& ctx, _Out_ zval* new_array TSRMLS_DC)
{
array_init(new_array); /*int zr = ::array_init(new_array);
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
#if PHP_VERSION_ID < 70300
int zr = ::array_init(new_array);
CHECK_ZEND_ERROR(zr, ctx, SQLSRV_ERROR_ZEND_HASH) {
throw CoreException();
}*/
}
#else
array_init(new_array);
#endif
}

inline void sqlsrv_php_stream_from_zval_no_verify( _Inout_ sqlsrv_context& ctx, _Outref_result_maybenull_ php_stream*& stream, _In_opt_ zval* stream_z TSRMLS_DC )
Expand Down
12 changes: 8 additions & 4 deletions source/sqlsrv/stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,14 @@ void fetch_fields_common( _Inout_ ss_sqlsrv_stmt* stmt, _In_ zend_long fetch_typ
}

int zr;
array_init( &fields ); /*int zr = array_init( &fields );
CHECK_ZEND_ERROR( zr, stmt, SQLSRV_ERROR_ZEND_HASH ) {
throw ss::SSException();
}*/
#if PHP_VERSION_ID < 70300
zr = array_init(&fields);
CHECK_ZEND_ERROR(zr, stmt, SQLSRV_ERROR_ZEND_HASH) {
throw ss::SSException();
}
#else
array_init(&fields);
#endif

for( int i = 0; i < num_cols; ++i ) {
SQLLEN field_len = -1;
Expand Down
63 changes: 39 additions & 24 deletions source/sqlsrv/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,23 @@ PHP_FUNCTION( sqlsrv_errors )

LOG_FUNCTION( "sqlsrv_errors" );

if(( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags ) == FAILURE ) ||
( flags != SQLSRV_ERR_ALL && flags != SQLSRV_ERR_ERRORS && flags != SQLSRV_ERR_WARNINGS )) {
LOG( SEV_ERROR, "An invalid parameter was passed to %1!s!.", _FN_ );
RETURN_FALSE;
}
int result;
zval err_z;
ZVAL_UNDEF( &err_z );
array_init( &err_z ); /*result = array_init( &err_z );
if( result == FAILURE ) {
RETURN_FALSE;
}*/
if(( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags ) == FAILURE ) ||
( flags != SQLSRV_ERR_ALL && flags != SQLSRV_ERR_ERRORS && flags != SQLSRV_ERR_WARNINGS )) {
LOG( SEV_ERROR, "An invalid parameter was passed to %1!s!.", _FN_ );
RETURN_FALSE;
}
int result;
zval err_z;
ZVAL_UNDEF(&err_z);
#if PHP_VERSION_ID < 70300
result = array_init(&err_z);
if (result == FAILURE) {
RETURN_FALSE;
}
#else
array_init(&err_z);
#endif

if( flags == SQLSRV_ERR_ALL || flags == SQLSRV_ERR_ERRORS ) {
if( Z_TYPE( SQLSRV_G( errors )) == IS_ARRAY && !sqlsrv_merge_zend_hash( &err_z, &SQLSRV_G( errors ) TSRMLS_CC )) {
zval_ptr_dtor(&err_z);
Expand Down Expand Up @@ -746,10 +751,13 @@ sqlsrv_error_const* get_error_message( _In_ unsigned int sqlsrv_error_code ) {
void copy_error_to_zval( _Inout_ zval* error_z, _In_ sqlsrv_error_const* error, _Inout_ zval* reported_chain, _Inout_ zval* ignored_chain,
_In_ bool warning TSRMLS_DC )
{

array_init( error_z ); /*if( array_init( error_z ) == FAILURE ) {
#if PHP_VERSION_ID < 70300
if (array_init(error_z) == FAILURE) {
DIE( "Fatal error during error processing" );
}*/
}
#else
array_init(error_z);
#endif

// sqlstate
zval temp;
Expand Down Expand Up @@ -837,10 +845,14 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo
if( Z_TYPE_P( reported_chain ) == IS_NULL ) {

reported_chain_was_null = true;
array_init( reported_chain ); /*zr = array_init( reported_chain );
if( zr == FAILURE ) {
DIE( "Fatal error in handle_errors_and_warnings" );
}*/
#if PHP_VERSION_ID < 70300
zr = array_init(reported_chain);
if (zr == FAILURE) {
DIE( "Fatal error during error processing" );
}
#else
array_init(reported_chain);
#endif
}
else {
prev_reported_cnt = zend_hash_num_elements( Z_ARRVAL_P( reported_chain ));
Expand All @@ -851,12 +863,15 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo

if( Z_TYPE_P( ignored_chain ) == IS_NULL ) {

ignored_chain_was_null = true;
array_init( ignored_chain );
/* zr = array_init( ignored_chain );
if( zr == FAILURE ) {
ignored_chain_was_null = true;
#if PHP_VERSION_ID < 70300
zr = array_init(ignored_chain);
if (zr == FAILURE) {
DIE( "Fatal error in handle_errors_and_warnings" );
} */
}
#else
array_init( ignored_chain );
#endif
}
}

Expand Down

0 comments on commit 3bc302b

Please sign in to comment.