pajoye                                   Thu, 01 Apr 2010 20:21:50 +0000

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

Log:
- revert revision 297277, break the builds (declaration must go 1st, size of 
void * and other known situations). Also Johannes, can you check that commit 
pls? Thought we were in bugs fixing only for 5.3

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_debug.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_enum_n_def.h
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_priv.h
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps_codec.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_statistics.c
    U   php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -529,7 +529,6 @@
 		db = "";
 		db_len = 0;
 	}
-
 	host_len = strlen(host);
 	{
 		char * transport = NULL;
@@ -554,7 +553,7 @@
 		DBG_INF_FMT("transport=%s", transport);
 		conn->scheme = mnd_pestrndup(transport, transport_len, conn->persistent);
 		conn->scheme_len = transport_len;
-		efree(transport); /* allocated by spprintf */
+		efree(transport);
 		transport = NULL;
 	}

@@ -644,7 +643,6 @@
 		}
 	} else {
 		CONN_SET_STATE(conn, CONN_READY);
-
 		if (!self_alloced && saved_compression) {
 			conn->net->compressed = TRUE;
 		}
@@ -664,14 +662,16 @@
 		conn->connect_or_select_db_len = db_len;

 		if (!unix_socket) {
+			char *p;

 			conn->host = mnd_pestrdup(host, conn->persistent);
 			conn->host_len = strlen(conn->host);
-			{
-				char *p;
-				spprintf(&p, 0, "%s via TCP/IP", conn->host);
-				conn->host_info =  mnd_pestrdup(p, conn->persistent);
-				efree(p); /* allocated by spprintf */
+			spprintf(&p, 0, "%s via TCP/IP", conn->host);
+			if (conn->persistent) {
+				conn->host_info = mnd_pestrdup(p, 1);
+				mnd_efree(p);
+			} else {
+				conn->host_info = p;
 			}
 		} else {
 			conn->unix_socket	= mnd_pestrdup(socket, conn->persistent);
@@ -693,6 +693,10 @@
 		SET_EMPTY_ERROR(conn->error_info);

 		mysqlnd_local_infile_default(conn);
+		{
+			unsigned int buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
+			conn->m->set_client_option(conn, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *)&buf_size TSRMLS_CC);
+		}

 		MYSQLND_INC_CONN_STATISTIC_W_VALUE2(conn->stats, STAT_CONNECT_SUCCESS, 1, STAT_OPENED_CONNECTIONS, 1);
 		if (reconnect) {
@@ -703,7 +707,6 @@
 		}

 		DBG_INF_FMT("connection_id=%llu", conn->thread_id);
-
 #if PHP_MAJOR_VERSION >= 6
 		{
 			unsigned int as_unicode = 1;
@@ -712,6 +715,7 @@
 			DBG_INF("unicode set");
 		}
 #endif
+
 		if (conn->options.init_commands) {
 			int current_command = 0;
 			for (; current_command < conn->options.num_commands; ++current_command) {
@@ -769,7 +773,7 @@
 						 unsigned int mysql_flags
 						 TSRMLS_DC)
 {
-	enum_func_status ret = FAIL;
+	enum_func_status ret;
 	zend_bool self_alloced = FALSE;

 	DBG_ENTER("mysqlnd_connect");
@@ -1135,7 +1139,7 @@
 		result = conn->m->store_result(conn TSRMLS_CC);
 	}
 	if (show_query != query) {
-		efree(show_query); /* allocated by spprintf */
+		mnd_efree(show_query);
 	}
 	DBG_RETURN(result);
 }
@@ -1221,7 +1225,7 @@
 	SET_ERROR_AFF_ROWS(conn);
 	if (ret == PASS) {
 		if (conn->connect_or_select_db) {
-			mnd_pefree(conn->connect_or_select_db, conn->persistent);
+			pefree(conn->connect_or_select_db, conn->persistent);
 		}
 		conn->connect_or_select_db = mnd_pestrndup(db, db_len, conn->persistent);
 		conn->connect_or_select_db_len = db_len;
@@ -1271,9 +1275,10 @@
 	if (FAIL == (ret = PACKET_READ(stats_header, conn))) {
 		DBG_RETURN(FAIL);
 	}
-	/* will be freed by Zend, thus don't use the mnd_ allocator */
-	*message = estrndup(stats_header->message, stats_header->message_len);
+	*message = stats_header->message;
 	*message_len = stats_header->message_len;
+	/* Ownership transfer */
+	stats_header->message = NULL;
 	PACKET_FREE(stats_header);

 	DBG_INF(*message);
@@ -1338,7 +1343,7 @@
 	} else {
 		conn->charset = charset;
 	}
-	efree(query); /* allocated by spprintf */
+	mnd_efree(query);

 	DBG_INF(ret == PASS? "PASS":"FAIL");
 	DBG_RETURN(ret);

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_debug.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_debug.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_debug.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -656,30 +656,24 @@
 #define __zend_filename "/unknown/unknown"
 #define __zend_lineno   0
 #endif
-
-#define REAL_SIZE(s) (collect_memory_statistics? (s) + sizeof(size_t) : (s))
-#define REAL_PTR(p) (collect_memory_statistics && (p)? ((p) - sizeof(size_t)) : (p))
-#define FAKE_PTR(p) (collect_memory_statistics && (p)? ((p) + sizeof(size_t)) : (p))

+
 /* {{{ _mysqlnd_emalloc */
 void * _mysqlnd_emalloc(size_t size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
-
 	DBG_ENTER(mysqlnd_emalloc_name);

 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
+	DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
+	ret = emalloc(size);
+	DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
+	DBG_INF_FMT("size=%lu ptr=%p", size, ret);

-	ret = emalloc(REAL_SIZE(size));
-
-	DBG_INF_FMT("size=%lu ptr=%p", size, ret);
-
-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EMALLOC_COUNT, 1, STAT_MEM_EMALLOC_AMOUNT, size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EMALLOC_COUNT, 1, STAT_MEM_EMALLOC_AMMOUNT, size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -688,21 +682,29 @@
 void * _mysqlnd_pemalloc(size_t size, zend_bool persistent MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_pemalloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
+	if (persistent == FALSE) {
+		DBG_INF_FMT("before: %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}

-	ret = pemalloc(REAL_SIZE(size), persistent);
-	DBG_INF_FMT("size=%lu ptr=%p persistent=%d", size, ret, persistent);
+	ret = pemalloc(size, persistent);
+	DBG_INF_FMT("size=%lu ptr=%p persistent=%d", size, ret, persistent);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
+	if (persistent == FALSE) {
+		DBG_INF_FMT("after : %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}
+
+	if (MYSQLND_G(collect_memory_statistics)) {
 		enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_MALLOC_COUNT:STAT_MEM_EMALLOC_COUNT;
-		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_MALLOC_AMOUNT:STAT_MEM_EMALLOC_AMOUNT;
+		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_MALLOC_AMMOUNT:STAT_MEM_EMALLOC_AMMOUNT;
+
+		*(size_t *) ret = size;
+
 		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size);
 	}

-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -711,20 +713,18 @@
 void * _mysqlnd_ecalloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_ecalloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));

-	ret = ecalloc(nmemb, REAL_SIZE(size));
+	ret = ecalloc(nmemb, size);

 	DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
 	DBG_INF_FMT("size=%lu ptr=%p", size, ret);
-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_ECALLOC_COUNT, 1, STAT_MEM_ECALLOC_AMOUNT, size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_ECALLOC_COUNT, 1, STAT_MEM_ECALLOC_AMMOUNT, size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -733,21 +733,26 @@
 void * _mysqlnd_pecalloc(unsigned int nmemb, size_t size, zend_bool persistent MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_pecalloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
+	if (persistent == FALSE) {
+		DBG_INF_FMT("before: %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}

-	ret = pecalloc(nmemb, REAL_SIZE(size), persistent);
+	ret = pecalloc(nmemb, size, persistent);
 	DBG_INF_FMT("size=%lu ptr=%p", size, ret);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
+	if (persistent == FALSE) {
+		DBG_INF_FMT("after : %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}
+
+	if (MYSQLND_G(collect_memory_statistics)) {
 		enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_CALLOC_COUNT:STAT_MEM_ECALLOC_COUNT;
-		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_CALLOC_AMOUNT:STAT_MEM_ECALLOC_AMOUNT;
+		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_CALLOC_AMMOUNT:STAT_MEM_ECALLOC_AMMOUNT;
 		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, size);
 	}

-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -756,20 +761,19 @@
 void * _mysqlnd_erealloc(void *ptr, size_t new_size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
-	size_t old_size = collect_memory_statistics && ptr? *(size_t *) (ptr - sizeof(size_t)) : 0;
 	DBG_ENTER(mysqlnd_erealloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
-	DBG_INF_FMT("ptr=%p old_size=%lu, new_size=%lu", ptr, old_size, new_size);
+	DBG_INF_FMT("ptr=%p new_size=%lu", ptr, new_size);
+	DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));

-	ret = erealloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+	ret = erealloc(ptr, new_size);

+	DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
 	DBG_INF_FMT("new_ptr=%p", ret);
-	if (collect_memory_statistics) {
-		*(size_t *) ret = new_size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EREALLOC_COUNT, 1, STAT_MEM_EREALLOC_AMOUNT, new_size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EREALLOC_COUNT, 1, STAT_MEM_EREALLOC_AMMOUNT, new_size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -778,23 +782,27 @@
 void * _mysqlnd_perealloc(void *ptr, size_t new_size, zend_bool persistent MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
-	size_t old_size = collect_memory_statistics && ptr? *(size_t *) (ptr - sizeof(size_t)) : 0;
 	DBG_ENTER(mysqlnd_perealloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
-	DBG_INF_FMT("ptr=%p old_size=%lu new_size=%lu persist=%d", ptr, old_size, new_size, persistent);
+	DBG_INF_FMT("ptr=%p new_size=%lu persist=%d", ptr, new_size, persistent);
+	if (persistent == FALSE) {
+		DBG_INF_FMT("before: %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}

-	ret = perealloc(REAL_PTR(ptr), REAL_SIZE(new_size), persistent);
+	ret = perealloc(ptr, new_size, persistent);

 	DBG_INF_FMT("new_ptr=%p", ret);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = new_size;
+	if (persistent == FALSE) {
+		DBG_INF_FMT("after : %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}
+	MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_REALLOC_COUNT:STAT_MEM_EREALLOC_COUNT);
+	if (MYSQLND_G(collect_memory_statistics)) {
 		enum mysqlnd_collected_stats s1 = persistent? STAT_MEM_REALLOC_COUNT:STAT_MEM_EREALLOC_COUNT;
-		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_REALLOC_AMOUNT:STAT_MEM_EREALLOC_AMOUNT;
+		enum mysqlnd_collected_stats s2 = persistent? STAT_MEM_REALLOC_AMMOUNT:STAT_MEM_EREALLOC_AMMOUNT;
 		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(s1, 1, s2, new_size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -802,23 +810,15 @@
 /* {{{ _mysqlnd_efree */
 void _mysqlnd_efree(void *ptr MYSQLND_MEM_D)
 {
-	size_t free_amount = 0;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_efree_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("ptr=%p", ptr);
+	DBG_INF_FMT("before: %lu", zend_memory_usage(FALSE TSRMLS_CC));
+	MYSQLND_INC_GLOBAL_STATISTIC(STAT_MEM_EFREE_COUNT);

-	if (ptr) {
-		if (collect_memory_statistics) {
-			free_amount = *(size_t *)(ptr - sizeof(size_t));
-			DBG_INF_FMT("ptr=%p size=%u", ptr - sizeof(size_t), (unsigned int) free_amount);
-		}
-		efree(REAL_PTR(ptr));
-	}
+	efree(ptr);

-	if (collect_memory_statistics) {
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_EFREE_COUNT, 1, STAT_MEM_EFREE_AMOUNT, free_amount);
-	}
+	DBG_INF_FMT("after : %lu", zend_memory_usage(FALSE TSRMLS_CC));
 	DBG_VOID_RETURN;
 }
 /* }}} */
@@ -827,24 +827,23 @@
 /* {{{ _mysqlnd_pefree */
 void _mysqlnd_pefree(void *ptr, zend_bool persistent MYSQLND_MEM_D)
 {
-	size_t free_amount = 0;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_pefree_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("ptr=%p persistent=%d", ptr, persistent);
+	if (persistent == FALSE) {
+		DBG_INF_FMT("before: %lu", zend_memory_usage(persistent TSRMLS_CC));
+	}

 	if (ptr) {
-		if (collect_memory_statistics) {
-			free_amount = *(size_t *)(ptr - sizeof(size_t));
-			DBG_INF_FMT("ptr=%p size=%u", ptr - sizeof(size_t), (unsigned int) free_amount);
-		}
-		pefree(REAL_PTR(ptr), persistent);
+		pefree(ptr, persistent);
 	}

-	if (collect_memory_statistics) {
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(persistent? STAT_MEM_FREE_COUNT:STAT_MEM_EFREE_COUNT, 1,
-											  persistent? STAT_MEM_FREE_AMOUNT:STAT_MEM_EFREE_AMOUNT, free_amount);
+	if (persistent == FALSE) {
+		DBG_INF_FMT("after : %lu", zend_memory_usage(persistent TSRMLS_CC));
 	}
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_FREE_COUNT:STAT_MEM_EFREE_COUNT);
+	}
 	DBG_VOID_RETURN;
 }

@@ -853,18 +852,16 @@
 void * _mysqlnd_malloc(size_t size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_malloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);

-	ret = malloc(REAL_SIZE(size));
+	ret = malloc(size);

 	DBG_INF_FMT("size=%lu ptr=%p", size, ret);
-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_MALLOC_COUNT, 1, STAT_MEM_MALLOC_AMOUNT, size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_MALLOC_COUNT, 1, STAT_MEM_MALLOC_AMMOUNT, size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -873,18 +870,16 @@
 void * _mysqlnd_calloc(unsigned int nmemb, size_t size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_calloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);

-	ret = calloc(nmemb, REAL_SIZE(size));
+	ret = calloc(nmemb, size);

 	DBG_INF_FMT("size=%lu ptr=%p", size, ret);
-	if (collect_memory_statistics) {
-		*(size_t *) ret = size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_CALLOC_COUNT, 1, STAT_MEM_CALLOC_AMOUNT, size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_CALLOC_COUNT, 1, STAT_MEM_CALLOC_AMMOUNT, size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -893,21 +888,19 @@
 void * _mysqlnd_realloc(void *ptr, size_t new_size MYSQLND_MEM_D)
 {
 	void *ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_realloc_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("ptr=%p new_size=%lu ", new_size, ptr);
 	DBG_INF_FMT("before: %lu", zend_memory_usage(TRUE TSRMLS_CC));

-	ret = realloc(REAL_PTR(ptr), REAL_SIZE(new_size));
+	ret = realloc(ptr, new_size);

 	DBG_INF_FMT("new_ptr=%p", ret);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = new_size;
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_REALLOC_COUNT, 1, STAT_MEM_REALLOC_AMOUNT, new_size);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_REALLOC_COUNT, 1, STAT_MEM_REALLOC_AMMOUNT, new_size);
 	}
-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -915,58 +908,35 @@
 /* {{{ _mysqlnd_free */
 void _mysqlnd_free(void *ptr MYSQLND_MEM_D)
 {
-	size_t free_amount = 0;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_free_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("ptr=%p", ptr);

-	if (ptr) {
-		if (collect_memory_statistics) {
-			free_amount = *(size_t *)(ptr - sizeof(size_t));
-			DBG_INF_FMT("ptr=%p size=%u", ptr - sizeof(size_t), (unsigned int) free_amount);
-		}
-		free(REAL_PTR(ptr));
-	}
+	free(ptr);

-	if (collect_memory_statistics) {
-		MYSQLND_INC_GLOBAL_STATISTIC_W_VALUE2(STAT_MEM_FREE_COUNT, 1, STAT_MEM_FREE_AMOUNT, free_amount);
+	if (MYSQLND_G(collect_memory_statistics)) {
+		MYSQLND_INC_GLOBAL_STATISTIC(STAT_MEM_FREE_COUNT);
 	}
 	DBG_VOID_RETURN;
 }
 /* }}} */

-#define SMART_STR_START_SIZE 2048
-#define SMART_STR_PREALLOC 512
-#include "ext/standard/php_smart_str.h"

-
 /* {{{ _mysqlnd_pestrndup */
 char * _mysqlnd_pestrndup(const char * const ptr, size_t length, zend_bool persistent MYSQLND_MEM_D)
 {
 	char * ret;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_pestrndup_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
 	DBG_INF_FMT("ptr=%p", ptr);

-	ret = pemalloc(REAL_SIZE(length) + 1, persistent);
-	{
-		size_t l = length;
-		char * p = (char *) ptr;
-		char * dest = (char *) FAKE_PTR(ret);
-		while (*p && l--) {
-			*dest++ = *p++;
-		}
-		*dest = '\0';
-	}
+	ret = pestrndup(ptr, length, persistent);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = length;
+	if (MYSQLND_G(collect_memory_statistics)) {
 		MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_STRNDUP_COUNT : STAT_MEM_ESTRNDUP_COUNT);
 	}

-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -975,26 +945,17 @@
 char * _mysqlnd_pestrdup(const char * const ptr, zend_bool persistent MYSQLND_MEM_D)
 {
 	char * ret;
-	smart_str tmp_str = {0, 0, 0};
-	char * p = ptr;
-	zend_bool collect_memory_statistics = MYSQLND_G(collect_memory_statistics);
 	DBG_ENTER(mysqlnd_pestrdup_name);
 	DBG_INF_FMT("file=%-15s line=%4d", strrchr(__zend_filename, PHP_DIR_SEPARATOR) + 1, __zend_lineno);
-	DBG_INF_FMT("ptr=%p", ptr);
-	do {
-		smart_str_appendc(&tmp_str, *p);
-	} while (*p++);
+	DBG_INF_FMT("ptr=%p", ptr);

-	ret = pemalloc(tmp_str.len + sizeof(size_t), persistent);
-	memcpy(FAKE_PTR(ret), tmp_str.c, tmp_str.len);
+	ret = pestrdup(ptr, persistent);

-	if (collect_memory_statistics) {
-		*(size_t *) ret = tmp_str.len;
+	if (MYSQLND_G(collect_memory_statistics)) {
 		MYSQLND_INC_GLOBAL_STATISTIC(persistent? STAT_MEM_STRDUP_COUNT : STAT_MEM_ESTRDUP_COUNT);
 	}
-	smart_str_free(&tmp_str);

-	DBG_RETURN(FAKE_PTR(ret));
+	DBG_RETURN(ret);
 }
 /* }}} */

@@ -1047,11 +1008,11 @@
 			zval copy; \
 			int use_copy; \
 			zend_make_printable_zval(*tmp, &copy, &use_copy); \
-			TRACE_APPEND_STRL(Z_STRVAL(copy), Z_STRLEN(copy)); \
-			zval_dtor(&copy); \
+	    TRACE_APPEND_STRL(Z_STRVAL(copy), Z_STRLEN(copy)); \
+	    zval_dtor(&copy); \
 		} else { \
-		TRACE_APPEND_STRL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));           \
-		} \
+	    TRACE_APPEND_STRL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));           \
+	  } \
 	}
 /* }}} */


Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_enum_n_def.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_enum_n_def.h	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_enum_n_def.h	2010-04-01 20:21:50 UTC (rev 297303)
@@ -388,21 +388,19 @@
 	STAT_STMT_CLOSE_EXPLICIT,
 	STAT_STMT_CLOSE_IMPLICIT,
 	STAT_MEM_EMALLOC_COUNT,
-	STAT_MEM_EMALLOC_AMOUNT,
+	STAT_MEM_EMALLOC_AMMOUNT,
 	STAT_MEM_ECALLOC_COUNT,
-	STAT_MEM_ECALLOC_AMOUNT,
+	STAT_MEM_ECALLOC_AMMOUNT,
 	STAT_MEM_EREALLOC_COUNT,
-	STAT_MEM_EREALLOC_AMOUNT,
+	STAT_MEM_EREALLOC_AMMOUNT,
 	STAT_MEM_EFREE_COUNT,
-	STAT_MEM_EFREE_AMOUNT,
 	STAT_MEM_MALLOC_COUNT,
-	STAT_MEM_MALLOC_AMOUNT,
+	STAT_MEM_MALLOC_AMMOUNT,
 	STAT_MEM_CALLOC_COUNT,
-	STAT_MEM_CALLOC_AMOUNT,
+	STAT_MEM_CALLOC_AMMOUNT,
 	STAT_MEM_REALLOC_COUNT,
-	STAT_MEM_REALLOC_AMOUNT,
+	STAT_MEM_REALLOC_AMMOUNT,
 	STAT_MEM_FREE_COUNT,
-	STAT_MEM_FREE_AMOUNT,
 	STAT_MEM_ESTRNDUP_COUNT,
 	STAT_MEM_STRNDUP_COUNT,
 	STAT_MEM_ESTRDUP_COUNT,

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_net.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -121,14 +121,14 @@
 		tv.tv_usec = 0;
 	}

-	DBG_INF_FMT("calling php_stream_xport_create");
 	net->stream = php_stream_xport_create(scheme, scheme_len, streams_options, streams_flags,
 										  hashed_details, (net->options.timeout_connect) ? &tv : NULL,
 										  NULL /*ctx*/, errstr, errcode);

+
 	if (*errstr || !net->stream) {
 		if (hashed_details) {
-			efree(hashed_details); /* allocated by spprintf */
+			efree(hashed_details);
 		}
 		*errcode = CR_CONNECTION_ERROR;
 		DBG_RETURN(FAIL);
@@ -231,7 +231,7 @@
 	if (net->compressed == TRUE) {
 		size_t comp_buf_size = MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE + MYSQLND_HEADER_SIZE + MIN(left, MYSQLND_MAX_PACKET_SIZE);
 		DBG_INF_FMT("compress_buf_size=%d", comp_buf_size);
-		compress_buf = mnd_emalloc(comp_buf_size);
+		compress_buf = emalloc(comp_buf_size);
 	}

 	do {
@@ -264,7 +264,7 @@
   #if WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY
 			if (res == Z_OK) {
 				size_t decompressed_size = left + MYSQLND_HEADER_SIZE;
-				zend_uchar * decompressed_data = mnd_malloc(decompressed_size);
+				zend_uchar * decompressed_data = malloc(decompressed_size);
 				int error = net->m.decode(decompressed_data, decompressed_size, compress_buf + MYSQLND_HEADER_SIZE + COMPRESSED_HEADER_SIZE, payload_size);
 				if (error == Z_OK) {
 					int i;
@@ -279,7 +279,7 @@
 				} else {
 					DBG_INF("error decompressing");
 				}
-				mnd_free(decompressed_data);
+				free(decompressed_data);
 			}
   #endif /* WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY */
 		} else
@@ -322,7 +322,7 @@

 	net->stream->chunk_size = old_chunk_size;
 	if (compress_buf) {
-		mnd_efree(compress_buf);
+		efree(compress_buf);
 	}
 	DBG_RETURN(ret);
 }
@@ -415,7 +415,7 @@
 	/* we need to decompress the data */

 	if (decompressed_size) {
-		compressed_data = mnd_emalloc(net_payload_size);
+		compressed_data = emalloc(net_payload_size);
 		if (FAIL == conn->net->m.network_read(conn, compressed_data, net_payload_size TSRMLS_CC)) {
 			ret = FAIL;
 			goto end;
@@ -435,7 +435,7 @@
 	}
 end:
 	if (compressed_data) {
-		mnd_efree(compressed_data);
+		efree(compressed_data);
 	}
 	DBG_RETURN(ret);
 }
@@ -688,7 +688,7 @@
 	net->m.free_contents = MYSQLND_METHOD(mysqlnd_net, free_contents);

 	{
-		unsigned int buf_size = MYSQLND_G(net_cmd_buffer_size); /* this is long, cast to unsigned int*/
+		unsigned int buf_size = MYSQLND_G(net_read_buffer_size); /* this is long, cast to unsigned int*/
 		net->m.set_client_option(net, MYSQLND_OPT_NET_CMD_BUFFER_SIZE, (char *) &buf_size TSRMLS_CC);
 	}
 	DBG_RETURN(net);
@@ -716,7 +716,7 @@
 			if (pers) {
 				php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE_PERSISTENT | PHP_STREAM_FREE_RSRC_DTOR);
 			} else {
-				php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
+				php_stream_free(net->stream, PHP_STREAM_FREE_CLOSE);
 			}
 			net->stream = NULL;
 		}

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_priv.h
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_priv.h	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_priv.h	2010-04-01 20:21:50 UTC (rev 297303)
@@ -93,10 +93,10 @@
 #define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
 	{\
 		if ((buf)) { \
-			mnd_pefree((buf), (persistent)); \
+			pefree((buf), (persistent)); \
 		} \
 		if ((message)) { \
-			(buf) = mnd_pestrndup((message), (len), (persistent)); \
+			(buf) = pestrndup((message), (len), (persistent)); \
 		} else { \
 			buf = NULL; \
 		} \
@@ -106,7 +106,7 @@
 #define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
 	{\
 		if ((buf)) { \
-			mnd_pefree((buf), (persistent)); \
+			pefree((buf), (persistent)); \
 			(buf) = NULL; \
 		} \
 		(buf_len) = 0; \

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -599,7 +599,7 @@
 					 not_bound, not_bound>1 ?"s":"");
 			SET_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, UNKNOWN_SQLSTATE, msg);
 			if (msg) {
-				efree(msg); /* allocated by spprintf */
+				efree(msg);
 			}
 			DBG_INF("FAIL");
 			DBG_RETURN(FAIL);
@@ -2055,7 +2055,7 @@
 {
 	MYSQLND_STMT_DATA * stmt = s->data;
 	DBG_ENTER("mysqlnd_stmt::alloc_param_bind");
-	DBG_RETURN(mnd_pecalloc(stmt->param_count, sizeof(MYSQLND_PARAM_BIND), stmt->persistent));
+	DBG_RETURN(pecalloc(stmt->param_count, sizeof(MYSQLND_PARAM_BIND), stmt->persistent));
 }
 /* }}} */

@@ -2066,7 +2066,7 @@
 {
 	MYSQLND_STMT_DATA * stmt = s->data;
 	DBG_ENTER("mysqlnd_stmt::alloc_result_bind");
-	DBG_RETURN(mnd_pecalloc(stmt->field_count, sizeof(MYSQLND_RESULT_BIND), stmt->persistent));
+	DBG_RETURN(pecalloc(stmt->field_count, sizeof(MYSQLND_RESULT_BIND), stmt->persistent));
 }
 /* }}} */


Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps_codec.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps_codec.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_ps_codec.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -270,7 +270,7 @@
 	if (!as_unicode) {
 #endif
 		ZVAL_STRINGL(zv, to, length, 1);
-		efree(to);  /* allocated by spprintf */
+		mnd_efree(to);
 #if PHP_MAJOR_VERSION >= 6
 	} else {
 		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
@@ -321,7 +321,7 @@
 	if (!as_unicode) {
 #endif
 		ZVAL_STRINGL(zv, to, length, 1);
-		efree(to); /* allocated by spprintf */
+		mnd_efree(to);
 #if PHP_MAJOR_VERSION >= 6
 	} else {
 		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
@@ -380,7 +380,7 @@
 	if (!as_unicode) {
 #endif
 		ZVAL_STRINGL(zv, to, length, 1);
-		efree(to); /* allocated by spprintf */
+		mnd_efree(to);
 #if PHP_MAJOR_VERSION >= 6
 	} else {
 		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_statistics.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_statistics.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_statistics.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -99,21 +99,19 @@
 	{ STR_W_LEN("explicit_stmt_close") },
 	{ STR_W_LEN("implicit_stmt_close") },
 	{ STR_W_LEN("mem_emalloc_count") },
-	{ STR_W_LEN("mem_emalloc_amount") },
+	{ STR_W_LEN("mem_emalloc_ammount") },
 	{ STR_W_LEN("mem_ecalloc_count") },
-	{ STR_W_LEN("mem_ecalloc_amount") },
+	{ STR_W_LEN("mem_ecalloc_ammount") },
 	{ STR_W_LEN("mem_erealloc_count") },
-	{ STR_W_LEN("mem_erealloc_amount") },
+	{ STR_W_LEN("mem_erealloc_ammount") },
 	{ STR_W_LEN("mem_efree_count") },
-	{ STR_W_LEN("mem_efree_amount") },
 	{ STR_W_LEN("mem_malloc_count") },
-	{ STR_W_LEN("mem_malloc_amount") },
+	{ STR_W_LEN("mem_malloc_ammount") },
 	{ STR_W_LEN("mem_calloc_count") },
-	{ STR_W_LEN("mem_calloc_amount") },
+	{ STR_W_LEN("mem_calloc_ammount") },
 	{ STR_W_LEN("mem_realloc_count") },
-	{ STR_W_LEN("mem_realloc_amount") },
+	{ STR_W_LEN("mem_realloc_ammount") },
 	{ STR_W_LEN("mem_free_count") },
-	{ STR_W_LEN("mem_free_amount") },
 	{ STR_W_LEN("mem_estrndup_count") },
 	{ STR_W_LEN("mem_strndup_count") },
 	{ STR_W_LEN("mem_estndup_count") },

Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c	2010-04-01 19:59:52 UTC (rev 297302)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_wireprotocol.c	2010-04-01 20:21:50 UTC (rev 297303)
@@ -542,7 +542,7 @@

 	/* There is a message */
 	if (packet->header.size > p - buf && (i = php_mysqlnd_net_field_length(&p))) {
-		packet->message = mnd_pestrndup((char *)p, MIN(i, buf_len - (p - begin)), FALSE);
+		packet->message = estrndup((char *)p, MIN(i, buf_len - (p - begin)));
 		packet->message_len = i;
 	} else {
 		packet->message = NULL;
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to