Nothing Special   »   [go: up one dir, main page]

Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

SakiTakamachi
Copy link
Member
@SakiTakamachi SakiTakamachi commented Jan 11, 2024

closes #13119

At first, I made the base branch master by mistake, so the label was...

@SakiTakamachi SakiTakamachi marked this pull request as ready for review January 14, 2024 02:30
@SakiTakamachi
Copy link
Member Author

I think there's probably a lot of conflict with master, so when merging this into master, it might be a good idea to prioritize master and create a separate PR for master later.

cc:
@nielsdos @Girgias

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);
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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));
Copy link
Member

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).

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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));
Copy link
Member

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"
Copy link
Member

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.

Copy link
Member Author

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.

https://3v4l.org/DL0bk

@SakiTakamachi
Copy link
Member Author

Hmm. Windows....

@SakiTakamachi
Copy link
Member Author

Maybe it's due to ZTS rather than Windows?

@nielsdos
Copy link
Member

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.

@SakiTakamachi
Copy link
Member Author

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...)

static void xbuf_format_converter(void *xbuf, bool is_char, const char *fmt, va_list ap) /* {{{ */

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)));
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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 :)

Copy link
Member Author

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 :)

Copy link
Member

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 :)

Copy link
Member
@Girgias Girgias left a 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

@SakiTakamachi SakiTakamachi changed the title Fix GH-13119: Changed to convert float and double values ​​into strings using zend_gcvt Fix GH-13119: Changed to convert float and double values ​​into strings using H format Jan 15, 2024
SakiTakamachi added a commit that referenced this pull request Jan 16, 2024
SakiTakamachi added a commit that referenced this pull request Jan 16, 2024
@SakiTakamachi SakiTakamachi deleted the fix/gh-13119 branch March 15, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants