Skip to content

Fix FFI calling conventions inside nested declarators - #25126

Open
nicolas-grekas wants to merge 1 commit into
php:PHP-8.4from
nicolas-grekas:ffi-nested-callconv
Open

nicolas-grekas wants to merge 1 commit into
php:PHP-8.4from
nicolas-grekas:ffi-nested-callconv

Conversation

@nicolas-grekas

@nicolas-grekas nicolas-grekas commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

FFI ignores the calling convention in void (__stdcall *f)(void). That's how Windows headers declare callbacks, for example PAPCFUNC. On x86, such a callback is created as cdecl. The callback then doesn't pop its argument and the stdcall caller crashes. That's why sleep_alertable_win32.phpt from #24399 crashes on nightly (#25125 changes the test).

In a parameter or a type name, as in FFI::type('void (__stdcall *)(int)'), the same syntax fails with "Unsupported type specifier combination".

A convention that the platform doesn't support is still ignored inside the parentheses. For example, void (__stdcall *f)(void) keeps parsing on x64, like before.

I updated ffi_parser.c by hand, the same way LLK generates the other cases.

FFI ignored the calling convention in "void (__stdcall *f)(void)", and
failed to parse it in parameters and type names.

A convention that the platform doesn't support stays ignored inside the
parentheses, so that such declarations keep parsing on x64.
@nicolas-grekas

Copy link
Copy Markdown
Contributor Author

PR updated. A calling convention that the platform doesn't support is ignored inside the parentheses again, as before this PR. typedef int (__stdcall *F)(void *); parses on x64 today, so I don't want to make it throw in a patch release.

The x86 Windows job only runs with the "CI: All variations" label. Could someone add it?

/cc @shivammathur @ndossche since this fixes the cause of #25125

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.

1 participant