Skip to content

Commit d902b3a

Browse files
Replace macro with inline function (#7365)
1 parent 6db4b97 commit d902b3a

File tree

5 files changed

+16
-31
lines changed

5 files changed

+16
-31
lines changed

ext/mysqlnd/mysqlnd_alloc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ static inline MYSQLND_CSTRING mnd_str2c(const MYSQLND_STRING str)
7171
return ret;
7272
}
7373

74+
static inline void mysqlnd_set_string(MYSQLND_STRING *buf, const char *string, size_t len) {
75+
if (buf->s) {
76+
mnd_efree(buf->s);
77+
buf->s = NULL;
78+
buf->l = 0;
79+
}
80+
if (string) {
81+
buf->s = mnd_pestrndup(string, len, 0);
82+
buf->l = len;
83+
}
84+
}
85+
7486
#endif /* MYSQLND_ALLOC_H */

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
353353
goto end;
354354
}
355355

356-
SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l, auth_resp_packet.message, auth_resp_packet.message_len);
356+
mysqlnd_set_string(&conn->last_message, auth_resp_packet.message, auth_resp_packet.message_len);
357357
ret = PASS;
358358
end:
359359
PACKET_FREE(&auth_resp_packet);

ext/mysqlnd/mysqlnd_connection.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@ void mysqlnd_upsert_status_init(MYSQLND_UPSERT_STATUS * const upsert_status);
4040
#define UPSERT_STATUS_GET_LAST_INSERT_ID(status) (status)->last_insert_id
4141
#define UPSERT_STATUS_SET_LAST_INSERT_ID(status, id) (status)->last_insert_id = (id)
4242

43-
44-
/* Error handling */
45-
#define SET_NEW_MESSAGE(buf, buf_len, message, len) \
46-
{\
47-
if ((buf)) { \
48-
mnd_efree((buf)); \
49-
} \
50-
if ((message)) { \
51-
(buf) = mnd_pestrndup((message), (len), 0); \
52-
} else { \
53-
(buf) = NULL; \
54-
} \
55-
(buf_len) = (len); \
56-
}
57-
58-
#define SET_EMPTY_MESSAGE(buf, buf_len) \
59-
{\
60-
if ((buf)) { \
61-
mnd_efree((buf)); \
62-
(buf) = NULL; \
63-
} \
64-
(buf_len) = 0; \
65-
}
66-
67-
6843
PHPAPI void mysqlnd_error_info_init(MYSQLND_ERROR_INFO * const info, const bool persistent);
6944
PHPAPI void mysqlnd_error_info_free_contents(MYSQLND_ERROR_INFO * const info);
7045

ext/mysqlnd/mysqlnd_result.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s)
236236
UPSERT_STATUS_SET_SERVER_STATUS(conn->upsert_status, rset_header.server_status);
237237
UPSERT_STATUS_SET_AFFECTED_ROWS(conn->upsert_status, rset_header.affected_rows);
238238
UPSERT_STATUS_SET_LAST_INSERT_ID(conn->upsert_status, rset_header.last_insert_id);
239-
SET_NEW_MESSAGE(conn->last_message.s, conn->last_message.l,
240-
rset_header.info_or_local_file.s, rset_header.info_or_local_file.l);
239+
mysqlnd_set_string(&conn->last_message, rset_header.info_or_local_file.s, rset_header.info_or_local_file.l);
241240
/* Result set can follow UPSERT statement, check server_status */
242241
if (UPSERT_STATUS_GET_SERVER_STATUS(conn->upsert_status) & SERVER_MORE_RESULTS_EXISTS) {
243242
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)
252251
enum_mysqlnd_collected_stats statistic = STAT_LAST;
253252

254253
DBG_INF("Result set pending");
255-
SET_EMPTY_MESSAGE(conn->last_message.s, conn->last_message.l);
254+
mysqlnd_set_string(&conn->last_message, NULL, 0);
256255

257256
MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_RSET_QUERY);
258257
UPSERT_STATUS_RESET(conn->upsert_status);

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,8 +2505,7 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_OK)(
25052505
upsert_status->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
25062506
UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(upsert_status);
25072507
} else {
2508-
SET_NEW_MESSAGE(last_message->s, last_message->l,
2509-
ok_response.message, ok_response.message_len);
2508+
mysqlnd_set_string(last_message, ok_response.message, ok_response.message_len);
25102509
if (!ignore_upsert_status) {
25112510
UPSERT_STATUS_RESET(upsert_status);
25122511
UPSERT_STATUS_SET_WARNINGS(upsert_status, ok_response.warning_count);

0 commit comments

Comments
 (0)