summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2014-05-10 00:43:02 +0800
committerXinchen Hui <laruence@php.net>2014-05-10 00:43:02 +0800
commitb1c9d5ddeebb266a7d6d21a2561664e1369f6e42 (patch)
tree875d81d4de17ba91b00dcd94ebbb405421d0ee8b
parent88c550a7998d4af00767237b89f020ae3acac61b (diff)
downloadphp-git-b1c9d5ddeebb266a7d6d21a2561664e1369f6e42.tar.gz
Use strpprintf
-rw-r--r--ext/pdo/pdo_dbh.c12
-rw-r--r--ext/standard/fsock.c1
-rw-r--r--ext/standard/math.c26
-rw-r--r--ext/standard/uniqid.c10
4 files changed, 23 insertions, 26 deletions
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index da39634c79..9f286a5ca6 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -104,7 +104,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
const char *msg = "<<Unknown>>";
char *supp = NULL;
long native_code = 0;
- char *message = NULL;
+ zend_string *message = NULL;
zval info;
if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) {
@@ -141,20 +141,20 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
}
if (supp) {
- spprintf(&message, 0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
+ message = strpprintf(0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
} else {
- spprintf(&message, 0, "SQLSTATE[%s]: %s", *pdo_err, msg);
+ message = strpprintf(0, "SQLSTATE[%s]: %s", *pdo_err, msg);
}
if (dbh->error_mode == PDO_ERRMODE_WARNING) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message->val);
} else if (EG(exception) == NULL) {
zval ex;
zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception();
object_init_ex(&ex, pdo_ex);
- zend_update_property_string(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
+ zend_update_property_str(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
zend_update_property_string(def_ex, &ex, "code", sizeof("code") - 1, *pdo_err TSRMLS_CC);
if (!Z_ISUNDEF(info)) {
@@ -169,7 +169,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
}
if (message) {
- efree(message);
+ STR_RELEASE(message);
}
if (supp) {
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index 8e164bab38..5eacc2fe46 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -126,6 +126,7 @@ PHP_FUNCTION(fsockopen)
php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
+
/* {{{ proto resource pfsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
Open persistent Internet or Unix domain socket connection */
PHP_FUNCTION(pfsockopen)
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 71a2abc6d3..9e98fd35ff 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -1063,11 +1063,11 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len)
{
zend_string *res;
- char *tmpbuf;
+ zend_string *tmpbuf;
char *s, *t; /* source, target */
char *dp;
int integral;
- int tmplen, reslen = 0;
+ int reslen = 0;
int count = 0;
int is_negative=0;
@@ -1078,28 +1078,26 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
dec = MAX(0, dec);
d = _php_math_round(d, dec, PHP_ROUND_HALF_UP);
- tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d);
+ tmpbuf = strpprintf(0, "%.*F", dec, d);
if (tmpbuf == NULL) {
return NULL;
- } else if (!isdigit((int)tmpbuf[0])) {
- res = STR_INIT(tmpbuf, tmplen, 0);
- efree(tmpbuf);
- return res;
+ } else if (!isdigit((int)tmpbuf->val[0])) {
+ return tmpbuf;
}
/* find decimal point, if expected */
if (dec) {
- dp = strpbrk(tmpbuf, ".,");
+ dp = strpbrk(tmpbuf->val, ".,");
} else {
dp = NULL;
}
/* calculate the length of the return buffer */
if (dp) {
- integral = dp - tmpbuf;
+ integral = dp - tmpbuf->val;
} else {
/* no decimal point was found */
- integral = tmplen;
+ integral = tmpbuf->len;
}
/* allow for thousand separators */
@@ -1123,7 +1121,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
}
res = STR_ALLOC(reslen, 0);
- s = tmpbuf + tmplen - 1;
+ s = tmpbuf->val + tmpbuf->len - 1;
t = res->val + reslen;
*t-- = '\0';
@@ -1156,9 +1154,9 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
/* copy the numbers before the decimal point, adding thousand
* separator every three digits */
- while(s >= tmpbuf) {
+ while (s >= tmpbuf->val) {
*t-- = *s--;
- if (thousand_sep && (++count%3)==0 && s>=tmpbuf) {
+ if (thousand_sep && (++count%3)==0 && s>=tmpbuf->val) {
t -= thousand_sep_len;
memcpy(t + 1, thousand_sep, thousand_sep_len);
}
@@ -1170,7 +1168,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
}
res->len = reslen;
- efree(tmpbuf);
+ STR_RELEASE(tmpbuf);
return res;
}
diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c
index 610fb2809c..ddc87f51a8 100644
--- a/ext/standard/uniqid.c
+++ b/ext/standard/uniqid.c
@@ -49,7 +49,7 @@ PHP_FUNCTION(uniqid)
#else
zend_bool more_entropy = 0;
#endif
- char *uniqid;
+ zend_string *uniqid;
int sec, usec, prefix_len = 0;
struct timeval tv;
@@ -76,14 +76,12 @@ PHP_FUNCTION(uniqid)
* digits for usecs.
*/
if (more_entropy) {
- spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
+ uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
} else {
- spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
+ uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec);
}
- // TODO: avoid reallocation ???
- RETVAL_STRING(uniqid);
- efree(uniqid);
+ RETURN_STR(uniqid);
}
#endif
/* }}} */