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: Fix zend_object std layout for _pdo_row_t #17606

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2267,7 +2267,7 @@ static zval *row_read_column_number(pdo_stmt_t *stmt, zend_long column, zval *rv

static zval *row_prop_read(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
{
pdo_row_t *row = (pdo_row_t *)object;
pdo_row_t *row = php_pdo_row_fetch_object(object);
pdo_stmt_t *stmt = row->stmt;
zend_long lval;
zval *retval;
Expand Down Expand Up @@ -2304,7 +2304,7 @@ static zval *row_dim_read(zend_object *object, zval *offset, int type, zval *rv)
return NULL;
}
if (Z_TYPE_P(offset) == IS_LONG) {
pdo_row_t *row = (pdo_row_t *)object;
pdo_row_t *row = php_pdo_row_fetch_object(object);
pdo_stmt_t *stmt = row->stmt;
ZEND_ASSERT(stmt);

Expand Down Expand Up @@ -2342,7 +2342,7 @@ static void row_dim_write(zend_object *object, zval *member, zval *value)
// todo: make row_prop_exists return bool as well
static int row_prop_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot)
{
pdo_row_t *row = (pdo_row_t *)object;
pdo_row_t *row = php_pdo_row_fetch_object(object);
pdo_stmt_t *stmt = row->stmt;
zend_long lval;
zval tmp_val;
Expand Down Expand Up @@ -2370,7 +2370,7 @@ static int row_prop_exists(zend_object *object, zend_string *name, int check_emp
static int row_dim_exists(zend_object *object, zval *offset, int check_empty)
{
if (Z_TYPE_P(offset) == IS_LONG) {
pdo_row_t *row = (pdo_row_t *)object;
pdo_row_t *row = php_pdo_row_fetch_object(object);
pdo_stmt_t *stmt = row->stmt;
ZEND_ASSERT(stmt);
zend_long column = Z_LVAL_P(offset);
Expand Down Expand Up @@ -2411,7 +2411,7 @@ static void row_dim_delete(zend_object *object, zval *offset)

static HashTable *row_get_properties_for(zend_object *object, zend_prop_purpose purpose)
{
pdo_row_t *row = (pdo_row_t *)object;
pdo_row_t *row = php_pdo_row_fetch_object(object);
pdo_stmt_t *stmt = row->stmt;
HashTable *props;
int i;
Expand Down Expand Up @@ -2453,7 +2453,7 @@ static zval *pdo_row_get_property_ptr_ptr(zend_object *object, zend_string *name

void pdo_row_free_storage(zend_object *std)
{
pdo_row_t *row = (pdo_row_t *)std;
pdo_row_t *row = php_pdo_row_fetch_object(std);
if (row->stmt) {
ZVAL_UNDEF(&row->stmt->lazy_object_ref);
OBJ_RELEASE(&row->stmt->std);
Expand Down Expand Up @@ -2490,6 +2490,7 @@ void pdo_stmt_init(void)
pdo_row_ce->default_object_handlers = &pdo_row_object_handlers;

memcpy(&pdo_row_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
pdo_row_object_handlers.offset = XtOffsetOf(pdo_row_t, std);
pdo_row_object_handlers.free_obj = pdo_row_free_storage;
pdo_row_object_handlers.clone_obj = NULL;
pdo_row_object_handlers.get_property_ptr_ptr = pdo_row_get_property_ptr_ptr;
Expand Down
6 changes: 5 additions & 1 deletion ext/pdo/php_pdo_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,14 @@ static inline pdo_stmt_t *php_pdo_stmt_fetch_object(zend_object *obj) {
#define Z_PDO_STMT_P(zv) php_pdo_stmt_fetch_object(Z_OBJ_P((zv)))

struct _pdo_row_t {
zend_object std;
pdo_stmt_t *stmt;
zend_object std;
};

static inline pdo_row_t *php_pdo_row_fetch_object(zend_object *obj) {
return (pdo_row_t *)((char*)(obj) - XtOffsetOf(pdo_row_t, std));
}

struct _pdo_scanner_t {
const char *ptr, *cur, *tok, *end;
};
Expand Down
Loading