com php-src: Cleanup (avoid reallocation): ext/odbc/php_odbc .c
| From: | Dmitry Stogov | Date: | Thu, 02 Jul 2015 16:09:37 +0000 |
| Subject: | com php-src: Cleanup (avoid reallocation): ext/odbc/php_odbc .c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87707@lists.php.net to get a copy of this message | ||
Commit: 07e646f8ffcbb896766c5df910cdb73eb6e3505f
Author: Dmitry Stogov <dmitry@zend.com> Thu, 2 Jul 2015 19:09:37 +0300
Parents: 9ea98d676b0b27e68a33d872928407750270503e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=07e646f8ffcbb896766c5df910cdb73eb6e3505f
Log:
Cleanup (avoid reallocation)
Changed paths:
M ext/odbc/php_odbc.c
Diff:
diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c
index 49432b6..b5f3b97 100644
--- a/ext/odbc/php_odbc.c
+++ b/ext/odbc/php_odbc.c
@@ -2058,6 +2058,7 @@ PHP_FUNCTION(odbc_fetch_row)
PHP_FUNCTION(odbc_result)
{
char *field;
+ zend_string *field_str;
int field_ind;
SQLSMALLINT sql_c_type = SQL_C_CHAR;
odbc_result *result;
@@ -2163,25 +2164,25 @@ PHP_FUNCTION(odbc_result)
}
/* For char data, the length of the returned string will be longreadlen - 1 */
fieldsize = (result->longreadlen <= 0) ? 4096 : result->longreadlen;
- field = emalloc(fieldsize);
+ field_str = zend_string_alloc(fieldsize, 0);
/* SQLGetData will truncate CHAR data to fieldsize - 1 bytes and append \0.
* For binary data it is truncated to fieldsize bytes.
*/
rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1), sql_c_type,
- field, fieldsize, &result->values[field_ind].vallen);
+ ZSTR_VAL(field_str), fieldsize, &result->values[field_ind].vallen);
if (rc == SQL_ERROR) {
odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
- efree(field);
+ zend_string_free(field_str);
RETURN_FALSE;
}
if (result->values[field_ind].vallen == SQL_NULL_DATA) {
- efree(field);
+ zend_string_free(field_str);
RETURN_NULL();
} else if (rc == SQL_NO_DATA_FOUND) {
- efree(field);
+ zend_string_free(field_str);
RETURN_FALSE;
}
/* Reduce fieldlen by 1 if we have char data. One day we might
@@ -2196,10 +2197,10 @@ PHP_FUNCTION(odbc_result)
/* Don't duplicate result, saves one emalloc.
For SQL_SUCCESS, the length is in vallen.
*/
- RETVAL_STRINGL(field, (rc == SQL_SUCCESS_WITH_INFO) ? fieldsize :
result->values[field_ind].vallen);
- // TODO: avoid dpouble reallocation ???
- efree(field);
- return;
+ if (rc != SQL_SUCCESS_WITH_INFO) {
+ field_str = zend_string_truncate(field_str, result->values[field_ind].vallen, 0);
+ }
+ RETURN_NEW_STR(field_str);
break;
default: