[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

Compile error on MacOS with C++ extension when using ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX #12123

Closed
dktapps opened this issue Sep 4, 2023 · 10 comments

Comments

@dktapps
Copy link
Contributor
dktapps commented Sep 4, 2023

Description

https://github.com/pmmp/ext-morton/blob/2532e9f09d3bc6f6975d78b6632086b894dcef75/morton.cpp#L45

This code compiles fine with GCC on Ubuntu 20.04 on 8.3.0RC1, but fails on MacOS with clang with the following errors:

/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/ext/morton/morton.cpp:45:1: error: expected '(' for function-style cast or type construction
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_morton2d_encode, 0, 2, IS_LONG, 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_API.h:202:2: note: expanded from macro 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX'
        ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2(name, return_reference, required_num_args, type, allow_null, 0)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_API.h:199:50: note: expanded from macro 'ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX2'
                { (const char*)(uintptr_t)(required_num_args), ZEND_TYPE_INIT_CODE(type, allow_null, _ZEND_ARG_INFO_FLAGS(return_reference, 0, is_tentative_return_type)), NULL },
                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_types.h:287:2: note: expanded from macro 'ZEND_TYPE_INIT_CODE'
        ZEND_TYPE_INIT_MASK(((code) == _IS_BOOL ? MAY_BE_BOOL : ( (code) == IS_ITERABLE ? _ZEND_TYPE_ITERABLE_BIT : ((code) == IS_MIXED ? MAY_BE_ANY : (1 << (code))))) \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_types.h:284:20: note: expanded from macro 'ZEND_TYPE_INIT_MASK'
        _ZEND_TYPE_PREFIX { NULL, (_type_mask) }
        ~~~~~~~~~~~~~~~~~ ^
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/ext/morton/morton.cpp:46:2: error: expected '(' for function-style cast or type construction
        ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0)
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_API.h:135:11: note: expanded from macro 'ZEND_ARG_TYPE_INFO'
        { #name, ZEND_TYPE_INIT_CODE(type_hint, allow_null, _ZEND_ARG_INFO_FLAGS(pass_by_ref, 0, 0)), NULL },
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_types.h:287:2: note: expanded from macro 'ZEND_TYPE_INIT_CODE'
        ZEND_TYPE_INIT_MASK(((code) == _IS_BOOL ? MAY_BE_BOOL : ( (code) == IS_ITERABLE ? _ZEND_TYPE_ITERABLE_BIT : ((code) == IS_MIXED ? MAY_BE_ANY : (1 << (code))))) \
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/runner/work/PHP-Binaries/PHP-Binaries/install_data/subdir/php/Zend/zend_types.h:284:20: note: expanded from macro 'ZEND_TYPE_INIT_MASK'
        _ZEND_TYPE_PREFIX { NULL, (_type_mask) }
        ~~~~~~~~~~~~~~~~~ ^

I believe this problem was caused by a change in #11978.

PHP Version

8.3.0RC1

Operating System

MacOS 11 (GitHub Actions)

@iluuu1994
Copy link
Member

@kocsismate Can you take a look?

@kocsismate kocsismate self-assigned this Sep 4, 2023
@Girgias
Copy link
Member
Girgias commented Sep 4, 2023

Considering the intl extensions compiles just fine on MacOS, the only difference is that it defines the arg infos in an autogenerated header file.

So maybe the new macro _ZEND_TYPE_PREFIX to fix the Windows issue is causing some weird CPP issues?

@dktapps
Copy link
Contributor Author
dktapps commented Sep 5, 2023

Not sure which Windows issue you're referring to, as I've been compiling the linked C++ extension on Windows and *nix for years across several different PHP versions with no issues.

If the intl arginfos are included inside an extern "C", that would likely explain the difference in behaviour.

@Girgias
Copy link
Member
Girgias commented Sep 6, 2023

Not sure which Windows issue you're referring to, as I've been compiling the linked C++ extension on Windows and *nix for years across several different PHP versions with no issues.

If the intl arginfos are included inside an extern "C", that would likely explain the difference in behaviour.

I am talking about the introduction of:

/* FIXME: We could add (zend_type) here at some point but this breaks in MSVC because
 * (zend_type)(zend_type){} is no longer considered constant. */
# define _ZEND_TYPE_PREFIX

Which as far as I can see was introduced because of a MSVC issue, and MSVC is the Windows compiler.

But yes, they include the arginfos via an extern "C" {}

@dktapps
Copy link
Contributor Author
dktapps commented Sep 6, 2023

The empty macro appears to be working correct. The other branch under #ifdef __cplusplus is the problem.

@kocsismate
Copy link
Member

The empty macro appears to be working correct. The other branch under #ifdef __cplusplus is the problem.

Thanks for the confirmation ! I guess we have to make it only apply to MSVC.

@dktapps
Copy link
Contributor Author
dktapps commented Sep 6, 2023

I'm just a little puzzled as to what this new macro actually fixes. As I said, the C++ extension I linked has been compiled with MSVC, clang and gcc on Linux, MacOS and Windows for several years, and had no issues without this macro.

I found this commit in the PR that added it, but I don't see any specifics on what exactly it fixed: 62341c0

@kocsismate
Copy link
Member
kocsismate commented Sep 6, 2023

Finally, I found it: https://github.com/php/php-src/actions/runs/5442753605/job/14732712171#step:7:1318

D:\a\php-src\php-src\ext\intl\timezone\timezone_arginfo.h(177): error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax (compiling source file ext\intl\timezone\timezone_class.cpp)

For reference: the following line made untyped constants and properties use the construct unsupported by MSVC: https://github.com/php/php-src/pull/10170/files#diff-5df7a541a3649c4a1ad7870312ebdcd836b6c36dc1dc65c8fda8271c210e014dR2267 (line 2267 in gen_stub.php) The test failure appeared when I merged my original PR to master (#10170). On the other hand, the build was green on PHP-8.2. Then the PR was reverted, and the new one was applied along with Ilija's fix a few weeks later.

@Girgias
Copy link
Member
Girgias commented Sep 6, 2023

Okay so the need for this type macro prefix is only when we include the arg infos in an extern C in a C++ file for MSVC?

I wonder if it makes more sense to move the arginfo includes out of the extern C for intl and see if we can remove the macro altogether?

@iluuu1994
Copy link
Member

I'm not sure if that helps. AFAIK (not knowing C++ at all), designated initializers are a g++ extension, until C++20 where they have finally been standardized with C compatibility. The usual way to initialize structs in C++ is struct_name { ... }, hence the marco. MS doesn't support many extensions in C/C++, that's likely the cause for this failure.

kocsismate added a commit that referenced this issue Sep 10, 2023
* PHP-8.3:
  Fix #12123 Make _ZEND_TYPE_PREFIX apply only for MSVC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants