Skip to content

Commit

Permalink
Fixed PDO objects binary incompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed May 6, 2010
1 parent 1381b14 commit 77b2e54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 42 deletions.
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
. session_is_registered(), session_register() and session_unregister()
functions. (Kalle)
. y2k_compliance ini option. (Kalle)


- Fixed PDO objects binary incompatibility. (Dmitry)

?? ??? 20??, PHP 5.3.3
- Upgraded bundled PCRE to version 8.01. (Ilia)

Expand Down
28 changes: 11 additions & 17 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,20 @@ static PHP_METHOD(PDO, dbh_constructor)
memcpy((char *)pdbh->persistent_id, hashkey, plen+1);
pdbh->persistent_id_len = plen+1;
pdbh->refcount = 1;
pdbh->properties = NULL;
pdbh->std.properties = NULL;
}
}

if (pdbh) {
/* let's copy the emalloc bits over from the other handle */
if (pdbh->properties) {
zend_hash_destroy(dbh->properties);
efree(dbh->properties);
if (pdbh->std.properties) {
zend_hash_destroy(dbh->std.properties);
efree(dbh->std.properties);
} else {
pdbh->ce = dbh->ce;
pdbh->std.ce = dbh->std.ce;
pdbh->def_stmt_ce = dbh->def_stmt_ce;
pdbh->def_stmt_ctor_args = dbh->def_stmt_ctor_args;
pdbh->properties = dbh->properties;
pdbh->std.properties = dbh->std.properties;
}
/* kill the non-persistent thingamy */
efree(dbh);
Expand Down Expand Up @@ -1286,7 +1286,7 @@ int pdo_hash_methods(pdo_dbh_t *dbh, int kind TSRMLS_DC)
ifunc->type = ZEND_INTERNAL_FUNCTION;
ifunc->handler = funcs->handler;
ifunc->function_name = (char*)funcs->fname;
ifunc->scope = dbh->ce;
ifunc->scope = dbh->std.ce;
ifunc->prototype = NULL;
if (funcs->arg_info) {
ifunc->arg_info = (zend_arg_info*)funcs->arg_info + 1;
Expand Down Expand Up @@ -1539,16 +1539,12 @@ static void pdo_dbh_free_storage(pdo_dbh_t *dbh TSRMLS_DC)
dbh->methods->rollback(dbh TSRMLS_CC);
dbh->in_txn = 0;
}

if (dbh->properties) {
zend_hash_destroy(dbh->properties);
efree(dbh->properties);
dbh->properties = NULL;
}

if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) {
dbh->methods->persistent_shutdown(dbh TSRMLS_CC);
}
zend_object_std_dtor(&dbh->std TSRMLS_CC);
dbh->std.properties = NULL;
dbh_free(dbh TSRMLS_CC);
}

Expand All @@ -1560,11 +1556,9 @@ zend_object_value pdo_dbh_new(zend_class_entry *ce TSRMLS_DC)

dbh = emalloc(sizeof(*dbh));
memset(dbh, 0, sizeof(*dbh));
dbh->ce = ce;
zend_object_std_init(&dbh->std, ce TSRMLS_CC);
zend_hash_copy(dbh->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
dbh->refcount = 1;
ALLOC_HASHTABLE(dbh->properties);
zend_hash_init(dbh->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(dbh->properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
dbh->def_stmt_ce = pdo_dbstmt_ce;

retval.handle = zend_objects_store_put(dbh, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbh_free_storage, NULL TSRMLS_CC);
Expand Down
23 changes: 7 additions & 16 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,11 +2319,9 @@ static zend_object_value dbstmt_clone_obj(zval *zobject TSRMLS_DC)
zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);

stmt = ecalloc(1, sizeof(*stmt));
stmt->ce = Z_OBJCE_P(zobject);
zend_object_std_init(&stmt->std, Z_OBJCE_P(zobject) TSRMLS_CC);
zend_hash_copy(stmt->std.properties, &stmt->std.ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
stmt->refcount = 1;
ALLOC_HASHTABLE(stmt->properties);
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(stmt->properties, &stmt->ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));

old_stmt = (pdo_stmt_t *)zend_object_store_get_object(zobject TSRMLS_CC);

Expand Down Expand Up @@ -2366,12 +2364,6 @@ void pdo_stmt_init(TSRMLS_D)

static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
{
if (stmt->properties) {
zend_hash_destroy(stmt->properties);
efree(stmt->properties);
stmt->properties = NULL;
}

if (stmt->bound_params) {
zend_hash_destroy(stmt->bound_params);
FREE_HASHTABLE(stmt->bound_params);
Expand Down Expand Up @@ -2420,6 +2412,7 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
if (stmt->dbh) {
php_pdo_dbh_delref(stmt->dbh TSRMLS_CC);
}
zend_object_std_dtor(&stmt->std TSRMLS_CC);
efree(stmt);
}

Expand Down Expand Up @@ -2448,11 +2441,9 @@ zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
pdo_stmt_t *stmt;
stmt = emalloc(sizeof(*stmt));
memset(stmt, 0, sizeof(*stmt));
stmt->ce = ce;
zend_object_std_init(&stmt->std, ce TSRMLS_CC);
zend_hash_copy(stmt->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
stmt->refcount = 1;
ALLOC_HASHTABLE(stmt->properties);
zend_hash_init(stmt->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_copy(stmt->properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));

retval.handle = zend_objects_store_put(stmt, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t)pdo_dbstmt_free_storage, (zend_objects_store_clone_t)dbstmt_clone_obj TSRMLS_CC);
retval.handlers = &pdo_dbstmt_object_handlers;
Expand Down Expand Up @@ -2694,10 +2685,10 @@ static HashTable *row_get_properties(zval *object TSRMLS_DC)
MAKE_STD_ZVAL(val);
fetch_value(stmt, val, i, NULL TSRMLS_CC);

zend_hash_update(stmt->properties, stmt->columns[i].name, stmt->columns[i].namelen + 1, (void *)&val, sizeof(zval *), NULL);
zend_hash_update(stmt->std.properties, stmt->columns[i].name, stmt->columns[i].namelen + 1, (void *)&val, sizeof(zval *), NULL);
}

return stmt->properties;
return stmt->std.properties;
}

static union _zend_function *row_method_get(
Expand Down
10 changes: 2 additions & 8 deletions ext/pdo/php_pdo_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ struct _pdo_dbh_t {
to allow the extending class to escape all the custom handlers
that PDO declares.
*/
zend_class_entry *ce;
HashTable *properties;
unsigned int in_get:1;
unsigned int in_set:1;
zend_object std;

/* driver specific methods */
struct pdo_dbh_methods *methods;
Expand Down Expand Up @@ -548,10 +545,7 @@ struct _pdo_stmt_t {
to allow the extending class to escape all the custom handlers
that PDO declares.
*/
zend_class_entry *ce;
HashTable *properties;
unsigned int in_get:1;
unsigned int in_set:1;
zend_object std;

/* driver specifics */
struct pdo_stmt_methods *methods;
Expand Down

0 comments on commit 77b2e54

Please sign in to comment.