From 784a371829f286efe214a14f195a07cb1b3f9cc1 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Mon, 12 Oct 2015 18:50:58 +0200 Subject: [PATCH] MNDR: - Inject the object factory --- ext/mysqlnd/mysqlnd.c | 13 +++++++------ ext/mysqlnd/mysqlnd.h | 4 ++-- ext/mysqlnd/mysqlnd_driver.c | 3 ++- ext/mysqlnd/mysqlnd_structs.h | 6 +++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ext/mysqlnd/mysqlnd.c b/ext/mysqlnd/mysqlnd.c index 0a7fe8d859..27b258cf5d 100644 --- a/ext/mysqlnd/mysqlnd.c +++ b/ext/mysqlnd/mysqlnd.c @@ -1166,7 +1166,7 @@ PHPAPI MYSQLND * mysqlnd_connection_connect(MYSQLND * conn_handle, if (!conn_handle) { self_alloced = TRUE; - if (!(conn_handle = mysqlnd_connection_init(client_api_flags, FALSE))) { + if (!(conn_handle = mysqlnd_connection_init(client_api_flags, FALSE, NULL))) { /* OOM */ DBG_RETURN(NULL); } @@ -2979,8 +2979,8 @@ MYSQLND_STMT * MYSQLND_METHOD(mysqlnd_conn_data, stmt_init)(MYSQLND_CONN_DATA * const conn) { MYSQLND_STMT * ret; - DBG_ENTER("_mysqlnd_stmt_init"); - ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_prepared_statement(conn, conn->persistent); + DBG_ENTER("mysqlnd_conn_data::stmt_init"); + ret = conn->object_factory.get_prepared_statement(conn, conn->persistent); DBG_RETURN(ret); } /* }}} */ @@ -3086,7 +3086,7 @@ MYSQLND_METHOD(mysqlnd_conn, clone_object)(MYSQLND * const conn) { MYSQLND * ret; DBG_ENTER("mysqlnd_conn::get_reference"); - ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).clone_connection_object(conn); + ret = conn->data->object_factory.clone_connection_object(conn); DBG_RETURN(ret); } /* }}} */ @@ -3155,11 +3155,12 @@ MYSQLND_CLASS_METHODS_END; /* {{{ mysqlnd_connection_init */ PHPAPI MYSQLND * -mysqlnd_connection_init(unsigned int client_flags, zend_bool persistent) +mysqlnd_connection_init(unsigned int client_flags, zend_bool persistent, struct st_mysqlnd_object_factory_methods * object_factory) { + struct st_mysqlnd_object_factory_methods * factory = object_factory? object_factory : &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory); MYSQLND * ret; DBG_ENTER("mysqlnd_connection_init"); - ret = MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory).get_connection(persistent); + ret = factory->get_connection(factory, persistent); if (ret && ret->data) { ret->data->m->negotiate_client_api_capabilities(ret->data, client_flags); } diff --git a/ext/mysqlnd/mysqlnd.h b/ext/mysqlnd/mysqlnd.h index 0fb13d57d9..d49f765108 100644 --- a/ext/mysqlnd/mysqlnd.h +++ b/ext/mysqlnd/mysqlnd.h @@ -83,11 +83,11 @@ PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const char /* Connect */ -#define mysqlnd_init(flags, persistent) mysqlnd_connection_init((flags), (persistent)) +#define mysqlnd_init(flags, persistent) mysqlnd_connection_init((flags), (persistent), NULL /*use default factory*/) #define mysqlnd_connect(conn, host, user, pass, pass_len, db, db_len, port, socket, mysql_flags, client_api_flags) \ mysqlnd_connection_connect((conn), (host), (user), (pass), (pass_len), (db), (db_len), (port), (socket), (mysql_flags), (client_api_flags)) -PHPAPI MYSQLND * mysqlnd_connection_init(unsigned int client_flags, zend_bool persistent); +PHPAPI MYSQLND * mysqlnd_connection_init(unsigned int client_flags, zend_bool persistent, struct st_mysqlnd_object_factory_methods * object_factory); PHPAPI MYSQLND * mysqlnd_connection_connect(MYSQLND * conn, const char * host, const char * user, const char * passwd, unsigned int passwd_len, diff --git a/ext/mysqlnd/mysqlnd_driver.c b/ext/mysqlnd/mysqlnd_driver.c index e3c126c5c5..fa7643c925 100644 --- a/ext/mysqlnd/mysqlnd_driver.c +++ b/ext/mysqlnd/mysqlnd_driver.c @@ -111,7 +111,7 @@ mysqlnd_error_list_pdtor(void * pDest) /* {{{ mysqlnd_object_factory::get_connection */ static MYSQLND * -MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent) +MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_factory_methods * factory, zend_bool persistent) { size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *); size_t alloc_size_ret_data = sizeof(MYSQLND_CONN_DATA) + mysqlnd_plugin_count() * sizeof(void *); @@ -139,6 +139,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(zend_bool persistent) data->persistent = persistent; data->m = mysqlnd_conn_data_get_methods(); + data->object_factory = *factory; CONN_SET_STATE(data, CONN_ALLOCED); data->m->get_reference(data); diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h index 4413ccbda5..c7920aeca8 100644 --- a/ext/mysqlnd/mysqlnd_structs.h +++ b/ext/mysqlnd/mysqlnd_structs.h @@ -399,7 +399,9 @@ struct st_mysqlnd_protocol_payload_decoder_factory_methods }; -typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(zend_bool persistent); +struct st_mysqlnd_object_factory_methods; + +typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(struct st_mysqlnd_object_factory_methods * factory, zend_bool persistent); typedef MYSQLND * (*func_mysqlnd_object_factory__clone_connection_object)(MYSQLND * conn); typedef MYSQLND_STMT * (*func_mysqlnd_object_factory__get_prepared_statement)(MYSQLND_CONN_DATA * conn, zend_bool persistent); typedef MYSQLND_NET * (*func_mysqlnd_object_factory__get_io_channel)(zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info); @@ -978,6 +980,8 @@ struct st_mysqlnd_connection_data zend_bool in_async_read_cb; zend_bool in_async_err_cb; + struct st_mysqlnd_object_factory_methods object_factory; + struct st_mysqlnd_conn_data_methods * m; /* persistent connection */ -- 2.40.0