fix +/* feature/bug prefix
[m6w6/ext-pq] / src / php_pqlob.c
index 2dc9be3d28004529cca0d35db95b5eb265bb766b..1c6e7b71bd499f7e7cb96aa27e548873f9acc99a 100644 (file)
@@ -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);
@@ -449,6 +450,12 @@ static zend_function_entry php_pqlob_methods[] = {
        {0}
 };
 
+PHP_MSHUTDOWN_FUNCTION(pqlob)
+{
+       zend_hash_destroy(&php_pqlob_object_prophandlers);
+       return SUCCESS;
+}
+
 PHP_MINIT_FUNCTION(pqlob)
 {
        zend_class_entry ce = {0};
@@ -463,6 +470,7 @@ PHP_MINIT_FUNCTION(pqlob)
        php_pqlob_object_handlers.write_property = php_pq_object_write_prop;
        php_pqlob_object_handlers.clone_obj = NULL;
        php_pqlob_object_handlers.get_property_ptr_ptr = NULL;
+       php_pqlob_object_handlers.get_gc = NULL;
        php_pqlob_object_handlers.get_properties = php_pq_object_properties;
        php_pqlob_object_handlers.get_debug_info = php_pq_object_debug_info;