Skip to content

Commit aad974a

Browse files
committed
Cleanup (avoid reallocations)
1 parent 44d8d01 commit aad974a

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

ibase_blobs.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,15 @@ int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd) /* {{{ */
7070
}
7171
/* }}} */
7272

73-
char *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */
73+
zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */
7474
{
75-
char *result;
76-
7775
/* shortcut for most common case */
7876
if (sizeof(ISC_QUAD) == sizeof(ISC_UINT64)) {
79-
spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd);
77+
return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd);
8078
} else {
8179
ISC_UINT64 res = ((ISC_UINT64) qd.gds_quad_high << 0x20) | qd.gds_quad_low;
82-
spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res);
80+
return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res);
8381
}
84-
return result;
8582
}
8683
/* }}} */
8784

@@ -347,7 +344,6 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
347344
{
348345
zval *blob_arg;
349346
ibase_blob *ib_blob;
350-
char *s;
351347

352348
RESET_ERRMSG;
353349

@@ -367,10 +363,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
367363
}
368364
ib_blob->bl_handle = NULL;
369365

370-
s = _php_ibase_quad_to_string(ib_blob->bl_qd);
371-
// TODO: avoid double reallocation???
372-
RETVAL_STRINGL(s, BLOB_ID_LEN);
373-
efree(s);
366+
RETVAL_NEW_STR(_php_ibase_quad_to_string(ib_blob->bl_qd));
374367
} else { /* discard created blob */
375368
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
376369
_php_ibase_error();
@@ -550,7 +543,6 @@ PHP_FUNCTION(ibase_blob_import)
550543
ibase_trans *trans = NULL;
551544
char bl_data[IBASE_BLOB_SEG];
552545
php_stream *stream;
553-
char *s;
554546

555547
RESET_ERRMSG;
556548

@@ -578,11 +570,7 @@ PHP_FUNCTION(ibase_blob_import)
578570
if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) {
579571
break;
580572
}
581-
s = _php_ibase_quad_to_string(ib_blob.bl_qd);
582-
// TODO: avoid double reallocation???
583-
RETVAL_STRINGL(s, BLOB_ID_LEN);
584-
efree(s);
585-
return;
573+
RETURN_NEW_STR(_php_ibase_quad_to_string(ib_blob.bl_qd));
586574
} while (0);
587575

588576
_php_ibase_error();

ibase_query.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
15991599
} else { /* blob id only */
16001600
char *s;
16011601
ISC_QUAD bl_qd = *(ISC_QUAD *) var->sqldata;
1602-
s = _php_ibase_quad_to_string(bl_qd);
1603-
ZVAL_STRINGL(&result, s, BLOB_ID_LEN);
1604-
efree(s);
1602+
ZVAL_NEW_STR(&result, _php_ibase_quad_to_string(bl_qd));
16051603
}
16061604
break;
16071605
case SQL_ARRAY:
@@ -1626,10 +1624,8 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
16261624
efree(ar_data);
16271625

16281626
} else { /* blob id only */
1629-
char *s;
16301627
ISC_QUAD ar_qd = *(ISC_QUAD *) var->sqldata;
1631-
s = _php_ibase_quad_to_string(ar_qd);
1632-
ZVAL_STRINGL(&result, s, BLOB_ID_LEN);
1628+
ZVAL_NEW_STR(&result, _php_ibase_quad_to_string(ar_qd));
16331629
}
16341630
break;
16351631
_php_ibase_fetch_error:

php_ibase_includes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void php_ibase_query_minit(INIT_FUNC_ARGS);
180180
/* provided by ibase_blobs.c */
181181
void php_ibase_blobs_minit(INIT_FUNC_ARGS);
182182
int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd);
183-
char *_php_ibase_quad_to_string(ISC_QUAD const qd);
183+
zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd);
184184
int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long max_len);
185185
int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob);
186186

0 commit comments

Comments
 (0)