Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/pdo: Refactor PDO::FETCH_CLASS to not rely on a FCI and use a HashTable for ctor_arg #17427

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jan 10, 2025

Commits should be reviewed in order.

This removes the last usage of zend_fcall_info_args_ex() and basically supersedes #9725, which would allow merging #9723.

This also aligns the behaviour of the ctor_arguments to be have like CUFA.

Some follow-up ideas:

  • Deprecate the automatic wrapping of by-ref arguments for the constructor
  • Figure out how to remove the various dummy fields to reduce the size of the struct

@Girgias Girgias force-pushed the pdo-stmt-remove-fci-usage branch 3 times, most recently from 702f741 to 2bad75c Compare January 15, 2025 19:01
@Girgias Girgias marked this pull request as ready for review January 15, 2025 20:00
@Girgias Girgias requested a review from nielsdos January 15, 2025 20:00
@Girgias Girgias force-pushed the pdo-stmt-remove-fci-usage branch from 2bad75c to 81490b2 Compare January 16, 2025 12:46
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
@Girgias Girgias force-pushed the pdo-stmt-remove-fci-usage branch from 81490b2 to 5711354 Compare January 17, 2025 18:44
@Girgias Girgias force-pushed the pdo-stmt-remove-fci-usage branch from 5711354 to 808b10e Compare January 17, 2025 18:45
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
@Girgias Girgias force-pushed the pdo-stmt-remove-fci-usage branch from 808b10e to 4791772 Compare January 21, 2025 05:24
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
stmt->fetch.cls.ce = cep;
zval ce_name_from_column;
fetch_value(stmt, &ce_name_from_column, column_index_to_fetch++, NULL);
if (Z_TYPE(ce_name_from_column) == IS_STRING) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the type is not string, then we silently ignore it? That seems not nice... should warn or throw or something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoyingly, due to the previous usage of try_convert_to_string() it would accept integers/null/floats convert them to string, and because no class could possibly exist set the CE to stdClass.

fci->param_count = 0;
fci->params = NULL;

zend_fcall_info_args_ex(fci, ce->constructor, &stmt->fetch.cls.ctor_args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document the new behaviour wrt references in UPGRADING please?

zval_ptr_dtor(return_value);
RETVAL_FALSE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay let's just make it consistently not use it then as it's a big refactor anyway it seems like a good opportunity to do so.

ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
zend_argument_value_error(3, "must be empty when class provided in argument #2 ($class) does not have a constructor");
return false;
}
GC_TRY_ADDREF(Z_ARRVAL(args[1]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay without looking too deep again: check why you refcount

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HashTable comes from userland via the call to POD::setFetchMode()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants