Replace macro with inline function (#7365)

This commit is contained in:
Kamil Tekiela 2021-08-13 20:03:26 +01:00 committed by GitHub
parent 6db4b972d0
commit d902b3a844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 31 deletions

View File

@ -71,4 +71,16 @@ static inline MYSQLND_CSTRING mnd_str2c(const MYSQLND_STRING str)
return ret;
}
static inline void mysqlnd_set_string(MYSQLND_STRING *buf, const char *string, size_t len) {
if (buf->s) {
mnd_efree(buf->s);
buf->s = NULL;
buf->l = 0;
}
if (string) {
buf->s = mnd_pestrndup(string, len, 0);
buf->l = len;
}
}
#endif /* MYSQLND_ALLOC_H */

View File

@ -353,7 +353,7 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
goto end;
}
SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l, auth_resp_packet.message, auth_resp_packet.message_len);
mysqlnd_set_string(&conn->last_message, auth_resp_packet.message, auth_resp_packet.message_len);
ret = PASS;
end:
PACKET_FREE(&auth_resp_packet);

View File

@ -40,31 +40,6 @@ void mysqlnd_upsert_status_init(MYSQLND_UPSERT_STATUS * const upsert_status);
#define UPSERT_STATUS_GET_LAST_INSERT_ID(status) (status)->last_insert_id
#define UPSERT_STATUS_SET_LAST_INSERT_ID(status, id) (status)->last_insert_id = (id)
/* Error handling */
#define SET_NEW_MESSAGE(buf, buf_len, message, len) \
{\
if ((buf)) { \
mnd_efree((buf)); \
} \
if ((message)) { \
(buf) = mnd_pestrndup((message), (len), 0); \
} else { \
(buf) = NULL; \
} \
(buf_len) = (len); \
}
#define SET_EMPTY_MESSAGE(buf, buf_len) \
{\
if ((buf)) { \
mnd_efree((buf)); \
(buf) = NULL; \
} \
(buf_len) = 0; \
}
PHPAPI void mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, const bool persistent);
PHPAPI void mysqlnd_error_info_free_contents(MYSQLND_ERROR_INFO * const info);

View File

@ -236,8 +236,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
UPSERT_STATUS_SET_SERVER_STATUS(conn->upsert_status, rset_header.server_status);
UPSERT_STATUS_SET_AFFECTED_ROWS(conn->upsert_status, rset_header.affected_rows);
UPSERT_STATUS_SET_LAST_INSERT_ID(conn->upsert_status, rset_header.last_insert_id);
SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l,
rset_header.info_or_local_file.s, rset_header.info_or_local_file.l);
mysqlnd_set_string(&conn->last_message, rset_header.info_or_local_file.s, rset_header.info_or_local_file.l);
/* Result set can follow UPSERT statement, check server_status */
if (UPSERT_STATUS_GET_SERVER_STATUS(conn->upsert_status) & SERVER_MORE_RESULTS_EXISTS) {
SET_CONNECTION_STATE(&conn->state, CONN_NEXT_RESULT_PENDING);
@ -252,7 +251,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
enum_mysqlnd_collected_stats statistic = STAT_LAST;
DBG_INF("Result set pending");
SET_EMPTY_MESSAGE(conn->last_message.s, conn->last_message.l);
mysqlnd_set_string(&conn->last_message, NULL, 0);
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_RSET_QUERY);
UPSERT_STATUS_RESET(conn->upsert_status);

View File

@ -2505,8 +2505,7 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_OK)(
upsert_status->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(upsert_status);
} else {
SET_NEW_MESSAGE(last_message->s, last_message->l,
ok_response.message, ok_response.message_len);
mysqlnd_set_string(last_message, ok_response.message, ok_response.message_len);
if (!ignore_upsert_status) {
UPSERT_STATUS_RESET(upsert_status);
UPSERT_STATUS_SET_WARNINGS(upsert_status, ok_response.warning_count);