Skip to content

Pdo refactoring #7

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

Closed
wants to merge 18 commits into from
Closed
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
18 changes: 9 additions & 9 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
RETURN_OBJ(&cdata->std);
} else {
zend_wrong_parameter_class_error(2, "FFI\\CData", zv);
return;
RETURN_THROWS();
}
}

Expand Down Expand Up @@ -4006,7 +4006,7 @@ ZEND_METHOD(FFI, typeof) /* {{{ */
}
} else {
zend_wrong_parameter_class_error(1, "FFI\\CData", zv);
return;
RETURN_THROWS();
}

ctype = (zend_ffi_ctype*)zend_ffi_ctype_new(zend_ffi_ctype_ce);
Expand Down Expand Up @@ -4110,7 +4110,7 @@ ZEND_METHOD(FFI, addr) /* {{{ */
ZVAL_DEREF(zv);
if (Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != zend_ffi_cdata_ce) {
zend_wrong_parameter_class_error(1, "FFI\\CData", zv);
return;
RETURN_THROWS();
}

cdata = (zend_ffi_cdata*)Z_OBJ_P(zv);
Expand Down Expand Up @@ -4165,7 +4165,7 @@ ZEND_METHOD(FFI, sizeof) /* {{{ */
type = ZEND_FFI_TYPE(ctype->type);
} else {
zend_wrong_parameter_class_error(1, "FFI\\CData or FFI\\CType", zv);
return;
RETURN_THROWS();
}

RETURN_LONG(type->size);
Expand All @@ -4191,7 +4191,7 @@ ZEND_METHOD(FFI, alignof) /* {{{ */
type = ZEND_FFI_TYPE(ctype->type);
} else {
zend_wrong_parameter_class_error(1, "FFI\\CData or FFI\\CType", zv);
return;
RETURN_THROWS();
}

RETURN_LONG(type->align);
Expand Down Expand Up @@ -4246,7 +4246,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */
}
} else {
zend_wrong_parameter_class_error(2, "FFI\\CData or string", zv2);
return;
RETURN_THROWS();
}

memcpy(ptr1, ptr2, size);
Expand Down Expand Up @@ -4290,7 +4290,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */
}
} else {
zend_wrong_parameter_class_error(1, "FFI\\CData or string", zv1);
return;
RETURN_THROWS();
}

ZVAL_DEREF(zv2);
Expand All @@ -4314,7 +4314,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */
}
} else {
zend_wrong_parameter_class_error(2, "FFI\\CData or string", zv2);
return;
RETURN_THROWS();
}

ret = memcmp(ptr1, ptr2, size);
Expand Down Expand Up @@ -4416,7 +4416,7 @@ ZEND_METHOD(FFI, isNull) /* {{{ */
ZVAL_DEREF(zv);
if (Z_TYPE_P(zv) != IS_OBJECT || Z_OBJCE_P(zv) != zend_ffi_cdata_ce) {
zend_wrong_parameter_class_error(1, "FFI\\CData", zv);
return;
RETURN_THROWS();
}

cdata = (zend_ffi_cdata*)Z_OBJ_P(zv);
Expand Down
18 changes: 12 additions & 6 deletions ext/ffi/ffi.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ public static function cast(FFI\CType|string $type, $ptr): ?FFI\CData {}
public static function type(string $type): ?FFI\CType {}

/** @prefer-ref $ptr */
public static function typeof(FFI\CData $ptr): ?FFI\CType {}
public static function typeof(FFI\CData $ptr): FFI\CType {}

public static function arrayType(FFI\CType $type, array $dimensions): ?FFI\CType {}

/** @prefer-ref $ptr */
public static function addr(FFI\CData $ptr): FFI\CData {}

/** @prefer-ref $ptr */
public static function sizeof(object $ptr): ?int {}
/**
* @param FFI\CData|FFI\CType $ptr
* @prefer-ref $ptr
*/
public static function sizeof($ptr): int {}

/** @prefer-ref $ptr */
public static function alignof(object $ptr): ?int {}
/**
* @param FFI\CData|FFI\CType $ptr
* @prefer-ref $ptr
*/
public static function alignof($ptr): int {}

/**
* @param FFI\CData|string $from
Expand All @@ -52,7 +58,7 @@ public static function memcpy(FFI\CData $to, $from, int $size): void {}
* @prefer-ref $ptr2
* @param string|FFI\CData $ptr2
*/
public static function memcmp($ptr1, $ptr2, int $size): ?int {}
public static function memcmp($ptr1, $ptr2, int $size): int {}

/** @prefer-ref $ptr */
public static function memset(FFI\CData $ptr, int $value, int $size): void {}
Expand Down
10 changes: 5 additions & 5 deletions ext/ffi/ffi_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: abd3bc186ae3f71f2b7eb1d47f3b6bab84fb2bda */
* Stub hash: 677c62adf295003b4b2d273995a4bda623d507bf */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
Expand Down Expand Up @@ -33,7 +33,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_type, 0, 1, FFI\\CType,
ZEND_ARG_TYPE_INFO(0, type, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_typeof, 0, 1, FFI\\CType, 1)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_typeof, 0, 1, FFI\\CType, 0)
ZEND_ARG_OBJ_INFO(ZEND_SEND_PREFER_REF, ptr, FFI\\CData, 0)
ZEND_END_ARG_INFO()

Expand All @@ -46,8 +46,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_addr, 0, 1, FFI\\CData,
ZEND_ARG_OBJ_INFO(ZEND_SEND_PREFER_REF, ptr, FFI\\CData, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_sizeof, 0, 1, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(ZEND_SEND_PREFER_REF, ptr, IS_OBJECT, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_sizeof, 0, 1, IS_LONG, 0)
ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr)
ZEND_END_ARG_INFO()

#define arginfo_class_FFI_alignof arginfo_class_FFI_sizeof
Expand All @@ -58,7 +58,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcpy, 0, 3, IS_VOID,
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcmp, 0, 3, IS_LONG, 1)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_FFI_memcmp, 0, 3, IS_LONG, 0)
ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr1)
ZEND_ARG_INFO(ZEND_SEND_PREFER_REF, ptr2)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
Expand Down
2 changes: 1 addition & 1 deletion ext/imap/php_imap_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 1dbf85a4f8740bf02df35a4e184a67af6cf93e91 */
* Stub hash: 6fa602f286cb156c92ead840e149456dc0c07869 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_open, 0, 3, IMAPConnection, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0)
Expand Down
30 changes: 12 additions & 18 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ PHP_METHOD(PDO, prepare)
/* }}} */


static zend_bool pdo_is_in_transaction(pdo_dbh_t *dbh) {
static bool pdo_is_in_transaction(pdo_dbh_t *dbh) {
if (dbh->methods->in_transaction) {
return dbh->methods->in_transaction(dbh);
}
Expand All @@ -600,14 +600,13 @@ PHP_METHOD(PDO, beginTransaction)
}

if (!dbh->methods->begin) {
/* TODO: this should be an exception; see the auto-commit mode
* comments below */
/* Throw an exception when the driver does not support transactions */
zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support transactions");
RETURN_THROWS();
}

if (dbh->methods->begin(dbh)) {
dbh->in_txn = 1;
dbh->in_txn = true;
RETURN_TRUE;
}

Expand All @@ -631,7 +630,7 @@ PHP_METHOD(PDO, commit)
}

if (dbh->methods->commit(dbh)) {
dbh->in_txn = 0;
dbh->in_txn = false;
RETURN_TRUE;
}

Expand All @@ -655,7 +654,7 @@ PHP_METHOD(PDO, rollBack)
}

if (dbh->methods->rollback(dbh)) {
dbh->in_txn = 0;
dbh->in_txn = false;
RETURN_TRUE;
}

Expand Down Expand Up @@ -894,18 +893,13 @@ PHP_METHOD(PDO, getAttribute)
RETURN_FALSE;
}

switch (dbh->methods->get_attribute(dbh, attr, return_value)) {
case -1:
PDO_HANDLE_DBH_ERR();
RETURN_FALSE;

case 0:
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute");
RETURN_FALSE;

default:
return;
if (dbh->methods->get_attribute(dbh, attr, return_value) == false) {
pdo_raise_impl_error(dbh, NULL, "IM001", "driver does not support that attribute");
RETURN_FALSE;
}
/* No error state, just return as the return_value has been assigned
* by the get_attribute handler */
return;
}
/* }}} */

Expand Down Expand Up @@ -1461,7 +1455,7 @@ static void pdo_dbh_free_storage(zend_object *std)
pdo_dbh_t *dbh = php_pdo_dbh_fetch_inner(std);
if (dbh->in_txn && dbh->methods && dbh->methods->rollback) {
dbh->methods->rollback(dbh);
dbh->in_txn = 0;
dbh->in_txn = false;
}

if (dbh->is_persistent && dbh->methods && dbh->methods->persistent_shutdown) {
Expand Down
10 changes: 4 additions & 6 deletions ext/pdo/pdo_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ PHP_METHOD(PDOStatement, getIterator)
/* {{{ overloaded handlers for PDOStatement class */
static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *value, void **cache_slot)
{
if (strcmp(ZSTR_VAL(name), "queryString") == 0) {
if (zend_string_equals_literal(name, "queryString")) {
zend_throw_error(NULL, "Property queryString is read only");
return value;
} else {
Expand All @@ -2028,7 +2028,7 @@ static zval *dbstmt_prop_write(zend_object *object, zend_string *name, zval *val

static void dbstmt_prop_delete(zend_object *object, zend_string *name, void **cache_slot)
{
if (strcmp(ZSTR_VAL(name), "queryString") == 0) {
if (zend_string_equals_literal(name, "queryString")) {
zend_throw_error(NULL, "Property queryString is read only");
} else {
zend_std_unset_property(object, name, cache_slot);
Expand Down Expand Up @@ -2282,8 +2282,7 @@ static zval *row_prop_read(zend_object *object, zend_string *name, int type, voi
return rv;
}
}
if (strcmp(ZSTR_VAL(name), "queryString") == 0) {
//zval_ptr_dtor(rv);
if (zend_string_equals_literal(name, "queryString")) {
return zend_std_read_property(&stmt->std, name, type, cache_slot, rv);
}
}
Expand Down Expand Up @@ -2324,8 +2323,7 @@ static zval *row_dim_read(zend_object *object, zval *member, int type, zval *rv)
return rv;
}
}
if (strcmp(Z_STRVAL_P(member), "queryString") == 0) {
//zval_ptr_dtor(rv);
if (zend_string_equals_literal(Z_STR_P(member), "queryString")) {
return zend_std_read_property(&stmt->std, Z_STR_P(member), type, NULL, rv);
}
}
Expand Down
41 changes: 24 additions & 17 deletions ext/pdo/php_pdo_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,42 +226,48 @@ typedef struct {
/* {{{ methods for a database handle */

/* close or otherwise disconnect the database */
typedef int (*pdo_dbh_close_func)(pdo_dbh_t *dbh);
typedef void (*pdo_dbh_close_func)(pdo_dbh_t *dbh);

/* prepare a statement and stash driver specific portion into stmt */
typedef int (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options);
/* prepare a statement and stash driver specific portion into stmt
* return true on success, false otherwise */
typedef bool (*pdo_dbh_prepare_func)(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options);

/* execute a statement (that does not return a result set) */
typedef zend_long (*pdo_dbh_do_func)(pdo_dbh_t *dbh, const char *sql, size_t sql_len);

/* quote a string */
typedef int (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype);
typedef bool (*pdo_dbh_quote_func)(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype);

/* transaction related */
typedef int (*pdo_dbh_txn_func)(pdo_dbh_t *dbh);
/* transaction related (beingTransaction(), commit, rollBack, inTransaction)
* return true in case of success, false otherwise */
typedef bool (*pdo_dbh_txn_func)(pdo_dbh_t *dbh);

/* setting of attributes */
typedef int (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val);
/* setting of attributes
* Return true on success and false in case of failure */
typedef bool (*pdo_dbh_set_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val);

/* return last insert id. NULL indicates error condition, otherwise, the return value
* MUST be an emalloc'd NULL terminated string. */
typedef char *(*pdo_dbh_last_id_func)(pdo_dbh_t *dbh, const char *name, size_t *len);

/* fetch error information. if stmt is not null, fetch information pertaining
* to the statement, otherwise fetch global error information. The driver
* should add the following information to the array "info" in this order:
* to the statement, otherwise fetch global error information.
* Return true if there messages, otherwise return false.
* The driver should add the following information to the array "info" in this order:
* - native error code
* - string representation of the error code ... any other optional driver
* specific data ... */
typedef int (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);
* specific data ...
* PDO takes care of normalizing the array. */
typedef bool (*pdo_dbh_fetch_error_func)(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info);

/* fetching of attributes */
typedef int (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val);
/* fetching of attributes
* Return true on success and false in case of failure */
typedef bool (*pdo_dbh_get_attr_func)(pdo_dbh_t *dbh, zend_long attr, zval *val);

/* checking/pinging persistent connections; return SUCCESS if the connection
* is still alive and ready to be used, FAILURE otherwise.
* You may set this handler to NULL, which is equivalent to returning SUCCESS. */
typedef int (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh);
typedef zend_result (*pdo_dbh_check_liveness_func)(pdo_dbh_t *dbh);

/* called at request end for each persistent dbh; this gives the driver
* the opportunity to safely release resources that only have per-request
Expand Down Expand Up @@ -301,7 +307,8 @@ struct pdo_dbh_methods {
pdo_dbh_check_liveness_func check_liveness;
pdo_dbh_get_driver_methods_func get_driver_methods;
pdo_dbh_request_shutdown persistent_shutdown;
pdo_dbh_txn_func in_transaction;
pdo_dbh_txn_func in_transaction; /* if defined to NULL, PDO will use
* its internal transaction tracking state */
pdo_dbh_get_gc_func get_gc;
};

Expand Down Expand Up @@ -442,7 +449,7 @@ struct _pdo_dbh_t {
unsigned alloc_own_columns:1;

/* if true, commit or rollBack is allowed to be called */
unsigned in_txn:1;
bool in_txn:1;

/* max length a single character can become after correct quoting */
unsigned max_escaped_char_length:3;
Expand Down
Loading