[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] PHP-8.2: Fix GH-12558 Escape \N in generated stubs (#12562)
From:       Máté_Kocsis_via_GitHub <noreply () php ! net>
Date:       2023-10-31 9:20:31
Message-ID: 4w9lbsQT0HukrZJxwtlMzcwjXsSN1ts7MxlB83rR44Q () main ! php ! net
[Download RAW message or body]

Author: Máté Kocsis (kocsismate)
Committer: GitHub (web-flow)
Pusher: kocsismate
Date: 2023-10-31T10:06:56+01:00

Commit: https://github.com/php/php-src/commit/d4e40dc0e1dc48533fc42ec167d99f8cad64ae37
 Raw diff: https://github.com/php/php-src/commit/d4e40dc0e1dc48533fc42ec167d99f8cad64ae37.diff


Fix GH-12558 Escape \N in generated stubs (#12562)

Changed paths:
  M  NEWS
  M  build/gen_stub.php
  M  ext/zend_test/test.c
  M  ext/zend_test/test.stub.php
  M  ext/zend_test/test_arginfo.h
  M  ext/zend_test/tests/gen_stub_test_01.phpt


Diff:

diff --git a/NEWS b/NEWS
index c1f6557de1003..a09e308174154 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ PHP                                                                 \
NEWS  property via trait). (ilutov)
   . Fixed segfault caused by weak references to FFI objects. (sj-i)
   . Fixed max_execution_time: don't delete an unitialized timer. (Kévin Dunglas)
+  . Fixed bug GH-12558 (Arginfo soft-breaks with namespaced class return type
+    if the class name starts with N). (kocsismate)
 
 - DOM:
   . Fix registerNodeClass with abstract class crashing. (nielsdos)
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 7df5290883691..0c745c8c03068 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -527,10 +527,10 @@ public function toOptimizerTypeMask(): string {
     }
 
     public function toEscapedName(): string {
-        // Escape backslashes, and also encode \u and \U to avoid compilation errors \
in generated macros +        // Escape backslashes, and also encode \u, \U, and \N to \
avoid compilation errors in generated macros  return str_replace(
-            ['\\', '\\u', '\\U'],
-            ['\\\\', '\\\\165', '\\\\125'],
+            ['\\', '\\u', '\\U', '\\N'],
+            ['\\\\', '\\\\165', '\\\\125', '\\\\116'],
             $this->name
         );
     }
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index 88b7d5d904eef..4371459a910bd 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -52,6 +52,7 @@ static zend_class_entry \
*zend_test_child_class_with_method_with_parameter_attrib  static zend_class_entry \
*zend_test_forbid_dynamic_call;  static zend_class_entry *zend_test_ns_foo_class;
 static zend_class_entry *zend_test_ns_unlikely_compile_error_class;
+static zend_class_entry *zend_test_ns_not_unlikely_compile_error_class;
 static zend_class_entry *zend_test_ns2_foo_class;
 static zend_class_entry *zend_test_ns2_ns_foo_class;
 static zend_class_entry *zend_test_unit_enum;
@@ -636,6 +637,13 @@ static ZEND_METHOD(ZendTestNS_UnlikelyCompileError, method)
 	RETURN_NULL();
 }
 
+static ZEND_METHOD(ZendTestNS_NotUnlikelyCompileError, method)
+{
+	ZEND_PARSE_PARAMETERS_NONE();
+
+	RETURN_NULL();
+}
+
 static ZEND_METHOD(ZendTestNS2_Foo, method)
 {
 	ZEND_PARSE_PARAMETERS_NONE();
@@ -818,6 +826,7 @@ PHP_MINIT_FUNCTION(zend_test)
 
 	zend_test_ns_foo_class = register_class_ZendTestNS_Foo();
 	zend_test_ns_unlikely_compile_error_class = \
register_class_ZendTestNS_UnlikelyCompileError(); \
+	zend_test_ns_not_unlikely_compile_error_class = \
register_class_ZendTestNS_NotUnlikelyCompileError();  zend_test_ns2_foo_class = \
register_class_ZendTestNS2_Foo();  zend_test_ns2_ns_foo_class = \
register_class_ZendTestNS2_ZendSubNS_Foo();  
diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php
index 5ebe6b574b666..eaed7e2794aeb 100644
--- a/ext/zend_test/test.stub.php
+++ b/ext/zend_test/test.stub.php
@@ -190,6 +190,11 @@ class UnlikelyCompileError {
         public function method(): ?UnlikelyCompileError {}
     }
 
+    class NotUnlikelyCompileError {
+        /* This method signature would create a compile error due to the string
+         * "ZendTestNS\NotUnlikelyCompileError" in the generated macro call */
+        public function method(): ?NotUnlikelyCompileError {}
+    }
 }
 
 namespace ZendTestNS2 {
diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h
index 5a3af3879d7d6..72b89ef33342f 100644
--- a/ext/zend_test/test_arginfo.h
+++ b/ext/zend_test/test_arginfo.h
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: fa6d8c58bdef20c6c9c8db75dbb6ede775324193 */
+ * Stub hash: 37c6d5e5e28a60b3d1cf89c1a2f82a0196fceae7 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, \
IS_ARRAY, 0)  ZEND_END_ARG_INFO()
@@ -171,6 +171,9 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ZendTestNS_UnlikelyCompileError_method, \
0, 0, ZendTestNS\\\125nlikelyCompileError, 1)  ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_ZendTestNS_NotUnlikelyCompileError_method, \
0, 0, ZendTestNS\\\116otUnlikelyCompileError, 1) +ZEND_END_ARG_INFO()
+
 #define arginfo_class_ZendTestNS2_Foo_method arginfo_zend_test_void_return
 
 #define arginfo_class_ZendTestNS2_ZendSubNS_Foo_method arginfo_zend_test_void_return
@@ -225,6 +228,7 @@ static ZEND_METHOD(ZendTestForbidDynamicCall, call);
 static ZEND_METHOD(ZendTestForbidDynamicCall, callStatic);
 static ZEND_METHOD(ZendTestNS_Foo, method);
 static ZEND_METHOD(ZendTestNS_UnlikelyCompileError, method);
+static ZEND_METHOD(ZendTestNS_NotUnlikelyCompileError, method);
 static ZEND_METHOD(ZendTestNS2_Foo, method);
 static ZEND_METHOD(ZendTestNS2_ZendSubNS_Foo, method);
 
@@ -364,6 +368,12 @@ static const zend_function_entry \
class_ZendTestNS_UnlikelyCompileError_methods[]  };
 
 
+static const zend_function_entry class_ZendTestNS_NotUnlikelyCompileError_methods[] \
= { +	ZEND_ME(ZendTestNS_NotUnlikelyCompileError, method, \
arginfo_class_ZendTestNS_NotUnlikelyCompileError_method, ZEND_ACC_PUBLIC) \
+	ZEND_FE_END +};
+
+
 static const zend_function_entry class_ZendTestNS2_Foo_methods[] = {
 	ZEND_ME(ZendTestNS2_Foo, method, arginfo_class_ZendTestNS2_Foo_method, \
ZEND_ACC_PUBLIC)  ZEND_FE_END
@@ -698,6 +708,16 @@ static zend_class_entry \
*register_class_ZendTestNS_UnlikelyCompileError(void)  return class_entry;
 }
 
+static zend_class_entry *register_class_ZendTestNS_NotUnlikelyCompileError(void)
+{
+	zend_class_entry ce, *class_entry;
+
+	INIT_NS_CLASS_ENTRY(ce, "ZendTestNS", "NotUnlikelyCompileError", \
class_ZendTestNS_NotUnlikelyCompileError_methods); +	class_entry = \
zend_register_internal_class_ex(&ce, NULL); +
+	return class_entry;
+}
+
 static zend_class_entry *register_class_ZendTestNS2_Foo(void)
 {
 	zend_class_entry ce, *class_entry;
diff --git a/ext/zend_test/tests/gen_stub_test_01.phpt \
b/ext/zend_test/tests/gen_stub_test_01.phpt index 0a020a6f3457c..0f5d525322d62 100644
--- a/ext/zend_test/tests/gen_stub_test_01.phpt
+++ b/ext/zend_test/tests/gen_stub_test_01.phpt
@@ -11,6 +11,8 @@ $foo->foo = new \ZendTestNS2\ZendSubNS\Foo();
 var_dump($foo);
 $foo = new \ZendTestNS\UnlikelyCompileError();
 var_dump($foo);
+$foo = new \ZendTestNS\NotUnlikelyCompileError();
+var_dump($foo);
 ?>
 --EXPECTF--
 object(ZendTestNS2\Foo)#%d (%d) {
@@ -24,3 +26,5 @@ object(ZendTestNS2\Foo)#%d (%d) {
 }
 object(ZendTestNS\UnlikelyCompileError)#%d (%d) {
 }
+object(ZendTestNS\NotUnlikelyCompileError)#%d (%d) {
+}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic