Skip to content

Escape \U and \u in generated stubs #9154

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

Closed
wants to merge 3 commits into from

Conversation

alcaeus
Copy link
Contributor

@alcaeus alcaeus commented Jul 26, 2022

This fixes an issue where a namespaced class beginning with "U" or "u" would yield an invalid arginfo file due to the occurrence of a unicode escape sequence, causing a compile error.

Note: waiting for CI test results due to the absence of a local test environment.

@kocsismate
Copy link
Member

Hmm, I registered the UnlikelyCompileError class you added in this PR and everything seems to be working just fine without your fix. 🤔 Do you have an idea what makes the difference? Do we use different platform (I'm on a Mac)?

@alcaeus
Copy link
Contributor Author

alcaeus commented Jul 27, 2022

That's a good question. I'm compiling on MacOS as well. This is the macro that first caused the issue:

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___set_state, 0, 1, MongoDB\\BSON\\UTCDateTime, 0)

Replacing the U with \125 fixed the error for me:

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___set_state, 0, 1, MongoDB\\BSON\\\125TCDateTime, 0)

For reference, here's the compiler output:

In file included from src/BSON/UTCDateTime.c:28:
src/BSON/UTCDateTime_arginfo.h:22:112: error: \U used with no following hex digits; treating as '\' followed by identifier [-Werror,-Wunicode]
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___set_state, 0, 1, MongoDB\\BSON\\UTCDateTime, 0)
                                                                                                               ^
1 error generated.
make: *** [src/BSON/UTCDateTime.lo] Error 1

Let me know if I can provide any other information to help figure it out. I'll hold off on fixing the tests in the meantime so we can confirm whether this is a general issue or just something weird happening on my machine.

@guilliamxavier
Copy link
Contributor

guilliamxavier commented Jul 27, 2022

This seems to vary by compiler (at least GCC vs Clang vs MSVC), e.g. https://godbolt.org/z/vYh87Ghd4 (or https://godbolt.org/z/46PPb14f5)
(to be clear: this PR looks good)

Copy link
Contributor

@guilliamxavier guilliamxavier left a comment

Choose a reason for hiding this comment

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

A couple nits

@alcaeus alcaeus force-pushed the fix-class-escape-sequence branch from df2f415 to cb42578 Compare July 28, 2022 06:54
alcaeus and others added 2 commits July 28, 2022 09:02
This fixes an issue where a namespaced class beginning with "U" or "u" would yield an invalid arginfo file due to the occurrence of a unicode escape sequence, causing a compile error.
@alcaeus alcaeus force-pushed the fix-class-escape-sequence branch from cb42578 to 4373b22 Compare July 28, 2022 07:02
@cmb69
Copy link
Member

cmb69 commented Jul 28, 2022

This seems to vary by compiler (at least GCC vs Clang vs MSVC) , e.g. https://godbolt.org/z/vYh87Ghd4

Interesting! Using the new conformant preprocessor (/Zc:preprocessor) with MSVC, I get:

Foo??
Foo??
---
Foo\U0001F600
Foo\U0001F600
Foo\Unlikely
Foo\Unlikely
===
Foo\U0001F600
Foo\U0001F600
Foo\Unlikely
Foo\Unlikely

So a bit more conforming to GCC and clang.

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!

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.

4 participants