-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-13119: Changed to convert float and double values into strings using H
format
#13125
Conversation
e97a292
to
ffdd21f
Compare
…s using zend_gcvt
ffdd21f
to
ecd9839
Compare
ZVAL_STR(result, zend_strpprintf(0, "%F", *(float*)var->sqldata)); | ||
{ | ||
char f_buf[256]; | ||
zend_gcvt((double) get_float_from_sqldata(var->sqldata), 8, '.', 'E', f_buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't our custom %H
format specifier with zend_spprintf_unchecked
/[zend_strpprintf_unchecked](https://heap.space/s?defs=zend_strpprintf_unchecked&project=php-src)
do the trick?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that makes sense! I fixed it.
ZVAL_STR(result, zend_strpprintf(0, "%F", get_double_from_sqldata(var->sqldata))); | ||
{ | ||
char d_buf[256]; | ||
zend_gcvt(get_double_from_sqldata(var->sqldata), 16, '.', 'E', d_buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
@@ -459,11 +464,11 @@ static int firebird_stmt_get_col( | |||
break; | |||
case SQL_FLOAT: | |||
/* TODO: Why is this not returned as the native type? */ | |||
ZVAL_STR(result, zend_strpprintf(0, "%F", *(float*)var->sqldata)); | |||
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.*H", get_float_from_sqldata(var->sqldata), 8)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can use "%.8H" instead of "%.*H" (and get rid of the argument 8).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in that case, it seemed to use a macro that converted a string to a number, so I thought it would be more efficient to pass a number as an argument from the beginning.
TBH, I don't know how much the efficiency will change. Personally, I think either way of writing is fine, but do you think there is much difference in terms of efficiency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, then we can leave this as-is. I don't think the efficiency between the two differs noticeably though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand, but after correcting this, the test that was failing on Windows_ZTS passed.
break; | ||
case SQL_DOUBLE: | ||
/* TODO: Why is this not returned as the native type? */ | ||
ZVAL_STR(result, zend_strpprintf(0, "%F", get_double_from_sqldata(var->sqldata))); | ||
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.*H", get_double_from_sqldata(var->sqldata), 16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, but with 16 instead of 8.
[1]=> | ||
array(2) { | ||
["F_VAL"]=> | ||
string(7) "1.0E-16" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether the use of scientific notation breaks BC somehow though, although in arithmetic they might not as they're numeric strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do the calculations, so I think it's okay.
Hmm. Windows.... |
Maybe it's due to ZTS rather than Windows? |
I don't expect ZTS to make a difference here, there might be a subtle bug in the sprintf implementation from Zend, but I haven't investigated that yet. |
I haven't looked into it properly yet either. In this case, there are at least two places with conditional compilation related to ZTS. I thought it might not be an issue with ZTS itself, but rather an impact from these conditional compilations. (I won't know until I look into it properly...) Line 181 in ad9ec26
|
break; | ||
case SQL_DOUBLE: | ||
/* TODO: Why is this not returned as the native type? */ | ||
ZVAL_STR(result, zend_strpprintf(0, "%F", get_double_from_sqldata(var->sqldata))); | ||
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.16H", get_double_from_sqldata(var->sqldata))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need the unchecked variant now that we only pass one parameter. As I thought, the reason for the unchecked is to be able to pass the precision without the compiler freaking out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Do you think it's better to use zend_strpprintf
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the compiler doesn't complain, yes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you would expect, the compiler complained to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the current PR is fine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me if CI is happy and stable
zend_gcvt
H
format
closes #13119
At first, I made the base branch master by mistake, so the label was...