andrey                                   Mon, 24 Oct 2011 12:34:44 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=318365

Log:
move plugin specific stuff to one file. create object factory
for similar objects

Changed paths:
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd.c
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_driver.c
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_priv.h
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_structs.h
    U   php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_wireprotocol.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_driver.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -63,22 +63,6 @@

 PHPAPI MYSQLND_STATS *mysqlnd_global_stats = NULL;

-static struct st_mysqlnd_plugin_core mysqlnd_plugin_core;
-
-/* {{{ mysqlnd_error_list_pdtor */
-static void
-mysqlnd_error_list_pdtor(void * pDest)
-{
-	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
-	TSRMLS_FETCH();
-	DBG_ENTER("mysqlnd_error_list_pdtor");
-	if (element->error) {
-		mnd_pefree(element->error, TRUE);
-	}
-	DBG_VOID_RETURN;
-}
-/* }}} */
-
 /* {{{ mysqlnd_conn::free_options */
 static void
 MYSQLND_METHOD(mysqlnd_conn, free_options)(MYSQLND * conn TSRMLS_DC)
@@ -2470,37 +2454,13 @@
 MYSQLND_CLASS_METHODS_END;


-/* {{{ mysqlnd_init */
-PHPAPI MYSQLND * _mysqlnd_init(zend_bool persistent TSRMLS_DC)
+/* {{{ _mysqlnd_init */
+PHPAPI MYSQLND *
+_mysqlnd_init(zend_bool persistent TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND *ret;
-
+	MYSQLND * ret;
 	DBG_ENTER("mysqlnd_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	ret = mnd_pecalloc(1, alloc_size, persistent);
-	if (!ret) {
-		DBG_RETURN(NULL);
-	}
-
-	ret->persistent = persistent;
-	ret->m = mysqlnd_conn_get_methods();
-	CONN_SET_STATE(ret, CONN_ALLOCED);
-	ret->m->get_reference(ret TSRMLS_CC);
-
-	if (PASS != ret->m->init(ret TSRMLS_CC)) {
-		ret->m->dtor(ret TSRMLS_CC);
-		ret = NULL;
-	}
-
-	ret->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
-	if (!ret->error_info.error_list) {
-		ret->m->dtor(ret TSRMLS_CC);
-		ret = NULL;
-	} else {
-		zend_llist_init(ret->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
-	}
-
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_connection(persistent TSRMLS_CC);
 	DBG_RETURN(ret);
 }
 /* }}} */

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_driver.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_driver.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_driver.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -89,6 +89,163 @@
 }
 /* }}} */

+
+/* {{{ mysqlnd_error_list_pdtor */
+static void
+mysqlnd_error_list_pdtor(void * pDest)
+{
+	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
+	TSRMLS_FETCH();
+	DBG_ENTER("mysqlnd_error_list_pdtor");
+	if (element->error) {
+		mnd_pefree(element->error, TRUE);
+	}
+	DBG_VOID_RETURN;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_connection */
+static MYSQLND *
+MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND *ret;
+
+	DBG_ENTER("mysqlnd_driver::get_connection");
+	DBG_INF_FMT("persistent=%u", persistent);
+	ret = mnd_pecalloc(1, alloc_size, persistent);
+	if (!ret) {
+		DBG_RETURN(NULL);
+	}
+
+	ret->persistent = persistent;
+	ret->m = mysqlnd_conn_get_methods();
+	CONN_SET_STATE(ret, CONN_ALLOCED);
+	ret->m->get_reference(ret TSRMLS_CC);
+
+	if (PASS != ret->m->init(ret TSRMLS_CC)) {
+		ret->m->dtor(ret TSRMLS_CC);
+		ret = NULL;
+	}
+
+	ret->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
+	if (!ret->error_info.error_list) {
+		ret->m->dtor(ret TSRMLS_CC);
+		ret = NULL;
+	} else {
+		zend_llist_init(ret->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
+	}
+
+	DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_prepared_statement */
+static MYSQLND_STMT *
+MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND * const conn TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
+	MYSQLND_STMT_DATA * stmt = NULL;
+
+	DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
+	do {
+		if (!ret) {
+			break;
+		}
+		ret->m = mysqlnd_stmt_get_methods();
+		ret->persistent = conn->persistent;
+
+		stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
+		DBG_INF_FMT("stmt=%p", stmt);
+		if (!stmt) {
+			break;
+		}
+		stmt->persistent = conn->persistent;
+		stmt->state = MYSQLND_STMT_INITTED;
+		stmt->execute_cmd_buffer.length = 4096;
+		stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
+		if (!stmt->execute_cmd_buffer.buffer) {
+			break;
+		}
+
+		stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
+		/*
+		  Mark that we reference the connection, thus it won't be
+		  be destructed till there is open statements. The last statement
+		  or normal query result will close it then.
+		*/
+		stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
+		stmt->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
+		if (!stmt->error_info.error_list) {
+			break;
+		}
+		zend_llist_init(stmt->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_error_list_pdtor, conn->persistent);
+
+		DBG_RETURN(ret);
+	} while (0);
+
+	SET_OOM_ERROR(conn->error_info);
+	if (ret) {
+		ret->m->dtor(ret, TRUE TSRMLS_CC);
+		ret = NULL;
+	}
+	DBG_RETURN(NULL);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_io_channel */
+PHPAPI MYSQLND_NET *
+MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
+
+	DBG_ENTER("mysqlnd_object_factory::get_io_channel");
+	DBG_INF_FMT("persistent=%u", persistent);
+	if (net) {
+		net->persistent = persistent;
+		net->m = *mysqlnd_net_get_methods();
+
+		if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
+			net->m.dtor(net, stats, error_info TSRMLS_CC);
+			net = NULL;
+		}
+	}
+	DBG_RETURN(net);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_protocol_decoder */
+PHPAPI MYSQLND_PROTOCOL *
+MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)(zend_bool persistent TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);
+
+	DBG_ENTER("mysqlnd_object_factory::get_protocol_decoder");
+	DBG_INF_FMT("persistent=%u", persistent);
+	if (ret) {
+		ret->persistent = persistent;
+		ret->m = mysqlnd_mysqlnd_protocol_methods;
+	}
+
+	DBG_RETURN(ret);
+}
+/* }}} */
+
+
+MYSQLND_CLASS_METHODS_START(mysqlnd_object_factory)
+	MYSQLND_METHOD(mysqlnd_object_factory, get_connection),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)
+MYSQLND_CLASS_METHODS_END;
+
 /*
  * Local variables:
  * tab-width: 4

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_net.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_net.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -1037,20 +1037,9 @@
 PHPAPI MYSQLND_NET *
 mysqlnd_net_init(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
-
+	MYSQLND_NET * net;
 	DBG_ENTER("mysqlnd_net_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	if (net) {
-		net->persistent = persistent;
-		net->m = *mysqlnd_net_get_methods();
-
-		if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
-			net->m.dtor(net, stats, error_info TSRMLS_CC);
-			net = NULL;
-		}
-	}
+	net = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_io_channel(persistent, stats, error_info TSRMLS_CC);
 	DBG_RETURN(net);
 }
 /* }}} */

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_priv.h
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_priv.h	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_priv.h	2011-10-24 12:34:44 UTC (rev 318365)
@@ -47,11 +47,6 @@
 #define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
 #endif

-#define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
-#define MYSQLND_CLASS_METHODS_START(class)	MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) = {
-#define MYSQLND_CLASS_METHODS_END			}
-#define MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class)
-
 #if MYSQLND_UNICODE
 #define mysqlnd_array_init(arg, field_count) \
 { \
@@ -205,6 +200,7 @@
 PHPAPI extern const char * const mysqlnd_server_gone;
 PHPAPI extern const char * const mysqlnd_out_of_memory;

+extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_object_factory);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_res);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_protocol);

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_ps.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_ps.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -51,21 +51,6 @@
 static void mysqlnd_stmt_separate_one_result_bind(MYSQLND_STMT * const stmt, unsigned int param_no TSRMLS_DC);


-/* {{{ mysqlnd_ps_error_list_pdtor */
-static void
-mysqlnd_ps_error_list_pdtor(void * pDest)
-{
-	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
-	TSRMLS_FETCH();
-	DBG_ENTER("mysqlnd_ps_error_list_pdtor");
-	if (element->error) {
-		mnd_pefree(element->error, TRUE);
-	}
-	DBG_VOID_RETURN;
-}
-/* }}} */
-
-
 /* {{{ mysqlnd_stmt::store_result */
 static MYSQLND_RES *
 MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC)
@@ -2362,55 +2347,13 @@


 /* {{{ _mysqlnd_stmt_init */
-MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
+MYSQLND_STMT *
+_mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
-	MYSQLND_STMT_DATA * stmt = NULL;
-
+	MYSQLND_STMT * ret;
 	DBG_ENTER("_mysqlnd_stmt_init");
-	do {
-		if (!ret) {
-			break;
-		}
-		ret->m = mysqlnd_stmt_get_methods();
-		ret->persistent = conn->persistent;
-
-		stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
-		DBG_INF_FMT("stmt=%p", stmt);
-		if (!stmt) {
-			break;
-		}
-		stmt->persistent = conn->persistent;
-		stmt->state = MYSQLND_STMT_INITTED;
-		stmt->execute_cmd_buffer.length = 4096;
-		stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
-		if (!stmt->execute_cmd_buffer.buffer) {
-			break;
-		}
-
-		stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
-		/*
-		  Mark that we reference the connection, thus it won't be
-		  be destructed till there is open statements. The last statement
-		  or normal query result will close it then.
-		*/
-		stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
-		stmt->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
-		if (!stmt->error_info.error_list) {
-			break;
-		}
-		zend_llist_init(stmt->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_ps_error_list_pdtor, conn->persistent);
-
-		DBG_RETURN(ret);
-	} while (0);
-
-	SET_OOM_ERROR(conn->error_info);
-	if (ret) {
-		ret->m->dtor(ret, TRUE TSRMLS_CC);
-		ret = NULL;
-	}
-	DBG_RETURN(NULL);
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_prepared_statement(conn TSRMLS_CC);
+	DBG_RETURN(ret);
 }
 /* }}} */


Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_structs.h	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_structs.h	2011-10-24 12:34:44 UTC (rev 318365)
@@ -25,6 +25,12 @@

 #define MYSQLND_TYPEDEFED_METHODS

+#define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
+#define MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class)
+
+#define MYSQLND_CLASS_METHODS_START(class)	MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) = {
+#define MYSQLND_CLASS_METHODS_END			}
+
 typedef struct st_mysqlnd_memory_pool MYSQLND_MEMORY_POOL;
 typedef struct st_mysqlnd_memory_pool_chunk MYSQLND_MEMORY_POOL_CHUNK;
 typedef struct st_mysqlnd_memory_pool_chunk_llist MYSQLND_MEMORY_POOL_CHUNK_LLIST;
@@ -368,6 +374,21 @@
 };


+typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(zend_bool persistent TSRMLS_DC);
+typedef MYSQLND_STMT * (*func_mysqlnd_object_factory__get_prepared_statement)(MYSQLND * conn TSRMLS_DC);
+typedef MYSQLND_NET * (*func_mysqlnd_object_factory__get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC);
+typedef MYSQLND_PROTOCOL * (*func_mysqlnd_object_factory__get_protocol_decoder)(zend_bool persistent TSRMLS_DC);
+
+
+struct st_mysqlnd_object_factory_methods
+{
+	func_mysqlnd_object_factory__get_connection get_connection;
+	func_mysqlnd_object_factory__get_prepared_statement get_prepared_statement;
+	func_mysqlnd_object_factory__get_io_channel get_io_channel;
+	func_mysqlnd_object_factory__get_protocol_decoder get_protocol_decoder;
+};
+
+
 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_or_pipe, unsigned int mysql_flags TSRMLS_DC);
 typedef ulong				(*func_mysqlnd_conn__escape_string)(MYSQLND * const conn, char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC);

Modified: php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_wireprotocol.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/branches/PHP_5_4/ext/mysqlnd/mysqlnd_wireprotocol.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -2371,16 +2371,9 @@
 PHPAPI MYSQLND_PROTOCOL *
 mysqlnd_protocol_init(zend_bool persistent TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);
-
+	MYSQLND_PROTOCOL * ret;
 	DBG_ENTER("mysqlnd_protocol_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	if (ret) {
-		ret->persistent = persistent;
-		ret->m = mysqlnd_mysqlnd_protocol_methods;
-	}
-
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_protocol_decoder(persistent TSRMLS_CC);
 	DBG_RETURN(ret);
 }
 /* }}} */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -63,22 +63,6 @@

 PHPAPI MYSQLND_STATS *mysqlnd_global_stats = NULL;

-static struct st_mysqlnd_plugin_core mysqlnd_plugin_core;
-
-/* {{{ mysqlnd_error_list_pdtor */
-static void
-mysqlnd_error_list_pdtor(void * pDest)
-{
-	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
-	TSRMLS_FETCH();
-	DBG_ENTER("mysqlnd_error_list_pdtor");
-	if (element->error) {
-		mnd_pefree(element->error, TRUE);
-	}
-	DBG_VOID_RETURN;
-}
-/* }}} */
-
 /* {{{ mysqlnd_conn::free_options */
 static void
 MYSQLND_METHOD(mysqlnd_conn, free_options)(MYSQLND * conn TSRMLS_DC)
@@ -2470,37 +2454,13 @@
 MYSQLND_CLASS_METHODS_END;


-/* {{{ mysqlnd_init */
-PHPAPI MYSQLND * _mysqlnd_init(zend_bool persistent TSRMLS_DC)
+/* {{{ _mysqlnd_init */
+PHPAPI MYSQLND *
+_mysqlnd_init(zend_bool persistent TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND *ret;
-
+	MYSQLND * ret;
 	DBG_ENTER("mysqlnd_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	ret = mnd_pecalloc(1, alloc_size, persistent);
-	if (!ret) {
-		DBG_RETURN(NULL);
-	}
-
-	ret->persistent = persistent;
-	ret->m = mysqlnd_conn_get_methods();
-	CONN_SET_STATE(ret, CONN_ALLOCED);
-	ret->m->get_reference(ret TSRMLS_CC);
-
-	if (PASS != ret->m->init(ret TSRMLS_CC)) {
-		ret->m->dtor(ret TSRMLS_CC);
-		ret = NULL;
-	}
-
-	ret->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
-	if (!ret->error_info.error_list) {
-		ret->m->dtor(ret TSRMLS_CC);
-		ret = NULL;
-	} else {
-		zend_llist_init(ret->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
-	}
-
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_connection(persistent TSRMLS_CC);
 	DBG_RETURN(ret);
 }
 /* }}} */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_driver.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_driver.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_driver.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -90,6 +90,163 @@
 /* }}} */


+
+/* {{{ mysqlnd_error_list_pdtor */
+static void
+mysqlnd_error_list_pdtor(void * pDest)
+{
+	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
+	TSRMLS_FETCH();
+	DBG_ENTER("mysqlnd_error_list_pdtor");
+	if (element->error) {
+		mnd_pefree(element->error, TRUE);
+	}
+	DBG_VOID_RETURN;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_connection */
+static MYSQLND *
+MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND *ret;
+
+	DBG_ENTER("mysqlnd_driver::get_connection");
+	DBG_INF_FMT("persistent=%u", persistent);
+	ret = mnd_pecalloc(1, alloc_size, persistent);
+	if (!ret) {
+		DBG_RETURN(NULL);
+	}
+
+	ret->persistent = persistent;
+	ret->m = mysqlnd_conn_get_methods();
+	CONN_SET_STATE(ret, CONN_ALLOCED);
+	ret->m->get_reference(ret TSRMLS_CC);
+
+	if (PASS != ret->m->init(ret TSRMLS_CC)) {
+		ret->m->dtor(ret TSRMLS_CC);
+		ret = NULL;
+	}
+
+	ret->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
+	if (!ret->error_info.error_list) {
+		ret->m->dtor(ret TSRMLS_CC);
+		ret = NULL;
+	} else {
+		zend_llist_init(ret->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
+	}
+
+	DBG_RETURN(ret);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_prepared_statement */
+static MYSQLND_STMT *
+MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND * const conn TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
+	MYSQLND_STMT_DATA * stmt = NULL;
+
+	DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
+	do {
+		if (!ret) {
+			break;
+		}
+		ret->m = mysqlnd_stmt_get_methods();
+		ret->persistent = conn->persistent;
+
+		stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
+		DBG_INF_FMT("stmt=%p", stmt);
+		if (!stmt) {
+			break;
+		}
+		stmt->persistent = conn->persistent;
+		stmt->state = MYSQLND_STMT_INITTED;
+		stmt->execute_cmd_buffer.length = 4096;
+		stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
+		if (!stmt->execute_cmd_buffer.buffer) {
+			break;
+		}
+
+		stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
+		/*
+		  Mark that we reference the connection, thus it won't be
+		  be destructed till there is open statements. The last statement
+		  or normal query result will close it then.
+		*/
+		stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
+		stmt->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
+		if (!stmt->error_info.error_list) {
+			break;
+		}
+		zend_llist_init(stmt->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_error_list_pdtor, conn->persistent);
+
+		DBG_RETURN(ret);
+	} while (0);
+
+	SET_OOM_ERROR(conn->error_info);
+	if (ret) {
+		ret->m->dtor(ret, TRUE TSRMLS_CC);
+		ret = NULL;
+	}
+	DBG_RETURN(NULL);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_io_channel */
+PHPAPI MYSQLND_NET *
+MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
+
+	DBG_ENTER("mysqlnd_object_factory::get_io_channel");
+	DBG_INF_FMT("persistent=%u", persistent);
+	if (net) {
+		net->persistent = persistent;
+		net->m = *mysqlnd_net_get_methods();
+
+		if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
+			net->m.dtor(net, stats, error_info TSRMLS_CC);
+			net = NULL;
+		}
+	}
+	DBG_RETURN(net);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_object_factory::get_protocol_decoder */
+PHPAPI MYSQLND_PROTOCOL *
+MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)(zend_bool persistent TSRMLS_DC)
+{
+	size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
+	MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);
+
+	DBG_ENTER("mysqlnd_object_factory::get_protocol_decoder");
+	DBG_INF_FMT("persistent=%u", persistent);
+	if (ret) {
+		ret->persistent = persistent;
+		ret->m = mysqlnd_mysqlnd_protocol_methods;
+	}
+
+	DBG_RETURN(ret);
+}
+/* }}} */
+
+
+MYSQLND_CLASS_METHODS_START(mysqlnd_object_factory)
+	MYSQLND_METHOD(mysqlnd_object_factory, get_connection),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_io_channel),
+	MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_decoder)
+MYSQLND_CLASS_METHODS_END;
+
 /*
  * Local variables:
  * tab-width: 4

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_net.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -1037,20 +1037,9 @@
 PHPAPI MYSQLND_NET *
 mysqlnd_net_init(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_NET) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_NET * net = mnd_pecalloc(1, alloc_size, persistent);
-
+	MYSQLND_NET * net;
 	DBG_ENTER("mysqlnd_net_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	if (net) {
-		net->persistent = persistent;
-		net->m = *mysqlnd_net_get_methods();
-
-		if (PASS != net->m.init(net, stats, error_info TSRMLS_CC)) {
-			net->m.dtor(net, stats, error_info TSRMLS_CC);
-			net = NULL;
-		}
-	}
+	net = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_io_channel(persistent, stats, error_info TSRMLS_CC);
 	DBG_RETURN(net);
 }
 /* }}} */

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_priv.h	2011-10-24 12:34:44 UTC (rev 318365)
@@ -47,11 +47,6 @@
 #define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
 #endif

-#define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
-#define MYSQLND_CLASS_METHODS_START(class)	MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) = {
-#define MYSQLND_CLASS_METHODS_END			}
-#define MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class)
-
 #if MYSQLND_UNICODE
 #define mysqlnd_array_init(arg, field_count) \
 { \
@@ -205,6 +200,7 @@
 PHPAPI extern const char * const mysqlnd_server_gone;
 PHPAPI extern const char * const mysqlnd_out_of_memory;

+extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_object_factory);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_res);
 extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_protocol);

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_ps.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -51,21 +51,6 @@
 static void mysqlnd_stmt_separate_one_result_bind(MYSQLND_STMT * const stmt, unsigned int param_no TSRMLS_DC);


-/* {{{ mysqlnd_ps_error_list_pdtor */
-static void
-mysqlnd_ps_error_list_pdtor(void * pDest)
-{
-	MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
-	TSRMLS_FETCH();
-	DBG_ENTER("mysqlnd_ps_error_list_pdtor");
-	if (element->error) {
-		mnd_pefree(element->error, TRUE);
-	}
-	DBG_VOID_RETURN;
-}
-/* }}} */
-
-
 /* {{{ mysqlnd_stmt::store_result */
 static MYSQLND_RES *
 MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC)
@@ -2362,55 +2347,13 @@


 /* {{{ _mysqlnd_stmt_init */
-MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
+MYSQLND_STMT *
+_mysqlnd_stmt_init(MYSQLND * const conn TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_STMT * ret = mnd_pecalloc(1, alloc_size, conn->persistent);
-	MYSQLND_STMT_DATA * stmt = NULL;
-
+	MYSQLND_STMT * ret;
 	DBG_ENTER("_mysqlnd_stmt_init");
-	do {
-		if (!ret) {
-			break;
-		}
-		ret->m = mysqlnd_stmt_get_methods();
-		ret->persistent = conn->persistent;
-
-		stmt = ret->data = mnd_pecalloc(1, sizeof(MYSQLND_STMT_DATA), conn->persistent);
-		DBG_INF_FMT("stmt=%p", stmt);
-		if (!stmt) {
-			break;
-		}
-		stmt->persistent = conn->persistent;
-		stmt->state = MYSQLND_STMT_INITTED;
-		stmt->execute_cmd_buffer.length = 4096;
-		stmt->execute_cmd_buffer.buffer = mnd_pemalloc(stmt->execute_cmd_buffer.length, stmt->persistent);
-		if (!stmt->execute_cmd_buffer.buffer) {
-			break;
-		}
-
-		stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
-		/*
-		  Mark that we reference the connection, thus it won't be
-		  be destructed till there is open statements. The last statement
-		  or normal query result will close it then.
-		*/
-		stmt->conn = conn->m->get_reference(conn TSRMLS_CC);
-		stmt->error_info.error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
-		if (!stmt->error_info.error_list) {
-			break;
-		}
-		zend_llist_init(stmt->error_info.error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_ps_error_list_pdtor, conn->persistent);
-
-		DBG_RETURN(ret);
-	} while (0);
-
-	SET_OOM_ERROR(conn->error_info);
-	if (ret) {
-		ret->m->dtor(ret, TRUE TSRMLS_CC);
-		ret = NULL;
-	}
-	DBG_RETURN(NULL);
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_prepared_statement(conn TSRMLS_CC);
+	DBG_RETURN(ret);
 }
 /* }}} */


Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2011-10-24 12:34:44 UTC (rev 318365)
@@ -25,6 +25,12 @@

 #define MYSQLND_TYPEDEFED_METHODS

+#define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
+#define MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class)
+
+#define MYSQLND_CLASS_METHODS_START(class)	MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) = {
+#define MYSQLND_CLASS_METHODS_END			}
+
 typedef struct st_mysqlnd_memory_pool MYSQLND_MEMORY_POOL;
 typedef struct st_mysqlnd_memory_pool_chunk MYSQLND_MEMORY_POOL_CHUNK;
 typedef struct st_mysqlnd_memory_pool_chunk_llist MYSQLND_MEMORY_POOL_CHUNK_LLIST;
@@ -367,6 +373,21 @@
 };


+typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(zend_bool persistent TSRMLS_DC);
+typedef MYSQLND_STMT * (*func_mysqlnd_object_factory__get_prepared_statement)(MYSQLND * conn TSRMLS_DC);
+typedef MYSQLND_NET * (*func_mysqlnd_object_factory__get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info TSRMLS_DC);
+typedef MYSQLND_PROTOCOL * (*func_mysqlnd_object_factory__get_protocol_decoder)(zend_bool persistent TSRMLS_DC);
+
+
+struct st_mysqlnd_object_factory_methods
+{
+	func_mysqlnd_object_factory__get_connection get_connection;
+	func_mysqlnd_object_factory__get_prepared_statement get_prepared_statement;
+	func_mysqlnd_object_factory__get_io_channel get_io_channel;
+	func_mysqlnd_object_factory__get_protocol_decoder get_protocol_decoder;
+};
+
+
 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_or_pipe, unsigned int mysql_flags TSRMLS_DC);
 typedef ulong				(*func_mysqlnd_conn__escape_string)(MYSQLND * const conn, char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC);

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c	2011-10-24 10:53:17 UTC (rev 318364)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_wireprotocol.c	2011-10-24 12:34:44 UTC (rev 318365)
@@ -2371,16 +2371,9 @@
 PHPAPI MYSQLND_PROTOCOL *
 mysqlnd_protocol_init(zend_bool persistent TSRMLS_DC)
 {
-	size_t alloc_size = sizeof(MYSQLND_PROTOCOL) + mysqlnd_plugin_count() * sizeof(void *);
-	MYSQLND_PROTOCOL *ret = mnd_pecalloc(1, alloc_size, persistent);
-
+	MYSQLND_PROTOCOL * ret;
 	DBG_ENTER("mysqlnd_protocol_init");
-	DBG_INF_FMT("persistent=%u", persistent);
-	if (ret) {
-		ret->persistent = persistent;
-		ret->m = mysqlnd_mysqlnd_protocol_methods;
-	}
-
+	ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_protocol_decoder(persistent TSRMLS_CC);
 	DBG_RETURN(ret);
 }
 /* }}} */
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to