diff options
| author | Xinchen Hui <laruence@gmail.com> | 2014-05-05 14:26:23 +0800 | 
|---|---|---|
| committer | Xinchen Hui <laruence@gmail.com> | 2014-05-05 14:26:23 +0800 | 
| commit | fee9d4cafd02cb37177179b216fb21baf7041d30 (patch) | |
| tree | 28fea6dd63ecd9429d295435c716e798e204189e /ext/bcmath/libbcmath/src | |
| parent | 7e3989f3014eba41fcdc44535723833029dc1ecf (diff) | |
| download | php-git-fee9d4cafd02cb37177179b216fb21baf7041d30.tar.gz | |
Refactor bcmath
Diffstat (limited to 'ext/bcmath/libbcmath/src')
| -rw-r--r-- | ext/bcmath/libbcmath/src/bcmath.h | 2 | ||||
| -rw-r--r-- | ext/bcmath/libbcmath/src/num2str.c | 58 | 
2 files changed, 31 insertions, 29 deletions
diff --git a/ext/bcmath/libbcmath/src/bcmath.h b/ext/bcmath/libbcmath/src/bcmath.h index 3d7c478648..1e75cbdca3 100644 --- a/ext/bcmath/libbcmath/src/bcmath.h +++ b/ext/bcmath/libbcmath/src/bcmath.h @@ -111,7 +111,7 @@ _PROTOTYPE(void bc_init_num, (bc_num *num TSRMLS_DC));  _PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale TSRMLS_DC)); -_PROTOTYPE(char *bc_num2str, (bc_num num)); +_PROTOTYPE(zend_string *bc_num2str, (bc_num num));  _PROTOTYPE(void bc_int2num, (bc_num *num, int val)); diff --git a/ext/bcmath/libbcmath/src/num2str.c b/ext/bcmath/libbcmath/src/num2str.c index 14c57726fe..47990d2e92 100644 --- a/ext/bcmath/libbcmath/src/num2str.c +++ b/ext/bcmath/libbcmath/src/num2str.c @@ -40,40 +40,42 @@  /* Convert a numbers to a string.  Base 10 only.*/ -char +zend_string  *bc_num2str (num)        bc_num num;  { -  char *str, *sptr; -  char *nptr; -  int  index, signch; +	zend_string *str; +	char *sptr; +	char *nptr; +	int  index, signch; -  /* Allocate the string memory. */ -  signch = ( num->n_sign == PLUS ? 0 : 1 );  /* Number of sign chars. */ -  if (num->n_scale > 0) -    str = (char *) safe_emalloc (1, num->n_len + num->n_scale, 2 + signch); -  else -    str = (char *) safe_emalloc (1, num->n_len, 1 + signch); -  if (str == NULL) bc_out_of_memory(); +	/* Allocate the string memory. */ +	signch = ( num->n_sign == PLUS ? 0 : 1 );  /* Number of sign chars. */ +	if (num->n_scale > 0) +		str = STR_ALLOC(num->n_len + num->n_scale + signch + 1, 0); +	else +		str = STR_ALLOC(num->n_len + signch, 0); +	if (str == NULL) bc_out_of_memory(); -  /* The negative sign if needed. */ -  sptr = str; -  if (signch) *sptr++ = '-'; +	/* The negative sign if needed. */ +	sptr = str->val; +	if (signch) *sptr++ = '-'; -  /* Load the whole number. */ -  nptr = num->n_value; -  for (index=num->n_len; index>0; index--) -    *sptr++ = BCD_CHAR(*nptr++); +	/* Load the whole number. */ +	nptr = num->n_value; +	for (index=num->n_len; index>0; index--) +		*sptr++ = BCD_CHAR(*nptr++); -  /* Now the fraction. */ -  if (num->n_scale > 0) -    { -      *sptr++ = '.'; -      for (index=0; index<num->n_scale; index++) -	*sptr++ = BCD_CHAR(*nptr++); -    } +	/* Now the fraction. */ +	if (num->n_scale > 0) +	{ +		*sptr++ = '.'; +		for (index=0; index<num->n_scale; index++) +			*sptr++ = BCD_CHAR(*nptr++); +	} -  /* Terminate the string and return it! */ -  *sptr = '\0'; -  return (str); +	/* Terminate the string and return it! */ +	*sptr = '\0'; +	str->len = sptr - (char *)str->val; +	return str;  }  | 
