X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqlob.c;h=1c6e7b71bd499f7e7cb96aa27e548873f9acc99a;hp=96b495ec5e90c7e2afee81c44316d032f346300c;hb=f2b5f0a77cd3d7fbf5a4ba88320dcfbd03f02107;hpb=88440266c0a9fa8354688b5ed0d2a6cc3bf04db5 diff --git a/src/php_pqlob.c b/src/php_pqlob.c index 96b495e..1c6e7b7 100644 --- a/src/php_pqlob.c +++ b/src/php_pqlob.c @@ -153,7 +153,7 @@ static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t len return read; } -static STATUS php_pqlob_stream_close(php_stream *stream, int close_handle TSRMLS_DC) +static ZEND_RESULT_CODE php_pqlob_stream_close(php_stream *stream, int close_handle TSRMLS_DC) { return SUCCESS; } @@ -163,9 +163,9 @@ static int php_pqlob_stream_flush(php_stream *stream TSRMLS_DC) return SUCCESS; } -static STATUS php_pqlob_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) +static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) { - STATUS rv = FAILURE; + ZEND_RESULT_CODE rv = FAILURE; php_pqlob_object_t *obj = stream->abstract; if (obj) { @@ -236,16 +236,19 @@ static PHP_METHOD(pqlob, __construct) { zend_error_handling zeh; zval *ztxn; long mode = INV_WRITE|INV_READ, loid = InvalidOid; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &ztxn, php_pqtxn_class_entry, &loid, &mode); zend_restore_error_handling(&zeh TSRMLS_CC); if (SUCCESS == rv) { + php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); php_pqtxn_object_t *txn_obj = zend_object_store_get_object(ztxn TSRMLS_CC); - if (!txn_obj->intern) { + if (obj->intern) { + throw_exce(EX_BAD_METHODCALL TSRMLS_CC, "pq\\LOB already initialized"); + } else if (!txn_obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Transaction not initialized"); } else if (!txn_obj->intern->open) { throw_exce(EX_RUNTIME TSRMLS_CC, "pq\\Transation already closed"); @@ -255,15 +258,13 @@ static PHP_METHOD(pqlob, __construct) { } if (loid == InvalidOid) { - throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create large object with mode '%s' (%s)", strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn)); + throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to create large object with mode '%s' (%s)", php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn)); } else { int lofd = lo_open(txn_obj->intern->conn->intern->conn, loid, mode); if (lofd < 0) { - throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn)); + throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to open large object with oid=%u with mode '%s' (%s)", loid, php_pq_strmode(mode), PHP_PQerrorMessage(txn_obj->intern->conn->intern->conn)); } else { - php_pqlob_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - obj->intern = ecalloc(1, sizeof(*obj->intern)); obj->intern->lofd = lofd; obj->intern->loid = loid; @@ -284,7 +285,7 @@ static PHP_METHOD(pqlob, write) { zend_error_handling zeh; char *data_str; int data_len; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_str, &data_len); @@ -317,7 +318,7 @@ static PHP_METHOD(pqlob, read) { zend_error_handling zeh; long length = 0x1000; zval *zread = NULL; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lz!", &length, &zread); @@ -356,7 +357,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(pqlob, seek) { zend_error_handling zeh; long offset, whence = SEEK_SET; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &offset, &whence); @@ -385,7 +386,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_tell, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(pqlob, tell) { zend_error_handling zeh; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters_none(); @@ -416,7 +417,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(pqlob, truncate) { zend_error_handling zeh; long length = 0; - STATUS rv; + ZEND_RESULT_CODE rv; zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC); rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &length);