Author: ahristov
Date: 2007-11-09 14:23:57 +0100 (Fri, 09 Nov 2007)
New Revision: 1147
Modified:
trunk/mysqlnd/mysqlnd.c
trunk/mysqlnd/mysqlnd_debug.h
trunk/php5/ext/mysql/config.m4
trunk/php5/ext/mysql/config.w32
trunk/php5/ext/mysql/php_mysql.c
trunk/php5/ext/mysqli/config.m4
trunk/php5/ext/mysqli/mysqli.c
trunk/php5/ext/mysqli/mysqli_api.c
trunk/php5/ext/mysqli/mysqli_nonapi.c
trunk/php5/ext/mysqli/php_mysqli_structs.h
trunk/php6/ext/mysql/config.w32
trunk/php6/ext/mysql/php_mysql.c
trunk/php6/ext/mysql/php_mysql.h
trunk/php6/ext/mysql/php_mysql_structs.h
trunk/php6/ext/mysqli/config.w32
trunk/php6/ext/mysqli/mysqli.c
trunk/php6/ext/mysqli/mysqli_api.c
trunk/php6/ext/mysqli/mysqli_nonapi.c
trunk/php6/ext/mysqli/php_mysqli_structs.h
Log:
- Fix crashes with pconn (merge from CVS)
- Merge other code from CVS
Modified: trunk/mysqlnd/mysqlnd.c
===================================================================
--- trunk/mysqlnd/mysqlnd.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/mysqlnd/mysqlnd.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -571,6 +571,10 @@
NULL /*ctx*/, &errstr, &errcode);
DBG_INF_FMT("stream=%p", conn->net.stream);
+ if (errstr || !conn->net.stream) {
+ goto err;
+ }
+
if (hashed_details) {
/*
If persistent, the streams register it in EG(persistent_list).
@@ -597,10 +601,6 @@
mnd_efree(hashed_details);
}
- if (errstr || !conn->net.stream) {
- goto err;
- }
-
if (conn->options.timeout_read)
{
tv.tv_sec = conn->options.timeout_read;
@@ -2032,7 +2032,7 @@
DBG_ENTER("RSHUTDOWN");
if (dbg) {
dbg->m->close(dbg);
- dbg->m->free(dbg);
+ dbg->m->free_handle(dbg);
MYSQLND_G(dbg) = NULL;
}
#endif
Modified: trunk/mysqlnd/mysqlnd_debug.h
===================================================================
--- trunk/mysqlnd/mysqlnd_debug.h 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/mysqlnd/mysqlnd_debug.h 2007-11-09 13:23:57 UTC (rev 1147)
@@ -39,7 +39,7 @@
char * func_name, uint func_name_len);
enum_func_status (*func_leave)(MYSQLND_DEBUG *self, unsigned int line, const char *
const file);
enum_func_status (*close)(MYSQLND_DEBUG *self);
- enum_func_status (*free)(MYSQLND_DEBUG *self);
+ enum_func_status (*free_handle)(MYSQLND_DEBUG *self);
};
struct st_mysqlnd_debug
Modified: trunk/php5/ext/mysql/config.m4
===================================================================
--- trunk/php5/ext/mysql/config.m4 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysql/config.m4 2007-11-09 13:23:57 UTC (rev 1147)
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.70 2007/07/25 23:47:32 jani Exp $
+dnl $Id: config.m4,v 1.67.2.1.2.1.2.2 2007/11/06 10:00:04 jani Exp $
dnl
AC_DEFUN([MYSQL_LIB_CHK], [
@@ -40,8 +40,9 @@
PHP_ARG_WITH(mysql, for MySQL support,
-[ --with-mysql[=DIR] Include MySQL support. DIR is the MySQL base directory.
- If mysqlnd is passed as DIR, the MySQL native driver will be
used])
+[ --with-mysql[=DIR] Include MySQL support. DIR is the MySQL base
+ directory. If mysqlnd is passed as DIR,
+ the MySQL native driver will be used [/usr/local]])
PHP_ARG_WITH(mysql-sock, for specified location of the MySQL UNIX socket,
[ --with-mysql-sock[=DIR] MySQL: Location of the MySQL unix socket pointer.
@@ -155,7 +156,7 @@
PHP_NEW_EXTENSION(mysql, php_mysql.c, $ext_shared)
PHP_SUBST(MYSQL_SHARED_LIBADD)
- if test "$PHP_MYSQLI" = "mysqlnd"; then
- PHP_ADD_EXTENSION_DEP(mysqli, mysqlnd)
+ if test "$PHP_MYSQL" = "mysqlnd"; then
+ PHP_ADD_EXTENSION_DEP(mysql, mysqlnd)
fi
fi
Modified: trunk/php5/ext/mysql/config.w32
===================================================================
--- trunk/php5/ext/mysql/config.w32 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysql/config.w32 2007-11-09 13:23:57 UTC (rev 1147)
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.3 2007/07/25 23:47:32 jani Exp $
+// $Id: config.w32,v 1.2.6.1 2007/10/05 21:23:55 andrey Exp $
// vim:ft=javascript
ARG_WITH("mysql", "MySQL support", "no");
Modified: trunk/php5/ext/mysql/php_mysql.c
===================================================================
--- trunk/php5/ext/mysql/php_mysql.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysql/php_mysql.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.c,v 1.213.2.6.2.16.2.4 2007/10/08 16:14:56 andrey Exp $ */
+/* $Id: php_mysql.c,v 1.213.2.6.2.16.2.5 2007/11/08 13:29:06 tony2001 Exp $ */
/* TODO:
*
@@ -2031,6 +2031,7 @@
if ((result_type & MYSQL_BOTH) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The result type should be either
MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH");
+ result_type = MYSQL_BOTH;
}
ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
Modified: trunk/php5/ext/mysqli/config.m4
===================================================================
--- trunk/php5/ext/mysqli/config.m4 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysqli/config.m4 2007-11-09 13:23:57 UTC (rev 1147)
@@ -1,13 +1,15 @@
dnl
-dnl $Id: config.m4,v 1.22.2.1.2.2.2.1 2007/10/05 21:23:56 andrey Exp $
+dnl $Id: config.m4,v 1.22.2.1.2.2.2.2 2007/11/06 10:00:39 jani Exp $
dnl config.m4 for extension mysqli
PHP_ARG_WITH(mysqli, for MySQLi support,
-[ --with-mysqli[=FILE] Include MySQLi support. FILE is the optional pathname to
mysql_config [mysql_config].
- If mysqlnd is passed as FILE, the MySQL native driver will be
used])
+[ --with-mysqli[=FILE] Include MySQLi support. FILE is the path
+ to mysql_config. If mysqlnd is passed as FILE,
+ the MySQL native driver will be used [mysql_config]])
PHP_ARG_ENABLE(embedded_mysqli, whether to enable embedded MySQLi support,
-[ --enable-embedded-mysqli MYSQLi: Enable embedded support], no, no)
+[ --enable-embedded-mysqli MYSQLi: Enable embedded support
+ Note: Does not work with MySQL native driver!], no, no)
if test "$PHP_MYSQLI" = "mysqlnd"; then
dnl This needs to be set in any extension which wishes to use mysqlnd
Modified: trunk/php5/ext/mysqli/mysqli.c
===================================================================
--- trunk/php5/ext/mysqli/mysqli.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysqli/mysqli.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -15,7 +15,7 @@
| Author: Georg Richter <georg@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli.c,v 1.72.2.16.2.17.2.6 2007/10/17 08:18:09 tony2001 Exp $
+ $Id: mysqli.c,v 1.72.2.16.2.17.2.7 2007/11/09 10:56:28 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -70,50 +70,25 @@
static int le_pmysqli;
-static int php_mysqli_persistent_on_rshut(zend_rsrc_list_entry *le TSRMLS_DC)
-{
- if (le->type == le_pmysqli) {
- mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
- HashPosition pos;
- MYSQL **mysql;
- ulong idx;
- dtor_func_t pDestructor = plist->used_links.pDestructor;
- plist->used_links.pDestructor = NULL; /* Don't call pDestructor now */
- zend_hash_internal_pointer_reset_ex(&plist->used_links, &pos);
- while (SUCCESS == zend_hash_get_current_data_ex(&plist->used_links, (void
**)&mysql, &pos)) {
- zend_hash_get_current_key_ex(&plist->used_links, NULL, NULL, &idx, FALSE,
&pos);
- /* Make it free */
- zend_hash_next_index_insert(&plist->free_links, mysql, sizeof(MYSQL *), NULL);
- /* First move forward */
- zend_hash_move_forward_ex(&plist->used_links, &pos);
- /* The delete, because del will free memory, but we need it's ->nextItem */
- zend_hash_index_del(&plist->used_links, idx);
- }
-
- /* restore pDestructor, which should be php_mysqli_dtor_p_elements() */
- plist->used_links.pDestructor = pDestructor;
- }
- return ZEND_HASH_APPLY_KEEP;
-}
-
/* Destructor for mysqli entries in free_links/used_links */
void php_mysqli_dtor_p_elements(void *data)
{
- MYSQL **mysql = (MYSQL **) data;
+ MYSQL *mysql = (MYSQL *) data;
TSRMLS_FETCH();
#if defined(HAVE_MYSQLND)
- mysqlnd_end_psession(*mysql);
+ mysqlnd_end_psession(mysql);
#endif
- mysqli_close(*mysql, MYSQLI_CLOSE_IMPLICIT);
+ mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT);
}
+/* le_pmysqli dtor*/
ZEND_RSRC_DTOR_FUNC(php_mysqli_dtor)
{
if (rsrc->ptr) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) rsrc->ptr;
- zend_hash_destroy(&plist->free_links);
- zend_hash_destroy(&plist->used_links);
+ zend_ptr_stack_clean(&plist->free_links, php_mysqli_dtor_p_elements, 0);
+ zend_ptr_stack_destroy(&plist->free_links);
free(plist);
}
}
@@ -222,6 +197,8 @@
}
/* }}} */
+/* mysqli_link_free_storage partly doubles the work of PHP_FUNCTION(mysqli_close) */
+
/* {{{ mysqli_link_free_storage
*/
static void mysqli_link_free_storage(void *object TSRMLS_DC)
@@ -235,6 +212,19 @@
if (mysql->mysql) {
if (!mysql->persistent) {
mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
+ } else {
+ zend_rsrc_list_entry *le;
+ if (zend_hash_find(&EG(persistent_list), mysql->hash_key,
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
+ if (Z_TYPE_P(le) == php_le_pmysqli()) {
+ mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
+
+ zend_ptr_stack_push(&plist->free_links, mysql->mysql);
+
+ MyG(num_links)--;
+ MyG(num_active_persistent)--;
+ MyG(num_inactive_persistent)++;
+ }
+ }
}
}
php_clear_mysql(mysql);
@@ -854,7 +844,6 @@
PHP_RSHUTDOWN_FUNCTION(mysqli)
{
/* check persistent connections, move used to free */
- zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_on_rshut
TSRMLS_CC);
#if !defined(HAVE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >=
40000
mysql_thread_end();
Modified: trunk/php5/ext/mysqli/mysqli_api.c
===================================================================
--- trunk/php5/ext/mysqli/mysqli_api.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysqli/mysqli_api.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
| Ulf Wendel <uw@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli_api.c,v 1.118.2.22.2.16.2.6 2007/10/17 08:19:07 tony2001 Exp $
+ $Id: mysqli_api.c,v 1.118.2.22.2.16.2.8 2007/11/09 10:56:28 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -105,7 +105,11 @@
break;
case 'i': /* Integer */
- bind[ofs].buffer_type = (sizeof(long) > 4) ? MYSQL_TYPE_LONGLONG :
MYSQL_TYPE_LONG;
+#if SIZEOF_LONG==8
+ bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
+#elif SIZEOF_LONG==4
+ bind[ofs].buffer_type = MYSQL_TYPE_LONG;
+#endif
bind[ofs].buffer = &Z_LVAL_PP(args[i]);
bind[ofs].is_null = &stmt->param.is_null[ofs];
break;
@@ -559,13 +563,8 @@
if (zend_hash_find(&EG(persistent_list), mysql->hash_key,
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
if (Z_TYPE_P(le) == php_le_pmysqli()) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
- dtor_func_t pDestructor = plist->used_links.pDestructor;
+ zend_ptr_stack_push(&plist->free_links, mysql->mysql);
- plist->used_links.pDestructor = NULL; /* Don't call pDestructor now */
- zend_hash_index_del(&plist->used_links, mysql->hash_index);
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
-
- zend_hash_next_index_insert(&plist->free_links, &mysql->mysql,
sizeof(MYSQL *), NULL);
MyG(num_links)--;
MyG(num_active_persistent)--;
MyG(num_inactive_persistent)++;
@@ -719,6 +718,7 @@
convert_to_double_ex(&stmt->param.vars[i]);
stmt->stmt->params[i].buffer = &Z_LVAL_PP(&stmt->param.vars[i]);
break;
+ case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_LONG:
convert_to_long_ex(&stmt->param.vars[i]);
stmt->stmt->params[i].buffer = &Z_LVAL_PP(&stmt->param.vars[i]);
Modified: trunk/php5/ext/mysqli/mysqli_nonapi.c
===================================================================
--- trunk/php5/ext/mysqli/mysqli_nonapi.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysqli/mysqli_nonapi.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
| Ulf Wendel <uw@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli_nonapi.c,v 1.54.2.7.2.5.2.1 2007/10/05 21:23:56 andrey Exp $
+ $Id: mysqli_nonapi.c,v 1.54.2.7.2.5.2.3 2007/11/09 11:06:07 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -109,37 +109,18 @@
port, SAFE_STR(username), SAFE_STR(dbname),
SAFE_STR(passwd));
+ mysql->hash_key = hash_key;
+
/* check if we can reuse exisiting connection ... */
if (zend_hash_find(&EG(persistent_list), hash_key, hash_len + 1, (void **)&le)
== SUCCESS) {
if (Z_TYPE_P(le) == php_le_pmysqli()) {
plist = (mysqli_plist_entry *) le->ptr;
do {
- if (zend_hash_num_elements(&plist->free_links)) {
- HashPosition pos;
- MYSQL **free_mysql;
- ulong idx;
- dtor_func_t pDestructor = plist->free_links.pDestructor;
+ if (zend_ptr_stack_num_elements(&plist->free_links)) {
+ mysql->mysql = zend_ptr_stack_pop(&plist->free_links);
- zend_hash_internal_pointer_reset_ex(&plist->free_links, &pos);
- if (SUCCESS != zend_hash_get_current_data_ex(&plist->free_links,
- (void **)&free_mysql, &pos)) {
- break;
- }
- if (HASH_KEY_IS_LONG != zend_hash_get_current_key_ex(&plist->free_links,
NULL,
- NULL, &idx, FALSE, &pos)) {
- break;
- }
- plist->free_links.pDestructor = NULL; /* Don't call pDestructor now */
- if (SUCCESS != zend_hash_index_del(&plist->free_links, idx)) {
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
- break;
- }
- plist->free_links.pDestructor = pDestructor; /* Restore the destructor */
- mysql->mysql = *free_mysql;
-
MyG(num_inactive_persistent)--;
- MyG(num_active_persistent)++;
/* reset variables */
/* todo: option for ping or change_user */
#if G0
@@ -150,16 +131,14 @@
#ifdef HAVE_MYSQLND
mysqlnd_restart_psession(mysql->mysql);
#endif
- idx = zend_hash_next_free_element(&plist->used_links);
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links,
&free_mysql,
- sizeof(MYSQL *), NULL)) {
- php_mysqli_dtor_p_elements(free_mysql);
- MyG(num_links)--;
- break;
- }
- mysql->hash_index = idx;
- mysql->hash_key = hash_key;
+ MyG(num_active_persistent)++;
goto end;
+ } else {
+#if defined(HAVE_MYSQLND)
+ mysqlnd_end_psession(mysql->mysql);
+#endif
+ mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
+ mysql->mysql = NULL;
}
}
} while (0);
@@ -169,8 +148,7 @@
le.type = php_le_pmysqli();
le.ptr = plist = calloc(1, sizeof(mysqli_plist_entry));
- zend_hash_init(&plist->free_links, MAX(2, MyG(max_persistent)), NULL,
php_mysqli_dtor_p_elements, 1);
- zend_hash_init(&plist->used_links, MAX(2, MyG(max_persistent)), NULL,
php_mysqli_dtor_p_elements, 1);
+ zend_ptr_stack_init_ex(&plist->free_links, 1);
zend_hash_update(&EG(persistent_list), hash_key, hash_len + 1, (void *)&le,
sizeof(le), NULL);
}
}
@@ -244,18 +222,9 @@
/* store persistent connection */
if (persistent && new_connection) {
- /* save persistent connection */
- ulong hash_index = zend_hash_next_free_element(&plist->used_links);
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links,
&mysql->mysql,
- sizeof(MYSQL *), NULL)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't store persistent connection");
- } else {
- mysql->hash_index = hash_index;
- }
MyG(num_active_persistent)++;
}
- mysql->hash_key = hash_key;
MyG(num_links)++;
#if !defined(HAVE_MYSQLND)
@@ -274,7 +243,7 @@
err:
efree(mysql);
- if (persistent) {
+ if (hash_key) {
efree(hash_key);
}
RETVAL_FALSE;
Modified: trunk/php5/ext/mysqli/php_mysqli_structs.h
===================================================================
--- trunk/php5/ext/mysqli/php_mysqli_structs.h 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php5/ext/mysqli/php_mysqli_structs.h 2007-11-09 13:23:57 UTC (rev 1147)
@@ -15,7 +15,7 @@
| Author: Georg Richter <georg@stripped> |
+----------------------------------------------------------------------+
- $Id: php_mysqli_structs.h,v 1.4.2.3 2007/10/08 15:38:47 andrey Exp $
+ $Id: php_mysqli_structs.h,v 1.4.2.4 2007/11/09 10:56:28 andrey Exp $
*/
#ifndef PHP_MYSQLI_STRUCTS_H
@@ -91,7 +91,6 @@
zval *li_read;
php_stream *li_stream;
zend_bool persistent;
- unsigned long hash_index; /* Used when persistent, hold the index in
plist->used_links */
unsigned int multi_query;
} MY_MYSQL;
@@ -136,8 +135,7 @@
#endif
typedef struct {
- HashTable free_links;
- HashTable used_links;
+ zend_ptr_stack free_links;
} mysqli_plist_entry;
#ifdef PHP_WIN32
Modified: trunk/php6/ext/mysql/config.w32
===================================================================
--- trunk/php6/ext/mysql/config.w32 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysql/config.w32 2007-11-09 13:23:57 UTC (rev 1147)
@@ -1,19 +1,20 @@
-// $Id: config.w32,v 1.3 2007/07/25 23:47:32 jani Exp $
+// $Id: config.w32,v 1.4 2007/10/23 10:44:25 andrey Exp $
// vim:ft=javascript
ARG_WITH("mysql", "MySQL support", "no");
if (PHP_MYSQL != "no") {
- if (PHP_MYSQLI != "mysqlnd") {
- if (CHECK_LIB("libmysql.lib", "mysql", PHP_MYSQL) &&
- CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQL",
- PHP_MYSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\mysql;" + PHP_MYSQL)) {
- } else {
- WARNING("mysql not enabled; libraries and headers not found");
- }
- } else {
- ADD_EXTENSION_DEP('mysql', 'mysqlnd', true);
- }
- EXTENSION("mysql", "php_mysql.c");
- AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
+ if (PHP_MYSQLI != "mysqlnd") {
+ if (CHECK_LIB("libmysql.lib", "mysql", PHP_MYSQL) &&
+ CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQL",
+ PHP_MYSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\mysql;" + PHP_MYSQL)) {
+ } else {
+ WARNING("mysql not enabled; libraries and headers not found");
+ }
+ } else {
+ AC_DEFINE('HAVE_MYSQLND', 1, 'MySQL native driver support enabled');
+ ADD_EXTENSION_DEP('mysql', 'mysqlnd', true);
+ }
+ EXTENSION("mysql", "php_mysql.c");
+ AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
}
Modified: trunk/php6/ext/mysql/php_mysql.c
===================================================================
--- trunk/php6/ext/mysql/php_mysql.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysql/php_mysql.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.c,v 1.245 2007/10/12 07:23:44 tony2001 Exp $ */
+/* $Id: php_mysql.c,v 1.247 2007/11/08 13:28:38 tony2001 Exp $ */
/* TODO:
*
@@ -2056,6 +2056,7 @@
if ((result_type & MYSQL_BOTH) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The result type should be either
MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH");
+ result_type = MYSQL_BOTH;
}
ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL result", le_result);
Modified: trunk/php6/ext/mysql/php_mysql.h
===================================================================
--- trunk/php6/ext/mysql/php_mysql.h 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysql/php_mysql.h 2007-11-09 13:23:57 UTC (rev 1147)
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.h,v 1.42 2007/07/25 23:47:32 jani Exp $ */
+/* $Id: php_mysql.h,v 1.43 2007/10/16 20:58:35 andrey Exp $ */
#ifndef PHP_MYSQL_H
#define PHP_MYSQL_H
Modified: trunk/php6/ext/mysql/php_mysql_structs.h
===================================================================
--- trunk/php6/ext/mysql/php_mysql_structs.h 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysql/php_mysql_structs.h 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mysql.h,v 1.42 2007/07/25 23:47:32 jani Exp $ */
+/* $Id: php_mysql_structs.h,v 1.2 2007/10/16 20:58:35 andrey Exp $ */
#ifndef PHP_MYSQL_STRUCTS_H
#define PHP_MYSQL_STRUCTS_H
Modified: trunk/php6/ext/mysqli/config.w32
===================================================================
--- trunk/php6/ext/mysqli/config.w32 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysqli/config.w32 2007-11-09 13:23:57 UTC (rev 1147)
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.9 2007/07/25 23:47:32 jani Exp $
+// $Id: config.w32,v 1.10 2007/10/23 10:44:25 andrey Exp $
// vim:ft=javascript
// Note: The extension name is "mysqli", you enable it with "--with-mysqli".
@@ -9,36 +9,34 @@
ARG_WITH("mysqli", "MySQLi support", "no");
if (PHP_MYSQLI != "no") {
+ mysqli_source =
+ "mysqli.c " +
+ "mysqli_api.c " +
+ "mysqli_driver.c " +
+ "mysqli_embedded.c " +
+ "mysqli_exception.c " +
+ "mysqli_fe.c " +
+ "mysqli_nonapi.c " +
+ "mysqli_prop.c " +
+ "mysqli_report.c " +
+ "mysqli_warning.c";
- mysqli_source =
- "mysqli.c " +
- "mysqli_api.c " +
- "mysqli_driver.c " +
- "mysqli_embedded.c " +
- "mysqli_exception.c " +
- "mysqli_fe.c " +
- "mysqli_nonapi.c " +
- "mysqli_prop.c " +
- "mysqli_report.c " +
- "mysqli_warning.c";
-
- if (PHP_MYSQLI != "mysqlnd") {
- if (CHECK_LIB("libmysql.lib", "mysqli", PHP_MYSQLI) &&
- CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQLI", PHP_MYSQLI +
- "\\include;" + PHP_PHP_BUILD +
- "\\include\\mysql;" + PHP_MYSQLI)) {
- // No "mysqli_repl.c" when using "mysqlnd"
- mysqli_extra_sources = "mysqli_repl.c";
- EXTENSION("mysqli", mysqli_source + " " + mysqli_extra_sources);
- AC_DEFINE('HAVE_MYSQLILIB', 1, 'Have MySQLi library');
- } else {
- WARNING("mysqli not enabled; libraries and headers not found");
- }
-
- } else {
-
- EXTENSION("mysqli", mysqli_source);
- AC_DEFINE('HAVE_MYSQLILIB', 1, 'Have MySQLi library');
- ADD_EXTENSION_DEP('mysqli', 'mysqlnd', true);
- }
+ if (PHP_MYSQLI != "mysqlnd") {
+ if (CHECK_LIB("libmysql.lib", "mysqli", PHP_MYSQLI) &&
+ CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQLI", PHP_MYSQLI +
+ "\\include;" + PHP_PHP_BUILD +
+ "\\include\\mysql;" + PHP_MYSQLI)) {
+ // No "mysqli_repl.c" when using "mysqlnd"
+ mysqli_extra_sources = "mysqli_repl.c";
+ EXTENSION("mysqli", mysqli_source + " " + mysqli_extra_sources);
+ AC_DEFINE('HAVE_MYSQLILIB', 1, 'Have MySQLi library');
+ } else {
+ WARNING("mysqli not enabled; libraries and headers not found");
+ }
+ } else {
+ EXTENSION("mysqli", mysqli_source);
+ AC_DEFINE('HAVE_MYSQLND', 1, 'MySQLi with native driver support enabled');
+ AC_DEFINE('HAVE_MYSQLILIB', 1, 'Have MySQLi library');
+ ADD_EXTENSION_DEP('mysqli', 'mysqlnd', true);
+ }
}
Modified: trunk/php6/ext/mysqli/mysqli.c
===================================================================
--- trunk/php6/ext/mysqli/mysqli.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysqli/mysqli.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
| Ulf Wendel <uw@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli.c,v 1.112 2007/10/17 08:17:34 tony2001 Exp $
+ $Id: mysqli.c,v 1.113 2007/11/09 12:13:15 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -73,42 +73,16 @@
static int le_pmysqli;
-static int php_mysqli_persistent_on_rshut(zend_rsrc_list_entry *le TSRMLS_DC)
-{
- if (le->type == le_pmysqli) {
- mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
- HashPosition pos;
- MYSQL **mysql;
- ulong idx;
- dtor_func_t pDestructor = plist->used_links.pDestructor;
- plist->used_links.pDestructor = NULL; /* Don't call pDestructor now */
- zend_hash_internal_pointer_reset_ex(&plist->used_links, &pos);
- while (SUCCESS == zend_hash_get_current_data_ex(&plist->used_links, (void
**)&mysql, &pos)) {
- zend_hash_get_current_key_ex(&plist->used_links, NULL, NULL, &idx, FALSE,
&pos);
- /* Make it free */
- zend_hash_next_index_insert(&plist->free_links, mysql, sizeof(MYSQL *), NULL);
- /* First move forward */
- zend_hash_move_forward_ex(&plist->used_links, &pos);
- /* The delete, because del will free memory, but we need it's ->nextItem */
- zend_hash_index_del(&plist->used_links, idx);
- }
-
- /* restore pDestructor, which should be php_mysqli_dtor_p_elements() */
- plist->used_links.pDestructor = pDestructor;
- }
- return ZEND_HASH_APPLY_KEEP;
-}
-
/* Destructor for mysqli entries in free_links/used_links */
void php_mysqli_dtor_p_elements(void *data)
{
- MYSQL **mysql = (MYSQL **) data;
+ MYSQL *mysql = (MYSQL *) data;
TSRMLS_FETCH();
#if defined(HAVE_MYSQLND)
- mysqlnd_end_psession(*mysql);
+ mysqlnd_end_psession(mysql);
#endif
- mysqli_close(*mysql, MYSQLI_CLOSE_IMPLICIT);
+ mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT);
}
@@ -116,8 +90,8 @@
{
if (rsrc->ptr) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) rsrc->ptr;
- zend_hash_destroy(&plist->free_links);
- zend_hash_destroy(&plist->used_links);
+ zend_ptr_stack_clean(&plist->free_links, php_mysqli_dtor_p_elements, 0);
+ zend_ptr_stack_destroy(&plist->free_links);
free(plist);
}
}
@@ -225,6 +199,8 @@
}
/* }}} */
+/* mysqli_link_free_storage partly doubles the work of PHP_FUNCTION(mysqli_close) */
+
/* {{{ mysqli_link_free_storage
*/
static void mysqli_link_free_storage(void *object TSRMLS_DC)
@@ -238,6 +214,19 @@
if (mysql->mysql) {
if (!mysql->persistent) {
mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
+ } else {
+ zend_rsrc_list_entry *le;
+ if (zend_hash_find(&EG(persistent_list), mysql->hash_key,
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
+ if (Z_TYPE_P(le) == php_le_pmysqli()) {
+ mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
+
+ zend_ptr_stack_push(&plist->free_links, mysql->mysql);
+
+ MyG(num_links)--;
+ MyG(num_active_persistent)--;
+ MyG(num_inactive_persistent)++;
+ }
+ }
}
}
php_clear_mysql(mysql);
@@ -851,9 +840,6 @@
*/
PHP_RSHUTDOWN_FUNCTION(mysqli)
{
- /* check persistent connections, move used to free */
- zend_hash_apply(&EG(persistent_list), (apply_func_t) php_mysqli_persistent_on_rshut
TSRMLS_CC);
-
#if !defined(HAVE_MYSQLND) && defined(ZTS) && MYSQL_VERSION_ID >=
40000
mysql_thread_end();
#endif
Modified: trunk/php6/ext/mysqli/mysqli_api.c
===================================================================
--- trunk/php6/ext/mysqli/mysqli_api.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysqli/mysqli_api.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
| Ulf Wendel <uw@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli_api.c,v 1.153 2007/10/17 08:22:01 tony2001 Exp $
+ $Id: mysqli_api.c,v 1.155 2007/11/09 12:13:15 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -105,7 +105,11 @@
break;
case 'i': /* Integer */
- bind[ofs].buffer_type = (sizeof(long) > 4) ? MYSQL_TYPE_LONGLONG :
MYSQL_TYPE_LONG;
+#if SIZEOF_LONG==8
+ bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG;
+#elif SIZEOF_LONG==4
+ bind[ofs].buffer_type = MYSQL_TYPE_LONG;
+#endif
bind[ofs].buffer = &Z_LVAL_PP(args[i]);
bind[ofs].is_null = &stmt->param.is_null[ofs];
break;
@@ -567,13 +571,8 @@
if (zend_hash_find(&EG(persistent_list), mysql->hash_key,
strlen(mysql->hash_key) + 1, (void **)&le) == SUCCESS) {
if (Z_TYPE_P(le) == php_le_pmysqli()) {
mysqli_plist_entry *plist = (mysqli_plist_entry *) le->ptr;
- dtor_func_t pDestructor = plist->used_links.pDestructor;
+ zend_ptr_stack_push(&plist->free_links, mysql->mysql);
- plist->used_links.pDestructor = NULL; /* Don't call pDestructor now */
- zend_hash_index_del(&plist->used_links, mysql->hash_index);
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
-
- zend_hash_next_index_insert(&plist->free_links, &mysql->mysql,
sizeof(MYSQL *), NULL);
MyG(num_links)--;
MyG(num_active_persistent)--;
MyG(num_inactive_persistent)++;
@@ -735,6 +734,7 @@
convert_to_double_ex(&stmt->param.vars[i]);
stmt->stmt->params[i].buffer = &Z_LVAL_PP(&stmt->param.vars[i]);
break;
+ case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_LONG:
convert_to_long_ex(&stmt->param.vars[i]);
stmt->stmt->params[i].buffer = &Z_LVAL_PP(&stmt->param.vars[i]);
Modified: trunk/php6/ext/mysqli/mysqli_nonapi.c
===================================================================
--- trunk/php6/ext/mysqli/mysqli_nonapi.c 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysqli/mysqli_nonapi.c 2007-11-09 13:23:57 UTC (rev 1147)
@@ -17,7 +17,7 @@
| Ulf Wendel <uw@stripped> |
+----------------------------------------------------------------------+
- $Id: mysqli_nonapi.c,v 1.73 2007/10/02 10:43:09 andrey Exp $
+ $Id: mysqli_nonapi.c,v 1.74 2007/11/09 12:13:15 andrey Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -111,37 +111,18 @@
port, SAFE_STR(username), SAFE_STR(dbname),
SAFE_STR(passwd));
+ mysql->hash_key = hash_key;
+
/* check if we can reuse exisiting connection ... */
if (zend_hash_find(&EG(persistent_list), hash_key, hash_len + 1, (void **)&le)
== SUCCESS) {
if (Z_TYPE_P(le) == php_le_pmysqli()) {
plist = (mysqli_plist_entry *) le->ptr;
do {
- if (zend_hash_num_elements(&plist->free_links)) {
- HashPosition pos;
- MYSQL **free_mysql;
- ulong idx;
- dtor_func_t pDestructor = plist->free_links.pDestructor;
+ if (zend_ptr_stack_num_elements(&plist->free_links)) {
+ mysql->mysql = zend_ptr_stack_pop(&plist->free_links);
- zend_hash_internal_pointer_reset_ex(&plist->free_links, &pos);
- if (SUCCESS != zend_hash_get_current_data_ex(&plist->free_links,
- (void **)&free_mysql, &pos)) {
- break;
- }
- if (HASH_KEY_IS_LONG != zend_hash_get_current_key_ex(&plist->free_links,
NULL,
- NULL, &idx, FALSE, &pos)) {
- break;
- }
- mysql->mysql = *free_mysql;
- plist->free_links.pDestructor = NULL; /* Don't call pDestructor now */
- if (SUCCESS != zend_hash_index_del(&plist->free_links, idx)) {
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
- break;
- }
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
MyG(num_inactive_persistent)--;
- MyG(num_active_persistent)++;
-
/* reset variables */
/* todo: option for ping or change_user */
#if G0
@@ -152,15 +133,14 @@
#ifdef HAVE_MYSQLND
mysqlnd_restart_psession(mysql->mysql);
#endif
- idx = zend_hash_next_free_element(&plist->used_links);
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links,
&free_mysql,
- sizeof(MYSQL *), NULL)) {
- php_mysqli_dtor_p_elements(free_mysql);
- break;
- }
- mysql->hash_index = idx;
- mysql->hash_key = hash_key;
- goto end;
+ MyG(num_active_persistent)++;
+ goto end;
+ } else {
+#if defined(HAVE_MYSQLND)
+ mysqlnd_end_psession(mysql->mysql);
+#endif
+ mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
+ mysql->mysql = NULL;
}
}
} while (0);
@@ -170,8 +150,7 @@
le.type = php_le_pmysqli();
le.ptr = plist = calloc(1, sizeof(mysqli_plist_entry));
- zend_hash_init(&plist->free_links, MAX(10, MyG(max_persistent)), NULL,
php_mysqli_dtor_p_elements, 1);
- zend_hash_init(&plist->used_links, MAX(10, MyG(max_persistent)), NULL,
php_mysqli_dtor_p_elements, 1);
+ zend_ptr_stack_init_ex(&plist->free_links, 1);
zend_hash_update(&EG(persistent_list), hash_key, hash_len + 1, (void *)&le,
sizeof(le), NULL);
}
}
@@ -254,14 +233,6 @@
/* store persistent connection */
if (persistent && new_connection) {
- ulong hash_index = zend_hash_next_free_element(&plist->used_links);
- /* save persistent connection */
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links,
&mysql->mysql,
- sizeof(MYSQL *), NULL)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't store persistent connection");
- } else {
- mysql->hash_index = hash_index;
- }
MyG(num_active_persistent)++;
}
@@ -284,7 +255,7 @@
err:
efree(mysql);
- if (persistent) {
+ if (hash_key) {
efree(hash_key);
}
RETVAL_FALSE;
Modified: trunk/php6/ext/mysqli/php_mysqli_structs.h
===================================================================
--- trunk/php6/ext/mysqli/php_mysqli_structs.h 2007-10-25 08:45:37 UTC (rev 1146)
+++ trunk/php6/ext/mysqli/php_mysqli_structs.h 2007-11-09 13:23:57 UTC (rev 1147)
@@ -15,7 +15,7 @@
| Author: Georg Richter <georg@stripped> |
+----------------------------------------------------------------------+
- $Id: php_mysqli_structs.h,v 1.5 2007/10/08 15:40:26 andrey Exp $
+ $Id: php_mysqli_structs.h,v 1.6 2007/11/09 12:13:15 andrey Exp $
*/
#ifndef PHP_MYSQLI_STRUCTS_H
@@ -102,7 +102,6 @@
zval *li_read;
php_stream *li_stream;
zend_bool persistent;
- unsigned long hash_index; /* Used when persistent, hold the index in
plist->used_links */
unsigned int multi_query;
UConverter *conv;
} MY_MYSQL;
@@ -148,8 +147,7 @@
#endif
typedef struct {
- HashTable free_links;
- HashTable used_links;
+ zend_ptr_stack free_links;
} mysqli_plist_entry;
#ifdef PHP_WIN32
| Thread |
|---|
| • PHP mysqlnd svn commit: r1147 - in trunk: mysqlnd php5/ext/mysql php5/ext/mysqli php6/ext/mysql php6/ext/mysqli | ahristov | 9 Nov |