Skip to content

Commit 2033c1b

Browse files
committed
some config.w32 fixes
moved mysqlnd's block allocator to a separate file and also now it's part of the connection, no MT problems.
1 parent e9914e9 commit 2033c1b

12 files changed

+271
-169
lines changed

ext/mysql/config.w32

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ if (PHP_MYSQL != "no") {
88
if (CHECK_LIB("libmysql.lib", "mysql", PHP_MYSQL) &&
99
CHECK_HEADER_ADD_INCLUDE("mysql.h", "CFLAGS_MYSQL",
1010
PHP_MYSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\mysql;" + PHP_MYSQL)) {
11+
EXTENSION("mysql", "php_mysql.c");
12+
AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
1113
} else {
1214
WARNING("mysql not enabled; libraries and headers not found");
1315
}
1416
} else {
1517
AC_DEFINE('HAVE_MYSQLND', 1, 'MySQL native driver support enabled');
1618
ADD_EXTENSION_DEP('mysql', 'mysqlnd', true);
19+
EXTENSION("mysql", "php_mysql.c");
20+
AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
1721
}
18-
EXTENSION("mysql", "php_mysql.c");
19-
AC_DEFINE('HAVE_MYSQL', 1, 'Have MySQL library');
2022
}

ext/mysqli/tests/mysqli_get_client_stats.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,9 @@ array(61) {
969969
["mem_efree_count"]=>
970970
string(1) "0"
971971
["mem_malloc_count"]=>
972-
string(1) "1"
972+
string(1) "0"
973973
["mem_malloc_ammount"]=>
974-
string(%d) "%d"
974+
string(1) "0"
975975
["mem_calloc_count"]=>
976976
string(1) "0"
977977
["mem_calloc_ammount"]=>
@@ -1106,9 +1106,9 @@ array(61) {
11061106
[u"mem_efree_count"]=>
11071107
unicode(1) "0"
11081108
[u"mem_malloc_count"]=>
1109-
unicode(1) "1"
1109+
unicode(1) "0"
11101110
[u"mem_malloc_ammount"]=>
1111-
unicode(%d) "%d"
1111+
unicode(1) "0"
11121112
[u"mem_calloc_count"]=>
11131113
unicode(1) "0"
11141114
[u"mem_calloc_ammount"]=>

ext/mysqlnd/config.w32

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// $Id$
22
// vim:ft=javascript
33

4-
ARG_WITH("mysqlnd", "MySQL-nd support", "no");
5-
6-
if (PHP_MYSQLND != "no") {
7-
mysqld_source = "";
84
if (CHECK_LIB("ws2_32.lib", "mysqlnd")) {
95
mysqlnd_source =
106
"mysqlnd.c " +
11-
"mysqlnd_debug.c " +
7+
"mysqlnd_block_alloc.c" +
128
"mysqlnd_charset.c " +
9+
"mysqlnd_debug.c " +
1310
"mysqlnd_loaddata.c " +
1411
"mysqlnd_palloc.c " +
1512
"mysqlnd_ps.c " +
@@ -21,4 +18,3 @@ if (CHECK_LIB("ws2_32.lib", "mysqlnd")) {
2118
"mysqlnd_wireprotocol.c";
2219
EXTENSION("mysqlnd", mysqlnd_source, false);
2320
}
24-
}

ext/mysqlnd/config9.m4

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ if test "$PHP_MYSQLND_ENABLED" = "yes"; then
77
mysqlnd_sources="mysqlnd.c mysqlnd_charset.c mysqlnd_wireprotocol.c \
88
mysqlnd_ps.c mysqlnd_loaddata.c mysqlnd_palloc.c \
99
mysqlnd_ps_codec.c mysqlnd_statistics.c mysqlnd_qcache.c\
10-
mysqlnd_result.c mysqlnd_result_meta.c mysqlnd_debug.c"
10+
mysqlnd_result.c mysqlnd_result_meta.c mysqlnd_debug.c\
11+
mysqlnd_block_alloc.c"
1112

1213
PHP_NEW_EXTENSION(mysqlnd, $mysqlnd_sources, no)
1314
PHP_ADD_BUILD_DIR([ext/mysqlnd], 1)

ext/mysqlnd/mysqlnd.c

+6-145
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "mysqlnd_statistics.h"
2828
#include "mysqlnd_charset.h"
2929
#include "mysqlnd_debug.h"
30+
#include "mysqlnd_block_alloc.h"
3031
#include "php_ini.h"
3132
#include "ext/standard/basic_functions.h"
3233
#include "ext/standard/php_lcg.h"
@@ -66,7 +67,6 @@ const char * mysqlnd_out_of_sync = "Commands out of sync; you can't run this com
6667
MYSQLND_STATS *mysqlnd_global_stats = NULL;
6768
static zend_bool mysqlnd_library_initted = FALSE;
6869

69-
MYSQLND_MEMORY_POOL mysqlnd_memory_pool;
7070

7171
static enum_func_status mysqlnd_send_close(MYSQLND * conn TSRMLS_DC);
7272

@@ -127,140 +127,6 @@ void * _mysqlnd_fetch_thread(void *arg)
127127
/* }}} */
128128
#endif /* MYSQLND_THREADED */
129129

130-
/************************************************************************************************/
131-
/* Let's don't use pool allocation for now */
132-
/* {{{ mysqlnd_mempool_free_chunk */
133-
static
134-
void mysqlnd_mempool_free_contents(MYSQLND_MEMORY_POOL * pool TSRMLS_DC)
135-
{
136-
DBG_ENTER("mysqlnd_mempool_dtor");
137-
uint i;
138-
for (i = 0; i < pool->free_chunk_list_elements; i++) {
139-
MYSQLND_MEMORY_POOL_CHUNK * chunk = pool->free_chunk_list[i];
140-
chunk->free_chunk(chunk, FALSE TSRMLS_CC);
141-
}
142-
143-
DBG_VOID_RETURN;
144-
}
145-
/* }}} */
146-
147-
/* Let's don't use pool allocation for now */
148-
/* {{{ mysqlnd_mempool_free_chunk */
149-
static
150-
void mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, zend_bool cache_it TSRMLS_DC)
151-
{
152-
DBG_ENTER("mysqlnd_mempool_free_chunk");
153-
MYSQLND_MEMORY_POOL * pool = chunk->pool;
154-
if (chunk->from_pool) {
155-
/* Try to back-off and guess if this is the last block allocated */
156-
if (chunk->ptr == (pool->arena + (pool->arena_size - pool->free_size - chunk->size))) {
157-
/*
158-
This was the last allocation. Lucky us, we can free
159-
a bit of memory from the pool. Next time we will return from the same ptr.
160-
*/
161-
pool->free_size += chunk->size;
162-
}
163-
pool->refcount--;
164-
} else {
165-
mnd_free(chunk->ptr);
166-
}
167-
if (cache_it && pool->free_chunk_list_elements < MYSQLND_MEMORY_POOL_CHUNK_LIST_SIZE) {
168-
chunk->ptr = NULL;
169-
pool->free_chunk_list[pool->free_chunk_list_elements++] = chunk;
170-
} else {
171-
/* We did not cache it -> free it */
172-
mnd_free(chunk);
173-
}
174-
DBG_VOID_RETURN;
175-
}
176-
/* }}} */
177-
178-
179-
/* {{{ mysqlnd_mempool_resize_chunk */
180-
static void
181-
mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, uint size TSRMLS_DC)
182-
{
183-
DBG_ENTER("mysqlnd_mempool_resize_chunk");
184-
if (chunk->from_pool) {
185-
MYSQLND_MEMORY_POOL * pool = chunk->pool;
186-
/* Try to back-off and guess if this is the last block allocated */
187-
if (chunk->ptr == (pool->arena + (pool->arena_size - pool->free_size - chunk->size))) {
188-
/*
189-
This was the last allocation. Lucky us, we can free
190-
a bit of memory from the pool. Next time we will return from the same ptr.
191-
*/
192-
if ((chunk->size + pool->free_size) < size) {
193-
zend_uchar *new_ptr;
194-
new_ptr = mnd_malloc(size);
195-
memcpy(new_ptr, chunk->ptr, chunk->size);
196-
chunk->ptr = new_ptr;
197-
pool->free_size += chunk->size;
198-
chunk->size = size;
199-
chunk->pool = NULL; /* now we have no pool memory */
200-
pool->refcount--;
201-
} else {
202-
/* If the chunk is > than asked size then free_memory increases, otherwise decreases*/
203-
pool->free_size += (chunk->size - size);
204-
}
205-
} else {
206-
/* Not last chunk, if the user asks for less, give it to him */
207-
if (chunk->size >= size) {
208-
; /* nop */
209-
} else {
210-
zend_uchar *new_ptr;
211-
new_ptr = mnd_malloc(size);
212-
memcpy(new_ptr, chunk->ptr, chunk->size);
213-
chunk->ptr = new_ptr;
214-
chunk->size = size;
215-
chunk->pool = NULL; /* now we have no pool memory */
216-
pool->refcount--;
217-
}
218-
}
219-
} else {
220-
chunk->ptr = mnd_realloc(chunk->ptr, size);
221-
}
222-
DBG_VOID_RETURN;
223-
}
224-
/* }}} */
225-
226-
227-
/* {{{ mysqlnd_mempool_get_chunk */
228-
static
229-
MYSQLND_MEMORY_POOL_CHUNK * mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool, uint size TSRMLS_DC)
230-
{
231-
MYSQLND_MEMORY_POOL_CHUNK *chunk = NULL;
232-
DBG_ENTER("mysqlnd_mempool_get_chunk");
233-
234-
if (pool->free_chunk_list_elements) {
235-
chunk = pool->free_chunk_list[--pool->free_chunk_list_elements];
236-
} else {
237-
chunk = mnd_malloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
238-
}
239-
240-
chunk->free_chunk = mysqlnd_mempool_free_chunk;
241-
chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
242-
chunk->size = size;
243-
/*
244-
Should not go over MYSQLND_MAX_PACKET_SIZE, since we
245-
expect non-arena memory in mysqlnd_wireprotocol.c . We
246-
realloc the non-arena memory.
247-
*/
248-
chunk->pool = pool;
249-
if (size > pool->free_size) {
250-
chunk->ptr = mnd_malloc(size);
251-
chunk->from_pool = FALSE;
252-
} else {
253-
chunk->from_pool = TRUE;
254-
++pool->refcount;
255-
chunk->ptr = pool->arena + (pool->arena_size - pool->free_size);
256-
/* Last step, update free_size */
257-
pool->free_size -= size;
258-
}
259-
DBG_RETURN(chunk);
260-
}
261-
/* }}} */
262-
/************************************************************************************************/
263-
264130

265131
/* {{{ mysqlnd_library_init */
266132
static
@@ -274,13 +140,6 @@ void mysqlnd_library_init(TSRMLS_D)
274140
#ifdef ZTS
275141
mysqlnd_global_stats->LOCK_access = tsrm_mutex_alloc();
276142
#endif
277-
mysqlnd_memory_pool.arena_size = 16000;
278-
mysqlnd_memory_pool.free_size = mysqlnd_memory_pool.arena_size;
279-
mysqlnd_memory_pool.refcount = 0;
280-
/* OOM ? */
281-
mysqlnd_memory_pool.arena = mnd_malloc(mysqlnd_memory_pool.arena_size);
282-
mysqlnd_memory_pool.get_chunk = mysqlnd_mempool_get_chunk;
283-
mysqlnd_memory_pool.free_contents = mysqlnd_mempool_free_contents;
284143
}
285144
}
286145
/* }}} */
@@ -291,9 +150,6 @@ static
291150
void mysqlnd_library_end(TSRMLS_D)
292151
{
293152
if (mysqlnd_library_initted == TRUE) {
294-
/* mnd_free will reference LOCK_access and won't crash...*/
295-
mysqlnd_memory_pool.free_contents(&mysqlnd_memory_pool TSRMLS_CC);
296-
free(mysqlnd_memory_pool.arena);
297153
#ifdef ZTS
298154
tsrm_mutex_free(mysqlnd_global_stats->LOCK_access);
299155
#endif
@@ -422,6 +278,10 @@ MYSQLND_METHOD(mysqlnd_conn, free_contents)(MYSQLND *conn TSRMLS_DC)
422278
mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache);
423279
conn->zval_cache = NULL;
424280
}
281+
if (conn->result_set_memory_pool) {
282+
mysqlnd_mempool_destroy(conn->result_set_memory_pool TSRMLS_CC);
283+
conn->result_set_memory_pool = NULL;
284+
}
425285
if (conn->qcache) {
426286
DBG_INF("Freeing qcache reference");
427287
mysqlnd_qcache_free_cache_reference(&conn->qcache);
@@ -971,6 +831,7 @@ PHPAPI MYSQLND *mysqlnd_connect(MYSQLND *conn,
971831
}
972832

973833
DBG_INF_FMT("connection_id=%llu", conn->thread_id);
834+
conn->result_set_memory_pool = mysqlnd_mempool_create(16000 TSRMLS_CC);
974835
#if PHP_MAJOR_VERSION >= 6
975836
{
976837
uint as_unicode = 1;

0 commit comments

Comments
 (0)