Skip to content

Commit

Permalink
Const changes
Browse files Browse the repository at this point in the history
  • Loading branch information
faizshukri committed Jan 7, 2019
1 parent 8975e4d commit d12443e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
22 changes: 11 additions & 11 deletions ext/mysqlnd/mysqlnd_result.c
Expand Up @@ -89,7 +89,7 @@ static enum_func_status
MYSQLND_METHOD(mysqlnd_result_buffered_c, initialize_result_set_rest)(MYSQLND_RES_BUFFERED * const result,
MYSQLND_RES_METADATA * const meta,
MYSQLND_STATS * stats,
zend_bool int_and_float_native)
const zend_bool int_and_float_native)
{
unsigned int i;
enum_func_status ret = PASS;
Expand Down Expand Up @@ -568,9 +568,9 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
completeness.
*/
static const size_t *
MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(MYSQLND_RES_BUFFERED * const result)
MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(const MYSQLND_RES_BUFFERED * const result)
{
const MYSQLND_RES_BUFFERED_ZVAL * set = (MYSQLND_RES_BUFFERED_ZVAL *) result;
const MYSQLND_RES_BUFFERED_ZVAL * const set = (const MYSQLND_RES_BUFFERED_ZVAL *) result;
/*
If:
- unbuffered result
Expand Down Expand Up @@ -600,9 +600,9 @@ MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(MYSQLND_RES_BUFFERED
completeness.
*/
static const size_t *
MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(MYSQLND_RES_BUFFERED * const result)
MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(const MYSQLND_RES_BUFFERED * const result)
{
const MYSQLND_RES_BUFFERED_C * set = (MYSQLND_RES_BUFFERED_C *) result;
const MYSQLND_RES_BUFFERED_C * const set = (const MYSQLND_RES_BUFFERED_C *) result;
DBG_ENTER("mysqlnd_result_buffered_c::fetch_lengths");

if (set->current_row > set->row_count || set->current_row == 0) {
Expand All @@ -617,7 +617,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(MYSQLND_RES_BUFFERED *

/* {{{ mysqlnd_result_unbuffered::fetch_lengths */
static const size_t *
MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(MYSQLND_RES_UNBUFFERED * const result)
MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(const MYSQLND_RES_UNBUFFERED * const result)
{
/* simulate output of libmysql */
return (result->last_row_data || result->eof_reached)? result->lengths : NULL;
Expand All @@ -627,7 +627,7 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(MYSQLND_RES_UNBUFFERED

/* {{{ mysqlnd_res::fetch_lengths */
static const size_t *
MYSQLND_METHOD(mysqlnd_res, fetch_lengths)(MYSQLND_RES * const result)
MYSQLND_METHOD(mysqlnd_res, fetch_lengths)(const MYSQLND_RES * const result)
{
const size_t * ret;
DBG_ENTER("mysqlnd_res::fetch_lengths");
Expand Down Expand Up @@ -939,12 +939,12 @@ MYSQLND_METHOD(mysqlnd_res, use_result)(MYSQLND_RES * const result, const zend_b

/* {{{ mysqlnd_result_buffered::fetch_row_c */
static enum_func_status
MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything)
MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * const fetched_anything)
{
enum_func_status ret = FAIL;
MYSQLND_ROW_C * row = (MYSQLND_ROW_C *) param;
const MYSQLND_RES_METADATA * const meta = result->meta;
unsigned int field_count = meta->field_count;
const unsigned int field_count = meta->field_count;
MYSQLND_CONN_DATA * const conn = result->conn;
DBG_ENTER("mysqlnd_result_buffered::fetch_row_c");

Expand Down Expand Up @@ -1032,7 +1032,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void

/* {{{ mysqlnd_result_buffered_zval::fetch_row */
static enum_func_status
MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_row)(MYSQLND_RES * result, void * param, const unsigned int flags, zend_bool * fetched_anything)
MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_row)(MYSQLND_RES * result, void * param, const unsigned int flags, zend_bool * const fetched_anything)
{
enum_func_status ret = FAIL;
zval * row = (zval *) param;
Expand Down Expand Up @@ -1802,7 +1802,7 @@ MYSQLND_METHOD(mysqlnd_res, fetch_all)(MYSQLND_RES * result, const unsigned int

/* {{{ mysqlnd_res::fetch_field_data */
static void
MYSQLND_METHOD(mysqlnd_res, fetch_field_data)(MYSQLND_RES * result, unsigned int offset, zval *return_value)
MYSQLND_METHOD(mysqlnd_res, fetch_field_data)(MYSQLND_RES * result, const unsigned int offset, zval *return_value)
{
zval row;
zval *entry;
Expand Down
14 changes: 7 additions & 7 deletions ext/mysqlnd/mysqlnd_structs.h
Expand Up @@ -639,16 +639,16 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)

/* for decoding - binary or text protocol */
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);
const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata,
const zend_bool as_int_or_float, MYSQLND_STATS * const stats);


typedef MYSQLND_RES * (*func_mysqlnd_res__use_result)(MYSQLND_RES * const result, const zend_bool ps_protocol);
typedef MYSQLND_RES * (*func_mysqlnd_res__store_result)(MYSQLND_RES * result, MYSQLND_CONN_DATA * const conn, const unsigned int flags);
typedef void (*func_mysqlnd_res__fetch_into)(MYSQLND_RES *result, const unsigned int flags, zval *return_value, enum_mysqlnd_extension ext ZEND_FILE_LINE_DC);
typedef MYSQLND_ROW_C (*func_mysqlnd_res__fetch_row_c)(MYSQLND_RES *result);
typedef void (*func_mysqlnd_res__fetch_all)(MYSQLND_RES *result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC);
typedef void (*func_mysqlnd_res__fetch_field_data)(MYSQLND_RES *result, unsigned int offset, zval *return_value);
typedef void (*func_mysqlnd_res__fetch_field_data)(MYSQLND_RES *result, const unsigned int offset, zval *return_value);
typedef uint64_t (*func_mysqlnd_res__num_rows)(const MYSQLND_RES * const result);
typedef unsigned int (*func_mysqlnd_res__num_fields)(const MYSQLND_RES * const result);
typedef enum_func_status (*func_mysqlnd_res__skip_result)(MYSQLND_RES * const result);
Expand All @@ -660,7 +660,7 @@ typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_field_direct)(MYSQLND_RES
typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_fields)(MYSQLND_RES * const result);

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 const size_t * (*func_mysqlnd_res__fetch_lengths)(const 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_ROW_BUFFER ** row_buffers, zend_bool binary_protocol);

typedef void (*func_mysqlnd_res__free_result_buffers)(MYSQLND_RES * result); /* private */
Expand Down Expand Up @@ -711,7 +711,7 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)


typedef uint64_t (*func_mysqlnd_result_unbuffered__num_rows)(const MYSQLND_RES_UNBUFFERED * const result);
typedef const size_t * (*func_mysqlnd_result_unbuffered__fetch_lengths)(MYSQLND_RES_UNBUFFERED * const result);
typedef const size_t * (*func_mysqlnd_result_unbuffered__fetch_lengths)(const MYSQLND_RES_UNBUFFERED * const result);
typedef void (*func_mysqlnd_result_unbuffered__free_last_data)(MYSQLND_RES_UNBUFFERED * result, MYSQLND_STATS * const global_stats);
typedef void (*func_mysqlnd_result_unbuffered__free_result)(MYSQLND_RES_UNBUFFERED * const result, MYSQLND_STATS * const global_stats);

Expand All @@ -727,8 +727,8 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered)

typedef uint64_t (*func_mysqlnd_result_buffered__num_rows)(const MYSQLND_RES_BUFFERED * const result);
typedef enum_func_status (*func_mysqlnd_result_buffered__initialize_result_set_rest)(MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta,
MYSQLND_STATS * stats, zend_bool int_and_float_native);
typedef const size_t * (*func_mysqlnd_result_buffered__fetch_lengths)(MYSQLND_RES_BUFFERED * const result);
MYSQLND_STATS * stats, const zend_bool int_and_float_native);
typedef const size_t * (*func_mysqlnd_result_buffered__fetch_lengths)(const MYSQLND_RES_BUFFERED * const result);
typedef enum_func_status (*func_mysqlnd_result_buffered__data_seek)(MYSQLND_RES_BUFFERED * const result, const uint64_t row);
typedef void (*func_mysqlnd_result_buffered__free_result)(MYSQLND_RES_BUFFERED * const result);

Expand Down
58 changes: 34 additions & 24 deletions ext/mysqlnd/mysqlnd_wireprotocol.c
Expand Up @@ -287,7 +287,8 @@ mysqlnd_read_packet_header_and_body(MYSQLND_PACKET_HEADER * packet_header,
MYSQLND_STATS * stats,
MYSQLND_ERROR_INFO * error_info,
MYSQLND_CONNECTION_STATE * connection_state,
zend_uchar * buf, size_t buf_size, const char * const packet_type_as_text,
zend_uchar * const buf, const size_t buf_size,
const char * const packet_type_as_text,
enum mysqlnd_packet_type packet_type)
{
DBG_ENTER("mysqlnd_read_packet_header_and_body");
Expand Down Expand Up @@ -621,7 +622,11 @@ size_t php_mysqlnd_auth_write(MYSQLND_CONN_DATA * conn, void * _packet)
ret = conn->command->change_user(conn, payload, silent);
DBG_RETURN(ret == PASS? (p - buffer - MYSQLND_HEADER_SIZE) : 0);
} else {
size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info);
/*
The auth handshake packet has no command in it. Thus we can't go over conn->command directly.
Well, we can have a command->no_command(conn, payload)
*/
const size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info);
if (!sent) {
SET_CONNECTION_STATE(connection_state, CONN_QUIT_SENT);
}
Expand Down Expand Up @@ -766,7 +771,7 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
zend_uchar * buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
zend_uchar * const buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len);
zend_uchar * p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */

DBG_ENTER("php_mysqlnd_change_auth_response_write");
Expand All @@ -777,7 +782,11 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet)
}

{
size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info);
/*
The auth handshake packet has no command in it. Thus we can't go over conn->command directly.
Well, we can have a command->no_command(conn, payload)
*/
const size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info);
if (buffer != pfc->cmd_buffer.buffer) {
mnd_efree(buffer);
}
Expand All @@ -803,8 +812,8 @@ php_mysqlnd_ok_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
zend_uchar local_buf[OK_BUFFER_SIZE];
size_t buf_len = pfc->cmd_buffer.buffer? pfc->cmd_buffer.length : OK_BUFFER_SIZE;
zend_uchar * buf = pfc->cmd_buffer.buffer? (zend_uchar *) pfc->cmd_buffer.buffer : local_buf;
const size_t buf_len = pfc->cmd_buffer.buffer? pfc->cmd_buffer.length : OK_BUFFER_SIZE;
zend_uchar * const buf = pfc->cmd_buffer.buffer? (zend_uchar *) pfc->cmd_buffer.buffer : local_buf;
const zend_uchar * p = buf;
const zend_uchar * const begin = buf;
zend_ulong net_len;
Expand Down Expand Up @@ -897,8 +906,8 @@ php_mysqlnd_eof_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
size_t buf_len = pfc->cmd_buffer.length;
zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const size_t buf_len = pfc->cmd_buffer.length;
zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const zend_uchar * p = buf;
const zend_uchar * const begin = buf;

Expand Down Expand Up @@ -965,7 +974,7 @@ size_t php_mysqlnd_cmd_write(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
unsigned int error_reporting = EG(error_reporting);
const unsigned int error_reporting = EG(error_reporting);
size_t sent = 0;

DBG_ENTER("php_mysqlnd_cmd_write");
Expand Down Expand Up @@ -1034,8 +1043,8 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
enum_func_status ret = PASS;
size_t buf_len = pfc->cmd_buffer.length;
zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const size_t buf_len = pfc->cmd_buffer.length;
zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const zend_uchar * p = buf;
const zend_uchar * const begin = buf;
size_t len;
Expand Down Expand Up @@ -1175,8 +1184,9 @@ php_mysqlnd_rset_field_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
size_t buf_len = pfc->cmd_buffer.length, total_len = 0;
zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const size_t buf_len = pfc->cmd_buffer.length;
size_t total_len = 0;
zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer;
const zend_uchar * p = buf;
const zend_uchar * const begin = buf;
char *root_ptr;
Expand Down Expand Up @@ -1353,7 +1363,7 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
MYSQLND_ERROR_INFO * error_info,
MYSQLND_MEMORY_POOL * pool,
MYSQLND_ROW_BUFFER * buffer,
size_t * data_size)
size_t * const data_size)
{
enum_func_status ret = PASS;
MYSQLND_PACKET_HEADER header;
Expand Down Expand Up @@ -1433,8 +1443,8 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,
/* {{{ php_mysqlnd_rowp_read_binary_protocol */
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)
const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata,
const zend_bool as_int_or_float, MYSQLND_STATS * const stats)
{
unsigned int i;
const zend_uchar * p = row_buffer->ptr;
Expand Down Expand Up @@ -1530,7 +1540,7 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval *
unsigned int i;
zval *current_field, *end_field, *start_field;
zend_uchar * p = row_buffer->ptr;
size_t data_size = row_buffer->size;
const 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");
Expand Down Expand Up @@ -1677,8 +1687,8 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval *
/* {{{ php_mysqlnd_rowp_read_text_protocol_zval */
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)
const unsigned int field_count, const MYSQLND_FIELD * fields_metadata,
const zend_bool as_int_or_float, MYSQLND_STATS * stats)
{
enum_func_status ret;
DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_zval");
Expand All @@ -1691,8 +1701,8 @@ php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_ROW_BUFFER * row_buffer, zval *
/* {{{ php_mysqlnd_rowp_read_text_protocol_c */
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)
const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata,
const zend_bool as_int_or_float, MYSQLND_STATS * const stats)
{
enum_func_status ret;
DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_c");
Expand Down Expand Up @@ -1836,7 +1846,7 @@ php_mysqlnd_stats_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
size_t buf_len = pfc->cmd_buffer.length;
const size_t buf_len = pfc->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer;

DBG_ENTER("php_mysqlnd_stats_read");
Expand Down Expand Up @@ -1883,7 +1893,7 @@ php_mysqlnd_prepare_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
/* In case of an error, we should have place to put it */
size_t buf_len = pfc->cmd_buffer.length;
const size_t buf_len = pfc->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer;
zend_uchar *p = buf;
const zend_uchar * const begin = buf;
Expand Down Expand Up @@ -1966,7 +1976,7 @@ php_mysqlnd_chg_user_read(MYSQLND_CONN_DATA * conn, void * _packet)
MYSQLND_STATS * stats = conn->stats;
MYSQLND_CONNECTION_STATE * connection_state = &conn->state;
/* There could be an error message */
size_t buf_len = pfc->cmd_buffer.length;
const size_t buf_len = pfc->cmd_buffer.length;
zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer;
zend_uchar *p = buf;
const zend_uchar * const begin = buf;
Expand Down

0 comments on commit d12443e

Please sign in to comment.