Skip to content

ext/intl: using a bit more modern c++ memory management features. #19163

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

Merged
merged 2 commits into from
Jul 18, 2025

Conversation

devnexen
Copy link
Member

not always possible (e.g. PHP objects) but when scoped we can manage here to simplify memory managament starting with IntlDateFormat.

not always possible (e.g. PHP objects) but when scoped we can manage
here to simplify memory managament starting with IntlDateFormat.
@devnexen devnexen marked this pull request as ready for review July 17, 2025 21:09
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the idea. Some comments.

@@ -70,10 +70,10 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
size_t locale_len;
bool pattern = false;
UDate date;
TimeZone *timeZone = NULL;
std::unique_ptr<TimeZone> timeZone = NULL;
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 it's not necessary to value-initialize these unique_ptrs.

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 true

"datefmt_format_object") == FAILURE) {
RETURN_FALSE;
}
cal = new GregorianCalendar(Locale::createFromName(locale_str), status);
timeZone = std::unique_ptr<TimeZone>(tz);
cal = std::unique_ptr<Calendar>(new GregorianCalendar(Locale::createFromName(locale_str), status));
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 you use make_unique here instead of unique_ptr+new ?

Copy link
Member Author

@devnexen devnexen Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish but isn't it C++14 minimum ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, and it's the ICU version that decides between C++11/C++17... Nvm then ;)

@devnexen devnexen merged commit 063d795 into php:master Jul 18, 2025
9 checks passed
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.

2 participants