Skip to content

Commit f543f49

Browse files
Clean up some minor things in ext/mysqli (php#20120)
* Remove unused fields and typedefs * Remove unused __name parameter
1 parent 8212593 commit f543f49

File tree

7 files changed

+22
-47
lines changed

7 files changed

+22
-47
lines changed

ext/mysqli/mysqli.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ void php_clear_mysql(MY_MYSQL *mysql) {
136136
zend_string_release_ex(mysql->hash_key, 0);
137137
mysql->hash_key = NULL;
138138
}
139-
if (!Z_ISUNDEF(mysql->li_read)) {
140-
zval_ptr_dtor(&(mysql->li_read));
141-
ZVAL_UNDEF(&mysql->li_read);
142-
}
143139
}
144140
/* }}} */
145141

@@ -788,7 +784,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
788784
}
789785
}
790786
}
791-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
787+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
792788

793789
if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
794790
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");

ext/mysqli/mysqli_api.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ PHP_FUNCTION(mysqli_data_seek)
324324
RETURN_THROWS();
325325
}
326326

327-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
327+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
328328

329329
if (mysqli_result_is_unbuffered(result)) {
330330
if (hasThis()) {
@@ -670,7 +670,7 @@ PHP_FUNCTION(mysqli_fetch_field)
670670
RETURN_THROWS();
671671
}
672672

673-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
673+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
674674

675675
if (!(field = mysql_fetch_field(result))) {
676676
RETURN_FALSE;
@@ -694,7 +694,7 @@ PHP_FUNCTION(mysqli_fetch_fields)
694694
RETURN_THROWS();
695695
}
696696

697-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
697+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
698698

699699
array_init(return_value);
700700
num_fields = mysql_num_fields(result);
@@ -727,7 +727,7 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
727727
RETURN_THROWS();
728728
}
729729

730-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
730+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
731731

732732
if (offset >= (zend_long) mysql_num_fields(result)) {
733733
zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
@@ -755,7 +755,7 @@ PHP_FUNCTION(mysqli_fetch_lengths)
755755
RETURN_THROWS();
756756
}
757757

758-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
758+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
759759

760760
// TODO Warning?
761761
if (!(ret = mysql_fetch_lengths(result))) {
@@ -809,7 +809,7 @@ PHP_FUNCTION(mysqli_field_seek)
809809
RETURN_THROWS();
810810
}
811811

812-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
812+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
813813

814814
if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
815815
zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
@@ -830,7 +830,7 @@ PHP_FUNCTION(mysqli_field_tell)
830830
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
831831
RETURN_THROWS();
832832
}
833-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
833+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
834834

835835
RETURN_LONG(mysql_field_tell(result));
836836
}
@@ -845,7 +845,7 @@ PHP_FUNCTION(mysqli_free_result)
845845
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
846846
RETURN_THROWS();
847847
}
848-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
848+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
849849

850850
mysqli_free_result(result, false);
851851
MYSQLI_CLEAR_RESOURCE(mysql_result);
@@ -1123,7 +1123,7 @@ PHP_FUNCTION(mysqli_num_fields)
11231123
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
11241124
RETURN_THROWS();
11251125
}
1126-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1126+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
11271127

11281128
RETURN_LONG(mysql_num_fields(result));
11291129
}
@@ -1138,7 +1138,7 @@ PHP_FUNCTION(mysqli_num_rows)
11381138
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
11391139
RETURN_THROWS();
11401140
}
1141-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
1141+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
11421142

11431143
if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
11441144
zend_throw_error(NULL, "mysqli_num_rows() cannot be used in MYSQLI_USE_RESULT mode");

ext/mysqli/mysqli_nonapi.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
107107
mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
108108
self_alloced = true;
109109
}
110-
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
111110
} else {
112111
/* We have flags too */
113112
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s!s!s!s!l!s!l", &object, mysqli_link_class_entry,
@@ -118,11 +117,10 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
118117
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
119118
MYSQLI_FETCH_RESOURCE_CONN(mysql, object, MYSQLI_STATUS_INITIALIZED);
120119

121-
/* set some required options */
122-
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
123120
/* remove some insecure options */
124121
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
125122
}
123+
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
126124

127125
if (!socket_len || !socket) {
128126
socket = MyG(default_socket);
@@ -316,7 +314,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
316314
mysql->hash_key = NULL;
317315
mysql->persistent = false;
318316
}
319-
if (!is_real_connect && self_alloced) {
317+
if (self_alloced) {
320318
efree(mysql);
321319
}
322320
RETVAL_FALSE;
@@ -393,7 +391,7 @@ PHP_FUNCTION(mysqli_fetch_column)
393391
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &col_no) == FAILURE) {
394392
RETURN_THROWS();
395393
}
396-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
394+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, MYSQLI_STATUS_VALID);
397395

398396
if (col_no < 0) {
399397
zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
@@ -425,7 +423,7 @@ PHP_FUNCTION(mysqli_fetch_all)
425423
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &mode) == FAILURE) {
426424
RETURN_THROWS();
427425
}
428-
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
426+
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
429427

430428
if (!mode || (mode & ~MYSQLI_BOTH)) {
431429
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");

ext/mysqli/mysqli_priv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ extern void php_clear_mysql(MY_MYSQL *);
5555
extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);
5656

5757
extern void php_clear_warnings(MYSQLI_WARNING *w);
58-
extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
5958
extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error);
6059
extern void php_mysqli_report_index(const char *query, unsigned int status);
6160
extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);

ext/mysqli/mysqli_result_iterator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter)
9898
mysqli_object *intern = iterator->result;
9999
MYSQL_RES *result;
100100

101-
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
101+
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);
102102

103103
zval_ptr_dtor(&iterator->current_row);
104104
php_mysqli_fetch_into_hash_aux(&iterator->current_row, result, MYSQLI_ASSOC);
@@ -115,7 +115,7 @@ static void php_mysqli_result_iterator_rewind(zend_object_iterator *iter)
115115
mysqli_object *intern = iterator->result;
116116
MYSQL_RES *result;
117117

118-
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
118+
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);
119119

120120
if (mysqli_result_is_unbuffered(result)) {
121121
if (result->unbuf->eof_reached) {

ext/mysqli/mysqli_warning.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ PHP_METHOD(mysqli_warning, next)
125125
}
126126

127127
if (obj->ptr) {
128-
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, "mysqli_warning", MYSQLI_STATUS_VALID);
128+
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, MYSQLI_STATUS_VALID);
129129

130130
if (w && w->next) {
131131
w = w->next;

ext/mysqli/php_mysqli_structs.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,14 @@ enum mysqli_status {
3838
MYSQLI_STATUS_VALID
3939
};
4040

41-
typedef struct {
42-
char *val;
43-
zend_ulong buflen;
44-
zend_ulong output_len;
45-
zend_ulong type;
46-
} VAR_BUFFER;
47-
48-
typedef struct {
49-
unsigned int var_cnt;
50-
VAR_BUFFER *buf;
51-
zval *vars;
52-
my_bool *is_null;
53-
} BIND_BUFFER;
54-
5541
typedef struct {
5642
MYSQL_STMT *stmt;
57-
BIND_BUFFER param;
58-
BIND_BUFFER result;
5943
char *query;
6044
} MY_STMT;
6145

6246
typedef struct {
6347
MYSQL *mysql;
6448
zend_string *hash_key;
65-
zval li_read;
66-
php_stream *li_stream;
6749
unsigned int multi_query;
6850
bool persistent;
6951
int async_result_fetch_type;
@@ -177,7 +159,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
177159
MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
178160
}
179161

180-
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
162+
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __check) \
181163
{ \
182164
MYSQLI_RESOURCE *my_res; \
183165
mysqli_object *intern = Z_MYSQLI_P(__id); \
@@ -192,7 +174,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
192174
}\
193175
}
194176

195-
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
177+
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __check) \
196178
{ \
197179
MYSQLI_RESOURCE *my_res; \
198180
if (!(my_res = (MYSQLI_RESOURCE *)(__obj->ptr))) {\
@@ -208,7 +190,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
208190

209191
#define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
210192
{ \
211-
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
193+
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), (__check)); \
212194
if (!(__ptr)->mysql) { \
213195
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(Z_OBJCE_P(__id)->name)); \
214196
RETURN_THROWS(); \
@@ -217,7 +199,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
217199

218200
#define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
219201
{ \
220-
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
202+
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), (__check)); \
221203
ZEND_ASSERT((__ptr)->stmt && "Missing statement?"); \
222204
}
223205

0 commit comments

Comments
 (0)