Skip to content

Remove custom alloca #8513

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 10 commits into from
May 27, 2022
Merged

Remove custom alloca #8513

merged 10 commits into from
May 27, 2022

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented May 7, 2022

Use do_alloca in place of alloca
Add support for Windows

There are 3 remaining usages of alloca which are located in FPM (fpm_sockets.c and fpm_env.c) which include the header. And I'm not sure if it is OK to include zend_portability.h in it.

@Girgias Girgias force-pushed the alloca branch 3 times, most recently from 212b11d to 62d021c Compare May 7, 2022 23:35
@Girgias Girgias marked this pull request as draft May 8, 2022 00:24
@Girgias Girgias marked this pull request as ready for review May 8, 2022 01:08
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

I guess it makes sense to drop our own alloca() implementation; it might be grossly out-dated, and might not be used often anyway.

}

if ((salt - (char *) 0) % __alignof__(uint32_t) != 0) {
char *tmp = (char *) alloca(salt_len + 1 + __alignof__(uint32_t));
tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint32_t), use_heap);
Copy link
Member

Choose a reason for hiding this comment

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

Same here, we can't reuse use_heap.

Comment on lines 350 to 356
# define ALLOCA_FLAG(name) \
bool name;
# define SET_ALLOCA_FLAG(name) \
name = 1
name = true
# define do_alloca_ex(size, limit, use_heap) \
((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size))
# define do_alloca(size, use_heap) \
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'm wondering, would it make sense to not enable it in debug mode? Which would make it clearer that a memory leak can appear if one forgets the corresponding free. As currently only macOS on CI is our safeguard, and I still don't really understand why it's not enabled on macOS

Copy link
Member

Choose a reason for hiding this comment

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

I don't know why it's not available on macOS, but the detection might not be handled properly from our side. Apparently, we doing AC_CHECK_HEADERS([alloca.h]), but later also AC_FUNC_ALLOCA, although that macro is supposed to check for alloca.h and set HAVE_ALLOCA_H, too. That might not be a real problem, though (I don't know enough about autoconf). I guess someone with access to a macOS machine would need to debug.

Anyhow, it might be a good idea to disable alloca() for debug mode.

Copy link
Member

@devnexen devnexen May 9, 2022

Choose a reason for hiding this comment

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

line 348, it s guarded with !defined(DARWIN)

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 know that, the reason is more why? I've been told apparently the behaviour on macOS and Linux is quite different.

Copy link
Member

Choose a reason for hiding this comment

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

seems it s like this since a long time, maybe the difference is no longer true ?

@bukka
Copy link
Member

bukka commented May 16, 2022

Think the FPM cases can be left as there's not much point to change them...

@ramsey ramsey added this to the PHP 8.2 milestone May 22, 2022
@Girgias Girgias merged commit 8685a7f into php:master May 27, 2022
@Girgias Girgias deleted the alloca branch May 27, 2022 08:05
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.

6 participants