summaryrefslogtreecommitdiff
path: root/ext/interbase/ibase_blobs.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-07-29 10:15:01 +0400
committerDmitry Stogov <dmitry@zend.com>2014-07-29 10:15:01 +0400
commit21dec5f511f8d3c5973e921d468359ad459545f5 (patch)
tree3c4db91ab5981ae894566e48af509c31e6d6f009 /ext/interbase/ibase_blobs.c
parent466816d4ef44a54a6846cc08ad583bf600f832aa (diff)
downloadphp-git-21dec5f511f8d3c5973e921d468359ad459545f5.tar.gz
ext/interbase support (incomplete)
Diffstat (limited to 'ext/interbase/ibase_blobs.c')
-rw-r--r--ext/interbase/ibase_blobs.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c
index 94f32f87ed..8b8d731d7b 100644
--- a/ext/interbase/ibase_blobs.c
+++ b/ext/interbase/ibase_blobs.c
@@ -32,7 +32,7 @@
static int le_blob;
-static void _php_ibase_free_blob(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
+static void _php_ibase_free_blob(zend_resource *rsrc TSRMLS_DC) /* {{{ */
{
ibase_blob *ib_blob = (ibase_blob *)rsrc->ptr;
@@ -118,26 +118,28 @@ int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long m
_php_ibase_error(TSRMLS_C);
return FAILURE;
}
- RETVAL_STRINGL(bl_data, cur_len, 0);
+ // TODO: avoid double reallocation???
+ RETVAL_STRINGL(bl_data, cur_len);
+ efree(bl_data);
} else { /* null blob */
- RETVAL_STRING("", 1); /* empty string */
+ RETVAL_EMPTY_STRING(); /* empty string */
}
return SUCCESS;
}
/* }}} */
-int _php_ibase_blob_add(zval **string_arg, ibase_blob *ib_blob TSRMLS_DC) /* {{{ */
+int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob TSRMLS_DC) /* {{{ */
{
unsigned long put_cnt = 0, rem_cnt;
unsigned short chunk_size;
convert_to_string_ex(string_arg);
- for (rem_cnt = Z_STRLEN_PP(string_arg); rem_cnt > 0; rem_cnt -= chunk_size) {
+ for (rem_cnt = Z_STRLEN_P(string_arg); rem_cnt > 0; rem_cnt -= chunk_size) {
chunk_size = rem_cnt > USHRT_MAX ? USHRT_MAX : (unsigned short)rem_cnt;
- if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &Z_STRVAL_PP(string_arg)[put_cnt] )) {
+ if (isc_put_segment(IB_STATUS, &ib_blob->bl_handle, chunk_size, &Z_STRVAL_P(string_arg)[put_cnt] )) {
_php_ibase_error(TSRMLS_C);
return FAILURE;
}
@@ -228,6 +230,7 @@ PHP_FUNCTION(ibase_blob_create)
}
ZEND_REGISTER_RESOURCE(return_value, ib_blob, le_blob);
+ Z_ADDREF_P(return_value);
}
/* }}} */
@@ -278,6 +281,7 @@ PHP_FUNCTION(ibase_blob_open)
}
ZEND_REGISTER_RESOURCE(return_value, ib_blob, le_blob);
+ Z_ADDREF_P(return_value);
return;
} while (0);
@@ -291,7 +295,7 @@ PHP_FUNCTION(ibase_blob_open)
Add data into created blob */
PHP_FUNCTION(ibase_blob_add)
{
- zval **blob_arg, **string_arg;
+ zval *blob_arg, *string_arg;
ibase_blob *ib_blob;
RESET_ERRMSG;
@@ -317,7 +321,7 @@ PHP_FUNCTION(ibase_blob_add)
Get len bytes data from open blob */
PHP_FUNCTION(ibase_blob_get)
{
- zval **blob_arg, **len_arg;
+ zval *blob_arg, *len_arg;
ibase_blob *ib_blob;
RESET_ERRMSG;
@@ -335,7 +339,7 @@ PHP_FUNCTION(ibase_blob_get)
convert_to_long_ex(len_arg);
- if (_php_ibase_blob_get(return_value, ib_blob, Z_LVAL_PP(len_arg) TSRMLS_CC) != SUCCESS) {
+ if (_php_ibase_blob_get(return_value, ib_blob, Z_LVAL_P(len_arg) TSRMLS_CC) != SUCCESS) {
RETURN_FALSE;
}
}
@@ -343,8 +347,9 @@ PHP_FUNCTION(ibase_blob_get)
static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ */
{
- zval **blob_arg;
+ zval *blob_arg;
ibase_blob *ib_blob;
+ char *s;
RESET_ERRMSG;
@@ -364,7 +369,10 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
}
ib_blob->bl_handle = NULL;
- RETVAL_STRINGL(_php_ibase_quad_to_string(ib_blob->bl_qd), BLOB_ID_LEN, 0);
+ s = _php_ibase_quad_to_string(ib_blob->bl_qd);
+ // TODO: avoid double reallocation???
+ RETVAL_STRINGL(s, BLOB_ID_LEN);
+ efree(s);
} else { /* discard created blob */
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
_php_ibase_error(TSRMLS_C);
@@ -373,7 +381,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
ib_blob->bl_handle = NULL;
RETVAL_TRUE;
}
- zend_list_delete(Z_LVAL_PP(blob_arg));
+ zend_list_delete(Z_RES_P(blob_arg));
}
/* }}} */
@@ -544,6 +552,7 @@ PHP_FUNCTION(ibase_blob_import)
ibase_trans *trans = NULL;
char bl_data[IBASE_BLOB_SEG];
php_stream *stream;
+ char *s;
RESET_ERRMSG;
@@ -554,7 +563,7 @@ PHP_FUNCTION(ibase_blob_import)
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
- php_stream_from_zval(stream, &file);
+ php_stream_from_zval(stream, file);
do {
if (isc_create_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob.bl_handle,
@@ -571,7 +580,11 @@ PHP_FUNCTION(ibase_blob_import)
if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) {
break;
}
- RETURN_STRINGL( _php_ibase_quad_to_string(ib_blob.bl_qd), BLOB_ID_LEN, 0);
+ s = _php_ibase_quad_to_string(ib_blob.bl_qd);
+ // TODO: avoid double reallocation???
+ RETVAL_STRINGL(s, BLOB_ID_LEN);
+ efree(s);
+ return;
} while (0);
_php_ibase_error(TSRMLS_C);