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

[4.x] properly define function aliasses #284

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

remicollet
Copy link
Contributor

@remicollet remicollet commented Dec 21, 2022

Digging in extension reflection, I notice:

    Method [ <internal:openswoole> public method swoole_timer_list ] {

      - Parameters [0] {
      }
      - Return [ <D9>' ]

1/ this is obviously not a method
2/ return type is corrupted

Looking its code, it seems SW_FUNCTION_ALIAS does wrong things.

This PR drop most usage and use standard API call.

NOTICE: some usages are still there, perhaps have to be cleaned later:

./ext-src/php_swoole.cc:        SW_FUNCTION_ALIAS(CG(function_table), "swoole_coroutine_create", CG(function_table), "go");
./ext-src/php_swoole.cc:        SW_FUNCTION_ALIAS(CG(function_table), "swoole_coroutine_defer", CG(function_table), "defer");

./ext-src/swoole_server.cc:    SW_FUNCTION_ALIAS(&swoole_timer_ce->function_table, "after", &swoole_server_ce->function_table, "after");
./ext-src/swoole_server.cc:    SW_FUNCTION_ALIAS(&swoole_timer_ce->function_table, "tick", &swoole_server_ce->function_table, "tick");
./ext-src/swoole_server.cc:    SW_FUNCTION_ALIAS(&swoole_timer_ce->function_table, "clear", &swoole_server_ce->function_table, "clearTimer");
./ext-src/swoole_server.cc:    SW_FUNCTION_ALIAS(&swoole_event_ce->function_table, "defer", &swoole_server_ce->function_table, "defer");

@remicollet
Copy link
Contributor Author

Reflection change with this PR

--- /tmp/old	2022-12-21 16:09:14.757429893 +0100
+++ /tmp/new	2022-12-21 16:34:08.664112546 +0100
@@ -1,4 +1,4 @@
-Extension [ <persistent> extension #120 openswoole version 4.12.1 ] {
+Extension [ <persistent> extension #19 openswoole version 4.12.1 ] {
 
   - Dependencies {
     Dependency [ swoole (Conflicts) ]
@@ -635,7 +635,7 @@
         Parameter #0 [ <required> callable $callback ]
       }
     }
-    Method [ <internal:openswoole> public method swoole_event_add ] {
+    Function [ <internal:openswoole> function swoole_event_add ] {
 
       - Parameters [4] {
         Parameter #0 [ <required> mixed $sock ]
@@ -645,14 +645,14 @@
       }
       - Return [ int|bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_del ] {
+    Function [ <internal:openswoole> function swoole_event_del ] {
 
       - Parameters [1] {
         Parameter #0 [ <required> mixed $sock ]
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_set ] {
+    Function [ <internal:openswoole> function swoole_event_set ] {
 
       - Parameters [4] {
         Parameter #0 [ <required> mixed $sock ]
@@ -662,7 +662,7 @@
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_isset ] {
+    Function [ <internal:openswoole> function swoole_event_isset ] {
 
       - Parameters [2] {
         Parameter #0 [ <required> mixed $sock ]
@@ -670,20 +670,20 @@
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_dispatch ] {
+    Function [ <internal:openswoole> function swoole_event_dispatch ] {
 
       - Parameters [0] {
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_defer ] {
+    Function [ <internal:openswoole> function swoole_event_defer ] {
 
       - Parameters [1] {
         Parameter #0 [ <required> callable $callback ]
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_cycle ] {
+    Function [ <internal:openswoole> function swoole_event_cycle ] {
 
       - Parameters [2] {
         Parameter #0 [ <required> callable $callback ]
@@ -691,7 +691,7 @@
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_write ] {
+    Function [ <internal:openswoole> function swoole_event_write ] {
 
       - Parameters [2] {
         Parameter #0 [ <required> mixed $sock ]
@@ -699,72 +699,74 @@
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_event_wait ] {
+    Function [ <internal:openswoole> function swoole_event_wait ] {
 
       - Parameters [0] {
       }
       - Return [ void ]
     }
-    Method [ <internal:openswoole> public method swoole_event_exit ] {
+    Function [ <internal:openswoole> function swoole_event_exit ] {
 
       - Parameters [0] {
       }
       - Return [ void ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_set ] {
+    Function [ <internal, deprecated:openswoole> function swoole_timer_set ] {
 
       - Parameters [1] {
         Parameter #0 [ <required> array $settings ]
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_after ] {
+    Function [ <internal:openswoole> function swoole_timer_after ] {
 
-      - Parameters [2] {
+      - Parameters [3] {
         Parameter #0 [ <required> int $ms ]
         Parameter #1 [ <required> callable $callback ]
+        Parameter #2 [ <optional> mixed ...$params ]
       }
       - Return [ int|bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_tick ] {
+    Function [ <internal:openswoole> function swoole_timer_tick ] {
 
-      - Parameters [2] {
+      - Parameters [3] {
         Parameter #0 [ <required> int $ms ]
         Parameter #1 [ <required> callable $callback ]
+        Parameter #2 [ <optional> mixed ...$params ]
       }
       - Return [ int|bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_exists ] {
+    Function [ <internal:openswoole> function swoole_timer_exists ] {
 
       - Parameters [0] {
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_info ] {
+    Function [ <internal:openswoole> function swoole_timer_info ] {
 
       - Parameters [0] {
       }
       - Return [ array|bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_stats ] {
+    Function [ <internal:openswoole> function swoole_timer_stats ] {
 
       - Parameters [0] {
       }
       - Return [ array ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_list ] {
+    Function [ <internal:openswoole> function swoole_timer_list ] {
 
       - Parameters [0] {
       }
-      - Return [ Ù' ]
+      - Return [ Swoole\Timer\Iterator ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_clear ] {
+    Function [ <internal:openswoole> function swoole_timer_clear ] {
 
       - Parameters [0] {
       }
       - Return [ bool ]
     }
-    Method [ <internal:openswoole> public method swoole_timer_clear_all ] {
+    Function [ <internal:openswoole> function swoole_timer_clear_all ] {
 
       - Parameters [0] {
       }

@doubaokun doubaokun changed the title properly define function aliasses [4.x] properly define function aliasses Dec 21, 2022
@doubaokun doubaokun changed the base branch from master to 4.x December 21, 2022 18:59
@remicollet
Copy link
Contributor Author

remicollet commented Dec 22, 2022

The second commit switches to MINIT standard API (for missing type arg), only for swooole_timer and swoole_event.

This can obviously be used for all the other MINIT, but also for RINIT, RSHUTDOWN, and MSHUTDOWN calls

@remicollet
Copy link
Contributor Author

Notice: same issue affects new version 22.0.0

    Method [ <internal:openswoole> public method swoole_timer_list ] {

      - Parameters [0] {
      }
      - Return [ ^A ]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant