]> granicus.if.org Git - php/commitdiff
MNDR:
authorAndrey Hristov <andrey@php.net>
Mon, 12 Oct 2015 16:50:58 +0000 (18:50 +0200)
committerAndrey Hristov <andrey@php.net>
Thu, 12 Nov 2015 15:19:16 +0000 (16:19 +0100)
- Inject the object factory

ext/mysqlnd/mysqlnd.c
ext/mysqlnd/mysqlnd.h
ext/mysqlnd/mysqlnd_driver.c
ext/mysqlnd/mysqlnd_structs.h

index 0a7fe8d859b2b3bcadcafd286769078ae9ee898e..27b258cf5d5d2ce1e770ef03aad9625227e2a8b3 100644 (file)
@@ -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);
        }
index 0fb13d57d9e1037cad0ccfc59226f423b5ae6211..d49f7651081de3adb79296889a0eb04fbf60aba6 100644 (file)
@@ -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,
index e3c126c5c56971f0e133a730af17caa5b0b081d8..fa7643c9250a8e7ca8a6a5af470237bf566e496e 100644 (file)
@@ -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);
 
index 4413ccbda53481f7426017d8ea0c7f5989ed76a6..c7920aeca87fe708fa3e012596728a311dde276d 100644 (file)
@@ -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 */