List:Commits« Previous MessageNext Message »
From:ahristov Date:May 2 2007 9:51am
Subject:PHP mysqlnd svn commit: r359 - in branches/qcache: mysqlnd php5/ext/mysqli php6/ext/mysqli
View as plain text  
Author: ahristov
Date: 2007-05-02 11:51:39 +0200 (Wed, 02 May 2007)
New Revision: 359

Modified:
   branches/qcache/mysqlnd/mysqlnd.c
   branches/qcache/mysqlnd/mysqlnd.h
   branches/qcache/mysqlnd/mysqlnd_palloc.c
   branches/qcache/mysqlnd/mysqlnd_palloc.h
   branches/qcache/mysqlnd/mysqlnd_priv.h
   branches/qcache/mysqlnd/mysqlnd_ps.c
   branches/qcache/mysqlnd/mysqlnd_wireprotocol.c
   branches/qcache/php5/ext/mysqli/mysqli.c
   branches/qcache/php5/ext/mysqli/mysqli_api.c
   branches/qcache/php5/ext/mysqli/mysqli_nonapi.c
   branches/qcache/php5/ext/mysqli/php_mysqli.h
   branches/qcache/php6/ext/mysqli/mysqli.c
   branches/qcache/php6/ext/mysqli/mysqli_api.c
   branches/qcache/php6/ext/mysqli/mysqli_nonapi.c
   branches/qcache/php6/ext/mysqli/php_mysqli.h
Log:
Manual merge from trunk


Modified: branches/qcache/mysqlnd/mysqlnd.c
===================================================================
--- branches/qcache/mysqlnd/mysqlnd.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -157,7 +157,7 @@
 void mysqlnd_free_buffered_data(MYSQLND_RES * result TSRMLS_DC)
 {
 	MYSQLND_RES_BUFFERED *set = result->data;
-	MYSQLND_ZVAL_PCACHE	*zval_cache = result->zval_cache;
+	MYSQLND_THD_ZVAL_PCACHE	*zval_cache = result->zval_cache;
 	uint field_count = result->field_count;
 	enum_mysqlnd_res_type result_type = result->type;
 	int row, col;
@@ -176,30 +176,23 @@
 		zval **current_row = set->data[row];
 
 		for (col = 0; col < field_count; col++) {
-			if (result_type == MYSQLND_RES_PS) {
-				/* For now PS always does create copies when fetching data */
-				zval_ptr_dtor(&current_row[col]);
-
-				MYSQLND_INC_CONN_STATISTIC(NULL, STAT_COPY_ON_WRITE_PERFORMED);
-			} else {
-				zend_bool copy_ctor_called;
-				if (set->persistent == TRUE) {
-					/* Now the block variable will point to the buffers */
-					set->block[ofs + col] = *(current_row[col]);
-					/* Set refcount to 1, because it had different value */
-					INIT_PZVAL(&(set->block[ofs + col]));
-				}
-				/*
-				  Free only if we haven't referenced it.
-				  Either the zval will be freed, but not what it points to
-				  in the buffers. Of separated, which is again ok.
-				*/
-				mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), zval_cache,
-											 FALSE, &copy_ctor_called TSRMLS_CC);
-				MYSQLND_INC_CONN_STATISTIC(NULL,
-						copy_ctor_called? STAT_COPY_ON_WRITE_PERFORMED:
-										  STAT_COPY_ON_WRITE_SAVED);
+			zend_bool copy_ctor_called;
+			if (result_type == MYSQLND_RES_NORMAL && set->persistent == TRUE) {
+				/* Now the block variable will point to the buffers */
+				set->block[ofs + col] = *(current_row[col]);
+				/* Set refcount to 1, because it had different value */
+				INIT_PZVAL(&(set->block[ofs + col]));
 			}
+			/*
+			  Free only if we haven't referenced it.
+			  Either the zval will be freed, but not what it points to
+			  in the buffers. Of separated, which is again ok.
+			*/
+			mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), zval_cache,
+										 (result_type == MYSQLND_RES_PS),
+										 &copy_ctor_called TSRMLS_CC);
+			MYSQLND_INC_CONN_STATISTIC(NULL, copy_ctor_called? STAT_COPY_ON_WRITE_PERFORMED:
+										  					   STAT_COPY_ON_WRITE_SAVED);
 		}
 		if (!set->persistent) {
 			efree(current_row);
@@ -330,7 +323,7 @@
 	}
 
 	if (result->zval_cache) {
-		mysqlnd_palloc_free_cache_reference(&result->zval_cache);
+		mysqlnd_palloc_free_thd_cache_reference(&result->zval_cache);
 		result->zval_cache = NULL;
 	}
 }
@@ -448,7 +441,7 @@
 		conn->options.ssl_cipher = NULL;
 	}
 	if (conn->zval_cache) {
-		mysqlnd_palloc_free_cache_reference(&conn->zval_cache);
+		mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache);
 		conn->zval_cache = NULL;
 	}
 	if (conn->qcache) {
@@ -656,7 +649,7 @@
 						 unsigned int port,
 						 char *socket,
 						 unsigned int mysql_flags,
-						 MYSQLND_ZVAL_PCACHE *zval_cache,
+						 MYSQLND_THD_ZVAL_PCACHE *zval_cache,
 						 MYSQLND_QCACHE *qcache
 						 TSRMLS_DC)
 {
@@ -778,7 +771,14 @@
 
 	auth_packet->user		= user;
 	auth_packet->password	= passwd;
-	auth_packet->charset_no	= greet_packet.charset_no;
+#if PHP_MAJOR_VERSION >= 6
+	if (UG(unicode)) {
+		auth_packet->charset_no	= 200;/* utf8 - swedish collation, check mysqlnd_charset.c
*/	
+	} else
+#endif
+	{
+		auth_packet->charset_no	= greet_packet.charset_no;
+	}
 	auth_packet->db			= db;
 	auth_packet->db_len		= db_len;
 	auth_packet->max_packet_size= 3UL*1024UL*1024UL*1024UL;
@@ -844,7 +844,7 @@
 		PACKET_FREE(auth_packet);
 		PACKET_FREE_ALLOCA(ok_packet);
 
-		conn->zval_cache = mysqlnd_palloc_get_cache_reference(zval_cache);
+		conn->zval_cache = mysqlnd_palloc_get_thd_cache_reference(zval_cache);
 		conn->qcache = mysqlnd_qcache_get_cache_reference(qcache);
 		conn->net.cmd_buffer.length = 128L*1024L;
 		conn->net.cmd_buffer.buffer = pemalloc(conn->net.cmd_buffer.length,
conn->persistent);
@@ -1186,7 +1186,7 @@
 					result =
 						conn->current_result=
 							mysqlnd_result_init(rset_header.field_count,
-												mysqlnd_palloc_get_cache_reference(conn->zval_cache));
+												mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache));
 				} else {
 					if (!stmt->result) {
 						/*
@@ -1198,7 +1198,7 @@
 						result =
 							stmt->result =
 								mysqlnd_result_init(rset_header.field_count,
-													mysqlnd_palloc_get_cache_reference(conn->zval_cache));
+													mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache));
 					} else {
 						/*
 						  Update result set metadata if it for some reason changed between
@@ -2839,7 +2839,7 @@
 
 
 /* {{{ mysqlnd_result_init */
-MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_ZVAL_PCACHE *cache)
+MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_THD_ZVAL_PCACHE
*cache)
 {
 	MYSQLND_RES *ret = ecalloc(1, sizeof(MYSQLND_RES));
 

Modified: branches/qcache/mysqlnd/mysqlnd.h
===================================================================
--- branches/qcache/mysqlnd/mysqlnd.h	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd.h	2007-05-02 09:51:39 UTC (rev 359)
@@ -411,6 +411,7 @@
 
 
 typedef struct st_mysqlnd_zval_pcache	MYSQLND_ZVAL_PCACHE;
+typedef struct st_mysqlnd_thread_zval_pcache	MYSQLND_THD_ZVAL_PCACHE;
 typedef struct st_mysqlnd_qcache		MYSQLND_QCACHE;
 
 
@@ -698,7 +699,7 @@
 	MYSQLND_OPTION	options;
 
 	/* zval cache */
-	MYSQLND_ZVAL_PCACHE	*zval_cache;
+	MYSQLND_THD_ZVAL_PCACHE	*zval_cache;
 
 	/* qcache */
 	MYSQLND_QCACHE		*qcache;
@@ -779,7 +780,7 @@
 	php_mysql_packet_row	*row_packet;	/* Unused for PS */
 
 	/* zval cache */
-	MYSQLND_ZVAL_PCACHE		*zval_cache;
+	MYSQLND_THD_ZVAL_PCACHE		*zval_cache;
 	char					*conn_hash_key;		/* user for query caching */
 	size_t					conn_hash_key_len;	/* user for query caching */
 
@@ -858,7 +859,7 @@
 						  unsigned int port,
 						  char *socket,
 						  unsigned int mysql_flags,
-						  MYSQLND_ZVAL_PCACHE *zval_cache,
+						  MYSQLND_THD_ZVAL_PCACHE *zval_cache,
 						  MYSQLND_QCACHE *qcache
 						  TSRMLS_DC);
 #define mysqlnd_change_user(conn, user, passwd, db)		(conn)->m->change_user((conn),
(user), (passwd), (db) TSRMLS_CC)
@@ -1038,15 +1039,21 @@
 
 /* Persistent caching zval allocator */
 PHPAPI MYSQLND_ZVAL_PCACHE* mysqlnd_palloc_init_cache(unsigned int cache_size);
-MYSQLND_ZVAL_PCACHE* mysqlnd_palloc_get_cache_reference(MYSQLND_ZVAL_PCACHE * const
cache);
-PHPAPI void			mysqlnd_palloc_free_cache_reference(MYSQLND_ZVAL_PCACHE **cache);
-PHPAPI void			mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * const cache);
-PHPAPI void			mysqlnd_palloc_rshutdown(MYSQLND_ZVAL_PCACHE * const cache);
+PHPAPI void 		mysqlnd_palloc_free_cache(MYSQLND_ZVAL_PCACHE *cache);
 PHPAPI void			mysqlnd_palloc_stats(const MYSQLND_ZVAL_PCACHE * const cache, zval
*return_value);
 
+PHPAPI MYSQLND_THD_ZVAL_PCACHE * mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * cache);
+PHPAPI void						 mysqlnd_palloc_rshutdown(MYSQLND_THD_ZVAL_PCACHE * cache);
+
+
+MYSQLND_THD_ZVAL_PCACHE*	mysqlnd_palloc_init_thd_cache(MYSQLND_ZVAL_PCACHE * const
cache);
+MYSQLND_THD_ZVAL_PCACHE*	mysqlnd_palloc_get_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE *
const cache);
+PHPAPI void					mysqlnd_palloc_free_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE **cache);
+
+
 /* There two should not be used from outside */
-void *				mysqlnd_palloc_get_zval(MYSQLND_ZVAL_PCACHE * const cache, zend_bool
*allocated);
-void				mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_ZVAL_PCACHE * const cache,
zend_bool ps,
+void *				mysqlnd_palloc_get_zval(MYSQLND_THD_ZVAL_PCACHE * const cache, zend_bool
*allocated);
+void				mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_THD_ZVAL_PCACHE * const cache,
zend_bool ps,
 												 zend_bool *copy_ctor_called TSRMLS_DC);
 
 

Modified: branches/qcache/mysqlnd/mysqlnd_palloc.c
===================================================================
--- branches/qcache/mysqlnd/mysqlnd_palloc.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd_palloc.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -61,18 +61,10 @@
 	ret->references = 1;
 
 	/* 1. First initialize the free list part of the structure */
-	ret->free_list = calloc(1, sizeof(mysqlnd_ndzval_list));
-
 	/* One more for empty position of last_added - always 0x0, bounds checking */
-	ret->free_list->ptr_line = calloc(ret->max_items + 1, sizeof(mysqlnd_zval *));
-	ret->free_list->last_added = ret->free_list->ptr_line + ret->max_items;
+	ret->free_list.ptr_line = calloc(ret->max_items + 1, sizeof(mysqlnd_zval *));
+	ret->free_list.last_added = ret->free_list.ptr_line + ret->max_items;
 
-	/* 2. Initialize the GC list */
-	ret->gc_list = calloc(1, sizeof(mysqlnd_ndzval_list));
-	ret->gc_list->ptr_line = calloc(ret->max_items, sizeof(mysqlnd_zval *));
-	/* Backward and forward looping is possible */
-	ret->gc_list->last_added = ret->gc_list->ptr_line;
-
 	/* 3. Allocate and initialize our zvals and initialize the free list */
 	ret->block = calloc(ret->max_items, sizeof(mysqlnd_zval));
 	ret->last_in_block = &(ret->block[ret->max_items]);
@@ -83,7 +75,7 @@
 		/* Assure it will never be freed before MSHUTDOWN */
 		ZVAL_ADDREF(&(ret->block[i].zv));
 		/* 2. Add to the free list  */
-		*(--ret->free_list->last_added) = &(ret->block[i]);
+		*(--ret->free_list.last_added) = &(ret->block[i]);
 	}
 	
 
@@ -113,7 +105,6 @@
   to the free list after usage. We ZVAL_NULL() them when we allocate them in the 
   constructor of the cache.
 */
-static
 void mysqlnd_palloc_free_cache(MYSQLND_ZVAL_PCACHE *cache)
 {
 #ifndef MYSQLND_SILENT
@@ -126,29 +117,81 @@
 
 	/* Data in pointed by 'block' was cleaned in RSHUTDOWN */
 	free(cache->block);
-	free(cache->free_list->ptr_line);
-	free(cache->free_list);
-	free(cache->gc_list->ptr_line);
-	free(cache->gc_list);
+	free(cache->free_list.ptr_line);
 	free(cache);
 }
 /* }}} */
 
 
-/* {{{ mysqlnd_palloc_free_cache_reference */
-PHPAPI void mysqlnd_palloc_free_cache_reference(MYSQLND_ZVAL_PCACHE **cache)
+/* {{{ mysqlnd_palloc_init_thd_cache */
+PHPAPI MYSQLND_THD_ZVAL_PCACHE* mysqlnd_palloc_init_thd_cache(MYSQLND_ZVAL_PCACHE * const
cache)
 {
+	MYSQLND_THD_ZVAL_PCACHE *ret = calloc(1, sizeof(MYSQLND_THD_ZVAL_PCACHE));
+#ifndef MYSQLND_SILENT
+	php_printf("[mysqlnd_palloc_init_thd_cache %p]\n", ret);
+#endif
+	ret->parent = mysqlnd_palloc_get_cache_reference(cache);
+
+#ifdef ZTS
+	ret->thread_id = tsrm_thread_id();
+#endif
+
+	ret->references = 1;
+
+	/* 1. Initialize the GC list */
+	ret->gc_list.ptr_line = calloc(cache->max_items, sizeof(mysqlnd_zval *));
+	/* Backward and forward looping is possible */
+	ret->gc_list.last_added = ret->gc_list.ptr_line;
+
+	return ret;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_palloc_get_thd_cache_reference */
+MYSQLND_THD_ZVAL_PCACHE* mysqlnd_palloc_get_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE *
const cache)
+{
+	if (cache) {
+		++cache->references;
+		mysqlnd_palloc_get_cache_reference(cache->parent);
+	}
+	return cache;
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_palloc_free_cache */
+/*
+  As this call will happen on MSHUTDOWN(), then we don't need to copy the zvals with
+  copy_ctor but scrap what they point to with zval_dtor() and then just free our
+  pre-allocated block. Precondition is that we ZVAL_NULL() the zvals when we put them
+  to the free list after usage. We ZVAL_NULL() them when we allocate them in the 
+  constructor of the cache.
+*/
+static
+void mysqlnd_palloc_free_thd_cache(MYSQLND_THD_ZVAL_PCACHE *cache)
+{
+#ifndef MYSQLND_SILENT
+	php_printf("[mysqlnd_palloc_free_thd_cache %p]\n", cache);
+#endif
+
+	free(cache->gc_list.ptr_line);
+	free(cache);
+}
+/* }}} */
+
+
+/* {{{ mysqlnd_palloc_free_thd_cache_reference */
+PHPAPI void mysqlnd_palloc_free_thd_cache_reference(MYSQLND_THD_ZVAL_PCACHE **cache)
+{
 	if (*cache) {
-		zend_bool to_free;
 #ifndef MYSQLND_SILENT
-		php_printf("[mysqlnd_palloc_free_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
+		php_printf("[mysqlnd_palloc_free_thd_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
 #endif
-		LOCK_PCACHE(*cache);
-		to_free = --(*cache)->references == 0;
-		/* Unlock before destroying */
-		UNLOCK_PCACHE(*cache);
-		if (to_free) {
-			mysqlnd_palloc_free_cache(*cache);
+		--(*cache)->parent->references;
+
+		if (--(*cache)->references == 0) {
+			mysqlnd_palloc_free_thd_cache(*cache);
 		}
 		*cache = NULL;
 	}
@@ -242,22 +285,24 @@
 
 
 /* {{{ mysqlnd_palloc_get_zval */
-void *mysqlnd_palloc_get_zval(MYSQLND_ZVAL_PCACHE * const cache, zend_bool *allocated)
+void *mysqlnd_palloc_get_zval(MYSQLND_THD_ZVAL_PCACHE * const thd_cache, zend_bool
*allocated)
 {
 	void *ret = NULL;
 
 #ifndef MYSQLND_SILENT
 	php_printf("[mysqlnd_palloc_get_zval %p] *last_added=%p free_items=%d\n",
-				cache, cache? cache->free_list->last_added:NULL, cache->free_items);
+				cache, cache? cache->free_list.last_added:NULL, cache->free_items);
 #endif
 
-	if (cache) {
+	if (thd_cache) {
+		MYSQLND_ZVAL_PCACHE *cache = thd_cache->parent;
 		LOCK_PCACHE(cache);
-		if ((ret = *cache->free_list->last_added)) {
-			*cache->free_list->last_added++ = NULL;
+		
+		if ((ret = *cache->free_list.last_added)) {
+			*cache->free_list.last_added++ = NULL;
 			*allocated = FALSE;
 #ifdef ZTS
-		    ((mysqlnd_zval *) ret)->thread_id = tsrm_thread_id();
+			((mysqlnd_zval *) ret)->thread_id = thd_cache->thread_id;
 #endif
 			--cache->free_items;
 			++cache->get_hits;
@@ -288,15 +333,17 @@
 
 
 /* {{{ mysqlnd_palloc_zval_ptr_dtor */
-void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_ZVAL_PCACHE * const cache, zend_bool
ps,
+void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_THD_ZVAL_PCACHE * const thd_cache,
zend_bool ps,
 								  zend_bool *copy_ctor_called TSRMLS_DC)
 {
+	MYSQLND_ZVAL_PCACHE *cache;
 #ifndef MYSQLND_SILENT
 	php_printf("[mysqlnd_palloc_zval_ptr_dtor %p] *zv=%p ps=%d refc=%d\n", cache, *zv, ps,
ZVAL_REFCOUNT(*zv));
 #endif
 	*copy_ctor_called = FALSE;
 	/* Check whether cache is used and the zval is from the cache */
-	if (!cache || ((char *)*zv < (char *)cache->block || (char *)*zv > (char
*)cache->last_in_block)) {
+	if (!thd_cache || !(cache = thd_cache->parent) || ((char *)*zv < (char
*)thd_cache->parent->block ||
+													   (char *)*zv > (char *)thd_cache->parent->last_in_block)) {
 		/* 
 		  This zval is not from the cache block.
 		  Thus the refcount is -1 than of a zval from the cache,
@@ -379,7 +426,7 @@
 		*/
 		LOCK_PCACHE(cache);
 		++cache->put_misses;
-		*(cache->gc_list->last_added++) = (mysqlnd_zval *)*zv;
+		*(thd_cache->gc_list.last_added++) = (mysqlnd_zval *)*zv;
 		UNLOCK_PCACHE(cache);
 	} else {
 		/* No user reference */
@@ -396,7 +443,7 @@
 #ifdef ZTS
 		memset(&((mysqlnd_zval *)*zv)->thread_id, 0, sizeof(THREAD_T));
 #endif
-		*(--cache->free_list->last_added) = (mysqlnd_zval *)*zv;
+		*(--cache->free_list.last_added) = (mysqlnd_zval *)*zv;
 
 		UNLOCK_PCACHE(cache);
 	}
@@ -405,56 +452,50 @@
 
 
 /* {{{ mysqlnd_palloc_rinit */
-PHPAPI void mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * const cache)
+PHPAPI MYSQLND_THD_ZVAL_PCACHE * mysqlnd_palloc_rinit(MYSQLND_ZVAL_PCACHE * cache)
 {
-	return;
+	return mysqlnd_palloc_init_thd_cache(cache);
 }
 /* }}} */
 
 
 /* {{{ mysqlnd_palloc_rshutdown */
-PHPAPI void mysqlnd_palloc_rshutdown(MYSQLND_ZVAL_PCACHE * const cache)
+PHPAPI void mysqlnd_palloc_rshutdown(MYSQLND_THD_ZVAL_PCACHE * thd_cache)
 {
-	unsigned int i;
-#ifdef ZTS
-	THREAD_T thread_id;
-#endif
+	MYSQLND_ZVAL_PCACHE *cache;
+	mysqlnd_zval **p;
 #ifndef MYSQLND_SILENT
 	php_printf("[mysqlnd_palloc_rshutdown %p]\n", cache);
 #endif
-	if (!cache) {
+	if (!thd_cache || !(cache = thd_cache->parent)) {
 		return;
 	}
 
-	thread_id = tsrm_thread_id();
 	/*
 	  Keep in mind that for pthreads pthread_equal() should be used to be
 	  fully standard compliant. However, the PHP code all-around, incl. the
 	  the Zend MM uses direct comparison.
 	*/
+	p = thd_cache->gc_list.ptr_line;
+	while (p < thd_cache->gc_list.last_added) {
+		zval_dtor(&(*p)->zv);
+		p++;
+	}
+
+	p = thd_cache->gc_list.ptr_line;
 	LOCK_PCACHE(cache);
-	for (i = 0; i < cache->max_items; i++) {
-		if (
-			cache->block[i].point_type == MYSQLND_POINTS_EXT_BUFFER
+	while (p < thd_cache->gc_list.last_added) {
+		(*p)->point_type = MYSQLND_POINTS_FREE;
+		*(--cache->free_list.last_added) = *p;
+		++cache->free_items;
 #ifdef ZTS
-#if defined(PTHREADS)
-			&& pthread_equal(cache->block[i].thread_id, thread_id)
-#else
-			&& cache->block[i].thread_id == thread_id
-#endif
-#endif
-			)
-		{
-			zval_dtor(&(cache->block[i].zv));
-			cache->block[i].point_type = MYSQLND_POINTS_FREE;
-			*(--cache->free_list->last_added) = &(cache->block[i]);
-			++cache->free_items;
-#ifdef ZTS
-			memset(&cache->block[i].thread_id, 0, sizeof(THREAD_T));
-#endif
-		}
+		memset(&((*p)->thread_id), 0, sizeof(THREAD_T));
+#endif	
+		p++;
 	}
 	UNLOCK_PCACHE(cache);
+
+	mysqlnd_palloc_free_thd_cache_reference(&thd_cache);
 }
 /* }}} */
 
@@ -512,4 +553,3 @@
 	}
 }
 /* }}} */
-

Modified: branches/qcache/mysqlnd/mysqlnd_palloc.h
===================================================================
--- branches/qcache/mysqlnd/mysqlnd_palloc.h	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd_palloc.h	2007-05-02 09:51:39 UTC (rev 359)
@@ -70,17 +70,16 @@
 struct st_mysqlnd_zval_pcache {
 	mysqlnd_zval		*block;
 	mysqlnd_zval		*last_in_block;
-	mysqlnd_ndzval_list	*free_list;	/* Fetch from here */
-	mysqlnd_ndzval_list	*gc_list;	/* GC these from time to time */
+	mysqlnd_ndzval_list	free_list;	/* Fetch from here */
 
-
 #ifdef ZTS
 	MUTEX_T 			LOCK_access;
 #endif
+	unsigned int		references;
+
 	/* These are just for statistics and not used for operational purposes */
 	unsigned int		free_items;
 	unsigned int		max_items;
-	unsigned int		references;
 
 	unsigned long		get_hits;
 	unsigned long		get_misses;
@@ -88,5 +87,14 @@
 	unsigned long		put_misses;
 };
 
+struct st_mysqlnd_thread_zval_pcache {
+	struct st_mysqlnd_zval_pcache *parent;
 
+	unsigned int		references;
+#ifdef ZTS
+	THREAD_T			thread_id;
+#endif
+	mysqlnd_ndzval_list	gc_list;		/* GC these from time to time */
+};
+
 #endif /* MYSQLND_PALLOC_H */

Modified: branches/qcache/mysqlnd/mysqlnd_priv.h
===================================================================
--- branches/qcache/mysqlnd/mysqlnd_priv.h	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd_priv.h	2007-05-02 09:51:39 UTC (rev 359)
@@ -156,7 +156,7 @@
 
 enum_func_status mysqlnd_read_result_metadata(MYSQLND *conn, MYSQLND_RES *result
TSRMLS_DC);
 
-MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_ZVAL_PCACHE
*cache);							
+MYSQLND_RES *mysqlnd_result_init(unsigned int field_count, MYSQLND_THD_ZVAL_PCACHE
*cache);							
 void mysqlnd_unbuffered_free_last_data(MYSQLND_RES *result TSRMLS_DC);
 void mysqlnd_internal_free_result_contents(MYSQLND_RES *result TSRMLS_DC);
 void mysqlnd_internal_free_result_buffers(MYSQLND_RES *result TSRMLS_DC);

Modified: branches/qcache/mysqlnd/mysqlnd_ps.c
===================================================================
--- branches/qcache/mysqlnd/mysqlnd_ps.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd_ps.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -1160,7 +1160,7 @@
 MYSQLND_RES * _mysqlnd_stmt_result_metadata(MYSQLND_STMT * const stmt)
 {
 	MYSQLND_RES *result;
-	MYSQLND_ZVAL_PCACHE * cache;
+	MYSQLND_THD_ZVAL_PCACHE * cache;
 
 	if (!stmt->field_count || !stmt->conn || !stmt->result) {
 		return NULL;
@@ -1173,7 +1173,7 @@
 			be handled in a better way.
 	
 	*/
-	cache = mysqlnd_palloc_get_cache_reference(stmt->conn->zval_cache);
+	cache = mysqlnd_palloc_get_thd_cache_reference(stmt->conn->zval_cache);
 	result = mysqlnd_result_init(stmt->field_count, cache);
 	result->type = MYSQLND_RES_NORMAL;
 	result->m.fetch_row = result->m.fetch_row_normal_unbuffered;

Modified: branches/qcache/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- branches/qcache/mysqlnd/mysqlnd_wireprotocol.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/mysqlnd/mysqlnd_wireprotocol.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -1280,7 +1280,9 @@
 #if PHP_MAJOR_VERSION < 6
 			{
 				ZVAL_STRINGL(*current_field, (char *)p, len, 0);
-				((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
+				if (allocated == FALSE) {
+					((mysqlnd_zval *) obj)->point_type = MYSQLND_POINTS_INT_BUFFER;
+				}
 			}
 #else
 			/*

Modified: branches/qcache/php5/ext/mysqli/mysqli.c
===================================================================
--- branches/qcache/php5/ext/mysqli/mysqli.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php5/ext/mysqli/mysqli.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -528,11 +528,8 @@
 #endif
 #ifdef HAVE_MYSQLND
 	mysqli_globals->cache_size = 0;
+	mysqli_globals->mysqlnd_thd_zval_cache = NULL;
 #endif
-#ifdef HAVE_MYSQLND
-	mysqlnd_zval_cache = NULL;
-	mysqlnd_qcache = NULL;
-#endif
 }
 /* }}} */
 
@@ -728,7 +725,7 @@
 	zend_hash_destroy(&mysqli_link_properties);
 	zend_hash_destroy(&classes);
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_free_cache_reference(&mysqlnd_zval_cache);
+	mysqlnd_palloc_free_cache(mysqlnd_zval_cache);
 	mysqlnd_library_end();
 #endif
 
@@ -744,7 +741,7 @@
 	MyG(error_msg) = NULL;
 	MyG(error_no) = 0;
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_rinit(mysqlnd_zval_cache);
+	MyG(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(mysqlnd_zval_cache);
 #endif
 
 	return SUCCESS;
@@ -759,7 +756,7 @@
 		efree(MyG(error_msg));
 	}
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_rshutdown(mysqlnd_zval_cache);
+	mysqlnd_palloc_rshutdown(MyG(mysqlnd_thd_zval_cache));
 #endif
 	return SUCCESS;
 }

Modified: branches/qcache/php5/ext/mysqli/mysqli_api.c
===================================================================
--- branches/qcache/php5/ext/mysqli/mysqli_api.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php5/ext/mysqli/mysqli_api.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -1633,7 +1633,7 @@
 	if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname ,port, socket
,flags) == NULL) 
 #else
 	if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname,
dbname_len,
-						  port, socket, flags, mysqlnd_zval_cache TSRMLS_CC) == NULL)
+						  port, socket, flags, MyG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
 #endif
 	{
 		php_mysqli_set_error(mysql_errno(mysql->mysql), (char *)
mysql_error(mysql->mysql) TSRMLS_CC);

Modified: branches/qcache/php5/ext/mysqli/mysqli_nonapi.c
===================================================================
--- branches/qcache/php5/ext/mysqli/mysqli_nonapi.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php5/ext/mysqli/mysqli_nonapi.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -143,7 +143,7 @@
 	if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port,
socket, CLIENT_MULTI_RESULTS) == NULL)
 #else
 	if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname,
dbname_len,
-						  port, socket, CLIENT_MULTI_RESULTS, mysqlnd_zval_cache TSRMLS_CC) == NULL)
+						  port, socket, CLIENT_MULTI_RESULTS, MyG(mysqlnd_thd_zval_cache) TSRMLS_CC) ==
NULL)
 #endif
 	{
 		/* Save error messages */

Modified: branches/qcache/php5/ext/mysqli/php_mysqli.h
===================================================================
--- branches/qcache/php5/ext/mysqli/php_mysqli.h	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php5/ext/mysqli/php_mysqli.h	2007-05-02 09:51:39 UTC (rev 359)
@@ -468,6 +468,9 @@
 	HashTable		*report_ht;
 	unsigned int	multi_query;
 	unsigned int	embedded;
+#ifdef HAVE_MYSQLND
+	MYSQLND_THD_ZVAL_PCACHE	*mysqlnd_thd_zval_cache;
+#endif
 ZEND_END_MODULE_GLOBALS(mysqli)
 
 

Modified: branches/qcache/php6/ext/mysqli/mysqli.c
===================================================================
--- branches/qcache/php6/ext/mysqli/mysqli.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php6/ext/mysqli/mysqli.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -543,8 +543,7 @@
 	mysqli_globals->cache_size = 0;
 	mysqli_globals->qc_TTL = 0;
 	mysqli_globals->qc_hash_buffer_size = 0;
-	mysqlnd_zval_cache = NULL;
-	mysqlnd_qcache = NULL;
+	mysqli_globals->mysqlnd_thd_zval_cache = NULL;
 #endif
 }
 /* }}} */
@@ -747,7 +746,7 @@
 	zend_hash_destroy(&mysqli_link_properties);
 	zend_hash_destroy(&classes);
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_free_cache_reference(&mysqlnd_zval_cache);
+	mysqlnd_palloc_free_cache(mysqlnd_zval_cache);
 	mysqlnd_qcache_free_cache_reference(&mysqlnd_qcache);
 	mysqlnd_library_end();
 #endif
@@ -763,7 +762,7 @@
 	MyG(error_msg) = NULL;
 	MyG(error_no) = 0;
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_rinit(mysqlnd_zval_cache);
+	MyG(mysqlnd_thd_zval_cache) = mysqlnd_palloc_rinit(mysqlnd_zval_cache);
 #endif
 
 	return SUCCESS;
@@ -778,7 +777,7 @@
 		efree(MyG(error_msg));
 	}
 #ifdef HAVE_MYSQLND
-	mysqlnd_palloc_rshutdown(mysqlnd_zval_cache);
+	mysqlnd_palloc_rshutdown(MyG(mysqlnd_thd_zval_cache));
 #endif
 	return SUCCESS;
 }

Modified: branches/qcache/php6/ext/mysqli/mysqli_api.c
===================================================================
--- branches/qcache/php6/ext/mysqli/mysqli_api.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php6/ext/mysqli/mysqli_api.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -1653,7 +1653,7 @@
 	if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname ,port, socket
,flags) == NULL) 
 #else
 	if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname,
dbname_len,
-						  port, socket, flags, mysqlnd_zval_cache, mysqlnd_qcache TSRMLS_CC) == NULL)
+						  port, socket, flags, MyG(mysqlnd_thd_zval_cache), mysqlnd_qcache TSRMLS_CC) ==
NULL)
 #endif
 	{
 		php_mysqli_set_error(mysql_errno(mysql->mysql), (char *)
mysql_error(mysql->mysql) TSRMLS_CC);

Modified: branches/qcache/php6/ext/mysqli/mysqli_nonapi.c
===================================================================
--- branches/qcache/php6/ext/mysqli/mysqli_nonapi.c	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php6/ext/mysqli/mysqli_nonapi.c	2007-05-02 09:51:39 UTC (rev 359)
@@ -149,7 +149,7 @@
 	if (mysql_real_connect(mysql->mysql, hostname, username, passwd, dbname, port,
socket, CLIENT_MULTI_RESULTS) == NULL)
 #else
 	if (mysqlnd_connect(mysql->mysql, hostname, username, passwd, passwd_len, dbname,
dbname_len,
-						  port, socket, CLIENT_MULTI_RESULTS, mysqlnd_zval_cache, mysqlnd_qcache TSRMLS_CC)
== NULL)
+						  port, socket, CLIENT_MULTI_RESULTS, MyG(mysqlnd_thd_zval_cache), mysqlnd_qcache
TSRMLS_CC) == NULL)
 #endif
 	{
 		/* Save error messages */

Modified: branches/qcache/php6/ext/mysqli/php_mysqli.h
===================================================================
--- branches/qcache/php6/ext/mysqli/php_mysqli.h	2007-04-30 20:18:22 UTC (rev 358)
+++ branches/qcache/php6/ext/mysqli/php_mysqli.h	2007-05-02 09:51:39 UTC (rev 359)
@@ -489,6 +489,7 @@
 	long				cache_size;
 	size_t				qc_hash_buffer_size;
 	time_t				qc_TTL;
+	MYSQLND_THD_ZVAL_PCACHE	*mysqlnd_thd_zval_cache;
 #endif
 ZEND_END_MODULE_GLOBALS(mysqli)
 

Thread
PHP mysqlnd svn commit: r359 - in branches/qcache: mysqlnd php5/ext/mysqli php6/ext/mysqliahristov2 May