Skip to content

Commit 69f4a40

Browse files
committed
Merge with internal version
1 parent b9dcdd4 commit 69f4a40

15 files changed

+296
-115
lines changed

Diff for: ext/mysqlnd/mysqlnd.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ MYSQLND_STATS *mysqlnd_global_stats = NULL;
6767
static zend_bool mysqlnd_library_initted = FALSE;
6868

6969

70-
enum_func_status mysqlnd_send_close(MYSQLND * conn TSRMLS_DC);
70+
static enum_func_status mysqlnd_send_close(MYSQLND * conn TSRMLS_DC);
7171

7272
/* {{{ mysqlnd_library_init */
7373
static
@@ -454,11 +454,11 @@ PHPAPI void mysqlnd_end_psession(MYSQLND *conn)
454454

455455
/* {{{ mysqlnd_connect */
456456
PHPAPI MYSQLND *mysqlnd_connect(MYSQLND *conn,
457-
char *host, char *user,
458-
char *passwd, unsigned int passwd_len,
459-
char *db, unsigned int db_len,
457+
const char *host, const char *user,
458+
const char *passwd, unsigned int passwd_len,
459+
const char *db, unsigned int db_len,
460460
unsigned int port,
461-
char *socket,
461+
const char *socket,
462462
unsigned int mysql_flags,
463463
MYSQLND_THD_ZVAL_PCACHE *zval_cache
464464
TSRMLS_DC)
@@ -949,7 +949,7 @@ MYSQLND_METHOD(mysqlnd_conn, sqlstate)(const MYSQLND * const conn)
949949

950950

951951
/* {{{ mysqlnd_old_escape_string */
952-
PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, int escapestr_len TSRMLS_DC)
952+
PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC)
953953
{
954954
DBG_ENTER("mysqlnd_old_escape_string");
955955
DBG_RETURN(mysqlnd_cset_escape_slashes(mysqlnd_find_charset_name("latin1"),
@@ -961,7 +961,7 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, int
961961
/* {{{ mysqlnd_conn::escape_string */
962962
static ulong
963963
MYSQLND_METHOD(mysqlnd_conn, escape_string)(const MYSQLND * const conn, char *newstr,
964-
const char *escapestr, int escapestr_len TSRMLS_DC)
964+
const char *escapestr, size_t escapestr_len TSRMLS_DC)
965965
{
966966
DBG_ENTER("mysqlnd_conn::escape_string");
967967
DBG_INF_FMT("conn=%llu", conn->thread_id);
@@ -1088,7 +1088,7 @@ MYSQLND_METHOD(mysqlnd_conn, kill)(MYSQLND *conn, unsigned int pid TSRMLS_DC)
10881088
/* }}} */
10891089

10901090

1091-
/* {{{ _mysqlnd_conn::set_charset */
1091+
/* {{{ mysqlnd_conn::set_charset */
10921092
static enum_func_status
10931093
MYSQLND_METHOD(mysqlnd_conn, set_charset)(MYSQLND * const conn, const char * const csname TSRMLS_DC)
10941094
{
@@ -1696,8 +1696,8 @@ MYSQLND_METHOD(mysqlnd_conn, set_client_option)(MYSQLND * const conn,
16961696
/* }}} */
16971697

16981698

1699-
/* {{{ _mysqlnd_conn::use_result */
1700-
MYSQLND_RES *
1699+
/* {{{ mysqlnd_conn::use_result */
1700+
static MYSQLND_RES *
17011701
MYSQLND_METHOD(mysqlnd_conn, use_result)(MYSQLND * const conn TSRMLS_DC)
17021702
{
17031703
MYSQLND_RES *result;
@@ -1729,8 +1729,8 @@ MYSQLND_METHOD(mysqlnd_conn, use_result)(MYSQLND * const conn TSRMLS_DC)
17291729
/* }}} */
17301730

17311731

1732-
/* {{{ _mysqlnd_conn::store_result */
1733-
MYSQLND_RES *
1732+
/* {{{ mysqlnd_conn::store_result */
1733+
static MYSQLND_RES *
17341734
MYSQLND_METHOD(mysqlnd_conn, store_result)(MYSQLND * const conn TSRMLS_DC)
17351735
{
17361736
MYSQLND_RES *result;
@@ -1762,7 +1762,7 @@ MYSQLND_METHOD(mysqlnd_conn, store_result)(MYSQLND * const conn TSRMLS_DC)
17621762

17631763

17641764
/* {{{ mysqlnd_conn::get_connection_stats */
1765-
void
1765+
static void
17661766
MYSQLND_METHOD(mysqlnd_conn, get_connection_stats)(const MYSQLND * const conn,
17671767
zval *return_value
17681768
TSRMLS_DC ZEND_FILE_LINE_DC)

Diff for: ext/mysqlnd/mysqlnd.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const char
6969
#define mysqlnd_init(persistent) _mysqlnd_init((persistent) TSRMLS_CC)
7070
PHPAPI MYSQLND * _mysqlnd_init(zend_bool persistent TSRMLS_DC);
7171
PHPAPI MYSQLND * mysqlnd_connect(MYSQLND *conn,
72-
char *host, char *user,
73-
char *passwd, unsigned int passwd_len,
74-
char *db, unsigned int db_len,
72+
const char *host, const char *user,
73+
const char *passwd, unsigned int passwd_len,
74+
const char *db, unsigned int db_len,
7575
unsigned int port,
76-
char *socket,
76+
const char *socket,
7777
unsigned int mysql_flags,
7878
MYSQLND_THD_ZVAL_PCACHE *zval_cache
7979
TSRMLS_DC);
@@ -85,6 +85,7 @@ void _mysqlnd_debug(const char *mode TSRMLS_DC);
8585

8686
/* Query */
8787
#define mysqlnd_fetch_into(result, flags, ret_val, ext) (result)->m.fetch_into((result), (flags), (ret_val), (ext) TSRMLS_CC ZEND_FILE_LINE_CC)
88+
#define mysqlnd_fetch_row_c(result) (result)->m.fetch_row_c((result) TSRMLS_CC)
8889
#define mysqlnd_fetch_all(result, flags, return_value) (result)->m.fetch_all((result), (flags), (return_value) TSRMLS_CC ZEND_FILE_LINE_CC)
8990
#define mysqlnd_result_fetch_field_data(res,offset,ret) (res)->m.fetch_field_data((res), (offset), (ret) TSRMLS_CC)
9091
#define mysqlnd_get_connection_stats(conn, values) (conn)->m->get_statistics((conn), (values) TSRMLS_CC ZEND_FILE_LINE_CC)
@@ -235,7 +236,7 @@ PHPAPI void mysqlnd_set_local_infile_handler(MYSQLND * const conn, const char *
235236
#define mysqlnd_escape_string(newstr, escapestr, escapestr_len) \
236237
mysqlnd_old_escape_string((newstr), (escapestr), (escapestr_len) TSRMLS_CC)
237238

238-
PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, int escapestr_len TSRMLS_DC);
239+
PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC);
239240

240241

241242
/* PS */
@@ -247,10 +248,10 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, int
247248
#define mysqlnd_stmt_execute(stmt) (stmt)->m->execute((stmt) TSRMLS_CC)
248249
#define mysqlnd_stmt_send_long_data(s,p,d,l) (s)->m->send_long_data((s), (p), (d), (l) TSRMLS_CC)
249250
#define mysqlnd_stmt_bind_param(stmt,bind) (stmt)->m->bind_param((stmt), (bind) TSRMLS_CC)
251+
#define mysqlnd_stmt_refresh_bind_param(s) (s)->m->refresh_bind_param((s) TSRMLS_CC)
250252
#define mysqlnd_stmt_bind_result(stmt,bind) (stmt)->m->bind_result((stmt), (bind) TSRMLS_CC)
251253
#define mysqlnd_stmt_param_metadata(stmt) (stmt)->m->get_parameter_metadata((stmt))
252254
#define mysqlnd_stmt_result_metadata(stmt) (stmt)->m->get_result_metadata((stmt) TSRMLS_CC)
253-
#define mysqlnd_stmt_ronly_result_metadata(stmt) ((stmt)->result)
254255

255256
#define mysqlnd_stmt_free_result(stmt) (stmt)->m->free_result((stmt) TSRMLS_CC)
256257
#define mysqlnd_stmt_close(stmt, implicit) (stmt)->m->dtor((stmt), (implicit) TSRMLS_CC)

Diff for: ext/mysqlnd/mysqlnd_charset.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const name
463463

464464
/* {{{ mysqlnd_cset_escape_quotes */
465465
PHPAPI ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char *newstr,
466-
const char *escapestr, int escapestr_len TSRMLS_DC)
466+
const char *escapestr, size_t escapestr_len TSRMLS_DC)
467467
{
468468
const char *newstr_s = newstr;
469469
const char *newstr_e = newstr + 2 * escapestr_len;
@@ -517,7 +517,7 @@ PHPAPI ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char
517517

518518
/* {{{ mysqlnd_cset_escape_slashes */
519519
PHPAPI ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char *newstr,
520-
const char *escapestr, int escapestr_len TSRMLS_DC)
520+
const char *escapestr, size_t escapestr_len TSRMLS_DC)
521521
{
522522
const char *newstr_s = newstr;
523523
const char *newstr_e = newstr + 2 * escapestr_len;

Diff for: ext/mysqlnd/mysqlnd_charset.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#define MYSQLND_CHARSET_H
2323

2424
PHPAPI ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char *newstr,
25-
const char *escapestr, int escapestr_len TSRMLS_DC);
25+
const char *escapestr, size_t escapestr_len TSRMLS_DC);
2626

2727
PHPAPI ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char *newstr,
28-
const char *escapestr, int escapestr_len TSRMLS_DC);
28+
const char *escapestr, size_t escapestr_len TSRMLS_DC);
2929

3030
#endif /* MYSQLND_CHARSET_H */
3131

Diff for: ext/mysqlnd/mysqlnd_libmysql_compat.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define MYSQL_STMT MYSQLND_STMT
2929
#define MYSQL_FIELD MYSQLND_FIELD
3030
#define MYSQL_RES MYSQLND_RES
31-
#define MYSQL_ROW MYSQLND_ROW
31+
#define MYSQL_ROW MYSQLND_ROW_C
3232
#define MYSQL MYSQLND
3333
#define my_bool zend_bool
3434
#define my_ulonglong uint64
@@ -58,7 +58,7 @@
5858
#define mysql_fetch_field(r) mysqlnd_fetch_field((r))
5959
#define mysql_fetch_field_direct(r,o) mysqlnd_fetch_field_direct((r), (o))
6060
#define mysql_fetch_lengths(r) mysqlnd_fetch_lengths((r))
61-
#define mysql_fetch_row(r) mysqlnd_fetch_row((r))
61+
#define mysql_fetch_row(r) mysqlnd_fetch_row_c((r))
6262
#define mysql_field_count(r) mysqlnd_field_count((r))
6363
#define mysql_field_seek(r,o) mysqlnd_field_seek((r), (o))
6464
#define mysql_field_tell(r) mysqlnd_field_tell((r))

Diff for: ext/mysqlnd/mysqlnd_loaddata.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int mysqlnd_local_infile_error(void *ptr, char *error_buf, uint error_buf_len TS
118118
DBG_RETURN(info->error_no);
119119
}
120120

121-
strncpy(error_buf, "Unknown error", error_buf_len);
121+
strlcpy(error_buf, "Unknown error", error_buf_len);
122122
DBG_INF_FMT("no info, %d", CR_UNKNOWN_ERROR);
123123
DBG_RETURN(CR_UNKNOWN_ERROR);
124124
}

Diff for: ext/mysqlnd/mysqlnd_palloc.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,11 @@ void *mysqlnd_palloc_get_zval(MYSQLND_THD_ZVAL_PCACHE * const thd_cache, zend_bo
294294
void *ret = NULL;
295295

296296
DBG_ENTER("mysqlnd_palloc_get_zval");
297-
DBG_INF_FMT("cache=%p *last_added=%p free_items=%d",
298-
thd_cache, thd_cache? thd_cache->parent->free_list.last_added:NULL,
299-
thd_cache->parent->free_items);
297+
if (thd_cache) {
298+
DBG_INF_FMT("cache=%p *last_added=%p free_items=%d",
299+
thd_cache, thd_cache->parent->free_list.last_added,
300+
thd_cache->parent->free_items);
301+
}
300302

301303
if (thd_cache) {
302304
MYSQLND_ZVAL_PCACHE *cache = thd_cache->parent;
@@ -343,11 +345,13 @@ void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_THD_ZVAL_PCACHE * const thd
343345
{
344346
MYSQLND_ZVAL_PCACHE *cache;
345347
DBG_ENTER("mysqlnd_palloc_zval_ptr_dtor");
346-
DBG_INF_FMT("cache=%p parent_block=%p last_in_block=%p *zv=%p refc=%d type=%d ",
347-
thd_cache,
348-
thd_cache->parent? thd_cache->parent->block:NULL,
349-
thd_cache->parent? thd_cache->parent->last_in_block:NULL,
350-
*zv, Z_REFCOUNT_PP(zv), type);
348+
if (thd_cache) {
349+
DBG_INF_FMT("cache=%p parent_block=%p last_in_block=%p *zv=%p refc=%d type=%d ",
350+
thd_cache,
351+
thd_cache->parent->block,
352+
thd_cache->parent->last_in_block,
353+
*zv, Z_REFCOUNT_PP(zv), type);
354+
}
351355
*copy_ctor_called = FALSE;
352356
/* Check whether cache is used and the zval is from the cache */
353357
if (!thd_cache || !(cache = thd_cache->parent) || ((char *)*zv < (char *)thd_cache->parent->block ||

Diff for: ext/mysqlnd/mysqlnd_portability.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ typedef union {
325325
(((uint32) ((uchar) (A)[3])) << 24))
326326

327327

328-
#define uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
328+
#define bit_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
329329
(((uint32) (((uchar*) (A))[6])) << 8) +\
330330
(((uint32) (((uchar*) (A))[5])) << 16) +\
331331
(((uint32) (((uchar*) (A))[4])) << 24)) +\

Diff for: ext/mysqlnd/mysqlnd_priv.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@
149149
#define SET_CLIENT_ERROR(error_info, a, b, c) \
150150
{ \
151151
error_info.error_no = a; \
152-
strncpy(error_info.sqlstate, b, sizeof(error_info.sqlstate)); \
153-
strncpy(error_info.error, c, sizeof(error_info.error)); \
152+
strlcpy(error_info.sqlstate, b, sizeof(error_info.sqlstate)); \
153+
strlcpy(error_info.error, c, sizeof(error_info.error)); \
154154
}
155155

156156
#define SET_STMT_ERROR(stmt, a, b, c) SET_CLIENT_ERROR(stmt->error_info, a, b, c)

Diff for: ext/mysqlnd/mysqlnd_ps.c

+36-29
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const stmt, const char * co
331331
no metadata at prepare.
332332
*/
333333
if (stmt_to_prepare->field_count) {
334-
MYSQLND_RES *result = mysqlnd_result_init(stmt_to_prepare->field_count, NULL TSRMLS_CC);
334+
MYSQLND_RES *result = mysqlnd_result_init(stmt_to_prepare->field_count,
335+
mysqlnd_palloc_get_thd_cache_reference(stmt->conn->zval_cache)
336+
TSRMLS_CC);
335337
/* Allocate the result now as it is needed for the reading of metadata */
336338
stmt_to_prepare->result = result;
337339

@@ -731,37 +733,16 @@ MYSQLND_METHOD(mysqlnd_stmt, use_result)(MYSQLND_STMT *stmt TSRMLS_DC)
731733
}
732734

733735
SET_EMPTY_ERROR(stmt->error_info);
734-
SET_EMPTY_ERROR(stmt->conn->error_info);
735736

736737
MYSQLND_INC_CONN_STATISTIC(&stmt->conn->stats, STAT_PS_UNBUFFERED_SETS);
737-
738-
result = stmt->result;
739-
result->type = MYSQLND_RES_PS_UNBUF;
740-
result->m.fetch_row = stmt->cursor_exists? mysqlnd_fetch_stmt_row_cursor:
741-
mysqlnd_stmt_fetch_row_unbuffered;
742-
result->m.fetch_lengths = NULL; /* makes no sense */
743-
result->zval_cache = mysqlnd_palloc_get_thd_cache_reference(conn->zval_cache);
744-
745-
result->unbuf = mnd_ecalloc(1, sizeof(MYSQLND_RES_UNBUFFERED));
746-
747-
DBG_INF_FMT("cursor=%d zval_cache=%p", stmt->cursor_exists, result->zval_cache);
748-
/*
749-
Will be freed in the mysqlnd_internal_free_result_contents() called
750-
by the resource destructor. mysqlnd_fetch_row_unbuffered() expects
751-
this to be not NULL.
752-
*/
753-
PACKET_INIT(result->row_packet, PROT_ROW_PACKET, php_mysql_packet_row *);
754-
result->row_packet->field_count = result->field_count;
755-
result->row_packet->binary_protocol = TRUE;
756-
result->row_packet->fields_metadata = stmt->result->meta->fields;
757-
result->row_packet->bit_fields_count = result->meta->bit_fields_count;
758-
result->row_packet->bit_fields_total_len = result->meta->bit_fields_total_len;
759-
result->lengths = NULL;
738+
result = stmt->result;
739+
740+
result->m.use_result(stmt->result, TRUE TSRMLS_CC);
741+
result->m.fetch_row = stmt->cursor_exists? mysqlnd_fetch_stmt_row_cursor:
742+
mysqlnd_stmt_fetch_row_unbuffered;
760743

761744
stmt->state = MYSQLND_STMT_USE_OR_STORE_CALLED;
762745

763-
/* No multithreading issues as we don't share the connection :) */
764-
765746
DBG_INF_FMT("%p", result);
766747
DBG_RETURN(result);
767748
}
@@ -1164,6 +1145,31 @@ MYSQLND_METHOD(mysqlnd_stmt, bind_param)(MYSQLND_STMT * const stmt,
11641145
/* }}} */
11651146

11661147

1148+
/* {{{ _mysqlnd_stmt_refresh_bind_param */
1149+
static enum_func_status
1150+
MYSQLND_METHOD(mysqlnd_stmt, refresh_bind_param)(MYSQLND_STMT * const stmt TSRMLS_DC)
1151+
{
1152+
DBG_ENTER("mysqlnd_stmt::refresh_bind_param");
1153+
DBG_INF_FMT("stmt=%lu param_count=%u", stmt->stmt_id, stmt->param_count);
1154+
1155+
if (stmt->state < MYSQLND_STMT_PREPARED) {
1156+
SET_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, UNKNOWN_SQLSTATE, mysqlnd_stmt_not_prepared);
1157+
DBG_ERR("not prepared");
1158+
DBG_RETURN(FAIL);
1159+
}
1160+
1161+
SET_EMPTY_ERROR(stmt->error_info);
1162+
SET_EMPTY_ERROR(stmt->conn->error_info);
1163+
1164+
if (stmt->param_count) {
1165+
stmt->send_types_to_server = 1;
1166+
}
1167+
DBG_INF("PASS");
1168+
DBG_RETURN(PASS);
1169+
}
1170+
/* }}} */
1171+
1172+
11671173
/* {{{ mysqlnd_stmt::bind_result */
11681174
static enum_func_status
11691175
MYSQLND_METHOD(mysqlnd_stmt, bind_result)(MYSQLND_STMT * const stmt,
@@ -1535,7 +1541,7 @@ void mysqlnd_internal_free_stmt_content(MYSQLND_STMT *stmt TSRMLS_DC)
15351541

15361542
/* Destroy the input bind */
15371543
if (stmt->param_bind) {
1538-
int i;
1544+
unsigned int i;
15391545
/*
15401546
Because only the bound variables can point to our internal buffers, then
15411547
separate or free only them. Free is possible because the user could have
@@ -1651,7 +1657,7 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, dtor)(MYSQLND_STMT * const stmt, zend_bool
16511657
{
16521658
enum_func_status ret;
16531659

1654-
DBG_ENTER("mysqlnd_stmt::close");
1660+
DBG_ENTER("mysqlnd_stmt::dtor");
16551661
DBG_INF_FMT("stmt=%p", stmt);
16561662

16571663
MYSQLND_INC_GLOBAL_STATISTIC(implicit == TRUE? STAT_STMT_CLOSE_IMPLICIT:
@@ -1683,6 +1689,7 @@ struct st_mysqlnd_stmt_methods mysqlnd_stmt_methods = {
16831689
MYSQLND_METHOD(mysqlnd_stmt, fetch),
16841690

16851691
MYSQLND_METHOD(mysqlnd_stmt, bind_param),
1692+
MYSQLND_METHOD(mysqlnd_stmt, refresh_bind_param),
16861693
MYSQLND_METHOD(mysqlnd_stmt, bind_result),
16871694
MYSQLND_METHOD(mysqlnd_stmt, send_long_data),
16881695
MYSQLND_METHOD(mysqlnd_stmt, param_metadata),

0 commit comments

Comments
 (0)