andrey Tue, 25 May 2010 22:40:47 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=299761
Log:
Init should return status value because initialization can fail.
In this case mysqlnd_init() should return NULL to the end-user.
Changed paths:
U php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c
U php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h
U php/php-src/trunk/ext/mysqlnd/mysqlnd.c
U php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c 2010-05-25 22:38:11 UTC
(rev 299760)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c 2010-05-25 22:40:47 UTC
(rev 299761)
@@ -2140,7 +2140,7 @@
MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC);
-static void MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn TSRMLS_DC);
+static enum_func_status MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn
TSRMLS_DC);
static
MYSQLND_CLASS_METHODS_START(mysqlnd_conn)
@@ -2217,17 +2217,17 @@
/* {{{ mysqlnd_conn::init */
-static void
+static enum_func_status
MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn TSRMLS_DC)
{
DBG_ENTER("mysqlnd_conn::init");
+ mysqlnd_stats_init(&conn->stats, STAT_LAST);
+ SET_ERROR_AFF_ROWS(conn);
+
conn->net = mysqlnd_net_init(conn->persistent TSRMLS_CC);
conn->protocol = mysqlnd_protocol_init(conn->persistent TSRMLS_CC);
- mysqlnd_stats_init(&conn->stats, STAT_LAST);
- SET_ERROR_AFF_ROWS(conn);
-
- DBG_VOID_RETURN;
+ DBG_RETURN(conn->net && conn->protocol? PASS:FAIL);
}
/* }}} */
@@ -2249,7 +2249,10 @@
CONN_SET_STATE(ret, CONN_ALLOCED);
ret->m->get_reference(ret TSRMLS_CC);
- ret->m->init(ret TSRMLS_CC);
+ if (PASS != ret->m->init(ret TSRMLS_CC)) {
+ ret->m->dtor(ret TSRMLS_CC);
+ ret = NULL;
+ }
DBG_RETURN(ret);
}
Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h 2010-05-25
22:38:11 UTC (rev 299760)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_structs.h 2010-05-25
22:40:47 UTC (rev 299761)
@@ -334,7 +334,7 @@
-typedef void (*func_mysqlnd_conn__init)(MYSQLND *
conn TSRMLS_DC);
+typedef enum_func_status (*func_mysqlnd_conn__init)(MYSQLND * conn
TSRMLS_DC);
typedef enum_func_status (*func_mysqlnd_conn__connect)(MYSQLND *conn,
const char *host, const char * user, const char * passwd, unsigned int
passwd_len, const char * db, unsigned int db_len, unsigned int port, const char
* socket, unsigned int mysql_flags TSRMLS_DC);
typedef ulong
(*func_mysqlnd_conn__escape_string)(const MYSQLND * const conn, char *newstr,
const char *escapestr, size_t escapestr_len TSRMLS_DC);
typedef enum_func_status (*func_mysqlnd_conn__set_charset)(MYSQLND *
const conn, const char * const charset TSRMLS_DC);
Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-05-25 22:38:11 UTC (rev
299760)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c 2010-05-25 22:40:47 UTC (rev
299761)
@@ -2140,7 +2140,7 @@
MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC);
-static void MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn TSRMLS_DC);
+static enum_func_status MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn
TSRMLS_DC);
static
MYSQLND_CLASS_METHODS_START(mysqlnd_conn)
@@ -2217,17 +2217,17 @@
/* {{{ mysqlnd_conn::init */
-static void
+static enum_func_status
MYSQLND_METHOD(mysqlnd_conn, init)(MYSQLND * conn TSRMLS_DC)
{
DBG_ENTER("mysqlnd_conn::init");
+ mysqlnd_stats_init(&conn->stats, STAT_LAST);
+ SET_ERROR_AFF_ROWS(conn);
+
conn->net = mysqlnd_net_init(conn->persistent TSRMLS_CC);
conn->protocol = mysqlnd_protocol_init(conn->persistent TSRMLS_CC);
- mysqlnd_stats_init(&conn->stats, STAT_LAST);
- SET_ERROR_AFF_ROWS(conn);
-
- DBG_VOID_RETURN;
+ DBG_RETURN(conn->net && conn->protocol? PASS:FAIL);
}
/* }}} */
@@ -2249,7 +2249,10 @@
CONN_SET_STATE(ret, CONN_ALLOCED);
ret->m->get_reference(ret TSRMLS_CC);
- ret->m->init(ret TSRMLS_CC);
+ if (PASS != ret->m->init(ret TSRMLS_CC)) {
+ ret->m->dtor(ret TSRMLS_CC);
+ ret = NULL;
+ }
DBG_RETURN(ret);
}
Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h 2010-05-25 22:38:11 UTC
(rev 299760)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h 2010-05-25 22:40:47 UTC
(rev 299761)
@@ -334,7 +334,7 @@
-typedef void (*func_mysqlnd_conn__init)(MYSQLND *
conn TSRMLS_DC);
+typedef enum_func_status (*func_mysqlnd_conn__init)(MYSQLND * conn
TSRMLS_DC);
typedef enum_func_status (*func_mysqlnd_conn__connect)(MYSQLND *conn,
const char *host, const char * user, const char * passwd, unsigned int
passwd_len, const char * db, unsigned int db_len, unsigned int port, const char
* socket, unsigned int mysql_flags TSRMLS_DC);
typedef ulong
(*func_mysqlnd_conn__escape_string)(const MYSQLND * const conn, char *newstr,
const char *escapestr, size_t escapestr_len TSRMLS_DC);
typedef enum_func_status (*func_mysqlnd_conn__set_charset)(MYSQLND *
const conn, const char * const charset TSRMLS_DC);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php