1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Clean up some minor things in ext/mysqli (#20120)

* Remove unused fields and typedefs

* Remove unused __name parameter
This commit is contained in:
Kamil Tekiela
2025-10-12 01:20:48 +01:00
committed by GitHub
parent 8212593694
commit f543f4951c
7 changed files with 22 additions and 47 deletions

View File

@@ -136,10 +136,6 @@ void php_clear_mysql(MY_MYSQL *mysql) {
zend_string_release_ex(mysql->hash_key, 0);
mysql->hash_key = NULL;
}
if (!Z_ISUNDEF(mysql->li_read)) {
zval_ptr_dtor(&(mysql->li_read));
ZVAL_UNDEF(&mysql->li_read);
}
}
/* }}} */
@@ -788,7 +784,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
}
}
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");

View File

@@ -324,7 +324,7 @@ PHP_FUNCTION(mysqli_data_seek)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered(result)) {
if (hasThis()) {
@@ -670,7 +670,7 @@ PHP_FUNCTION(mysqli_fetch_field)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (!(field = mysql_fetch_field(result))) {
RETURN_FALSE;
@@ -694,7 +694,7 @@ PHP_FUNCTION(mysqli_fetch_fields)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
array_init(return_value);
num_fields = mysql_num_fields(result);
@@ -727,7 +727,7 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (offset >= (zend_long) mysql_num_fields(result)) {
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)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
// TODO Warning?
if (!(ret = mysql_fetch_lengths(result))) {
@@ -809,7 +809,7 @@ PHP_FUNCTION(mysqli_field_seek)
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
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)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
RETURN_LONG(mysql_field_tell(result));
}
@@ -845,7 +845,7 @@ PHP_FUNCTION(mysqli_free_result)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
mysqli_free_result(result, false);
MYSQLI_CLEAR_RESOURCE(mysql_result);
@@ -1123,7 +1123,7 @@ PHP_FUNCTION(mysqli_num_fields)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
RETURN_LONG(mysql_num_fields(result));
}
@@ -1138,7 +1138,7 @@ PHP_FUNCTION(mysqli_num_rows)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
zend_throw_error(NULL, "mysqli_num_rows() cannot be used in MYSQLI_USE_RESULT mode");

View File

@@ -107,7 +107,6 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, bool is_real_connect, b
mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
self_alloced = true;
}
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
} else {
/* We have flags too */
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
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
MYSQLI_FETCH_RESOURCE_CONN(mysql, object, MYSQLI_STATUS_INITIALIZED);
/* set some required options */
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
/* remove some insecure options */
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
}
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
if (!socket_len || !socket) {
socket = MyG(default_socket);
@@ -316,7 +314,7 @@ err:
mysql->hash_key = NULL;
mysql->persistent = false;
}
if (!is_real_connect && self_alloced) {
if (self_alloced) {
efree(mysql);
}
RETVAL_FALSE;
@@ -393,7 +391,7 @@ PHP_FUNCTION(mysqli_fetch_column)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &col_no) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES*, mysql_result, MYSQLI_STATUS_VALID);
if (col_no < 0) {
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)
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &mode) == FAILURE) {
RETURN_THROWS();
}
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, MYSQLI_STATUS_VALID);
if (!mode || (mode & ~MYSQLI_BOTH)) {
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");

View File

@@ -55,7 +55,6 @@ extern void php_clear_mysql(MY_MYSQL *);
extern MYSQLI_WARNING *php_get_warnings(MYSQLND_CONN_DATA * mysql);
extern void php_clear_warnings(MYSQLI_WARNING *w);
extern void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type);
extern void php_mysqli_report_error(const char *sqlstate, int errorno, const char *error);
extern void php_mysqli_report_index(const char *query, unsigned int status);
extern void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...);

View File

@@ -98,7 +98,7 @@ static void php_mysqli_result_iterator_move_forward(zend_object_iterator *iter)
mysqli_object *intern = iterator->result;
MYSQL_RES *result;
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);
zval_ptr_dtor(&iterator->current_row);
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)
mysqli_object *intern = iterator->result;
MYSQL_RES *result;
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, "mysqli_result", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE_BY_OBJ(result, MYSQL_RES *, intern, MYSQLI_STATUS_VALID);
if (mysqli_result_is_unbuffered(result)) {
if (result->unbuf->eof_reached) {

View File

@@ -125,7 +125,7 @@ PHP_METHOD(mysqli_warning, next)
}
if (obj->ptr) {
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, "mysqli_warning", MYSQLI_STATUS_VALID);
MYSQLI_FETCH_RESOURCE(w, MYSQLI_WARNING *, ZEND_THIS, MYSQLI_STATUS_VALID);
if (w && w->next) {
w = w->next;

View File

@@ -38,32 +38,14 @@ enum mysqli_status {
MYSQLI_STATUS_VALID
};
typedef struct {
char *val;
zend_ulong buflen;
zend_ulong output_len;
zend_ulong type;
} VAR_BUFFER;
typedef struct {
unsigned int var_cnt;
VAR_BUFFER *buf;
zval *vars;
my_bool *is_null;
} BIND_BUFFER;
typedef struct {
MYSQL_STMT *stmt;
BIND_BUFFER param;
BIND_BUFFER result;
char *query;
} MY_STMT;
typedef struct {
MYSQL *mysql;
zend_string *hash_key;
zval li_read;
php_stream *li_stream;
unsigned int multi_query;
bool persistent;
int async_result_fetch_type;
@@ -177,7 +159,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
MYSQLI_REGISTER_RESOURCE_EX(__ptr, object)\
}
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __name, __check) \
#define MYSQLI_FETCH_RESOURCE(__ptr, __type, __id, __check) \
{ \
MYSQLI_RESOURCE *my_res; \
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
}\
}
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __name, __check) \
#define MYSQLI_FETCH_RESOURCE_BY_OBJ(__ptr, __type, __obj, __check) \
{ \
MYSQLI_RESOURCE *my_res; \
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
#define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \
MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), (__check)); \
if (!(__ptr)->mysql) { \
zend_throw_error(NULL, "%s object is not fully initialized", ZSTR_VAL(Z_OBJCE_P(__id)->name)); \
RETURN_THROWS(); \
@@ -217,7 +199,7 @@ extern void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * resul
#define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \
{ \
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \
MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), (__check)); \
ZEND_ASSERT((__ptr)->stmt && "Missing statement?"); \
}