fix master compatibility
[m6w6/ext-pq] / src / php_pqlob.c
index 51494720ab6b3df9d3dc021976d87b1ce71b0b38..5d1f6ba7e00b5328a1504beeb01a7bcae7ce1754 100644 (file)
@@ -32,7 +32,7 @@ static void php_pqlob_object_free(zend_object *o)
 {
        php_pqlob_object_t *obj = PHP_PQ_OBJ(NULL, o);
 #if DBG_GC
-       fprintf(stderr, "FREE lob(#%d) %p (txn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->txn->zv.handle, obj->intern->txn);
+       fprintf(stderr, "FREE lob(#%d) %p (txn(#%d): %p)\n", obj->zo.handle, obj, obj->intern->txn->zo.handle, obj->intern->txn);
 #endif
        if (obj->intern) {
                if (obj->intern->lofd) {
@@ -47,26 +47,13 @@ static void php_pqlob_object_free(zend_object *o)
                efree(obj->intern);
                obj->intern = NULL;
        }
-       zend_object_std_dtor(o);
-       efree(obj);
+       php_pq_object_dtor(o);
 }
 
 php_pqlob_object_t *php_pqlob_create_object_ex(zend_class_entry *ce, php_pqlob_t *intern)
 {
-       php_pqlob_object_t *o;
-
-       o = ecalloc(1, sizeof(*o) + zend_object_properties_size(ce));
-       zend_object_std_init(&o->zo, ce);
-       object_properties_init(&o->zo, ce);
-       o->prophandler = &php_pqlob_object_prophandlers;
-
-       if (intern) {
-               o->intern = intern;
-       }
-
-       o->zo.handlers = &php_pqlob_object_handlers;
-
-       return o;
+       return php_pq_object_create(ce, intern, sizeof(php_pqlob_object_t),
+                       &php_pqlob_object_handlers, &php_pqlob_object_prophandlers);
 }
 
 static zend_object *php_pqlob_create_object(zend_class_entry *class_type)
@@ -81,6 +68,15 @@ static void php_pqlob_object_read_transaction(zval *object, void *o, zval *retur
        php_pq_object_to_zval(obj->intern->txn, return_value);
 }
 
+static void php_pqlob_object_gc_transaction(zval *object, void *o, zval *return_value)
+{
+       php_pqlob_object_t *obj = o;
+       zval ztxn;
+
+       php_pq_object_to_zval_no_addref(obj->intern->txn, &ztxn);
+       add_next_index_zval(return_value, &ztxn);
+}
+
 static void php_pqlob_object_read_oid(zval *object, void *o, zval *return_value)
 {
        php_pqlob_object_t *obj = o;
@@ -101,10 +97,10 @@ static void php_pqlob_object_read_stream(zval *object, void *o, zval *return_val
                php_stream_to_zval(obj->intern->stream, &zstream);
        }
 
-       RETVAL_ZVAL(&zstream, 1, 1);
+       RETVAL_ZVAL(&zstream, 1, 0);
 }
 
-static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length TSRMLS_DC)
+static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, size_t length)
 {
        php_pqlob_object_t *obj = stream->abstract;
        int written = 0;
@@ -113,16 +109,16 @@ static size_t php_pqlob_stream_write(php_stream *stream, const char *buffer, siz
                written = lo_write(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, buffer, length);
 
                if (written < 0) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write to LOB with oid=%u (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                       php_error_docref(NULL, E_WARNING, "Failed to write to LOB with oid=%u (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                }
 
-               php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+               php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
        return written;
 }
 
-static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length TSRMLS_DC)
+static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t length)
 {
        php_pqlob_object_t *obj = stream->abstract;
        int read = 0;
@@ -137,27 +133,27 @@ static size_t php_pqlob_stream_read(php_stream *stream, char *buffer, size_t len
                        read = lo_read(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, buffer, length);
 
                        if (read < 0) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read from LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                               php_error_docref(NULL, E_WARNING, "Failed to read from LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        }
                }
 
-               php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+               php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
        return read;
 }
 
-static ZEND_RESULT_CODE 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)
 {
        return SUCCESS;
 }
 
-static int php_pqlob_stream_flush(php_stream *stream TSRMLS_DC)
+static int php_pqlob_stream_flush(php_stream *stream)
 {
        return SUCCESS;
 }
 
-static ZEND_RESULT_CODE 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)
 {
        ZEND_RESULT_CODE rv = FAILURE;
        php_pqlob_object_t *obj = stream->abstract;
@@ -166,14 +162,14 @@ static ZEND_RESULT_CODE php_pqlob_stream_seek(php_stream *stream, off_t offset,
                int position = lo_lseek(obj->intern->txn->intern->conn->intern->conn, obj->intern->lofd, offset, whence);
 
                if (position < 0) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek offset in LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
+                       php_error_docref(NULL, E_WARNING, "Failed to seek offset in LOB with oid=%d (%s)", obj->intern->loid, PHP_PQerrorMessage(obj->intern->txn->intern->conn->intern->conn));
                        rv = FAILURE;
                } else {
                        *newoffset = position;
                        rv = SUCCESS;
                }
 
-               php_pqconn_notify_listeners(obj->intern->txn->intern->conn TSRMLS_CC);
+               php_pqconn_notify_listeners(obj->intern->txn->intern->conn);
        }
 
        return rv;
@@ -209,6 +205,7 @@ static void php_pqlob_object_update_stream(zval *zpqlob, php_pqlob_object_t *obj
        php_stream_to_zval(obj->intern->stream, zstream);
 
        zend_get_std_object_handlers()->write_property(zpqlob, &zmember, zstream, NULL);
+       zval_ptr_dtor(&zmember);
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_pqlob_construct, 0, 0, 1)
@@ -426,7 +423,7 @@ static PHP_METHOD(pqlob, truncate) {
 }
 
 static zend_function_entry php_pqlob_methods[] = {
-       PHP_ME(pqlob, __construct, ai_pqlob_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+       PHP_ME(pqlob, __construct, ai_pqlob_construct, ZEND_ACC_PUBLIC)
        PHP_ME(pqlob, write, ai_pqlob_write, ZEND_ACC_PUBLIC)
        PHP_ME(pqlob, read, ai_pqlob_read, ZEND_ACC_PUBLIC)
        PHP_ME(pqlob, seek, ai_pqlob_seek, ZEND_ACC_PUBLIC)
@@ -457,23 +454,25 @@ 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_gc = php_pq_object_get_gc;
        php_pqlob_object_handlers.get_properties = php_pq_object_properties;
        php_pqlob_object_handlers.get_debug_info = php_pq_object_debug_info;
 
-       zend_hash_init(&php_pqlob_object_prophandlers, 3, NULL, NULL, 1);
+       zend_hash_init(&php_pqlob_object_prophandlers, 3, NULL, php_pq_object_prophandler_dtor, 1);
 
        zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("transaction"), ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_transaction;
+       ph.gc = php_pqlob_object_gc_transaction;
        zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "transaction", sizeof("transaction")-1, (void *) &ph, sizeof(ph));
+       ph.gc = NULL;
 
        zend_declare_property_long(php_pqlob_class_entry, ZEND_STRL("oid"), InvalidOid, ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_oid;
-       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "oid", sizeof("oid"), (void *) &ph, sizeof(ph));
+       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "oid", sizeof("oid")-1, (void *) &ph, sizeof(ph));
 
        zend_declare_property_null(php_pqlob_class_entry, ZEND_STRL("stream"), ZEND_ACC_PUBLIC);
        ph.read = php_pqlob_object_read_stream;
-       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "stream", sizeof("stream"), (void *) &ph, sizeof(ph));
+       zend_hash_str_add_mem(&php_pqlob_object_prophandlers, "stream", sizeof("stream")-1, (void *) &ph, sizeof(ph));
 
        zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("INVALID_OID"), InvalidOid);
        zend_declare_class_constant_long(php_pqlob_class_entry, ZEND_STRL("R"), INV_READ);