Changes made to source and tests to support PHP 7.3 (#822)

* Changes made to support php 7.3

* Correct use of the smart pointer

* Fixed the tests for 7.3

* Some clean up for array_init()

* Fixed formattings and clean up
This commit is contained in:
Jenny Tam 2018-07-26 15:21:03 -07:00 committed by GitHub
parent bd34cabdd2
commit b6d815bfc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 143 additions and 123 deletions

View file

@ -546,7 +546,7 @@ int pdo_sqlsrv_db_handle_factory( _Inout_ pdo_dbh_t *dbh, _In_opt_ zval *driver_
ALLOC_HASHTABLE( pdo_conn_options_ht );
core::sqlsrv_zend_hash_init( *g_pdo_henv_cp, pdo_conn_options_ht, 10 /* # of buckets */,
ZVAL_INTERNAL_DTOR, 0 /*persistent*/ TSRMLS_CC );
ZVAL_PTR_DTOR, 0 /*persistent*/ TSRMLS_CC );
// Either of g_pdo_henv_cp or g_pdo_henv_ncp can be used to propogate the error.
dsn_parser = new ( sqlsrv_malloc( sizeof( conn_string_parser ))) conn_string_parser( *g_pdo_henv_cp, dbh->data_source,

View file

@ -512,7 +512,7 @@ bool pdo_sqlsrv_handle_dbh_error( _Inout_ sqlsrv_context& ctx, _In_opt_ unsigned
msg = static_cast<char*>( sqlsrv_malloc( msg_len ) );
core_sqlsrv_format_message( msg, static_cast<unsigned int>( msg_len ), WARNING_TEMPLATE, error->sqlstate, error->native_code,
error->native_message );
php_error( E_WARNING, msg );
php_error(E_WARNING, "%s", msg.get());
}
ctx.set_last_error( error );
break;

View file

@ -693,9 +693,9 @@ public:
// free the original pointer and assign a new pointer. Use NULL to simply free the pointer.
void reset( _In_opt_ HashTable* ptr = NULL )
{
if( _ptr ) {
zend_hash_destroy( _ptr );
FREE_HASHTABLE( _ptr );
if (_ptr != NULL) {
zend_hash_destroy(_ptr);
FREE_HASHTABLE(_ptr);
}
_ptr = ptr;
}
@ -2377,10 +2377,13 @@ namespace core {
inline void sqlsrv_array_init( _Inout_ sqlsrv_context& ctx, _Out_ zval* new_array TSRMLS_DC)
{
int zr = ::array_init(new_array);
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
#if PHP_VERSION_ID < 70300
CHECK_ZEND_ERROR(::array_init(new_array), 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 )

View file

@ -352,11 +352,11 @@ void die( _In_opt_ const char* msg, ... )
va_start( format_args, msg );
DWORD rc = FormatMessage( FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, last_err_msg, sizeof( last_err_msg ), &format_args );
va_end( format_args );
if( rc == 0 ) {
php_error( E_ERROR, reinterpret_cast<const char*>( INTERNAL_FORMAT_ERROR ));
if (rc == 0) {
php_error(E_ERROR, "%s", reinterpret_cast<const char*>(INTERNAL_FORMAT_ERROR));
}
php_error( E_ERROR, last_err_msg );
php_error(E_ERROR, "%s", last_err_msg);
}
namespace {

View file

@ -889,7 +889,9 @@ PHP_FUNCTION( sqlsrv_fetch_object )
fci.object = Z_OBJ_P( &retval_z );
memset( &fcic, 0, sizeof( fcic ));
#if PHP_VERSION_ID < 70300
fcic.initialized = 1;
#endif
fcic.function_handler = class_entry->constructor;
fcic.calling_scope = class_entry;
@ -1806,10 +1808,14 @@ void fetch_fields_common( _Inout_ ss_sqlsrv_stmt* stmt, _In_ zend_long fetch_typ
field_names.transferred();
}
int zr = array_init( &fields );
CHECK_ZEND_ERROR( zr, stmt, SQLSRV_ERROR_ZEND_HASH ) {
throw ss::SSException();
}
int zr = SUCCESS;
#if PHP_VERSION_ID < 70300
CHECK_ZEND_ERROR(array_init(&fields), 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;

View file

@ -498,18 +498,21 @@ 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 );
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;
}
zval err_z;
ZVAL_UNDEF(&err_z);
#if PHP_VERSION_ID < 70300
if (array_init(&err_z) == 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);
@ -746,10 +749,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 )
{
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;
@ -828,7 +834,6 @@ bool handle_errors_and_warnings( _Inout_ sqlsrv_context& ctx, _Inout_ zval* repo
size_t prev_reported_cnt = 0;
bool reported_chain_was_null = false;
bool ignored_chain_was_null = false;
int zr = SUCCESS;
zval error_z;
ZVAL_UNDEF(&error_z);
sqlsrv_error_auto_ptr error;
@ -837,10 +842,13 @@ 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;
zr = array_init( reported_chain );
if( zr == FAILURE ) {
DIE( "Fatal error in handle_errors_and_warnings" );
#if PHP_VERSION_ID < 70300
if (array_init(reported_chain) == 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 ));
@ -851,11 +859,14 @@ 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;
zr = array_init( ignored_chain );
if( zr == FAILURE ) {
ignored_chain_was_null = true;
#if PHP_VERSION_ID < 70300
if (array_init(ignored_chain) == FAILURE) {
DIE( "Fatal error in handle_errors_and_warnings" );
}
#else
array_init( ignored_chain );
#endif
}
}

View file

@ -119,7 +119,7 @@ sqlsrv_close returns true even if an error happens.
echo "Test successfully done.\n";
?>
--EXPECTF--
Warning: sqlsrv_close() expects parameter 1 to be resource, boolean given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_close() expects parameter 1 to be resource, bool%S given in %Ssqlsrv_errors.php on line %x
Array
(
[0] => Array
@ -153,7 +153,7 @@ Array
)
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, integer given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_free_stmt() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
Array
(
[0] => Array
@ -172,7 +172,7 @@ Warning: sqlsrv_close(): supplied resource is not a valid ss_sqlsrv_conn resourc
Warning: sqlsrv_close() expects parameter 1 to be resource, null given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_close() expects parameter 1 to be resource, integer given in %Ssqlsrv_errors.php on line %x
Warning: sqlsrv_close() expects parameter 1 to be resource, int%S given in %Ssqlsrv_errors.php on line %x
Array
(
[0] => Array

View file

@ -1,24 +1,24 @@
--TEST--
crash caused by a statement being orphaned when an error occurred during sqlsrv_conn_execute.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn1 = Connect();
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
sqlsrv_close($conn1);
$row1 = sqlsrv_fetch_array($stmt1);
$conn3 = Connect();
echo "Test successful\n";
?>
--EXPECTREGEX--
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_conn_execute\.php on line 11
Test successful
--TEST--
crash caused by a statement being orphaned when an error occurred during sqlsrv_conn_execute.
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require( 'MsCommon.inc' );
$conn1 = Connect();
$stmt1 = sqlsrv_query($conn1, "SELECT * FROM Servers");
sqlsrv_close($conn1);
$row1 = sqlsrv_fetch_array($stmt1);
$conn3 = Connect();
echo "Test successful\n";
?>
--EXPECTREGEX--
Warning: sqlsrv_fetch_array\(\) expects parameter 1 to be resource, bool(ean){0,1} given in .+(\/|\\)test_conn_execute\.php on line 11
Test successful

View file

@ -1,61 +1,61 @@
--TEST--
password with non alphanumeric characters
--DESCRIPTION--
The first three cases should have no problem connecting. Only the last case fails because the
right curly brace should be escaped with another right brace.
In Azure for this test to pass do not specify any particular database when connecting
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require 'MsSetup.inc';
function toConnect($options = array())
{
global $server;
// this function makes a connection to the server WITHOUT specifying the database
return sqlsrv_connect($server, $options);
}
$conn = toConnect(array( "UID" => "test_password", "pwd" => "! ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password2", "pwd" => "!}} ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}}" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}" ));
if ($conn)
{
echo( "Shouldn't have connected" );
}
$errors = sqlsrv_errors();
echo $errors[0]["message"];
sqlsrv_close( $conn );
print "Test successful";
?>
--EXPECTREGEX--
An unescaped right brace \(}\) was found in either the user name or password. All right braces must be escaped with another right brace \(}}\)\.
Warning: sqlsrv_close\(\) expects parameter 1 to be resource, boolean given in .+(\/|\\)test_non_alpha_password\.php on line 45
Test successful
--TEST--
password with non alphanumeric characters
--DESCRIPTION--
The first three cases should have no problem connecting. Only the last case fails because the
right curly brace should be escaped with another right brace.
In Azure for this test to pass do not specify any particular database when connecting
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
require 'MsSetup.inc';
function toConnect($options = array())
{
global $server;
// this function makes a connection to the server WITHOUT specifying the database
return sqlsrv_connect($server, $options);
}
$conn = toConnect(array( "UID" => "test_password", "pwd" => "! ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password2", "pwd" => "!}} ;4triou" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}}" ));
if (!$conn)
{
$errors = sqlsrv_errors();
echo( $errors[0]["message"]);
}
sqlsrv_close( $conn );
$conn = toConnect(array( "UID" => "test_password3", "pwd" => "! ;4triou}" ));
if ($conn)
{
echo( "Shouldn't have connected" );
}
$errors = sqlsrv_errors();
echo $errors[0]["message"];
sqlsrv_close( $conn );
print "Test successful";
?>
--EXPECTREGEX--
An unescaped right brace \(}\) was found in either the user name or password. All right braces must be escaped with another right brace \(}}\)\.
Warning: sqlsrv_close\(\) expects parameter 1 to be resource, bool(ean){0,1} given in .+(\/|\\)test_non_alpha_password\.php on line 45
Test successful