mirror of
https://github.com/php/php-src.git
synced 2026-04-27 10:16:41 +02:00
Cleanup. Make difference between MYSQLND_ROW_BUFFER and MYSQLND_MEMORY_POOL_CHUNK (the last one is completely removed).
This commit is contained in:
@@ -78,16 +78,17 @@ static zend_always_inline void* mysqlnd_arena_alloc(zend_arena **arena_ptr, size
|
||||
|
||||
/* {{{ mysqlnd_mempool_free_chunk */
|
||||
static void
|
||||
mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk)
|
||||
mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL * pool, void * ptr)
|
||||
{
|
||||
DBG_ENTER("mysqlnd_mempool_free_chunk");
|
||||
/* Try to back-off and guess if this is the last block allocated */
|
||||
if ((char*)chunk == (char*)pool->arena->ptr - ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_MEMORY_POOL_CHUNK) + chunk->size)) {
|
||||
if (ptr == pool->last) {
|
||||
/*
|
||||
This was the last allocation. Lucky us, we can free
|
||||
a bit of memory from the pool. Next time we will return from the same ptr.
|
||||
*/
|
||||
pool->arena->ptr = (char*)chunk;
|
||||
pool->arena->ptr = (char*)ptr;
|
||||
pool->last = NULL;
|
||||
}
|
||||
DBG_VOID_RETURN;
|
||||
}
|
||||
@@ -95,41 +96,40 @@ mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK
|
||||
|
||||
|
||||
/* {{{ mysqlnd_mempool_resize_chunk */
|
||||
static MYSQLND_MEMORY_POOL_CHUNK *
|
||||
mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int size)
|
||||
static void *
|
||||
mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL * pool, void * ptr, size_t old_size, size_t size)
|
||||
{
|
||||
DBG_ENTER("mysqlnd_mempool_resize_chunk");
|
||||
|
||||
/* Try to back-off and guess if this is the last block allocated */
|
||||
if (((char*)chunk == (char*)pool->arena->ptr - ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_MEMORY_POOL_CHUNK) + chunk->size))
|
||||
&& (ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_MEMORY_POOL_CHUNK) + size) <= ((char*)pool->arena->end - (char*)chunk))) {
|
||||
if (ptr == pool->last
|
||||
&& (ZEND_MM_ALIGNED_SIZE(size) <= ((char*)pool->arena->end - (char*)ptr))) {
|
||||
/*
|
||||
This was the last allocation. Lucky us, we can free
|
||||
a bit of memory from the pool. Next time we will return from the same ptr.
|
||||
*/
|
||||
pool->arena->ptr = (char*)chunk + ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_MEMORY_POOL_CHUNK) + size);
|
||||
pool->arena->ptr = (char*)ptr + ZEND_MM_ALIGNED_SIZE(size);
|
||||
} else {
|
||||
MYSQLND_MEMORY_POOL_CHUNK *new_chunk = mysqlnd_arena_alloc(&pool->arena, sizeof(MYSQLND_MEMORY_POOL_CHUNK) + size);
|
||||
memcpy(new_chunk, chunk, sizeof(MYSQLND_MEMORY_POOL_CHUNK) + MIN(size, chunk->size));
|
||||
chunk = new_chunk;
|
||||
void *new_ptr = mysqlnd_arena_alloc(&pool->arena, size);
|
||||
memcpy(new_ptr, ptr, MIN(old_size, size));
|
||||
pool->last = ptr = new_ptr;
|
||||
}
|
||||
chunk->size = size;
|
||||
DBG_RETURN(chunk);
|
||||
DBG_RETURN(ptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ mysqlnd_mempool_get_chunk */
|
||||
static MYSQLND_MEMORY_POOL_CHUNK *
|
||||
mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool, unsigned int size)
|
||||
static void *
|
||||
mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool, size_t size)
|
||||
{
|
||||
MYSQLND_MEMORY_POOL_CHUNK *chunk = NULL;
|
||||
void *ptr = NULL;
|
||||
DBG_ENTER("mysqlnd_mempool_get_chunk");
|
||||
|
||||
chunk = mysqlnd_arena_alloc(&pool->arena, sizeof(MYSQLND_MEMORY_POOL_CHUNK) + size);
|
||||
chunk->size = size;
|
||||
ptr = mysqlnd_arena_alloc(&pool->arena, size);
|
||||
pool->last = ptr;
|
||||
|
||||
DBG_RETURN(chunk);
|
||||
DBG_RETURN(ptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
+12
-12
@@ -758,7 +758,7 @@ mysqlnd_stmt_fetch_row_buffered(MYSQLND_RES * result, void * param, const unsign
|
||||
|
||||
if (Z_ISUNDEF(current_row[0])) {
|
||||
uint64_t row_num = (set->data_cursor - set->data) / field_count;
|
||||
enum_func_status rc = result->stored_data->m.row_decoder(result->stored_data->row_buffers[row_num],
|
||||
enum_func_status rc = result->stored_data->m.row_decoder(&result->stored_data->row_buffers[row_num],
|
||||
current_row,
|
||||
meta->field_count,
|
||||
meta->fields,
|
||||
@@ -878,9 +878,9 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
|
||||
result->unbuf->last_row_data = row_packet->fields;
|
||||
result->unbuf->last_row_buffer = row_packet->row_buffer;
|
||||
row_packet->fields = NULL;
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
|
||||
if (PASS != result->unbuf->m.row_decoder(result->unbuf->last_row_buffer,
|
||||
if (PASS != result->unbuf->m.row_decoder(&result->unbuf->last_row_buffer,
|
||||
result->unbuf->last_row_data,
|
||||
row_packet->field_count,
|
||||
row_packet->fields_metadata,
|
||||
@@ -925,8 +925,8 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi
|
||||
report leaks.
|
||||
*/
|
||||
row_packet->result_set_memory_pool->free_chunk(
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer);
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer.ptr);
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
}
|
||||
|
||||
result->unbuf->row_count++;
|
||||
@@ -1062,9 +1062,9 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, const unsigned
|
||||
result->unbuf->last_row_data = row_packet->fields;
|
||||
result->unbuf->last_row_buffer = row_packet->row_buffer;
|
||||
row_packet->fields = NULL;
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
|
||||
if (PASS != result->unbuf->m.row_decoder(result->unbuf->last_row_buffer,
|
||||
if (PASS != result->unbuf->m.row_decoder(&result->unbuf->last_row_buffer,
|
||||
result->unbuf->last_row_data,
|
||||
row_packet->field_count,
|
||||
row_packet->fields_metadata,
|
||||
@@ -1114,15 +1114,15 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, const unsigned
|
||||
report leaks.
|
||||
*/
|
||||
row_packet->result_set_memory_pool->free_chunk(
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer);
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer.ptr);
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
}
|
||||
/* We asked for one row, the next one should be EOF, eat it */
|
||||
ret = PACKET_READ(conn, row_packet);
|
||||
if (row_packet->row_buffer) {
|
||||
if (row_packet->row_buffer.ptr) {
|
||||
row_packet->result_set_memory_pool->free_chunk(
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer);
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->result_set_memory_pool, row_packet->row_buffer.ptr);
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
}
|
||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_ROWS_FETCHED_FROM_CLIENT_PS_CURSOR);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_zval, initialize_result_set_rest)(MYSQLND
|
||||
if (Z_ISUNDEF(data_cursor[0])) {
|
||||
unsigned int i;
|
||||
const size_t current_row_num = (data_cursor - data_begin) / field_count;
|
||||
enum_func_status rc = result->m.row_decoder(result->row_buffers[current_row_num],
|
||||
enum_func_status rc = result->m.row_decoder(&result->row_buffers[current_row_num],
|
||||
data_cursor,
|
||||
field_count,
|
||||
meta->fields,
|
||||
@@ -112,7 +112,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, initialize_result_set_rest)(MYSQLND_RE
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = result->m.row_decoder(result->row_buffers[i], current_row, field_count, meta->fields, int_and_float_native, stats);
|
||||
rc = result->m.row_decoder(&result->row_buffers[i], current_row, field_count, meta->fields, int_and_float_native, stats);
|
||||
|
||||
if (rc != PASS) {
|
||||
ret = FAIL;
|
||||
@@ -163,12 +163,12 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, free_last_data)(MYSQLND_RES_UNBUFFERED
|
||||
mnd_efree(unbuf->last_row_data);
|
||||
unbuf->last_row_data = NULL;
|
||||
}
|
||||
if (unbuf->last_row_buffer) {
|
||||
if (unbuf->last_row_buffer.ptr) {
|
||||
DBG_INF("Freeing last row buffer");
|
||||
/* Nothing points to this buffer now, free it */
|
||||
unbuf->result_set_memory_pool->free_chunk(
|
||||
unbuf->result_set_memory_pool, unbuf->last_row_buffer);
|
||||
unbuf->last_row_buffer = NULL;
|
||||
unbuf->result_set_memory_pool, unbuf->last_row_buffer.ptr);
|
||||
unbuf->last_row_buffer.ptr = NULL;
|
||||
}
|
||||
|
||||
DBG_VOID_RETURN;
|
||||
@@ -680,14 +680,14 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row_c)(MYSQLND_RES * result, voi
|
||||
result->unbuf->last_row_data = row_packet->fields;
|
||||
result->unbuf->last_row_buffer = row_packet->row_buffer;
|
||||
row_packet->fields = NULL;
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
|
||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_ROWS_FETCHED_FROM_CLIENT_NORMAL_UNBUF);
|
||||
|
||||
if (!row_packet->skip_extraction) {
|
||||
unsigned int i, field_count = meta->field_count;
|
||||
|
||||
enum_func_status rc = result->unbuf->m.row_decoder(result->unbuf->last_row_buffer,
|
||||
enum_func_status rc = result->unbuf->m.row_decoder(&result->unbuf->last_row_buffer,
|
||||
result->unbuf->last_row_data,
|
||||
field_count,
|
||||
row_packet->fields_metadata,
|
||||
@@ -801,14 +801,14 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_row)(MYSQLND_RES * result, void
|
||||
result->unbuf->last_row_data = row_packet->fields;
|
||||
result->unbuf->last_row_buffer = row_packet->row_buffer;
|
||||
row_packet->fields = NULL;
|
||||
row_packet->row_buffer = NULL;
|
||||
row_packet->row_buffer.ptr = NULL;
|
||||
|
||||
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_ROWS_FETCHED_FROM_CLIENT_NORMAL_UNBUF);
|
||||
|
||||
if (!row_packet->skip_extraction) {
|
||||
unsigned int i, field_count = meta->field_count;
|
||||
|
||||
enum_func_status rc = result->unbuf->m.row_decoder(result->unbuf->last_row_buffer,
|
||||
enum_func_status rc = result->unbuf->m.row_decoder(&result->unbuf->last_row_buffer,
|
||||
result->unbuf->last_row_data,
|
||||
field_count,
|
||||
row_packet->fields_metadata,
|
||||
@@ -960,7 +960,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void
|
||||
|
||||
if (Z_ISUNDEF(current_row[0])) {
|
||||
uint64_t row_num = (set->data_cursor - set->data) / field_count;
|
||||
enum_func_status rc = set->m.row_decoder(set->row_buffers[row_num],
|
||||
enum_func_status rc = set->m.row_decoder(&set->row_buffers[row_num],
|
||||
current_row,
|
||||
field_count,
|
||||
meta->fields,
|
||||
@@ -1050,7 +1050,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_row)(MYSQLND_RES * result, vo
|
||||
|
||||
if (Z_ISUNDEF(current_row[0])) {
|
||||
const size_t row_num = (set->data_cursor - set->data) / field_count;
|
||||
enum_func_status rc = set->m.row_decoder(set->row_buffers[row_num],
|
||||
enum_func_status rc = set->m.row_decoder(&set->row_buffers[row_num],
|
||||
current_row,
|
||||
field_count,
|
||||
meta->fields,
|
||||
@@ -1142,7 +1142,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_row)(MYSQLND_RES * result, void
|
||||
DBG_RETURN(FAIL);
|
||||
}
|
||||
|
||||
rc = result->stored_data->m.row_decoder(result->stored_data->row_buffers[set->current_row],
|
||||
rc = result->stored_data->m.row_decoder(&result->stored_data->row_buffers[set->current_row],
|
||||
current_row,
|
||||
field_count,
|
||||
meta->fields,
|
||||
@@ -1241,7 +1241,7 @@ MYSQLND_METHOD(mysqlnd_res, fetch_row)(MYSQLND_RES * result, void * param, const
|
||||
enum_func_status
|
||||
MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const conn, MYSQLND_RES * result,
|
||||
MYSQLND_RES_METADATA * meta,
|
||||
MYSQLND_MEMORY_POOL_CHUNK ***row_buffers,
|
||||
MYSQLND_ROW_BUFFER **row_buffers,
|
||||
zend_bool binary_protocol)
|
||||
{
|
||||
enum_func_status ret;
|
||||
@@ -1270,7 +1270,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
|
||||
|
||||
while (FAIL != (ret = PACKET_READ(conn, &row_packet)) && !row_packet.eof) {
|
||||
if (!free_rows) {
|
||||
MYSQLND_MEMORY_POOL_CHUNK ** new_row_buffers;
|
||||
MYSQLND_ROW_BUFFER * new_row_buffers;
|
||||
total_allocated_rows += set->row_count;
|
||||
|
||||
if (total_allocated_rows < 1024) {
|
||||
@@ -1287,15 +1287,15 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
|
||||
}
|
||||
|
||||
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
|
||||
if (total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
|
||||
if (total_allocated_rows * sizeof(MYSQLND_ROW_BUFFER) > SIZE_MAX) {
|
||||
SET_OOM_ERROR(conn->error_info);
|
||||
ret = FAIL;
|
||||
goto free_end;
|
||||
}
|
||||
if (*row_buffers) {
|
||||
new_row_buffers = mnd_erealloc(*row_buffers, (size_t)(total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)));
|
||||
new_row_buffers = mnd_erealloc(*row_buffers, (size_t)(total_allocated_rows * sizeof(MYSQLND_ROW_BUFFER)));
|
||||
} else {
|
||||
new_row_buffers = mnd_emalloc((size_t)(total_allocated_rows * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)));
|
||||
new_row_buffers = mnd_emalloc((size_t)(total_allocated_rows * sizeof(MYSQLND_ROW_BUFFER)));
|
||||
}
|
||||
if (!new_row_buffers) {
|
||||
SET_OOM_ERROR(conn->error_info);
|
||||
@@ -1311,7 +1311,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
|
||||
|
||||
/* So row_packet's destructor function won't efree() it */
|
||||
row_packet.fields = NULL;
|
||||
row_packet.row_buffer = NULL;
|
||||
row_packet.row_buffer.ptr = NULL;
|
||||
|
||||
/*
|
||||
No need to FREE_ALLOCA as we can reuse the
|
||||
@@ -1336,12 +1336,12 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
|
||||
/* save some memory */
|
||||
if (free_rows) {
|
||||
/* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
|
||||
if (set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *) > SIZE_MAX) {
|
||||
if (set->row_count * sizeof(MYSQLND_ROW_BUFFER) > SIZE_MAX) {
|
||||
SET_OOM_ERROR(conn->error_info);
|
||||
ret = FAIL;
|
||||
goto free_end;
|
||||
}
|
||||
*row_buffers = mnd_erealloc(*row_buffers, (size_t) (set->row_count * sizeof(MYSQLND_MEMORY_POOL_CHUNK *)));
|
||||
*row_buffers = mnd_erealloc(*row_buffers, (size_t) (set->row_count * sizeof(MYSQLND_ROW_BUFFER)));
|
||||
}
|
||||
|
||||
if (UPSERT_STATUS_GET_SERVER_STATUS(conn->upsert_status) & SERVER_MORE_RESULTS_EXISTS) {
|
||||
@@ -1377,7 +1377,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result)(MYSQLND_RES * result,
|
||||
const unsigned int flags)
|
||||
{
|
||||
enum_func_status ret;
|
||||
MYSQLND_MEMORY_POOL_CHUNK ***row_buffers = NULL;
|
||||
MYSQLND_ROW_BUFFER **row_buffers = NULL;
|
||||
|
||||
DBG_ENTER("mysqlnd_res::store_result");
|
||||
|
||||
@@ -1917,10 +1917,10 @@ mysqlnd_result_unbuffered_init(const unsigned int field_count, const zend_bool p
|
||||
DBG_RETURN(NULL);
|
||||
}
|
||||
|
||||
ret = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, alloc_size));
|
||||
ret = pool->get_chunk(pool, alloc_size);
|
||||
memset(ret, 0, alloc_size);
|
||||
|
||||
ret->lengths = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, field_count * sizeof(size_t)));
|
||||
ret->lengths = pool->get_chunk(pool, field_count * sizeof(size_t));
|
||||
memset(ret->lengths, 0, field_count * sizeof(size_t));
|
||||
|
||||
ret->result_set_memory_pool = pool;
|
||||
@@ -1956,7 +1956,7 @@ mysqlnd_result_buffered_zval_init(const unsigned int field_count, const zend_boo
|
||||
DBG_RETURN(NULL);
|
||||
}
|
||||
|
||||
ret = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, alloc_size));
|
||||
ret = pool->get_chunk(pool, alloc_size);
|
||||
memset(ret, 0, alloc_size);
|
||||
|
||||
if (FAIL == mysqlnd_error_info_init(&ret->error_info, 0)) {
|
||||
@@ -1964,7 +1964,7 @@ mysqlnd_result_buffered_zval_init(const unsigned int field_count, const zend_boo
|
||||
DBG_RETURN(NULL);
|
||||
}
|
||||
|
||||
ret->lengths = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, field_count * sizeof(size_t)));
|
||||
ret->lengths = pool->get_chunk(pool, field_count * sizeof(size_t));
|
||||
memset(ret->lengths, 0, field_count * sizeof(size_t));
|
||||
|
||||
ret->result_set_memory_pool = pool;
|
||||
@@ -2003,7 +2003,7 @@ mysqlnd_result_buffered_c_init(const unsigned int field_count, const zend_bool p
|
||||
DBG_RETURN(NULL);
|
||||
}
|
||||
|
||||
ret = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, alloc_size));
|
||||
ret = pool->get_chunk(pool, alloc_size);
|
||||
memset(ret, 0, alloc_size);
|
||||
|
||||
if (FAIL == mysqlnd_error_info_init(&ret->error_info, 0)) {
|
||||
@@ -2011,7 +2011,7 @@ mysqlnd_result_buffered_c_init(const unsigned int field_count, const zend_bool p
|
||||
DBG_RETURN(NULL);
|
||||
}
|
||||
|
||||
ret->lengths = MYSQLND_MEMORY_POOL_CHUNK_PTR(pool->get_chunk(pool, field_count * sizeof(size_t)));
|
||||
ret->lengths = pool->get_chunk(pool, field_count * sizeof(size_t));
|
||||
memset(ret->lengths, 0, field_count * sizeof(size_t));
|
||||
|
||||
ret->result_set_memory_pool = pool;
|
||||
|
||||
@@ -49,29 +49,26 @@ typedef struct st_mysqlnd_const_string
|
||||
|
||||
|
||||
typedef struct st_mysqlnd_memory_pool MYSQLND_MEMORY_POOL;
|
||||
typedef struct st_mysqlnd_memory_pool_chunk MYSQLND_MEMORY_POOL_CHUNK;
|
||||
typedef struct st_mysqlnd_memory_pool_chunk_llist MYSQLND_MEMORY_POOL_CHUNK_LLIST;
|
||||
|
||||
|
||||
#define MYSQLND_MEMORY_POOL_CHUNK_LIST_SIZE 100
|
||||
|
||||
struct st_mysqlnd_memory_pool
|
||||
{
|
||||
zend_arena *arena;
|
||||
void *last;
|
||||
|
||||
MYSQLND_MEMORY_POOL_CHUNK* (*get_chunk)(MYSQLND_MEMORY_POOL * pool, unsigned int size);
|
||||
MYSQLND_MEMORY_POOL_CHUNK* (*resize_chunk)(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int size);
|
||||
void (*free_chunk)(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk);
|
||||
void* (*get_chunk)(MYSQLND_MEMORY_POOL * pool, size_t size);
|
||||
void* (*resize_chunk)(MYSQLND_MEMORY_POOL * pool, void * ptr, size_t old_size, size_t size);
|
||||
void (*free_chunk)(MYSQLND_MEMORY_POOL * pool, void * ptr);
|
||||
};
|
||||
|
||||
struct st_mysqlnd_memory_pool_chunk
|
||||
|
||||
typedef struct st_mysqlnd_row_buffer MYSQLND_ROW_BUFFER;
|
||||
|
||||
struct st_mysqlnd_row_buffer
|
||||
{
|
||||
size_t app;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#define MYSQLND_MEMORY_POOL_CHUNK_PTR(chunk) \
|
||||
((void*)((char*)(chunk) + sizeof(MYSQLND_MEMORY_POOL_CHUNK)))
|
||||
|
||||
typedef struct st_mysqlnd_cmd_buffer
|
||||
{
|
||||
@@ -585,7 +582,7 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)
|
||||
|
||||
|
||||
/* for decoding - binary or text protocol */
|
||||
typedef enum_func_status (*func_mysqlnd_res__row_decoder)(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
typedef enum_func_status (*func_mysqlnd_res__row_decoder)(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats);
|
||||
|
||||
@@ -608,7 +605,7 @@ typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_fields)(MYSQLND_RES * con
|
||||
|
||||
typedef enum_func_status (*func_mysqlnd_res__read_result_metadata)(MYSQLND_RES * result, MYSQLND_CONN_DATA * conn);
|
||||
typedef const size_t * (*func_mysqlnd_res__fetch_lengths)(MYSQLND_RES * const result);
|
||||
typedef enum_func_status (*func_mysqlnd_res__store_result_fetch_data)(MYSQLND_CONN_DATA * const conn, MYSQLND_RES * result, MYSQLND_RES_METADATA * meta, MYSQLND_MEMORY_POOL_CHUNK *** row_buffers, zend_bool binary_protocol);
|
||||
typedef enum_func_status (*func_mysqlnd_res__store_result_fetch_data)(MYSQLND_CONN_DATA * const conn, MYSQLND_RES * result, MYSQLND_RES_METADATA * meta, MYSQLND_ROW_BUFFER ** row_buffers, zend_bool binary_protocol);
|
||||
|
||||
typedef void (*func_mysqlnd_res__free_result_buffers)(MYSQLND_RES * result); /* private */
|
||||
typedef enum_func_status (*func_mysqlnd_res__free_result)(MYSQLND_RES * result, const zend_bool implicit);
|
||||
@@ -1140,7 +1137,7 @@ struct st_mysqlnd_result_metadata
|
||||
|
||||
|
||||
#define def_mysqlnd_buffered_result_parent \
|
||||
MYSQLND_MEMORY_POOL_CHUNK **row_buffers; \
|
||||
MYSQLND_ROW_BUFFER *row_buffers; \
|
||||
uint64_t row_count; \
|
||||
uint64_t initialized_rows; \
|
||||
\
|
||||
@@ -1193,7 +1190,7 @@ struct st_mysqlnd_unbuffered_result
|
||||
|
||||
/* For unbuffered (both normal and PS) */
|
||||
zval *last_row_data;
|
||||
MYSQLND_MEMORY_POOL_CHUNK *last_row_buffer;
|
||||
MYSQLND_ROW_BUFFER last_row_buffer;
|
||||
|
||||
/*
|
||||
Column lengths of current row - both buffered and unbuffered.
|
||||
|
||||
@@ -1381,7 +1381,7 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
|
||||
MYSQLND_STATS * stats,
|
||||
MYSQLND_ERROR_INFO * error_info,
|
||||
MYSQLND_MEMORY_POOL * pool,
|
||||
MYSQLND_MEMORY_POOL_CHUNK ** buffer,
|
||||
MYSQLND_ROW_BUFFER * buffer,
|
||||
size_t * data_size)
|
||||
{
|
||||
enum_func_status ret = PASS;
|
||||
@@ -1417,12 +1417,12 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
|
||||
|
||||
if (first_iteration) {
|
||||
first_iteration = FALSE;
|
||||
*buffer = pool->get_chunk(pool, *data_size + prealloc_more_bytes);
|
||||
if (!*buffer) {
|
||||
buffer->ptr = pool->get_chunk(pool, *data_size + prealloc_more_bytes);
|
||||
if (!buffer->ptr) {
|
||||
ret = FAIL;
|
||||
break;
|
||||
}
|
||||
p = MYSQLND_MEMORY_POOL_CHUNK_PTR(*buffer);
|
||||
p = buffer->ptr;
|
||||
} else if (!first_iteration) {
|
||||
/* Empty packet after MYSQLND_MAX_PACKET_SIZE packet. That's ok, break */
|
||||
if (!header.size) {
|
||||
@@ -1432,14 +1432,14 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
|
||||
/*
|
||||
We have to realloc the buffer.
|
||||
*/
|
||||
*buffer = pool->resize_chunk(pool, *buffer, *data_size + prealloc_more_bytes);
|
||||
if (!*buffer) {
|
||||
buffer->ptr = pool->resize_chunk(pool, buffer->ptr, *data_size - header.size, *data_size + prealloc_more_bytes);
|
||||
if (!buffer->ptr) {
|
||||
SET_OOM_ERROR(error_info);
|
||||
ret = FAIL;
|
||||
break;
|
||||
}
|
||||
/* The position could have changed, recalculate */
|
||||
p = (zend_uchar *) MYSQLND_MEMORY_POOL_CHUNK_PTR(*buffer) + (*data_size - header.size);
|
||||
p = (zend_uchar *) buffer->ptr + (*data_size - header.size);
|
||||
}
|
||||
|
||||
if (PASS != (ret = pfc->data->m.receive(pfc, vio, p, header.size, stats, error_info))) {
|
||||
@@ -1452,9 +1452,9 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret == FAIL && *buffer) {
|
||||
pool->free_chunk(pool, *buffer);
|
||||
*buffer = NULL;
|
||||
if (ret == FAIL && buffer->ptr) {
|
||||
pool->free_chunk(pool, buffer->ptr);
|
||||
buffer->ptr = NULL;
|
||||
}
|
||||
DBG_RETURN(ret);
|
||||
}
|
||||
@@ -1463,12 +1463,12 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
|
||||
|
||||
/* {{{ php_mysqlnd_rowp_read_binary_protocol */
|
||||
enum_func_status
|
||||
php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
php_mysqlnd_rowp_read_binary_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats)
|
||||
{
|
||||
unsigned int i;
|
||||
const zend_uchar * p = MYSQLND_MEMORY_POOL_CHUNK_PTR(row_buffer);
|
||||
const zend_uchar * p = row_buffer->ptr;
|
||||
const zend_uchar * null_ptr;
|
||||
zend_uchar bit;
|
||||
zval *current_field, *end_field, *start_field;
|
||||
@@ -1554,14 +1554,14 @@ php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zv
|
||||
|
||||
/* {{{ php_mysqlnd_rowp_read_text_protocol */
|
||||
enum_func_status
|
||||
php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats)
|
||||
{
|
||||
unsigned int i;
|
||||
zval *current_field, *end_field, *start_field;
|
||||
zend_uchar * p = MYSQLND_MEMORY_POOL_CHUNK_PTR(row_buffer);
|
||||
size_t data_size = row_buffer->app;
|
||||
zend_uchar * p = row_buffer->ptr;
|
||||
size_t data_size = row_buffer->size;
|
||||
const zend_uchar * const packet_end = (zend_uchar*) p + data_size;
|
||||
|
||||
DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_aux");
|
||||
@@ -1707,7 +1707,7 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
|
||||
|
||||
/* {{{ php_mysqlnd_rowp_read_text_protocol_zval */
|
||||
enum_func_status
|
||||
php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats)
|
||||
{
|
||||
@@ -1721,7 +1721,7 @@ php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
|
||||
|
||||
/* {{{ php_mysqlnd_rowp_read_text_protocol_c */
|
||||
enum_func_status
|
||||
php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats)
|
||||
{
|
||||
@@ -1772,9 +1772,9 @@ php_mysqlnd_rowp_read(MYSQLND_CONN_DATA * conn, void * _packet)
|
||||
to keep (and copy) the lengths externally.
|
||||
*/
|
||||
packet->header.size = data_size;
|
||||
packet->row_buffer->app = data_size;
|
||||
packet->row_buffer.size = data_size;
|
||||
|
||||
if (ERROR_MARKER == (*(p = MYSQLND_MEMORY_POOL_CHUNK_PTR(packet->row_buffer)))) {
|
||||
if (ERROR_MARKER == (*(p = packet->row_buffer.ptr))) {
|
||||
/*
|
||||
Error message as part of the result set,
|
||||
not good but we should not hang. See:
|
||||
@@ -1841,9 +1841,9 @@ php_mysqlnd_rowp_free_mem(void * _packet)
|
||||
|
||||
DBG_ENTER("php_mysqlnd_rowp_free_mem");
|
||||
p = (MYSQLND_PACKET_ROW *) _packet;
|
||||
if (p->row_buffer) {
|
||||
p->result_set_memory_pool->free_chunk(p->result_set_memory_pool, p->row_buffer);
|
||||
p->row_buffer = NULL;
|
||||
if (p->row_buffer.ptr) {
|
||||
p->result_set_memory_pool->free_chunk(p->result_set_memory_pool, p->row_buffer.ptr);
|
||||
p->row_buffer.ptr = NULL;
|
||||
}
|
||||
/*
|
||||
Don't free packet->fields :
|
||||
|
||||
@@ -217,7 +217,7 @@ typedef struct st_mysqlnd_packet_row {
|
||||
uint16_t warning_count;
|
||||
uint16_t server_status;
|
||||
|
||||
struct st_mysqlnd_memory_pool_chunk *row_buffer;
|
||||
MYSQLND_ROW_BUFFER row_buffer;
|
||||
MYSQLND_MEMORY_POOL * result_set_memory_pool;
|
||||
|
||||
zend_bool skip_extraction;
|
||||
@@ -287,16 +287,16 @@ size_t php_mysqlnd_net_store_length_size(uint64_t length);
|
||||
|
||||
PHPAPI extern const char * const mysqlnd_empty_string;
|
||||
|
||||
enum_func_status php_mysqlnd_rowp_read_binary_protocol(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
enum_func_status php_mysqlnd_rowp_read_binary_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats);
|
||||
|
||||
|
||||
enum_func_status php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
enum_func_status php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats);
|
||||
|
||||
enum_func_status php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_MEMORY_POOL_CHUNK * row_buffer, zval * fields,
|
||||
enum_func_status php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
|
||||
unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
|
||||
zend_bool as_int_or_float, MYSQLND_STATS * stats);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user